1 #!/bin/sh -- # no runable script, just for vi
6 if [ "$1" = "-q" ]; then
8 elif [ "$1" = "-v" ]; then
10 elif [ "$1" = '--color=no' ]; then
12 elif [ "$1" = '--color=yes' ]; then
14 elif [ "$1" = '--color' ]; then
15 export MSGCOLOR
="$(echo "$2" | tr 'a-z' 'A-Z')"
17 elif [ "$1" = '--level' ]; then
21 echo >&2 "WARNING: Unknown parameter »$1« will be ignored"
25 export MSGLEVEL
="${MSGLEVEL:-3}"
27 # we all like colorful messages
28 if [ "${MSGCOLOR:-YES}" = 'YES' ]; then
29 if [ ! -t 1 ]; then # but check that we output to a terminal
35 if [ "$MSGCOLOR" != 'NO' ]; then
36 CERROR
="\033[1;31m" # red
37 CWARNING
="\033[1;33m" # yellow
38 CMSG
="\033[1;32m" # green
39 CINFO
="\033[1;96m" # light blue
40 CDEBUG
="\033[1;94m" # blue
41 CNORMAL
="\033[0;39m" # default system console color
42 CDONE
="\033[1;32m" # green
43 CPASS
="\033[1;32m" # green
44 CFAIL
="\033[1;31m" # red
45 CCMD
="\033[1;35m" # pink
57 printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghks]\)#apt-\1#')"
63 msgdie
() { msgprintf
"${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; }
64 msgwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; }
65 msgmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; }
66 msginfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; }
67 msgdebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; }
68 msgdone
() { msgprintf
"${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; }
69 msgnwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; }
70 msgnmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}" "$@"; }
71 msgninfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
72 msgndebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
73 msgtest
() { msgprintf
"${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
74 msgpass
() { printf "${CPASS}PASS${CNORMAL}\n"; }
76 if [ -n "$MSGTEST_MSG" ]; then
77 test "$1" != 'msgfailoutput' || echo
78 if [ -n "$MSGTEST_MSGMSG" ]; then
79 echo "$MSGTEST_MSGMSG"
81 if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then
82 echo "${CFAIL}Part of the test group: $MSGTEST_GRP"
84 echo -n "$MSGTEST_MSG"
89 msgreportheader
'msgskip'
90 if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
91 else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
94 msgreportheader
'msgfail'
95 if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
96 else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
97 if [ -n "$APT_DEBUG_TESTS" ]; then
100 EXIT_CODE
=$((EXIT_CODE+1));
105 if [ $MSGGROUP_LEVEL = 0 ]; then
108 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL+1));
110 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL-1));
111 if [ $MSGGROUP_LEVEL = 0 ]; then
117 # enable / disable Debugging
118 if [ $MSGLEVEL -le 0 ]; then
121 if [ $MSGLEVEL -le 1 ]; then
125 if [ $MSGLEVEL -le 2 ]; then
127 MSGTEST_MSGMSG
="$(msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@")"
131 MSGTEST_MSG
="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")"
132 if [ "$MSGTEST_GRP" = 'NEXT' ]; then
133 MSGTEST_GRP
="$MSGTEST_MSG"
136 msgpass
() { printf " ${CPASS}P${CNORMAL}"; }
138 if [ $MSGLEVEL -le 3 ]; then
142 if [ $MSGLEVEL -le 4 ]; then
144 msgndebug
() { true
; }
147 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
148 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
149 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
150 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
151 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
154 printf "${CDONE}DONE${CNORMAL}\n";
158 if [ -f .
/aptconfig.conf
]; then
159 echo "$(readlink -f ./aptconfig.conf)"
160 elif [ -f ..
/aptconfig.conf
]; then
161 echo "$(readlink -f ../aptconfig.conf)"
162 elif [ -f ..
/..
/aptconfig.conf
]; then
163 echo "$(readlink -f ../../aptconfig.conf)"
164 elif [ -f "${TMPWORKINGDIRECTORY}/aptconfig.conf" ]; then
165 echo "$(readlink -f "${TMPWORKINGDIRECTORY}/aptconfig.conf")"
169 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
173 sh
|aptitude
|*/*|command) ;;
174 *) CMD
="${BUILDDIRECTORY}/$CMD";;
176 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
="${LIBRARYPATH}:${LD_LIBRARY_PATH}" "$CMD" "$@"
178 runpython3
() { runapt
command python3
"$@"; }
179 aptconfig
() { runapt apt
-config "$@"; }
180 aptcache
() { runapt apt
-cache "$@"; }
181 aptcdrom
() { runapt apt
-cdrom "$@"; }
182 aptget
() { runapt apt
-get "$@"; }
183 aptftparchive
() { runapt apt
-ftparchive "$@"; }
184 aptkey
() { runapt apt
-key "$@"; }
185 aptmark
() { runapt apt
-mark "$@"; }
186 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; }
187 apt
() { runapt apt
"$@"; }
188 apthelper
() { runapt
"${APTHELPERBINDIR}/apt-helper" "$@"; }
189 aptwebserver
() { runapt
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
190 aptitude
() { runapt aptitude
"$@"; }
191 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; }
192 aptinternalsolver
() { runapt
"${APTINTERNALSOLVER}" "$@"; }
193 aptdumpsolver
() { runapt
"${APTDUMPSOLVER}" "$@"; }
196 "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@"
198 dpkgcheckbuilddeps
() {
199 command dpkg
-checkbuilddeps --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" "$@"
204 aptget
) CMD
="apt-get";;
205 aptcache
) CMD
="apt-cache";;
206 aptcdrom
) CMD
="apt-cdrom";;
207 aptconfig
) CMD
="apt-config";;
208 aptmark
) CMD
="apt-mark";;
209 apthelper
) CMD
="apt-helper";;
210 aptftparchive
) CMD
="apt-ftparchive";;
211 dpkg
) shift; runapt
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" "$@"; return;;
215 if [ "${CMD##*/}" = "$CMD" ]; then
216 CMD
="${BUILDDIRECTORY}/${CMD}"
218 runapt
command gdb
--quiet -ex run
"$CMD" --args "$CMD" "$@"
222 # error if we about to overflow, but ...
223 # "255 failures ought to be enough for everybody"
224 if [ $EXIT_CODE -gt 255 ]; then
225 msgdie
"Total failure count $EXIT_CODE too big"
227 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
230 shellsetedetector
() {
232 if [ "$exit_status" != '0' ]; then
233 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
234 if [ "$EXIT_CODE" = '0' ]; then
235 EXIT_CODE
="$exit_status"
241 if [ "$1" = 'prefix' ]; then
242 CURRENTTRAP
="$2 $CURRENTTRAP"
244 CURRENTTRAP
="$CURRENTTRAP $1"
246 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
250 echo "$@" | sed -e "s#'#'\"'\"'#g"
254 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
255 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
258 TMPWORKINGDIRECTORY
="$(mktemp -d)"
259 addtrap
"cd /; rm -rf '$(escape_shell "$TMPWORKINGDIRECTORY")';"
260 if [ -n "$TMPDIR_ADD" ]; then
261 TMPWORKINGDIRECTORY
="${TMPWORKINGDIRECTORY}/${TMPDIR_ADD}"
262 mkdir -p "$TMPWORKINGDIRECTORY"
264 export TMPDIR
="$TMPWORKINGDIRECTORY"
266 msgninfo
"Preparing environment for ${0##*/} in ${TMPWORKINGDIRECTORY}…"
268 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
269 if [ "$(id -u)" = '0' ]; then
270 # relax permissions so that running as root with user switching works
272 chmod 711 "$TMPWORKINGDIRECTORY"
273 chown _apt
:root
"${TMPWORKINGDIRECTORY}/downloaded"
276 TESTDIRECTORY
="$(readlink -f "$(dirname $0)")"
277 # allow overriding the default BUILDDIR location
278 SOURCEDIRECTORY="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}"
279 BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}"
280 LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}"
281 METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}"
282 APTHELPERBINDIR="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}"
283 APTWEBSERVERBINDIR="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}"
284 APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}"
285 APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}"
286 test -x "${BUILDDIRECTORY}/apt
-get" || msgdie "You need to build tree first
"
289 cd "$TMPWORKINGDIRECTORY"
290 mkdir rootdir aptarchive keys
292 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
293 mkdir -p usr/bin var/cache var/lib var/log tmp
294 mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
295 touch var/lib/dpkg/available
297 ln -s "${METHODSDIR}" usr/lib/apt/methods
298 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
299 mkdir -p usr/lib/apt/solvers
300 ln -s "${BUILDDIRECTORY}/apt
-dump-solver" usr/lib/apt/solvers/dump
301 ln -s "${BUILDDIRECTORY}/apt
-internal-solver" usr/lib/apt/solvers/apt
302 echo "Dir
::Bin
::Solvers
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/solvers
\";" > etc/apt/apt.conf.d/externalsolver.conf
304 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
306 if [ -e "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" ]; then
307 ln -s "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" etc/apt/apt.conf.d/01autoremove
309 ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
312 local BASENAME="${0##*/}"
313 local PACKAGESFILE="Packages
-${BASENAME#*-}"
314 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
315 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
317 local SOURCESSFILE="Sources
-${BASENAME#*-}"
318 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
319 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
321 find "$TESTDIRECTORY" \( -name '*.pub' -o -name '*.sec' \) -exec cp '{}' keys/ \;
323 ln -s "${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub
" rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
325 echo "Dir
\"${TMPWORKINGDIRECTORY}/rootdir
\";" > aptconfig.conf
326 echo "Dir
::state
::status
\"${TMPWORKINGDIRECTORY}/rootdir
/var
/lib
/dpkg
/status
\";" >> aptconfig.conf
327 echo "APT
::Get
::Show
-User-Simulation-Note \"false
\";" >> aptconfig.conf
328 echo "Dir
::Bin
::Methods
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/methods
\";" >> aptconfig.conf
329 # either store apt-key were we can access it, even if we run it as a different user
330 #cp "${BUILDDIRECTORY}/apt
-key" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/"
331 #chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key"
332 #echo "Dir
::Bin
::apt
-key \"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key\";" >> aptconfig.conf
333 # destroys coverage reporting though, so we disable changing user for the calling gpgv
334 echo "Dir
::Bin
::apt
-key \"${BUILDDIRECTORY}/apt
-key\";" >> aptconfig.conf
335 if [ "$(id -u)" = '0' ]; then
336 echo 'Binary::gpgv::Debug::NoDropPrivs "true
";' >>aptconfig.conf
339 cat > "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
342 if [ -r '${TMPWORKINGDIRECTORY}/noopchroot.so' ]; then
343 if [ -n "\
$LD_LIBRARY_PATH" ]; then
344 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}:'"\
${LD_LIBRARY_PATH}"
346 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}'
348 if [ -n "\
$LD_PRELOAD" ]; then
349 export LD_PRELOAD="noopchroot.so \
${LD_PRELOAD}"
351 export LD_PRELOAD="noopchroot.so
"
355 cp "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
356 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
357 exec fakeroot '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
358 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
359 --force-not-root --force-bad-path "\$@
"
361 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg" <<EOF
362 exec fakeroot gdb --quiet -ex run '${DPKG:-dpkg}' --args '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
363 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
364 --force-not-root --force-bad-path "\$@
"
366 chmod +x "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
367 echo "Dir
::Bin
::dpkg
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
\";" > rootdir/etc/apt/apt.conf.d/99dpkg
370 if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
371 echo "DPKG
::options
:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
374 echo 'quiet::NoUpdate "true
";'
375 echo 'quiet::NoStatistic "true
";'
376 # too distracting for users, but helpful to detect changes
377 echo 'Acquire::Progress::Ignore::ShowErrorText "true
";'
378 echo 'Acquire::Progress::Diffpercent "true
";'
379 # in testcases, it can appear as if localhost has a rotation setup,
380 # hide this as we can't really deal with it properly
381 echo 'Acquire::Failure::ShowIP "false
";'
382 # fakeroot can't fake everything, so disabled in production but good for tests
383 echo 'APT::Sandbox::Verify "true
";'
386 cp "${TESTDIRECTORY}/apt.pem
" "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
387 if [ "$(id -u)" = '0' ]; then
388 chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
390 echo "Acquire
::https
::CaInfo
\"${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
\";" > rootdir/etc/apt/apt.conf.d/99https
391 echo "Apt
::Cmd
::Disable
-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
392 echo 'Acquire::Connect::AddrConfig "false
";' > rootdir/etc/apt/apt.conf.d/connect-addrconfig
394 configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
395 confighashes 'SHA256' # these are tests, not security best-practices
397 # create some files in /tmp and look at user/group to get what this means
398 TEST_DEFAULT_USER="$(id -un)"
399 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
400 TEST_DEFAULT_GROUP='root'
402 TEST_DEFAULT_GROUP="$(id -gn)"
405 # cleanup the environment a bit
406 # prefer our apt binaries over the system apt binaries
407 export PATH="${BUILDDIRECTORY}:${PATH}:/usr
/local
/sbin
:/usr
/sbin
:/sbin
"
408 export LC_ALL=C.UTF-8
409 unset LANGUAGE APT_CONFIG
410 unset GREP_OPTIONS DEB_BUILD_PROFILES
411 unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy
413 # If gpgv supports --weak-digest, pass it to make sure we can disable SHA1
414 if aptkey verify --weak-digest SHA1 --help 2>/dev/null >/dev/null; then
415 echo 'Acquire::gpgv::Options { "--weak-digest"; "sha1
"; };' > rootdir/etc/apt/apt.conf.d/no-sha1
422 if [ "$1" = "native
" -o -z "$1" ]; then
423 eval `aptconfig shell ARCH APT::Architecture`
424 if [ -n "$ARCH" ]; then
427 dpkg --print-architecture
435 aptconfig dump --no-empty --format '%v%n' APT::Architecture APT::Architectures | sort -u | tr '\n' ' '
438 getarchitecturesfromcommalist() {
439 echo "$1" | sed -e 's#,#\n#g' | sed -e "s
/^native\$
/$(getarchitecture 'native')/"
442 configarchitecture() {
444 echo "APT
::Architecture
\"$(getarchitecture $1)\";"
445 while [ -n "$1" ]; do
446 echo "APT
::Architectures
:: \"$(getarchitecture $1)\";"
449 } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
454 if [ ! -e rootdir/var/lib/dpkg/status ]; then
455 local BASENAME="${0##*/}"
456 local STATUSFILE="status
-${BASENAME#*-}"
457 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
458 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
460 echo -n > rootdir/var/lib/dpkg/status
463 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
464 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
465 local ARCHS="$(getarchitectures)"
466 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
467 DPKGARCH="$(dpkg --print-architecture)"
468 for ARCH in ${ARCHS}; do
469 if [ "${ARCH}" != "${DPKGARCH}" ]; then
470 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
471 # old-style used e.g. in Ubuntu-P – and as it seems travis
472 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
473 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
477 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
478 # dpkg doesn't really check the version as long as it is fully installed,
479 # but just to be sure we choose one above the required version
480 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
486 configdpkgnoopchroot() {
487 # create a library to noop chroot() and rewrite maintainer script executions
488 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
489 # chroot directory dpkg could chroot into to execute the maintainer scripts
490 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
491 cat > noopchroot.c << EOF
498 static char * chrootdir = NULL;
500 int chroot(const char *path) {
501 printf("WARNING
: CHROOTing to
%s was ignored
!\n", path);
503 chrootdir = strdup(path);
506 int execvp(const char *file, char *const argv[]) {
507 static int (*func_execvp) (const char *, char * const []) = NULL;
508 if (func_execvp == NULL)
509 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
");
510 if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0)
511 return func_execvp(file, argv);
512 printf("REWRITE execvp call
%s into
%s
\n", file, chrootdir);
514 if (asprintf(&newfile, "%s
%s
", chrootdir, file) == -1) {
518 char const * const baseadmindir = "/var
/lib
/dpkg
";
520 if (asprintf(&admindir, "%s
%s
", chrootdir, baseadmindir) == -1) {
524 setenv("DPKG_ADMINDIR
", admindir, 1);
525 return func_execvp(newfile, argv);
528 testempty --nomsg gcc -Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c -ldl
530 configcompression() {
531 if [ "$1" = 'ALL' ]; then
532 configcompression '.' $(aptconfig dump APT::Compressor --format '%t %v%n' | sed -n 's#^Extension \.\(.*\)$#\1#p')
535 local CMD='apthelper cat-file -C'
536 while [ -n "$1" ]; do
538 '.') printf ".
\t.
\tcat
\n";;
539 'gz') printf "gzip\tgz
\t$CMD $1\n";;
540 'bz2') printf "bzip2\tbz
2\t$CMD $1\n";;
541 *) printf "$1\t$1\t$CMD $1\n";;
544 done > "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
"
548 echo 'APT::FTPArchive {'
550 while [ -n "$1" ]; do
551 printf "$1" | tr 'a-z' 'A-Z'
552 printf "\t\"true
\";\n"
555 for h in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
556 printf "$h\t\"false
\";\n"
560 } >> "${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/ftparchive
-hashes.conf
"
565 COMPRESSOR_CMD="apthelper
cat-file -C $1"
567 gzip) COMPRESS='gz';;
568 bzip2) COMPRESS='bz2';;
570 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/00force
-compressor"
571 echo "Acquire
::CompressionTypes
::Order
{ \"${COMPRESS}\"; };
572 Dir
::Bin
::uncompressed
\"/does
/not
/exist
\";" > "$CONFFILE"
573 for COMP in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
574 if [ -z "$COMP" -o "$COMP" = '.' -o "$COMP" = "$COMPRESSOR" ]; then continue; fi
575 echo "Dir
::Bin
::${COMP} \"/does
/not
/exist
\";" >> "$CONFFILE"
576 echo "APT
::Compressor
::${COMP}::Name
\"${COMP}-disabled\";" >> "$CONFFILE"
580 setupsimplenativepackage() {
584 local RELEASE="${4:-unstable}"
585 local DEPENDENCIES="$5"
586 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
587 If you
find such a package installed on your system
,
588 something went horribly wrong
! They are autogenerated
589 und used only by testcases and serve no other purpose…
"}"
591 local SECTION
="${7:-others}"
593 if [ "$SECTION" = "${SECTION#*/}" ]; then
596 DISTSECTION
="${SECTION%/*}"
598 local BUILDDIR
=incoming
/${NAME}-${VERSION}
599 mkdir -p ${BUILDDIR}/debian
/source
601 echo "* most suckless software product ever" > FEATURES
602 test -e debian
/copyright
|| echo "Copyleft by Joe Sixpack $(date +%Y)" > debian
/copyright
603 test -e debian
/changelog
|| echo "$NAME ($VERSION) $RELEASE; urgency=low
607 -- Joe Sixpack <joe@example.org> $(date -R)" > debian
/changelog
608 test -e debian
/control
|| echo "Source: $NAME
611 Maintainer: Joe Sixpack <joe@example.org>
612 Build-Depends: debhelper (>= 7)
613 Standards-Version: 3.9.1
615 Package: $NAME" > debian
/control
616 if [ "$ARCH" = 'all' ]; then
617 echo "Architecture: all" >> debian
/control
619 echo "Architecture: any" >> debian
/control
621 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian
/control
622 echo "Description: $DESCRIPTION" >> debian
/control
624 test -e debian
/compat
|| echo "7" > debian
/compat
625 test -e debian
/source
/format
|| echo "3.0 (native)" > debian
/source
/format
626 test -e debian
/rules
|| cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny debian
/rules
630 buildsimplenativepackage
() {
633 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then
634 NM
="$(echo "$NAME" | cut -c 1-4)"
636 NM
="$(echo "$NAME" | cut -c 1)"
640 local RELEASE
="${4:-unstable}"
641 local DEPENDENCIES
="$5"
642 local DESCRIPTION
="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
643 If you find such a package installed on your system,
644 something went horribly wrong! They are autogenerated
645 und used only by testcases and serve no other purpose…"}"
647 local SECTION="${7:-others}"
648 local PRIORITY="${8:-optional}"
650 local COMPRESS_TYPE="${10:-gzip}"
652 if [ "$SECTION" = "${SECTION#*/}" ]; then
655 DISTSECTION="${SECTION%/*}"
657 local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming
/${NAME}-${VERSION}"
659 msgtest "Build
source package
in version
${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
660 mkdir -p "$BUILDDIR/debian
/source"
661 echo "* most suckless software product ever
" > "${BUILDDIR}/FEATURES
"
663 echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}"
665 echo "Copyleft by Joe Sixpack
$(date +%Y)" > "${BUILDDIR}/debian
/copyright
"
666 echo "$NAME ($VERSION) $RELEASE; urgency
=low
670 -- Joe Sixpack
<joe@example.org
> $(date -R)" > "${BUILDDIR}/debian
/changelog
"
674 Maintainer
: Joe Sixpack
<joe@example.org
>
675 Standards
-Version: 3.9.3"
676 if [ "$SECTION" != '<none>' ]; then
677 echo "Section
: $SECTION"
679 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
680 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
684 if [ "$ARCH" = 'all' ]; then
685 echo "Architecture
: all
"
687 echo "Architecture
: any
"
689 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
690 test -z "$DEPS" || echo "$DEPS"
691 echo "Description
: $DESCRIPTION"
692 } > "${BUILDDIR}/debian
/control
"
694 echo '3.0 (native)' > "${BUILDDIR}/debian
/source
/format
"
696 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
698 sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
" \
700 echo "pool
/${SRC}" >> "${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
"
701 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
702 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
703 # adv --yes --default-key 'Joe Sixpack' \
704 # --clearsign -o "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
705 # mv "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
709 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
710 msgtest "Build binary package
for ${RELEASE} in ${SECTION}" "$NAME"
711 rm -rf "${BUILDDIR}/debian
/tmp
"
712 mkdir -p "${BUILDDIR}/debian
/tmp
/DEBIAN
" "${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}" "${BUILDDIR}/debian
/tmp
/usr
/bin
"
713 cp "${BUILDDIR}/debian
/copyright
" "${BUILDDIR}/debian
/changelog
" "${BUILDDIR}/FEATURES
" "${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}"
714 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}"
715 if [ -n "$FILE_TREE" ]; then
716 cp -ar "$FILE_TREE" "${BUILDDIR}/debian
/tmp
"
719 (cd "${BUILDDIR}"; dpkg-gencontrol -DArchitecture=$arch)
720 (cd "${BUILDDIR}/debian
/tmp
"; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
721 local LOG="${BUILDDIR}/..
/${NAME}_
${VERSION}_
${arch}.dpkg
-deb.log
"
722 # ensure the right permissions as dpkg-deb insists
723 chmod 755 "${BUILDDIR}/debian
/tmp
/DEBIAN
"
724 testsuccess --nomsg dpkg-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian
/tmp
" "${BUILDDIR}/..
"
725 echo "pool
/${NAME}_
${VERSION}_
${arch}.deb
" >> "${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
"
728 local CHANGEPATH="${BUILDDIR}/..
/${DISTSECTION}/${NM}/${NAME}/${NAME}_
${VERSION}"
729 mkdir -p "$CHANGEPATH"
730 cp "${BUILDDIR}/debian
/changelog
" "$CHANGEPATH"
739 local ARCH=$(getarchitecture $4)
740 local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
741 local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
742 msgtest "Build package
for ${RELEASE} in ${SECTION}" "$PKGNAME"
744 if [ "$ARCH" = "all
" ]; then
745 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
747 testsuccess --nomsg dpkg-buildpackage -uc -us -a$ARCH
748 cp "${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
" "$BUILDLOG"
749 local PKGS="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
750 local SRCS="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
753 echo "pool
/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
"
756 echo "pool
/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
"
761 if [ -d incoming ]; then
762 buildaptarchivefromincoming "$@
"
764 buildaptarchivefromfiles "$@
"
768 createaptftparchiveconfig() {
769 local COMPRESSORS="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
770 local COMPRESSORS="${COMPRESSORS%* }"
771 local ARCHS="$(getarchitectures)"
772 cat > ftparchive.conf <<EOF
774 ArchiveDir "$(readlink -f .)";
775 CacheDir "$(readlink -f ..)";
776 FileListDir "$(readlink -f pool/)";
779 Packages::Compress "$COMPRESSORS";
780 Sources::Compress "$COMPRESSORS";
781 Contents::Compress "$COMPRESSORS";
782 Translation::Compress "$COMPRESSORS";
783 LongDescription "false
";
787 SrcDirectory "pool
/";
790 for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
793 Architectures "$ARCHS all
source";
794 FileList "${DIST}.\
$(SECTION).pkglist
";
795 SourceFileList "${DIST}.\
$(SECTION).srclist
";
796 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
799 done >> ftparchive.conf
802 buildaptftparchivedirectorystructure() {
803 local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
804 for DIST in $DISTS; do
805 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
806 for SECTION in $SECTIONS; do
807 local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
808 for ARCH in $ARCHS; do
809 mkdir -p "dists
/${DIST}/${SECTION}/binary
-${ARCH}"
811 mkdir -p "dists
/${DIST}/${SECTION}/source"
812 mkdir -p "dists
/${DIST}/${SECTION}/i18n
"
822 local DEPENDENCIES="$5"
823 local PRIORITY="${6:-optional}"
824 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
825 If you
find such a package installed on your system
,
826 something went horribly wrong
! They are autogenerated
827 und used only by testcases and serve no other purpose…
"}"
829 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
830 if [ "$RELEASE" = 'installed' ]; then
831 insertinstalledpackage
"$2" "$3" "$4" "$5" "$6" "$7"
834 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
835 if [ "$arch" = 'none' ]; then
836 ARCHS
="$(getarchitectures)"
840 for BUILDARCH
in $ARCHS; do
841 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
848 Maintainer: Joe Sixpack <joe@example.org>"
849 test "$arch" = 'none' || echo "Architecture: $arch"
850 echo "Version: $VERSION
851 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb"
852 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES"
853 echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)"
854 echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
856 } >> "${PPATH}/Packages"
859 mkdir -p "aptarchive/dists/${RELEASE}/main/source" "aptarchive/dists/${RELEASE}/main/i18n"
860 touch "aptarchive/dists/${RELEASE}/main/source/Sources"
862 Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
863 Description-en: $DESCRIPTION
864 " >> "aptarchive/dists/${RELEASE}/main/i18n/Translation-en"
873 local DEPENDENCIES
="$5"
874 local BINARY
="${6:-$NAME}"
876 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
877 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
879 local FILE
="${SPATH}/Sources"
880 local DSCFILE
="${NAME}_${VERSION}.dsc"
881 local TARFILE
="${NAME}_${VERSION}.tar.gz"
885 Maintainer: Joe Sixpack <joe@example.org>
886 Architecture: $ARCH" >> $FILE
887 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
889 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
890 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
892 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
893 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
898 insertinstalledpackage
() {
902 local DEPENDENCIES
="$4"
903 local PRIORITY
="${5:-optional}"
904 local STATUS
="${6:-install ok installed}"
905 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
906 If you find such a package installed on your system,
907 something went horribly wrong! They are autogenerated
908 und used only by testcases and serve no other purpose…"}"
910 local FILE='rootdir/var/lib/dpkg/status'
911 local INFO='rootdir/var/lib/dpkg/info'
912 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
918 Maintainer
: Joe Sixpack
<joe@example.org
>
919 Version
: $VERSION" >> "$FILE"
920 test "$arch" = 'none' || echo "Architecture
: $arch" >> "$FILE"
921 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
922 echo "Description
: $DESCRIPTION" >> "$FILE"
924 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
925 echo -n > "${INFO}/${NAME}:${arch}.list
"
927 echo -n > "${INFO}/${NAME}.list
"
933 buildaptarchivefromincoming() {
934 msginfo "Build APT archive
for ${CCMD}${0##*/}${CINFO} based on incoming packages…
"
936 [ -e pool ] || ln -s ../incoming pool
937 [ -e ftparchive.conf ] || createaptftparchiveconfig
938 [ -e dists ] || buildaptftparchivedirectorystructure
939 msgninfo "\tGenerate Packages
, Sources and Contents files…
"
940 testsuccess aptftparchive generate ftparchive.conf
943 generatereleasefiles "$@
"
946 buildaptarchivefromfiles() {
947 msginfo "Build APT archive
for ${CCMD}${0##*/}${CINFO} based on prebuild files…
"
948 local DIR='aptarchive'
949 if [ -d "${DIR}/dists
" ]; then DIR="${DIR}/dists
"; fi
950 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do
951 msgninfo "\t${line} file…
"
952 compressfile "$line" "$1"
955 generatereleasefiles "$@
"
959 while read compressor extension command; do
960 if [ "$compressor" = '.' ]; then
966 cat "$1" | $command > "${1}.
${extension}"
968 touch -d "$2" "${1}.
${extension}"
970 done < "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
"
973 # can be overridden by testcases for their pleasure
974 getcodenamefromsuite() {
976 unstable) echo 'sid';;
980 getreleaseversionfromsuite() { true; }
981 getlabelfromsuite() { true; }
982 getoriginfromsuite() { true; }
983 getarchitecturesfromreleasefile() { echo "all
$(getarchitectures)"; }
985 aptftparchiverelease() {
986 aptftparchive -qq release "$@
" | sed -e '/0 Release$/ d' # remove the self reference
988 generatereleasefiles() {
989 # $1 is the Date header and $2 is the ValidUntil header to be set
990 # both should be given in notation date/touch can understand
992 local VALIDUNTIL="$2"
993 if [ -e aptarchive/dists ]; then
994 msgninfo "\tGenerate Release files
for dists…
"
995 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
996 local ARCHITECTURES="$(getarchitecturesfromreleasefile "$dir")"
997 local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
998 local CODENAME="$(getcodenamefromsuite $SUITE)"
999 local VERSION="$(getreleaseversionfromsuite $SUITE)"
1000 local LABEL="$(getlabelfromsuite $SUITE)"
1001 local ORIGIN="$(getoriginfromsuite $SUITE)"
1002 aptftparchiverelease "$dir" \
1003 -o APT::FTPArchive::Release::Suite="${SUITE}" \
1004 -o APT::FTPArchive::Release::Codename="${CODENAME}" \
1005 -o APT::FTPArchive::Release::Architectures="${ARCHITECTURES}" \
1006 -o APT::FTPArchive::Release::Label="${LABEL}" \
1007 -o APT::FTPArchive::Release::Origin="${ORIGIN}" \
1008 -o APT::FTPArchive::Release::Version="${VERSION}" \
1010 if [ "$SUITE" = "experimental
" -o "$SUITE" = "experimental2
" ]; then
1011 sed -i '/^Date: / a\
1012 NotAutomatic: yes' "$dir/Release
"
1016 msgninfo "\tGenerate Release files
for flat…
"
1017 aptftparchiverelease ./aptarchive > aptarchive/Release
1019 if [ -n "$DATE" -a "$DATE" != "now
" ]; then
1020 for release in $(find ./aptarchive -name 'Release'); do
1021 sed -i "s
/^Date
: .
*$
/Date
: $(date -d "$DATE" '+%a, %d %b %Y %H:%M:%S %Z')/" "$release"
1022 touch -d "$DATE" "$release"
1025 if [ -n "$VALIDUNTIL" ]; then
1026 sed -i "/^Date
: / a\
1027 Valid
-Until: $(date -d "$VALIDUNTIL" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release')
1032 setupdistsaptarchive() {
1033 local APTARCHIVE="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1034 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
1035 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
1036 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1037 SECTIONS=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1038 msgninfo "\tadd deb and deb
-src sources.list lines
for ${CCMD}${DISTS} ${SECTIONS}${CINFO}…
"
1039 echo "deb
file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
"
1040 echo "deb
-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
"
1045 setupflataptarchive() {
1046 local APTARCHIVE="$(readlink -f ./aptarchive)"
1047 local APTARCHIVEURI="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1048 if [ -f "${APTARCHIVE}/Packages
" ]; then
1049 msgninfo "\tadd deb sources.list line…
"
1050 echo "deb
file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1053 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1055 if [ -f "${APTARCHIVE}/Sources
" ]; then
1056 msgninfo "\tadd deb
-src sources.list line…
"
1057 echo "deb
-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1060 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1066 if [ "$1" = '--no-update' ]; then
1070 buildaptarchive "$@
"
1071 if [ -e aptarchive/dists ]; then
1072 setupdistsaptarchive
1076 signreleasefiles 'Joe Sixpack'
1077 if [ "1" != "$NOUPDATE" ]; then
1078 testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true
1082 signreleasefiles() {
1083 local SIGNERS="${1:-Joe Sixpack}"
1084 local REPODIR="${2:-aptarchive}"
1085 local KEY="keys
/$(echo "$SIGNERS" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1086 msgninfo "\tSign archive with
$SIGNERS key
$KEY…
"
1087 local REXKEY='keys/rexexpired'
1088 local SECEXPIREBAK="${REXKEY}.sec.bak
"
1089 local PUBEXPIREBAK="${REXKEY}.pub.bak
"
1091 while [ -n "${SIGNERS%%,*}" ]; do
1092 local SIGNER="${SIGNERS%%,*}"
1093 if [ "${SIGNERS}" = "${SIGNER}" ]; then
1096 SIGNERS="${SIGNERS#*,}"
1097 # FIXME: This should be the full name, but we can't encode the space properly currently
1098 SIGUSERS="${SIGUSERS} -u ${SIGNER#* }"
1099 if [ "${SIGNER}" = 'Rex Expired' ]; then
1100 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1101 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1102 # therefore we 'temporary' make the key not expired and restore a backup after signing
1103 cp "${REXKEY}.sec
" "$SECEXPIREBAK"
1104 cp "${REXKEY}.pub
" "$PUBEXPIREBAK"
1105 local SECUNEXPIRED="${REXKEY}.sec.unexpired
"
1106 local PUBUNEXPIRED="${REXKEY}.pub.unexpired
"
1107 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1108 cp "$SECUNEXPIRED" "${REXKEY}.sec
"
1109 cp "$PUBUNEXPIRED" "${REXKEY}.pub
"
1111 if ! printf "expire
\n1w
\nsave
\n" | aptkey --quiet --keyring "${REXKEY}.pub
" --secret-keyring "${REXKEY}.sec
" \
1112 --readonly adv --batch --yes --digest-algo "${APT_TESTS_DIGEST_ALGO:-SHA512}" \
1113 --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then
1117 cp "${REXKEY}.sec
" "$SECUNEXPIRED"
1118 cp "${REXKEY}.pub
" "$PUBUNEXPIRED"
1121 if [ ! -e "${KEY}.pub
" ]; then
1122 local K="keys
/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1123 cat "${K}.pub
" >> "${KEY}.new.pub
"
1124 cat "${K}.sec
" >> "${KEY}.new.sec
"
1127 if [ ! -e "${KEY}.pub
" ]; then
1128 mv "${KEY}.new.pub
" "${KEY}.pub
"
1129 mv "${KEY}.new.sec
" "${KEY}.sec
"
1131 local GPG="aptkey
--quiet --keyring ${KEY}.pub
--secret-keyring ${KEY}.sec
--readonly adv
--batch --yes --digest-algo ${APT_TESTS_DIGEST_ALGO:-SHA512}"
1132 for RELEASE in $(find "${REPODIR}/" -name Release); do
1133 testsuccess $GPG $SIGUSERS --armor --detach-sign --sign --output "${RELEASE}.gpg
" "${RELEASE}"
1134 local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
1135 testsuccess $GPG $SIGUSERS --clearsign --output "$INRELEASE" "$RELEASE"
1136 # we might have set a specific date for the Release file, so copy it
1137 touch -d "$(stat --format "%y" ${RELEASE})" "${RELEASE}.gpg
" "${INRELEASE}"
1139 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1140 mv -f "$SECEXPIREBAK" "${REXKEY}.sec
"
1141 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub
"
1146 redatereleasefiles() {
1147 local DATE="$(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
1148 for release in $(find aptarchive/ -name 'Release'); do
1149 sed -i "s
/^Date
: .
*$
/Date
: ${DATE}/" "$release"
1150 touch -d "$DATE" "$release"
1152 signreleasefiles "${2:-Joe Sixpack}"
1156 local WEBSERVER="${3:-http://localhost:${APTHTTPPORT}}"
1158 if [ "$1" = '--no-check' ]; then
1162 local DOWNLOG='rootdir/tmp/download-testfile.log'
1163 local STATUS='downloaded/webserverconfig.status'
1164 rm -f "$STATUS" "$DOWNLOG"
1165 # very very basic URI encoding
1167 if [ -n "$2" ]; then
1168 msgtest "Set webserver config option
'${1}' to
" "$2"
1169 URI="${WEBSERVER}/_config
/set
/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1171 msgtest 'Clear webserver config option' "${1}"
1172 URI="${WEBSERVER}/_config
/clear
/$(echo "${1}" | sed -e 's/\//%2f/g')"
1174 if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then
1177 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir
/tmp
/webserverconfig.output
"
1178 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1179 msgfailoutput '' "$OUTPUT"
1181 $NOCHECK || testwebserverlaststatuscode '200'
1184 rewritesourceslist() {
1185 local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1186 local APTARCHIVE2="copy
://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1187 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1188 sed -i $LIST -e "s
#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
1189 -e "s#http://[^@]*@\?localhost:${APTHTTPPORT}/\?#${1}#" \
1190 -e "s#https://[^@]*@\?localhost:${APTHTTPSPORT}/\?#${1}#"
1194 # wait for up to 10s for a pid file to appear to avoid possible race
1195 # when a helper is started and dosn't write the PID quick enough
1198 for i
in $(seq 10); do
1199 if test -s "$PIDFILE"; then
1204 msgdie
"waiting for $PIDFILE failed"
1208 changetowebserver
() {
1210 if [ "$1" != '--no-rewrite' ]; then
1215 if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
1217 local LOG
="webserver.log"
1218 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1222 waitforpidfile aptwebserver.pid
1223 local PID
="$(cat aptwebserver.pid)"
1224 if [ -z "$PID" ]; then
1225 msgdie
'Could not fork aptwebserver successfully'
1227 addtrap
"kill $PID;"
1228 waitforpidfile aptwebserver.port
1229 APTHTTPPORT
="$(cat aptwebserver.port)"
1230 if [ -z "$APTHTTPPORT" ]; then
1231 msgdie
'Could not get port for aptwebserver successfully'
1235 msgdie
'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver'
1237 if [ "$REWRTE" != 'yes' ]; then
1238 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1242 changetohttpswebserver
() {
1243 if ! command -v stunnel4
>/dev
/null
2>&1; then
1244 msgdie
'You need to install stunnel4 for https testcases'
1246 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1247 changetowebserver
--no-rewrite "$@"
1249 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1250 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1255 connect = $APTHTTPPORT
1256 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1257 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1258 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1259 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1260 if [ -z "$PID" ]; then
1261 msgdie
'Could not fork stunnel4 successfully'
1263 addtrap
'prefix' "kill ${PID};"
1264 APTHTTPSPORT
="$(lsof -i -n | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1265 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1266 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1270 mkdir -p rootdir
/media
/cdrom
/.disk
1271 local CD
="$(readlink -f rootdir/media/cdrom)"
1272 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1273 acquire::cdrom::mount "${CD}";
1274 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1275 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1276 acquire::cdrom::autodetect 0;
1278 echo -n "$1" > "${CD}/.disk/info"
1279 if [ ! -d aptarchive
/dists
]; then
1280 msgdie
'Flat file archive cdroms can not be created currently'
1283 mv aptarchive
/dists
"$CD"
1284 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1285 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1286 # start with an unmounted disk
1287 mv "${CD}" "${CD}-unmounted"
1288 # we don't want the disk to be modifiable
1289 addtrap
'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;"
1290 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1294 local PROTO
="${1%%:*}"
1295 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1296 download
-file "$1" "$2" "$3" 2>&1 ; then
1299 # only if the file exists the download was successful
1300 if [ -r "$2" ]; then
1308 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1309 if [ -n "$DIFFTEXT" ]; then
1311 echo >&2 "$DIFFTEXT"
1319 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1320 local COMPAREFILE
="$1"
1322 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1325 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1326 cat "$COMPAREFILE" >>"${OUTPUT}"
1327 msgfailoutput
'' "$OUTPUT" "$@"
1332 msggroup
'testfileequal'
1333 local MSG
='Test for correctness of file'
1334 if [ "$1" = '--nomsg' ]; then
1340 if [ -n "$MSG" ]; then
1341 msgtest
"$MSG" "$FILE"
1343 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1344 if [ -z "$*" ]; then
1345 testoutputequal
"$FILE" echo -n ''
1347 testoutputequal
"$FILE" echo "$*"
1353 msggroup
'testempty'
1354 if [ "$1" = '--nomsg' ]; then
1357 msgtest
"Test for no output of" "$*"
1359 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1360 if "$@" >"$COMPAREFILE" 2>&1 && test ! -s "$COMPAREFILE"; then
1363 msgfailoutput
'' "$COMPAREFILE" "$@"
1365 aptautotest
'testempty' "$@"
1369 msggroup
'testnotempty'
1370 msgtest
"Test for some output of" "$*"
1371 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
1372 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then
1375 msgfailoutput
'' "$COMPAREFILE" "$@"
1377 aptautotest
'testnotempty' "$@"
1382 msggroup
'testequal'
1383 local MSG
='Test of equality of'
1384 if [ "$1" = '--nomsg' ]; then
1389 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1390 echo "$1" > "$COMPAREFILE"
1393 if [ -n "$MSG" ]; then
1396 testoutputequal
"$COMPAREFILE" "$@"
1397 aptautotest
'testequal' "$@"
1402 msggroup
'testequalor2'
1403 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1404 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1405 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1406 echo "$1" > "$COMPAREFILE1"
1407 echo "$2" > "$COMPAREFILE2"
1409 msgtest
"Test for equality OR of" "$*"
1410 "$@" >"$COMPAREAGAINST" 2>&1 || true
1411 if checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null
2>&1 || \
1412 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null
2>&1
1416 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1417 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1418 checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1419 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1420 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1421 msgfailoutput
'' "$OUTPUT"
1423 aptautotest
'testequalor2' "$@"
1428 msggroup
'testshowvirtual'
1429 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1432 while [ -n "$1" ]; do
1434 N: Can't select versions from package '$1' as it is purely virtual"
1435 PACKAGE
="${PACKAGE} $1"
1438 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1440 N: No packages found"
1441 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1442 local ARCH
="$(getarchitecture 'native')"
1443 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1444 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1445 testoutputequal
"$COMPAREFILE" aptcache show
"$PACKAGE"
1450 msggroup
'testnopackage'
1451 msgtest
"Test for non-existent packages" "apt-cache show $*"
1452 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1453 if [ -n "$SHOWPKG" ]; then
1454 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1455 echo "$SHOWPKG" >"$OUTPUT"
1456 msgfailoutput
'' "$OUTPUT"
1462 testnosrcpackage
() {
1463 msggroup
'testnosrcpackage'
1464 msgtest
"Test for non-existent source packages" "apt-cache showsrc $*"
1465 local SHOWPKG
="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')"
1466 if [ -n "$SHOWPKG" ]; then
1467 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output"
1468 echo "$SHOWPKG" >"$OUTPUT"
1469 msgfailoutput
'' "$OUTPUT"
1477 msggroup
'testdpkgstatus'
1481 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1482 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1483 if [ "$PKGS" != $NR ]; then
1484 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1485 echo "$PKGS" >"$OUTPUT"
1486 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1487 msgfailoutput
'' "$OUTPUT"
1494 testdpkginstalled
() {
1495 msggroup
'testdpkginstalled'
1496 testdpkgstatus
'ii' "$#" "$@"
1500 testdpkgnotinstalled
() {
1501 msggroup
'testdpkgnotinstalled'
1502 testdpkgstatus
'ii' '0' "$@"
1507 msggroup
'testmarkedauto'
1508 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1509 if [ -n "$1" ]; then
1510 msgtest
'Test for correctly marked as auto-installed' "$*"
1511 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1513 msgtest
'Test for correctly marked as auto-installed' 'no package'
1514 echo -n > "$COMPAREFILE"
1516 testoutputequal
"$COMPAREFILE" aptmark showauto
1519 testmarkedmanual
() {
1520 msggroup
'testmarkedmanual'
1521 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1522 if [ -n "$1" ]; then
1523 msgtest
'Test for correctly marked as manually installed' "$*"
1524 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1526 msgtest
'Test for correctly marked as manually installed' 'no package'
1527 echo -n > "$COMPAREFILE"
1529 testoutputequal
"$COMPAREFILE" aptmark showmanual
1534 msgreportheader
'msgfailoutput'
1538 if [ "$1" = 'grep' ]; then
1540 while [ -n "$2" ]; do shift; done
1541 echo "#### Complete file: $1 ####"
1542 cat >&2 "$1" || true
1543 echo '#### grep output ####'
1544 elif [ "$1" = 'test' ]; then
1546 # doesn't support ! or non-file flags
1547 msgfailoutputstatfile
() {
1548 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1549 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1550 echo "#### stat(2) of file: $2 ####"
1552 if test -d "$2"; then
1553 echo "#### The directory contains: $2 ####"
1555 elif test -e "$2"; then
1556 echo "#### Complete file: $2 ####"
1557 cat >&2 "$2" || true
1561 msgfailoutputstatfile
"$2" "$3"
1562 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1564 msgfailoutputstatfile
"$2" "$3"
1566 echo '#### test output ####'
1567 elif [ "$1" = 'cmp' ]; then
1569 while [ -n "$2" ]; do
1570 echo "#### Complete file: $2 ####"
1571 cat >&2 "$2" || true
1574 echo '#### cmp output ####'
1580 testsuccesswithglobalerror
() {
1585 if [ "$1" = '--nomsg' ]; then
1588 msgtest
'Test for successful execution of' "$*"
1590 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output"
1591 if "$@" >"${OUTPUT}" 2>&1; then
1592 if expr match
"$1" '^apt.*' >/dev
/null
; then
1593 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1594 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1595 elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1596 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1597 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1598 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1601 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1604 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1606 elif [ "$TYPE" = 'testsuccesswithnotice' ]; then
1607 if grep -q -E "^N: " "$OUTPUT"; then
1610 msgfailoutput
'successful run, but output had no notices' "$OUTPUT" "$@"
1620 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1622 aptautotest
"$TYPE" "$@"
1625 testsuccesswithnotice
() {
1626 testsuccesswithglobalerror
'testsuccesswithnotice' 'WE' "$@"
1629 testsuccesswithglobalerror
'testsuccess' 'NWE' "$@"
1632 msggroup
'testwarning'
1633 if [ "$1" = '--nomsg' ]; then
1636 msgtest
'Test for successful execution with warnings of' "$*"
1638 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1639 if "$@" >"${OUTPUT}" 2>&1; then
1640 if expr match
"$1" '^apt.*' >/dev
/null
; then
1641 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1642 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1643 elif grep -q -E '^E: ' "$OUTPUT"; then
1644 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1645 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1646 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1655 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1657 aptautotest
'testwarning' "$@"
1661 msggroup
'testfailure'
1662 if [ "$1" = '--nomsg' ]; then
1665 msgtest
'Test for failure in execution of' "$*"
1667 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1668 if "$@" >"${OUTPUT}" 2>&1; then
1670 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1673 if expr match
"$1" '^apt.*' >/dev
/null
; then
1674 if [ "$1" = 'aptkey' ]; then
1675 if grep -q -E " Can't check signature: " "$OUTPUT" || \
1676 grep -q -E " BAD signature from " "$OUTPUT"; then
1679 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1682 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1683 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1684 elif grep -q -E '==ERROR' "$OUTPUT"; then
1685 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1686 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1687 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1696 aptautotest
'testfailure' "$@"
1700 testreturnstateequal
() {
1702 if [ "$STATE" = 'testsuccesswithglobalerror' ]; then
1706 msggroup
"${STATE}equal"
1707 if [ "$1" != '--nomsg' ]; then
1710 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1711 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1715 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1716 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1719 msggroup
"${STATE}equal"
1720 if [ "$2" != '--nomsg' ]; then
1724 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1728 "$STATE" --nomsg "$@"
1729 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1734 testsuccessequal
() {
1735 # we compare output, so we know perfectly well about N:
1736 testreturnstateequal
'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@"
1738 testwarningequal
() {
1739 testreturnstateequal
'testwarning' "$@"
1741 testfailureequal
() {
1742 testreturnstateequal
'testfailure' "$@"
1746 msggroup
'testfailuremsg'
1750 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1751 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1752 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1753 testoutputequal
"$COMPAREFILE" echo "$CMP"
1757 msggroup
'testwarningmsg'
1761 msgtest
'Check that the output of the previous warned command has expected' 'warnings'
1762 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
1763 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
1764 testoutputequal
"$COMPAREFILE" echo "$CMP"
1769 msggroup
'testfilestats'
1770 msgtest
"Test that file $1 has $2 $3" "$4"
1771 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1774 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1777 echo -n "stat(1) reports for $2: "
1778 stat
--format "$2" "$1" || true
1780 msgfailoutput
'' "$OUTPUT"
1784 testaccessrights
() {
1785 msggroup
'testaccessrights'
1786 testfilestats
"$1" '%a' '=' "$2"
1790 testwebserverlaststatuscode
() {
1791 msggroup
'testwebserverlaststatuscode'
1792 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1793 local STATUS
='downloaded/webserverstatus-statusfile.log'
1794 rm -f "$DOWNLOG" "$STATUS"
1795 msgtest
'Test last status code from the webserver was' "$1"
1796 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1799 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1801 if [ -n "$2" ]; then
1803 echo >&2 '#### Additionally provided output files contain:'
1806 echo >&2 '#### Download log of the status code:'
1809 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1814 createlistofkeys
() {
1817 while [ -n "$1" ]; do
1818 # gpg 2.1.something starts printing [SC] at some point
1819 if grep -q ' rsa2048/' "$OUTPUT" && grep -qF '[SC]' "$OUTPUT"; then
1821 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';;
1822 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [SC] [expired: 2013-07-13]';;
1823 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16 [SC]';;
1824 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19 [SC]';;
1825 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';;
1826 *) echo 'UNKNOWN KEY';;
1828 # gpg 2.1 has a slightly different output format
1829 elif grep -q ' rsa2048/' "$OUTPUT"; then
1831 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1832 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1833 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16';;
1834 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19';;
1835 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1836 *) echo 'UNKNOWN KEY';;
1840 *Joe
*|*Sixpack
*) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1841 *Rex
*|*Expired
*) echo 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1842 *Marvin
*|*Paranoid
*) echo 'pub 2048R/528144E2 2011-01-16';;
1843 oldarchive
) echo 'pub 1024R/F68C85A3 2013-12-19';;
1844 newarchive
) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1845 *) echo 'UNKNOWN KEY';;
1852 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output"
1853 if ! aptkey list
| grep '^pub' > "$OUTPUT"; then
1856 testfileequal
"$OUTPUT" "$(createlistofkeys "$OUTPUT" "$@")"
1860 echo "STOPPED execution. Press enter to continue"
1865 logcurrentarchivedirectory
() {
1866 find "${TMPWORKINGDIRECTORY}/aptarchive/dists" -type f
| while read line
; do
1867 stat
--format '%U:%G:%a:%n' "$line"
1868 done | sort > "${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst"
1870 listcurrentlistsdirectory
() {
1872 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1873 stat
--format '%U:%G:%a:%n' "$line"
1875 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1876 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1880 forallsupportedcompressors
() {
1881 rm -f "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
1882 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
1883 if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi
1888 ### convenience hacks ###
1890 # creating some directories by hand is a tedious task, so make it look simple
1892 if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then
1893 # only the last directory created by mkdir is effected by the -m !
1894 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1895 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1896 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1897 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1898 if [ "$(id -u)" = '0' ]; then
1899 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1906 ### The following tests are run by most test methods automatically to check
1907 ### general things about commands executed without writing the test every time.
1913 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')"
1914 if command -v $AUTOTEST >/dev
/null
; then
1916 # save and restore the *.output files from other tests
1917 # as we might otherwise override them in these automatic tests
1918 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1919 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1920 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1921 $AUTOTEST "$TESTCALL" "$@"
1922 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1923 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1924 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1928 aptautotest_aptget_update
() {
1930 while [ -n "$2" ]; do
1931 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1934 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1935 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1936 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1937 # all copied files are properly chmodded
1938 local backupIFS
="$IFS"
1939 IFS
="$(printf "\n\b")"
1940 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1941 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1944 if [ "$TESTCALL" = 'testsuccess' ]; then
1945 # failure cases can retain partial files and such
1946 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
1948 if [ -s "${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" ]; then
1949 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" \
1950 "$(find "${TMPWORKINGDIRECTORY}/aptarchive/dists" -type f | while read line; do stat --format '%U:%G:%a:%n' "$line"; done | sort)"
1953 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1954 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
1956 testaptautotestnodpkgwarning
() {
1958 while [ -n "$2" ]; do
1959 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
1960 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
1963 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1966 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
1967 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
1968 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
1969 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
1970 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
1971 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }