Update cloud image list docs
[releng/builder.git] / jjb / packaging / test-rpm-deps.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 # Verify exactly 1 RPM is in the path we expect
10 set -- $HOME/rpmbuild/RPMS/noarch/*.rpm
11 if [ $# -eq 1 ]; then
12     echo "Found one RPM in build out dir, as expected"
13 else
14     echo "Expected 1 RPM, found $#"
15     echo 1
16 fi
17
18 # If path is globbed (/path/to/*.rpm), expand it
19 path=$(sudo find / -wholename $HOME/rpmbuild/RPMS/noarch/*.rpm)
20
21 # If no RPM found, fail clearly
22 if [ -z $path ]; then
23     echo "RPM not found"
24     exit 1
25 fi
26
27
28 if [ -f /usr/bin/yum ]; then
29   # Requirements for package where SRPM was built into noarch on CentOS CBS
30   # rpm -qp opendaylight-8.0.0-0.1.20171125rel2049.el7.noarch.rpm --requires
31   # shellcheck disable=SC2034
32   declare -a expected_deps=( "/bin/bash"
33                              "/bin/sh"
34                              "java >= 1:1.8.0"
35                              "rpmlib(CompressedFileNames) <= 3.0.4-1"
36                              "rpmlib(FileDigests) <= 4.6.0-1"
37                              "rpmlib(PartialHardlinkSets) <= 4.0.4-1"
38                              "rpmlib(PayloadFilesHavePrefix) <= 4.0-1"
39                              "shadow-utils"
40                              "rpmlib(PayloadIsXz) <= 5.2-1" )
41
42 elif [ -f /usr/bin/zypper ]; then
43   declare -a expected_deps=( "/bin/bash"
44                              "/bin/sh"
45                              "java >= 1.8.0"
46                              "rpmlib(CompressedFileNames) <= 3.0.4-1"
47                              "rpmlib(PayloadFilesHavePrefix) <= 4.0-1"
48                              "shadow"
49                              "rpmlib(PayloadIsLzma) <= 4.4.6-1" )
50
51 fi
52
53 # Karaf 4 distros also have a /usr/bin/env requirement INTPAK-120
54 if [[ ! $path == *opendaylight-6*  ]]; then
55     expected_deps+=( "/usr/bin/env" )
56 fi
57
58 # shellcheck disable=SC2034
59 mapfile -t actual_deps < <( rpm -qp $HOME/rpmbuild/RPMS/noarch/*.rpm --requires )
60 # shellcheck disable=SC2154 disable=SC2145
61 printf 'Dependency found: %s\n' "${actual_deps[@]}"
62
63 # shellcheck disable=SC2154,SC2145,SC2034,SC2207
64 diff_deps=(`echo "${expected_deps[@]}" "${actual_deps[@]}" | tr ' ' '\n' | sort | uniq -u`)
65
66 # shellcheck disable=SC2154 disable=SC2145 disable=SC2068 disable=SC2170 disable=SC1083
67 if [ ${#diff_deps[*]} -eq 0 ]; then
68     echo "RPM requirements are as expected"
69 else
70     echo "RPM requirements don't match the expected requirements"
71     # shellcheck disable=SC2154 disable=SC2145
72     printf 'Dependency mismatch: %s\n' ${diff_deps[@]}
73     exit 1
74 fi