Docker: Forwarding Pods.
[vineperf.git] / tools / docker / test-containers / dpdk-forwarding-pods / vpp / get-vpp.sh
1 #!/bin/bash
2
3 [ -z "$REPO_URL" ] && REPO_URL="https://packagecloud.io/install/repositories/fdio/${REPO:=release}"
4
5 # the code below comes from FDio's CSIT project.
6 function get_vpp () {
7         # Get and/or install Ubuntu VPP artifacts from packagecloud.io.
8     #
9     # Variables read:
10     # - REPO_URL - FD.io Packagecloud repository.
11     # - VPP_VERSION - VPP version.
12     # - INSTALL - If install packages or download only. Default: download
13
14         ls "*.deb" 2>/dev/null && { die "remove existing *.deb files"; }
15
16         set -exuo pipefail
17         trap '' PIPE
18
19         curl -sS "${REPO_URL}"/script.deb.sh | bash || {
20                 die "Packagecloud FD.io repo fetch failed."
21         }
22
23         # If version is set we will add suffix.
24         artifacts=()
25         both_quotes='"'"'"
26         match="[^${both_quotes}]*"
27         qmatch="[${both_quotes}]\?"
28         sed_command="s#.*apt_source_path=${qmatch}\(${match}\)${qmatch}#\1#p"
29         apt_fdio_repo_file=$(curl -s "${REPO_URL}"/script.deb.sh | \
30                                                  sed -n ${sed_command}) || {
31                                                          die "Local fdio repo file path fetch failed."
32                                                  }
33
34         if [ ! -f ${apt_fdio_repo_file} ]; then
35                 die "${apt_fdio_repo_file} not found, \
36                         repository installation was not successful."
37         fi
38
39         packages=$(apt-cache -o Dir::Etc::SourceList=${apt_fdio_repo_file} \
40                            -o Dir::Etc::SourceParts=${apt_fdio_repo_file} dumpavail \
41                            | grep Package: | cut -d " " -f 2) || {
42                                    die "Retrieval of available VPP packages failed."
43                            }
44         if [ -z "${VPP_VERSION-}" ]; then
45                 allVersions=$(apt-cache -o Dir::Etc::SourceList=${apt_fdio_repo_file} \
46                                           -o Dir::Etc::SourceParts=${apt_fdio_repo_file} \
47                                           show vpp | grep Version: | cut -d " " -f 2) || {
48                                                   die "Retrieval of available VPP versions failed."
49                                           }
50                 if [ "${REPO}" != "master" ]; then
51                         nonRcVersions=$(echo "$allVersions" | grep -v "\-rc[0-9]") || true
52                         [ -n "${nonRcVersions}" ] && allVersions=$nonRcVersions
53                 fi
54                 VPP_VERSION=$(echo "$allVersions" | head -n1) || true
55         fi
56
57         set +x
58         echo "Finding packages with version: ${VPP_VERSION-}"
59         for package in ${packages}; do
60                 # Filter packages with given version
61                 pkg_info=$(apt-cache show -- ${package}) || {
62                         die "apt-cache show on ${package} failed."
63                 }
64                 ver=$(echo ${pkg_info} | grep -o "Version: ${VPP_VERSION-}[^ ]*" | head -1) || true
65                 if [ -n "${ver-}" ]; then
66                         if [ "${package}" == "vom" ]; then
67                                 echo " x '${package}' skipped"
68                         else
69                                 echo "+++'${package}' found"
70                                 ver=$(echo "$ver" | cut -d " " -f 2)
71                                 artifacts+=(${package[@]/%/=${ver-}})
72                         fi
73                 else
74                         echo " - '${package}'"
75                 fi
76         done
77         set -x
78
79         if [ "${INSTALL:-false}" = true ]; then
80                 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 die () {
91     # Print the message to standard error end exit with error code specified
92     # by the second argument.
93     #
94     # Hardcoded values:
95     # - The default error message.
96     # Arguments:
97     # - ${1} - The whole error message, be sure to quote. Optional
98     # - ${2} - the code to exit with, default: 1.
99
100     set -x
101     set +eu
102     echo "${1:-Unspecified run-time error occurred!}"
103     exit "${2:-1}"
104 }
105
106 get_vpp