3 # Copyright (c) 2021 Cisco and/or its affiliates.
4 # Copyright (c) 2021 PANTHEON.tech and/or its affiliates.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at:
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
19 function download_artifacts () {
21 # Download or install VPP artifacts from packagecloud.io.
24 # - CSIT_DIR - Path to existing root of local CSIT git repository.
26 # - REPO_URL - FD.io Packagecloud repository.
27 # Functions conditionally called (see their documentation for side effects):
28 # - download_ubuntu_artifacts
29 # - download_centos_artifacts
30 # - download_opensuse_artifacts
34 os_id=$(grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g') || {
35 die "Get OS release failed."
38 repo_url_path="${CSIT_DIR}/VPP_REPO_URL"
39 if [ -e "${repo_url_path}" ]; then
40 REPO_URL="$(<${repo_url_path})" || {
41 die "Read repo URL from ${repo_url_path} failed."
44 REPO_URL="https://packagecloud.io/install/repositories/fdio/master"
47 if [ "${os_id}" == "ubuntu" ]; then
48 download_ubuntu_artifacts || die
49 elif [ "${os_id}" == "centos" ]; then
50 download_centos_artifacts || die
51 elif [ "${os_id}" == "opensuse" ]; then
52 download_opensuse_artifacts || die
54 die "${os_id} is not yet supported."
58 function download_ubuntu_artifacts () {
60 # Download or install Ubuntu VPP artifacts from packagecloud.io.
63 # - REPO_URL - FD.io Packagecloud repository.
64 # - VPP_VERSION - VPP version.
65 # - INSTALL - Whether install packages (if set to "true") or download only.
70 curl -s "${REPO_URL}"/script.deb.sh | sudo -E bash || {
71 die "Packagecloud FD.io repo fetch failed."
73 # If version is set we will add suffix.
76 match="[^${both_quotes}]*"
77 qmatch="[${both_quotes}]\?"
78 sed_command="s#.*apt_source_path=${qmatch}\(${match}\)${qmatch}#\1#p"
79 apt_fdio_repo_file=$(curl -s "${REPO_URL}"/script.deb.sh | \
80 sed -n ${sed_command}) || {
81 die "Local fdio repo file path fetch failed."
84 if [ ! -f ${apt_fdio_repo_file} ]; then
85 die "${apt_fdio_repo_file} not found, \
86 repository installation was not successful."
89 packages=$(apt-cache -o Dir::Etc::SourceList=${apt_fdio_repo_file} \
90 -o Dir::Etc::SourceParts=${apt_fdio_repo_file} dumpavail \
91 | grep Package: | cut -d " " -f 2 | grep vpp) || {
92 die "Retrieval of available VPP packages failed."
94 if [ -z "${VPP_VERSION-}" ]; then
95 # If version is not specified, find out the most recent version
96 VPP_VERSION=$(apt-cache -o Dir::Etc::SourceList=${apt_fdio_repo_file} \
97 -o Dir::Etc::SourceParts=${apt_fdio_repo_file} \
98 --no-all-versions show vpp | grep Version: | \
100 die "Retrieval of most recent VPP version failed."
105 for package in ${packages}; do
106 # Filter packages with given version
107 pkg_info=$(apt-cache show -- ${package}) || {
108 die "apt-cache show on ${package} failed."
110 ver=$(echo ${pkg_info} | grep -o "Version: ${VPP_VERSION-}[^ ]*" | \
112 if [ -n "${ver-}" ]; then
113 echo "Found '${VPP_VERSION-}' among '${package}' versions."
114 ver=$(echo "$ver" | cut -d " " -f 2)
115 artifacts+=(${package[@]/%/=${ver-}})
117 echo "Didn't find '${VPP_VERSION-}' among '${package}' versions."
122 if [[ "${INSTALL:-false}" == "true" ]]; then
123 sudo apt-get -y install "${artifacts[@]}" || {
124 die "Install VPP artifacts failed."
127 apt-get -y download "${artifacts[@]}" || {
128 die "Download VPP artifacts failed."
133 function download_centos_artifacts () {
135 # Download or install CentOS VPP artifacts from packagecloud.io.
138 # - REPO_URL - FD.io Packagecloud repository.
139 # - VPP_VERSION - VPP version.
140 # - INSTALL - Whether install packages (if set to "true") or download only.
145 curl -s "${REPO_URL}"/script.rpm.sh | sudo -E bash || {
146 die "Packagecloud FD.io repo fetch failed."
148 # If version is set we will add suffix.
150 packages=(vpp vpp-selinux-policy vpp-devel vpp-lib vpp-plugins vpp-api-python)
151 if [ -z "${VPP_VERSION-}" ]; then
152 artifacts+=(${packages[@]})
154 artifacts+=(${packages[@]/%/-${VPP_VERSION-}})
157 if [[ "${INSTALL:-false}" == "true" ]]; then
158 sudo yum -y install "${artifacts[@]}" || {
159 die "Install VPP artifact failed."
162 sudo yum -y install --downloadonly --downloaddir=. "${artifacts[@]}" || {
163 die "Download VPP artifacts failed."
168 function download_opensuse_artifacts () {
170 # Download or install OpenSuSE VPP artifacts from packagecloud.io.
173 # - REPO_URL - FD.io Packagecloud repository.
174 # - VPP_VERSION - VPP version.
175 # - INSTALL - Whether install packages (if set to "true") or download only.
180 curl -s "${REPO_URL}"/script.rpm.sh | sudo -E bash || {
181 die "Packagecloud FD.io repo fetch failed."
183 # If version is set we will add suffix.
185 packages=(vpp vpp-devel vpp-lib vpp-plugins libvpp0)
186 if [ -z "${VPP_VERSION-}" ]; then
187 artifacts+=(${packages[@]})
189 artifacts+=(${packages[@]/%/-${VPP_VERSION-}})
192 if [[ "${INSTALL:-false}" == "true" ]]; then
193 sudo yum -y install "${artifacts[@]}" || {
194 die "Install VPP artifact failed."
197 sudo yum -y install --downloadonly --downloaddir=. "${artifacts[@]}" || {
198 die "Download VPP artifacts failed."