Merge "Move dlux Sonar scan to Sonarcloud"
[releng/builder.git] / jjb / packaging / install-deb.sh
1 #!/bin/bash
2
3 # Options:
4 #   -x: Echo commands
5 #   -e: Fail on errors
6 #   -o pipefail: Fail on errors in scripts this calls, give stacktrace
7 set -ex -o pipefail
8 PACKAGE=${PACKAGE:-"$WORKSPACE/packaging/packages/deb/opendaylight/*.deb"}
9 URL_REGEX='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
10 # Wait for any background apt processes to finish
11 # There seems to be a backgroud apt process that locks /var/lib/dpkg/lock
12 # and causes our apt commands to fail.
13 while pgrep apt > /dev/null; do sleep 1; done
14
15 # Install ODL from .deb link or .repo url
16 if [[ $PACKAGE =~ $URL_REGEX ]]
17 then
18   # shellcheck disable=SC2154
19   pkg_basename="${PACKAGE##*/}"
20   curl -L --silent -o "$pkg_basename" "$PACKAGE"
21   sudo dpkg --install ./"$pkg_basename"
22 elif [[ $PACKAGE == *.deb ]]
23 then
24   echo "$PACKAGE"
25   sudo dpkg --install "$PACKAGE"
26 elif [[ $PACKAGE == ppa:* ]]
27 then
28   sudo add-apt-repository "$PACKAGE"
29   sudo apt-get update
30   sudo apt-get install -y opendaylight
31 else
32   echo "URL is not a link to a PPA repo or .deb"
33   exit 1
34 fi