21700: Install Bundler system-wide in Rails postinst
[arvados.git] / build / package-testing / deb-common-test-packages.sh
1 #!/bin/bash
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5 set -eu
6
7 # Set up
8 DEBUG=${ARVADOS_DEBUG:-0}
9 STDOUT_IF_DEBUG=/dev/null
10 STDERR_IF_DEBUG=/dev/null
11 DASHQQ_UNLESS_DEBUG=-qq
12 if [[ "$DEBUG" != "0" ]]; then
13   STDOUT_IF_DEBUG=/dev/stdout
14   STDERR_IF_DEBUG=/dev/stderr
15   DASHQQ_UNLESS_DEBUG=
16 fi
17
18 # Multiple .deb based distros symlink to this script, so extract the target
19 # from the invocation path.
20 target=$(echo $0 | sed 's/.*test-packages-\([^.]*\)\.sh.*/\1/')
21
22 export ARV_PACKAGES_DIR="/arvados/packages/$target"
23
24 dpkg-query --show > "$ARV_PACKAGES_DIR/$1.before"
25
26 apt-get $DASHQQ_UNLESS_DEBUG --allow-insecure-repositories update
27
28 apt-get $DASHQQ_UNLESS_DEBUG -y --allow-unauthenticated install "$1" >"$STDOUT_IF_DEBUG" 2>"$STDERR_IF_DEBUG"
29
30 dpkg-query --show > "$ARV_PACKAGES_DIR/$1.after"
31
32 set +e
33 diff "$ARV_PACKAGES_DIR/$1.before" "$ARV_PACKAGES_DIR/$1.after" > "$ARV_PACKAGES_DIR/$1.diff"
34 set -e
35
36 mkdir -p /tmp/opts
37 cd /tmp/opts
38
39 export ARV_PACKAGES_DIR="/arvados/packages/$target"
40
41 if [[ -f $(ls -t "$ARV_PACKAGES_DIR/$1"_*.deb 2>/dev/null | head -n1) ]] ; then
42     debpkg=$(ls -t "$ARV_PACKAGES_DIR/$1"_*.deb | head -n1)
43 else
44     debpkg=$(ls -t "$ARV_PACKAGES_DIR/processed/$1"_*.deb | head -n1)
45 fi
46
47 dpkg-deb -x $debpkg .
48
49 if [[ "$DEBUG" != "0" ]]; then
50   find -type f -name '*.so' | while read so; do
51       printf "\n== Package dependencies for %s ==\n" "$so"
52       # dpkg is not fully aware of merged-/usr systems: ldd may list a library
53       # under /lib where dpkg thinks it's under /usr/lib, or vice versa.
54       # awk constructs globs that we pass to `dpkg --search` to be flexible
55       # about which version we find. This could potentially return multiple
56       # results, but doing better probably requires restructuring this whole
57       # code to find and report the best match across multiple dpkg queries.
58       ldd "$so" \
59           | awk 'BEGIN { ORS="\0" } ($3 ~ /^\//) {print "*" $3}' \
60           | sort --unique --zero-terminated \
61           | xargs -0 --no-run-if-empty dpkg --search \
62           | cut -d: -f1 \
63           | sort --unique
64   done
65 fi
66
67 exec /jenkins/package-testing/common-test-packages.sh "$1"