3 [ -z "$REPO_URL" ] && REPO_URL="https://packagecloud.io/install/repositories/fdio/${REPO:=release}"
5 # the code below comes from FDio's CSIT project.
7 # Get and/or install Ubuntu VPP artifacts from packagecloud.io.
10 # - REPO_URL - FD.io Packagecloud repository.
11 # - VPP_VERSION - VPP version.
12 # - INSTALL - If install packages or download only. Default: download
14 ls "*.deb" 2>/dev/null && { die "remove existing *.deb files"; }
19 curl -sS "${REPO_URL}"/script.deb.sh | bash || {
20 die "Packagecloud FD.io repo fetch failed."
23 # If version is set we will add suffix.
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."
34 if [ ! -f ${apt_fdio_repo_file} ]; then
35 die "${apt_fdio_repo_file} not found, \
36 repository installation was not successful."
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."
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."
50 if [ "${REPO}" != "master" ]; then
51 nonRcVersions=$(echo "$allVersions" | grep -v "\-rc[0-9]") || true
52 [ -n "${nonRcVersions}" ] && allVersions=$nonRcVersions
54 VPP_VERSION=$(echo "$allVersions" | head -n1) || true
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."
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"
69 echo "+++'${package}' found"
70 ver=$(echo "$ver" | cut -d " " -f 2)
71 artifacts+=(${package[@]/%/=${ver-}})
74 echo " - '${package}'"
79 if [ "${INSTALL:-false}" = true ]; then
80 apt-get -y install "${artifacts[@]}" || {
81 die "Install VPP artifacts failed."
84 apt-get -y download "${artifacts[@]}" || {
85 die "Download VPP artifacts failed."
91 # Print the message to standard error end exit with error code specified
92 # by the second argument.
95 # - The default error message.
97 # - ${1} - The whole error message, be sure to quote. Optional
98 # - ${2} - the code to exit with, default: 1.
102 echo "${1:-Unspecified run-time error occurred!}"