Remove intrusive useless logging
[csit.git] / resources / libraries / bash / function / artifacts_hc.sh
1 #!/usr/bin/env bash
2
3 # Copyright (c) 2019 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 set -exuo pipefail
17
18 function download_artifacts_hc () {
19     # Get and/or install HC artifacts from packagecloud.io.
20     #
21     # Variables read:
22     # - CSIT_DIR - Path to existing root of local CSIT git repository.
23     # Variables set:
24     # - REPO_URL - FD.io Packagecloud repository.
25
26     set -exuo pipefail
27
28     os_id=$(grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g') || {
29         die "Get OS release failed."
30     }
31
32     repo_url_path="${CSIT_DIR}/VPP_REPO_URL"
33     if [ -e "${repo_url_path}" ]; then
34         REPO_URL="$(<${repo_url_path})" || {
35             die "Read repo URL from ${repo_url_path} failed."
36         }
37     else
38         REPO_URL="https://packagecloud.io/install/repositories/fdio/master"
39     fi
40
41     if [ "${os_id}" == "ubuntu" ]; then
42         download_ubuntu_artifacts_hc || die
43     elif [ "${os_id}" == "centos" ]; then
44         download_centos_artifacts_hc || die
45     else
46         die "${os_id} is not yet supported."
47     fi
48 }
49
50 function download_ubuntu_artifacts_hc () {
51     # Get and/or install Ubuntu HC artifacts from packagecloud.io.
52     #
53     # Variables read:
54     # - REPO_URL - FD.io Packagecloud repository.
55     # - HC_VERSION - HC version.
56     # - INSTALL - If install packages or download only. Default: download
57
58     set -exuo pipefail
59
60     curl -s "${REPO_URL}"/script.deb.sh | sudo bash || {
61         die "Packagecloud FD.io repo fetch failed."
62     }
63     # If version is set we will add suffix.
64     artifacts=()
65     hc=(honeycomb)
66     if [ -z "${HC_VERSION-}" ]; then
67         artifacts+=(${hc[@]})
68     else
69         artifacts+=(${hc[@]/%/=${HC_VERSION-}})
70     fi
71
72     if [ "${INSTALL:-false}" = true ]; then
73         sudo apt-get -y install "${artifacts[@]}" || {
74             die "Install HC artifacts failed."
75         }
76     else
77         apt-get -y download "${artifacts[@]}" || {
78             die "Download HC artifacts failed."
79         }
80     fi
81 }
82
83 function download_centos_artifacts_hc () {
84     # Get and/or install CentOS HC artifacts from packagecloud.io.
85     #
86     # Variables read:
87     # - REPO_URL - FD.io Packagecloud repository.
88     # - HC_VERSION - HC version.
89     # - INSTALL - If install packages or download only. Default: download
90
91     set -exuo pipefail
92
93     curl -s "${REPO_URL}"/script.rpm.sh | sudo bash || {
94         die "Packagecloud FD.io repo fetch failed."
95     }
96     # If version is set we will add suffix.
97     artifacts=()
98     hc=(honeycomb)
99     if [ -z "${HC_VERSION-}" ]; then
100         artifacts+=(${hc[@]})
101     else
102         artifacts+=(${hc[@]/%/-${HC_VERSION-}})
103     fi
104
105     if [ "${INSTALL:-false}" = true ]; then
106         sudo yum -y install "${artifacts[@]}" || {
107             die "Install HC artifact failed."
108         }
109     else
110         sudo yum -y install --downloadonly --downloaddir=. "${artifacts[@]}" || {
111             die "Download HC artifacts failed."
112         }
113     fi
114 }
115