Merge "Move dlux Sonar scan to Sonarcloud"
[releng/builder.git] / jjb / packaging / install-rpm.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
9 # Use local RPM in build-out dir if URL not passed
10 URL=${URL:-"$HOME/rpmbuild/RPMS/noarch/*.rpm"}
11
12 if [ -f /usr/bin/yum ]; then
13   # Update mirror list to avoid slow/hung one
14   sudo yum update -y yum-plugin-fastestmirror
15
16   # Install ODL from RPM path, RPM URL or .repo file url
17   # NB: Paths must be anchored at root
18   if [[ $URL == /*  ]]; then
19     # If path is globbed (/path/to/*.rpm), expand it
20     path=$(sudo find / -wholename "$URL")
21     sudo yum install -y "$path"
22   elif [[ $URL == *.rpm ]]; then
23     sudo yum install -y "$URL"
24   elif [[ $URL == *.repo ]]; then
25     # shellcheck disable=SC2154
26     repo_file="${URL##*/}"
27     sudo curl --silent -o /etc/yum.repos.d/"$repo_file" "$URL"
28     sudo yum install -y opendaylight
29   else
30     echo "URL is not a link to .rpm or .repo"
31     exit 1
32   fi
33 elif [ -f /usr/bin/zypper ]; then
34   # Install ODL from RPM path, RPM URL or .repo file url
35   # NB: Paths must be anchored at root
36   if [[ $URL == /*  ]]; then
37     # If path is globbed (/path/to/*.rpm), expand it
38     path=$(sudo find /root -wholename "$URL")
39     sudo zypper -n --no-gpg-checks install "$path"
40   elif [[ $URL == *.rpm ]]; then
41     sudo zypper -n --no-gpg-checks install "$URL"
42   elif [[ $URL == *.repo ]]; then
43     # shellcheck disable=SC2154
44     repo_file="${URL##*/}"
45     sudo curl --silent -o /etc/zypp/repos.d/"$repo_file" "$URL"
46     sudo zypper -n --no-gpg-checks install opendaylight
47   else
48     echo "URL is not a link to .rpm or .repo"
49     exit 1
50   fi
51 else
52   echo "The package manager is not supported (not yum or zypper)"
53   exit 1
54 fi