Merge "Restore vpp-csit-*tx2 jobs in production"
[ci-management.git] / jjb / scripts / setup_vpp_ext_deps.sh
1 #!/bin/bash
2
3 # Copyright (c) 2022 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 echo "---> jjb/scripts/setup_vpp_ext_deps.sh"
17
18 # Normally we would have the settings in any bash script stricter:
19 #    set -e -o pipefail
20 #
21 # But there is a corner case scenario that triggers an error,
22 # namely when a new packagecloud repo is created, it is completely
23 # empty. Then the installation fails. However, since this
24 # script is an optimization, it is okay for it to fail without failing
25 # the entire job.
26 #
27 # Therefore, we do not use the "-e" here.
28
29 set -o pipefail
30
31 OS_ID=$(grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
32 OS_VERSION_ID=$(grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
33
34 echo "Installing vpp-ext-deps..."
35 REPO_URL="https://packagecloud.io/fdio/${STREAM}"
36 echo "REPO_URL: $REPO_URL"
37 INSTALL_URL="https://packagecloud.io/install/repositories/fdio/${STREAM}"
38 echo "INSTALL_URL: $INSTALL_URL"
39
40 downloads_dir="/root/Downloads"
41
42 # Setup by installing vpp-dev and vpp-lib
43 if [ "${OS_ID,,}" == "ubuntu" ] || [ "${OS_ID,,}" == "debian" ] ; then
44     if [ "${STREAM}" != "master" ]; then
45         echo "stream '${STREAM}' is not master: replacing packagecloud apt sources list with stream specific list"
46         sudo apt-get -y remove vpp-ext-deps || true
47         sudo rm -f /etc/apt/sources.list.d/fdio_master.list
48         curl -s $INSTALL_URL/script.deb.sh | sudo bash || true
49     fi
50     sudo apt-get update -qq || true
51     vpp_ext_deps_version="$(apt-cache show vpp-ext-deps | mawk '/Version/ {print $2}' | head -1)"
52     vpp_ext_deps_arch="$(apt-cache show vpp-ext-deps | mawk '/Architecture/ {print $2}' | head -1)"
53     vpp_ext_deps_pkg="vpp-ext-deps_${vpp_ext_deps_version}_${vpp_ext_deps_arch}.deb"
54     if [ -f "$downloads_dir/$vpp_ext_deps_pkg" ] ; then
55         echo "Installing cached vpp-ext-deps pkg: $downloads_dir/$vpp_ext_deps_pkg"
56         sudo dpkg -i "$downloads_dir/$vpp_ext_deps_pkg" || true
57     else
58         echo "Installing vpp-ext-deps from packagecloud.io"
59         force_opts="--allow-downgrades --allow-remove-essential --allow-change-held-packages"
60         sudo apt-get -y $force_opts install vpp-ext-deps || true
61     fi
62     echo "Removing packagecloud.io repository references and running apt-get update"
63     sudo rm -f /etc/apt/sources.list.d/fdio_*.list
64     sudo apt-get update -qq || true
65 else
66     echo "ERROR: Unsupported OS '$OS_ID'!"
67 fi