CSIT-1282 Migrate from Nexus.fd.io to packagecloud.io
[csit.git] / resources / libraries / bash / function / artifacts.sh
1 #!/usr/bin/env bash
2
3 # Copyright (c) 2018 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 () {
19     # Get and/or install VPP artifacts from packagecloud.io.
20     #
21     # Variables set:
22     # - REPO_URL - FD.io Packagecloud repository.
23
24     set -exuo pipefail
25
26     os_id=$(grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g') || {
27         die "Get OS release failed."
28     }
29
30     repo_url_path="./VPP_REPO_URL"
31     if [ -e "${repo_url_path}" ]; then
32         REPO_URL="$(<${repo_url_path})" || {
33             die "Read repo URL from ${repo_url_path} failed."
34         }
35     else
36         REPO_URL="https://packagecloud.io/install/repositories/fdio/master"
37     fi
38
39     if [ "${os_id}" == "ubuntu" ]; then
40         download_ubuntu_artifacts || die
41     elif [ "${os_id}" == "centos" ]; then
42         download_centos_artifacts || die
43     elif [ "${os_id}" == "opensuse" ]; then
44         download_opensuse_artifacts || die
45     else
46         die "${os_id} is not yet supported."
47     fi
48 }
49
50 function download_ubuntu_artifacts () {
51     # Get and/or install Ubuntu VPP artifacts from packagecloud.io.
52     #
53     # Variables read:
54     # - REPO_URL - FD.io Packagecloud repository.
55     # - VPP_VERSION - VPP version.
56     # - DKMS_VERSION - DKMS version.
57     # - INSTALL - If install packages or download only. Default: download
58
59     set -exuo pipefail
60
61     curl -s "${REPO_URL}"/script.deb.sh | sudo bash || {
62         die "Packagecloud FD.io repo fetch failed."
63     }
64     # If version is set we will add suffix.
65     artifacts=()
66     vpp=(vpp vpp-dbg vpp-dev vpp-lib vpp-plugins)
67     if [ -z "${VPP_VERSION-}" ]; then
68         artifacts+=(${vpp[@]})
69     else
70         artifacts+=(${vpp[@]/%/=${VPP_VERSION-}})
71     fi
72     dkms=(vpp-dpdk-dkms)
73     if [ -z "${DKMS_VERSION-}" ]; then
74         artifacts+=(${dkms[@]})
75     else
76         artifacts+=(${dkms[@]/%/=${DKMS_VERSION-}})
77     fi
78
79     if [ "${INSTALL:-false}" = true ]; then
80         sudo apt-get -y install "${artifacts[@]}" || {
81             die "Install VPP artifacts failed."
82         }
83     else
84         apt-get -y download "${artifacts[@]}" || {
85             die "Download VPP artifacts failed."
86         }
87     fi
88 }
89
90 function download_centos_artifacts () {
91     # Get and/or install CentOS VPP artifacts from packagecloud.io.
92     #
93     # Variables read:
94     # - REPO_URL - FD.io Packagecloud repository.
95     # - VPP_VERSION - VPP version.
96     # - INSTALL - If install packages or download only. Default: download
97
98     set -exuo pipefail
99
100     curl -s "${REPO_URL}"/script.rpm.sh | sudo bash || {
101         die "Packagecloud FD.io repo fetch failed."
102     }
103     # If version is set we will add suffix.
104     artifacts=()
105     vpp=(vpp vpp-selinux-policy vpp-devel vpp-lib vpp-plugins)
106     if [ -z "${VPP_VERSION-}" ]; then
107         artifacts+=(${vpp[@]})
108     else
109         artifacts+=(${vpp[@]/%/-${VPP_VERSION-}})
110     fi
111
112     if [ "${INSTALL:-false}" = true ]; then
113         sudo yum -y install "${artifacts[@]}" || {
114             die "Install VPP artifact failed."
115         }
116     else
117         sudo yum -y install --downloadonly --downloaddir=. "${artifacts[@]}" || {
118             die "Download VPP artifacts failed."
119         }
120     fi
121 }
122
123 function download_opensuse_artifacts () {
124     # Get and/or install OpenSuSE VPP artifacts from packagecloud.io.
125     #
126     # Variables read:
127     # - REPO_URL - FD.io Packagecloud repository.
128     # - VPP_VERSION - VPP version.
129     # - INSTALL - If install packages or download only. Default: download
130
131     set -exuo pipefail
132
133     curl -s "${REPO_URL}"/script.rpm.sh | sudo bash || {
134         die "Packagecloud FD.io repo fetch failed."
135     }
136     # If version is set we will add suffix.
137     artifacts=()
138     vpp=(vpp vpp-devel vpp-lib vpp-plugins libvpp0)
139     if [ -z "${VPP_VERSION-}" ]; then
140         artifacts+=(${vpp[@]})
141     else
142         artifacts+=(${vpp[@]/%/-${VPP_VERSION-}})
143     fi
144
145     if [ "${INSTALL:-false}" = true ]; then
146         sudo yum -y install "${artifacts[@]}" || {
147             die "Install VPP artifact failed."
148         }
149     else
150         sudo yum -y install --downloadonly --downloaddir=. "${artifacts[@]}" || {
151             die "Download VPP artifacts failed."
152         }
153     fi
154 }
155