66# ($CIROOT) produced by `make stage-ciroot`, then runs the unmodified
77# downstream scripts vendored under ci/autopkgtest/debian-tests/.
88#
9- # For libppd the PPD-handling test invokes the installed test binary and test
10- # data through *absolute* paths (/usr/bin/testppd, /usr/share/ppd/testppd).
11- # Those are redirected into the staging tree, surgically and reversibly, via
12- # AUTOPKGTEST_BINDS (Fix C). Two backends are supported, chosen automatically:
13- #
14- # * mount --bind - when running as root or with passwordless sudo
15- # (CI native runners). Real kernel bind mounts: robust
16- # on every architecture, torn down on exit.
17- # * proot - fallback when unprivileged (local dev): no root, no
18- # host changes. (proot is ptrace-based and unreliable
19- # under QEMU emulation and on some kernels, hence it is
20- # only the fallback.)
9+ # The downstream scripts take environment overrides (e.g. LIBPPD_TESTPPD,
10+ # LIBPPD_PPDDIR) that default to the system /usr paths but can be redirected
11+ # into the staging tree. That keeps every test free of absolute-path
12+ # assumptions, so the wrapper needs no privilege and no bind mounts and runs
13+ # identically on native and QEMU-emulated architectures.
2114#
2215# Env in:
2316# CIROOT staging root (default: $PWD/_ciroot)
2417# CIPREFIX configured prefix (default: /usr)
2518# TOP_BUILDDIR build tree (default: $PWD)
26- # AUTOPKGTEST_BINDS optional space-separated "host:guest" binds for scripts
27- # that read installed binaries/data via absolute paths.
28- # Only the named paths are overlaid; the rest of the host
29- # /usr (compiler, system libs) stays intact.
30- # Any extra exported variables (e.g. PPDC_DATADIR, CUPS_DATADIR) are passed
31- # straight through to the test scripts.
19+ # Any extra exported variables (e.g. PPDC_DATADIR, CUPS_DATADIR,
20+ # LIBPPD_TESTPPD, LIBPPD_PPDDIR) are passed straight through to the scripts.
3221set -eu
3322
3423SCRIPT_DIR=$( CDPATH= cd -- " $( dirname -- " $0 " ) " && pwd)
@@ -52,61 +41,6 @@ LD_LIBRARY_PATH="$ROOT/lib${MULTIARCH:+:$ROOT/lib/$MULTIARCH}:$TOP_BUILDDIR/.lib
5241PKG_CONFIG_PATH=" $ROOT /lib/pkgconfig${MULTIARCH: +: $ROOT / lib/ $MULTIARCH / pkgconfig} :$ROOT /share/pkgconfig${PKG_CONFIG_PATH: +: $PKG_CONFIG_PATH } "
5342export PATH LD_LIBRARY_PATH PKG_CONFIG_PATH
5443
55- # ---------------------------------------------------------------------------
56- # Surgical /usr redirection (Fix C)
57- # ---------------------------------------------------------------------------
58- BIND_UNMOUNT=" "
59- BIND_RMDIRS=" "
60- cleanup_binds () {
61- # Unmount in reverse and remove any placeholder targets we created.
62- for m in $BIND_UNMOUNT ; do $BIND_SUDO umount " $m " 2> /dev/null || true ; done
63- for d in $BIND_RMDIRS ; do $BIND_SUDO rm -rf " $d " 2> /dev/null || true ; done
64- }
65-
66- if [ -n " ${AUTOPKGTEST_BINDS:- } " ] && [ -z " ${_REDIR_DONE:- } " ]; then
67- # Pick a privilege escalator for mount --bind, if available.
68- BIND_SUDO=" "
69- have_priv=0
70- if [ " $( id -u) " = 0 ]; then
71- have_priv=1
72- elif command -v sudo > /dev/null 2>&1 && sudo -n true 2> /dev/null; then
73- BIND_SUDO=" sudo"
74- have_priv=1
75- fi
76-
77- if [ " $have_priv " = 1 ]; then
78- trap cleanup_binds EXIT INT TERM
79- for pair in $AUTOPKGTEST_BINDS ; do
80- src=${pair%%:* }
81- dst=${pair#*: }
82- if [ -d " $src " ]; then
83- if [ ! -e " $dst " ]; then $BIND_SUDO mkdir -p " $dst " ; BIND_RMDIRS=" $dst $BIND_RMDIRS " ; fi
84- else
85- if [ ! -e " $dst " ]; then
86- $BIND_SUDO mkdir -p " $( dirname " $dst " ) "
87- $BIND_SUDO touch " $dst "
88- BIND_RMDIRS=" $dst $BIND_RMDIRS "
89- fi
90- fi
91- $BIND_SUDO mount --bind " $src " " $dst "
92- BIND_UNMOUNT=" $dst $BIND_UNMOUNT "
93- echo " run.sh: bound $src -> $dst (mount --bind)"
94- done
95- _REDIR_DONE=1
96- elif command -v proot > /dev/null 2>&1 ; then
97- binds=" "
98- for pair in $AUTOPKGTEST_BINDS ; do binds=" $binds -b $pair " ; done
99- _REDIR_DONE=1; export _REDIR_DONE
100- echo " run.sh: redirecting via proot (unprivileged fallback)"
101- # shellcheck disable=SC2086
102- exec proot $binds " $0 " " $@ "
103- else
104- echo " run.sh: AUTOPKGTEST_BINDS set but neither root/passwordless-sudo" >&2
105- echo " run.sh: (for mount --bind) nor proot is available." >&2
106- exit 1
107- fi
108- fi
109-
11044if [ " $# " -eq 0 ]; then
11145 echo " run.sh: usage: run.sh <test-name> [test-name...]" >&2
11246 exit 2
0 commit comments