Add a prefix variable to defaults as blank
[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/$USER/rpmbuild/RPMS/noarch/*.rpm
11 # shellcheck disable=SC1054
12 [ $# -eq 1 ] || {{ echo "Expected 1 RPM, found $#"; exit 1; }}
13
14 # If path is globbed (/path/to/*.rpm), expand it
15 path=$(sudo find / -wholename /home/$USER/rpmbuild/RPMS/noarch/*.rpm)
16
17 # If no RPM found, fail clearly
18 if [ -z $path ]; then
19     echo "RPM not found"
20     exit 1
21 fi
22
23 # Requirements for package where SRPM was built into noarch on CentOS CBS
24 # rpm -qp opendaylight-8.0.0-0.1.20171125rel2049.el7.noarch.rpm --requires
25 # shellcheck disable=SC2034
26 declare -a expected_deps=( "/bin/bash"
27                            "/bin/sh"
28                            "java >= 1:1.8.0"
29                            "rpmlib(CompressedFileNames) <= 3.0.4-1"
30                            "rpmlib(FileDigests) <= 4.6.0-1"
31                            "rpmlib(PartialHardlinkSets) <= 4.0.4-1"
32                            "rpmlib(PayloadFilesHavePrefix) <= 4.0-1"
33                            "shadow-utils"
34                            "rpmlib(PayloadIsXz) <= 5.2-1" )
35
36 # Karaf 4 distros also have a /usr/bin/env requirement INTPAK-120
37 if [[ ! $path == *opendaylight-6*  ]]; then
38     expected_deps+=( "/usr/bin/env" )
39 fi
40
41 # shellcheck disable=SC2034
42 mapfile -t actual_deps < <( rpm -qp /home/$USER/rpmbuild/RPMS/noarch/*.rpm --requires )
43 # shellcheck disable=SC2154 disable=SC2145
44 printf 'Dependency found: %s\n' "${{actual_deps[@]}}"
45
46 # shellcheck disable=SC2154,SC2145,SC2034,SC2207
47 diff_deps=(`echo "${{expected_deps[@]}}" "${{actual_deps[@]}}" | tr ' ' '\n' | sort | uniq -u`)
48 # shellcheck disable=SC2154 disable=SC2145 disable=SC2068 disable=SC2170 disable=SC1083
49 if [ ${{#diff_deps[*]}} -eq 0 ]; then
50     echo "RPM requirements are as expected"
51 else
52     echo "RPM requirements don't match the expected requirements"
53     # shellcheck disable=SC2154 disable=SC2145
54     printf 'Dependency mismatch: %s\n' ${{diff_deps[@]}}
55     exit 1
56 fi