Merge "Move dlux Sonar scan to Sonarcloud"
[releng/builder.git] / jjb / packaging / test-deb-deps.sh
1 #!/bin/bash
2
3 ##############################################################################
4 ## Copyright (c) 2018 Intracom Telecom and others.
5 ##
6 ## All rights reserved. This program and the accompanying materials
7 ## are made available under the terms of the Apache License, Version 2.0
8 ## which accompanies this distribution, and is available at
9 ## http://www.apache.org/licenses/LICENSE-2.0
10 ###############################################################################
11
12 # Options:
13 #   -x: Echo commands
14 #   -e: Fail on errors
15 #   -o pipefail: Fail on errors in scripts this calls, give stacktrace
16 set -ex -o pipefail
17
18 # Verify exactly 1 deb is in the path we expect
19 set -- "$WORKSPACE"/packaging/packages/deb/opendaylight/*.deb
20 if [ $# -eq 1 ]; then
21     echo "Found one deb in build out dir, as expected"
22 else
23     echo "Expected 1 deb, found $#"
24     echo 1
25 fi
26
27 # If path is globbed (/path/to/*.deb), expand it
28 path=$(sudo find / -wholename "$WORKSPACE"/packaging/packages/deb/opendaylight/*.deb)
29
30 # If no deb found, fail clearly
31 if [ -z "$path" ]; then
32     echo "deb not found"
33     exit 1
34 fi
35
36
37 if [ -f /usr/bin/dpkg ]; then
38     declare -a expected_deps=( "init-system-helpers (>= 1.18~)"
39                                "lsb-base (>= 4.1+Debian11ubuntu7)"
40                                "adduser"
41                                "openjdk-8-jre-headless" )
42
43 fi
44
45 # shellcheck disable=SC2034
46 mapfile -t actual_deps < <( dpkg -I "$WORKSPACE"/packaging/packages/deb/opendaylight/*.deb | grep Depends | sed 's/Depends: //g' | sed 's/,/\n/g' )
47 # shellcheck disable=SC2154 disable=SC2145
48 printf 'Dependency found: %s\n' "${actual_deps[@]}"
49
50 # shellcheck disable=SC2154,SC2145,SC2034,SC2207
51 diff_deps=($(echo "${expected_deps[@]}" "${actual_deps[@]}" | tr ' ' '\n' | sort | uniq -u))
52
53 # shellcheck disable=SC2154 disable=SC2145 disable=SC2068 disable=SC2170 disable=SC1083
54 if [ ${#diff_deps[*]} -eq 0 ]; then
55     echo "deb requirements are as expected"
56 else
57     echo "deb requirements don't match the expected requirements"
58     # shellcheck disable=SC2154 disable=SC2145
59     printf 'Dependency mismatch: %s\n' ${diff_deps[@]}
60     exit 1
61 fi