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 local CMD='apthelper cat-file -C'
532 while [ -n "$1" ]; do
534 '.') printf ".
\t.
\tcat
\n";;
535 'gz') printf "gzip\tgz
\t$CMD $1\n";;
536 'bz2') printf "bzip2\tbz
2\t$CMD $1\n";;
537 *) printf "$1\t$1\t$CMD $1\n";;
540 done > "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
"
544 echo 'APT::FTPArchive {'
546 while [ -n "$1" ]; do
547 printf "$1" | tr 'a-z' 'A-Z'
548 printf "\t\"true
\";\n"
551 for h in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
552 printf "$h\t\"false
\";\n"
556 } >> "${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/ftparchive
-hashes.conf
"
561 COMPRESSOR_CMD="apthelper
cat-file -C $1"
563 gzip) COMPRESS='gz';;
564 bzip2) COMPRESS='bz2';;
566 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/00force
-compressor"
567 echo "Acquire
::CompressionTypes
::Order
{ \"${COMPRESS}\"; };
568 Dir
::Bin
::uncompressed
\"/does
/not
/exist
\";" > "$CONFFILE"
571 setupsimplenativepackage() {
575 local RELEASE="${4:-unstable}"
576 local DEPENDENCIES="$5"
577 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
578 If you
find such a package installed on your system
,
579 something went horribly wrong
! They are autogenerated
580 und used only by testcases and serve no other purpose…
"}"
582 local SECTION
="${7:-others}"
584 if [ "$SECTION" = "${SECTION#*/}" ]; then
587 DISTSECTION
="${SECTION%/*}"
589 local BUILDDIR
=incoming
/${NAME}-${VERSION}
590 mkdir -p ${BUILDDIR}/debian
/source
592 echo "* most suckless software product ever" > FEATURES
593 test -e debian
/copyright
|| echo "Copyleft by Joe Sixpack $(date +%Y)" > debian
/copyright
594 test -e debian
/changelog
|| echo "$NAME ($VERSION) $RELEASE; urgency=low
598 -- Joe Sixpack <joe@example.org> $(date -R)" > debian
/changelog
599 test -e debian
/control
|| echo "Source: $NAME
602 Maintainer: Joe Sixpack <joe@example.org>
603 Build-Depends: debhelper (>= 7)
604 Standards-Version: 3.9.1
606 Package: $NAME" > debian
/control
607 if [ "$ARCH" = 'all' ]; then
608 echo "Architecture: all" >> debian
/control
610 echo "Architecture: any" >> debian
/control
612 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian
/control
613 echo "Description: $DESCRIPTION" >> debian
/control
615 test -e debian
/compat
|| echo "7" > debian
/compat
616 test -e debian
/source
/format
|| echo "3.0 (native)" > debian
/source
/format
617 test -e debian
/rules
|| cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny debian
/rules
621 buildsimplenativepackage
() {
624 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then
625 NM
="$(echo "$NAME" | cut -c 1-4)"
627 NM
="$(echo "$NAME" | cut -c 1)"
631 local RELEASE
="${4:-unstable}"
632 local DEPENDENCIES
="$5"
633 local DESCRIPTION
="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
634 If you find such a package installed on your system,
635 something went horribly wrong! They are autogenerated
636 und used only by testcases and serve no other purpose…"}"
638 local SECTION="${7:-others}"
639 local PRIORITY="${8:-optional}"
641 local COMPRESS_TYPE="${10:-gzip}"
643 if [ "$SECTION" = "${SECTION#*/}" ]; then
646 DISTSECTION="${SECTION%/*}"
648 local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming
/${NAME}-${VERSION}"
650 msgtest "Build
source package
in version
${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
651 mkdir -p "$BUILDDIR/debian
/source"
652 echo "* most suckless software product ever
" > "${BUILDDIR}/FEATURES
"
654 echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}"
656 echo "Copyleft by Joe Sixpack
$(date +%Y)" > "${BUILDDIR}/debian
/copyright
"
657 echo "$NAME ($VERSION) $RELEASE; urgency
=low
661 -- Joe Sixpack
<joe@example.org
> $(date -R)" > "${BUILDDIR}/debian
/changelog
"
665 Maintainer
: Joe Sixpack
<joe@example.org
>
666 Standards
-Version: 3.9.3"
667 if [ "$SECTION" != '<none>' ]; then
668 echo "Section
: $SECTION"
670 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
671 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
675 if [ "$ARCH" = 'all' ]; then
676 echo "Architecture
: all
"
678 echo "Architecture
: any
"
680 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
681 test -z "$DEPS" || echo "$DEPS"
682 echo "Description
: $DESCRIPTION"
683 } > "${BUILDDIR}/debian
/control
"
685 echo '3.0 (native)' > "${BUILDDIR}/debian
/source
/format
"
687 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
689 sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
" \
691 echo "pool
/${SRC}" >> "${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
"
692 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
693 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
694 # adv --yes --default-key 'Joe Sixpack' \
695 # --clearsign -o "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
696 # mv "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
700 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
701 msgtest "Build binary package
for ${RELEASE} in ${SECTION}" "$NAME"
702 rm -rf "${BUILDDIR}/debian
/tmp
"
703 mkdir -p "${BUILDDIR}/debian
/tmp
/DEBIAN
" "${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}" "${BUILDDIR}/debian
/tmp
/usr
/bin
"
704 cp "${BUILDDIR}/debian
/copyright
" "${BUILDDIR}/debian
/changelog
" "${BUILDDIR}/FEATURES
" "${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}"
705 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}"
706 if [ -n "$FILE_TREE" ]; then
707 cp -ar "$FILE_TREE" "${BUILDDIR}/debian
/tmp
"
710 (cd "${BUILDDIR}"; dpkg-gencontrol -DArchitecture=$arch)
711 (cd "${BUILDDIR}/debian
/tmp
"; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
712 local LOG="${BUILDDIR}/..
/${NAME}_
${VERSION}_
${arch}.dpkg
-deb.log
"
713 # ensure the right permissions as dpkg-deb insists
714 chmod 755 "${BUILDDIR}/debian
/tmp
/DEBIAN
"
715 testsuccess --nomsg dpkg-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian
/tmp
" "${BUILDDIR}/..
"
716 echo "pool
/${NAME}_
${VERSION}_
${arch}.deb
" >> "${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
"
719 local CHANGEPATH="${BUILDDIR}/..
/${DISTSECTION}/${NM}/${NAME}/${NAME}_
${VERSION}"
720 mkdir -p "$CHANGEPATH"
721 cp "${BUILDDIR}/debian
/changelog
" "$CHANGEPATH"
730 local ARCH=$(getarchitecture $4)
731 local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
732 local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
733 msgtest "Build package
for ${RELEASE} in ${SECTION}" "$PKGNAME"
735 if [ "$ARCH" = "all
" ]; then
736 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
738 testsuccess --nomsg dpkg-buildpackage -uc -us -a$ARCH
739 cp "${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
" "$BUILDLOG"
740 local PKGS="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
741 local SRCS="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
744 echo "pool
/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
"
747 echo "pool
/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
"
752 if [ -d incoming ]; then
753 buildaptarchivefromincoming "$@
"
755 buildaptarchivefromfiles "$@
"
759 createaptftparchiveconfig() {
760 local COMPRESSORS="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
761 local COMPRESSORS="${COMPRESSORS%* }"
762 local ARCHS="$(getarchitectures)"
763 cat > ftparchive.conf <<EOF
765 ArchiveDir "$(readlink -f .)";
766 CacheDir "$(readlink -f ..)";
767 FileListDir "$(readlink -f pool/)";
770 Packages::Compress "$COMPRESSORS";
771 Sources::Compress "$COMPRESSORS";
772 Contents::Compress "$COMPRESSORS";
773 Translation::Compress "$COMPRESSORS";
774 LongDescription "false
";
778 SrcDirectory "pool
/";
781 for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
784 Architectures "$ARCHS all
source";
785 FileList "${DIST}.\
$(SECTION).pkglist
";
786 SourceFileList "${DIST}.\
$(SECTION).srclist
";
787 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
790 done >> ftparchive.conf
793 buildaptftparchivedirectorystructure() {
794 local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
795 for DIST in $DISTS; do
796 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
797 for SECTION in $SECTIONS; do
798 local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
799 for ARCH in $ARCHS; do
800 mkdir -p "dists
/${DIST}/${SECTION}/binary
-${ARCH}"
802 mkdir -p "dists
/${DIST}/${SECTION}/source"
803 mkdir -p "dists
/${DIST}/${SECTION}/i18n
"
813 local DEPENDENCIES="$5"
814 local PRIORITY="${6:-optional}"
815 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
816 If you
find such a package installed on your system
,
817 something went horribly wrong
! They are autogenerated
818 und used only by testcases and serve no other purpose…
"}"
820 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
821 if [ "$RELEASE" = 'installed' ]; then
822 insertinstalledpackage
"$2" "$3" "$4" "$5" "$6" "$7"
825 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
826 if [ "$arch" = 'none' ]; then
827 ARCHS
="$(getarchitectures)"
831 for BUILDARCH
in $ARCHS; do
832 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
839 Maintainer: Joe Sixpack <joe@example.org>"
840 test "$arch" = 'none' || echo "Architecture: $arch"
841 echo "Version: $VERSION
842 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb"
843 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES"
844 echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)"
845 echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
847 } >> "${PPATH}/Packages"
850 mkdir -p "aptarchive/dists/${RELEASE}/main/source" "aptarchive/dists/${RELEASE}/main/i18n"
851 touch "aptarchive/dists/${RELEASE}/main/source/Sources"
853 Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
854 Description-en: $DESCRIPTION
855 " >> "aptarchive/dists/${RELEASE}/main/i18n/Translation-en"
864 local DEPENDENCIES
="$5"
865 local BINARY
="${6:-$NAME}"
867 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
868 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
870 local FILE
="${SPATH}/Sources"
871 local DSCFILE
="${NAME}_${VERSION}.dsc"
872 local TARFILE
="${NAME}_${VERSION}.tar.gz"
876 Maintainer: Joe Sixpack <joe@example.org>
877 Architecture: $ARCH" >> $FILE
878 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
880 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
881 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
883 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
884 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
889 insertinstalledpackage
() {
893 local DEPENDENCIES
="$4"
894 local PRIORITY
="${5:-optional}"
895 local STATUS
="${6:-install ok installed}"
896 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
897 If you find such a package installed on your system,
898 something went horribly wrong! They are autogenerated
899 und used only by testcases and serve no other purpose…"}"
901 local FILE='rootdir/var/lib/dpkg/status'
902 local INFO='rootdir/var/lib/dpkg/info'
903 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
909 Maintainer
: Joe Sixpack
<joe@example.org
>
910 Version
: $VERSION" >> "$FILE"
911 test "$arch" = 'none' || echo "Architecture
: $arch" >> "$FILE"
912 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
913 echo "Description
: $DESCRIPTION" >> "$FILE"
915 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
916 echo -n > "${INFO}/${NAME}:${arch}.list
"
918 echo -n > "${INFO}/${NAME}.list
"
924 buildaptarchivefromincoming() {
925 msginfo "Build APT archive
for ${CCMD}${0##*/}${CINFO} based on incoming packages…
"
927 [ -e pool ] || ln -s ../incoming pool
928 [ -e ftparchive.conf ] || createaptftparchiveconfig
929 [ -e dists ] || buildaptftparchivedirectorystructure
930 msgninfo "\tGenerate Packages
, Sources and Contents files…
"
931 testsuccess aptftparchive generate ftparchive.conf
934 generatereleasefiles "$@
"
937 buildaptarchivefromfiles() {
938 msginfo "Build APT archive
for ${CCMD}${0##*/}${CINFO} based on prebuild files…
"
939 local DIR='aptarchive'
940 if [ -d "${DIR}/dists
" ]; then DIR="${DIR}/dists
"; fi
941 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do
942 msgninfo "\t${line} file…
"
943 compressfile "$line" "$1"
946 generatereleasefiles "$@
"
950 cat "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
" | while read compressor extension command; do
951 if [ "$compressor" = '.' ]; then
957 cat "$1" | $command > "${1}.
${extension}"
959 touch -d "$2" "${1}.
${extension}"
964 # can be overridden by testcases for their pleasure
965 getcodenamefromsuite() {
967 unstable) echo 'sid';;
971 getreleaseversionfromsuite() { true; }
972 getlabelfromsuite() { true; }
973 getoriginfromsuite() { true; }
974 getarchitecturesfromreleasefile() { echo "all
$(getarchitectures)"; }
976 aptftparchiverelease() {
977 aptftparchive -qq release "$@
" | sed -e '/0 Release$/ d' # remove the self reference
979 generatereleasefiles() {
980 # $1 is the Date header and $2 is the ValidUntil header to be set
981 # both should be given in notation date/touch can understand
983 local VALIDUNTIL="$2"
984 if [ -e aptarchive/dists ]; then
985 msgninfo "\tGenerate Release files
for dists…
"
986 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
987 local ARCHITECTURES="$(getarchitecturesfromreleasefile "$dir")"
988 local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
989 local CODENAME="$(getcodenamefromsuite $SUITE)"
990 local VERSION="$(getreleaseversionfromsuite $SUITE)"
991 local LABEL="$(getlabelfromsuite $SUITE)"
992 local ORIGIN="$(getoriginfromsuite $SUITE)"
993 aptftparchiverelease "$dir" \
994 -o APT::FTPArchive::Release::Suite="${SUITE}" \
995 -o APT::FTPArchive::Release::Codename="${CODENAME}" \
996 -o APT::FTPArchive::Release::Architectures="${ARCHITECTURES}" \
997 -o APT::FTPArchive::Release::Label="${LABEL}" \
998 -o APT::FTPArchive::Release::Origin="${ORIGIN}" \
999 -o APT::FTPArchive::Release::Version="${VERSION}" \
1001 if [ "$SUITE" = "experimental
" -o "$SUITE" = "experimental2
" ]; then
1002 sed -i '/^Date: / a\
1003 NotAutomatic: yes' "$dir/Release
"
1007 msgninfo "\tGenerate Release files
for flat…
"
1008 aptftparchiverelease ./aptarchive > aptarchive/Release
1010 if [ -n "$DATE" -a "$DATE" != "now
" ]; then
1011 for release in $(find ./aptarchive -name 'Release'); do
1012 sed -i "s
/^Date
: .
*$
/Date
: $(date -d "$DATE" '+%a, %d %b %Y %H:%M:%S %Z')/" "$release"
1013 touch -d "$DATE" "$release"
1016 if [ -n "$VALIDUNTIL" ]; then
1017 sed -i "/^Date
: / a\
1018 Valid
-Until: $(date -d "$VALIDUNTIL" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release')
1023 setupdistsaptarchive() {
1024 local APTARCHIVE="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1025 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
1026 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
1027 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1028 SECTIONS=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1029 msgninfo "\tadd deb and deb
-src sources.list lines
for ${CCMD}${DISTS} ${SECTIONS}${CINFO}…
"
1030 echo "deb
file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
"
1031 echo "deb
-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
"
1036 setupflataptarchive() {
1037 local APTARCHIVE="$(readlink -f ./aptarchive)"
1038 local APTARCHIVEURI="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1039 if [ -f "${APTARCHIVE}/Packages
" ]; then
1040 msgninfo "\tadd deb sources.list line…
"
1041 echo "deb
file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1044 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1046 if [ -f "${APTARCHIVE}/Sources
" ]; then
1047 msgninfo "\tadd deb
-src sources.list line…
"
1048 echo "deb
-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1051 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1057 if [ "$1" = '--no-update' ]; then
1061 buildaptarchive "$@
"
1062 if [ -e aptarchive/dists ]; then
1063 setupdistsaptarchive
1067 signreleasefiles 'Joe Sixpack'
1068 if [ "1" != "$NOUPDATE" ]; then
1069 testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true
1073 signreleasefiles() {
1074 local SIGNER="${1:-Joe Sixpack}"
1075 local REPODIR="${2:-aptarchive}"
1076 local KEY="keys
/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
1077 local GPG="aptkey
--quiet --keyring ${KEY}.pub
--secret-keyring ${KEY}.sec
--readonly adv
--batch --yes --digest-algo SHA512
"
1078 msgninfo "\tSign archive with
$SIGNER key
$KEY…
"
1079 local REXKEY='keys/rexexpired'
1080 local SECEXPIREBAK="${REXKEY}.sec.bak
"
1081 local PUBEXPIREBAK="${REXKEY}.pub.bak
"
1082 if [ "${SIGNER}" = 'Rex Expired' ]; then
1083 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1084 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1085 # therefore we 'temporary' make the key not expired and restore a backup after signing
1086 cp "${REXKEY}.sec
" "$SECEXPIREBAK"
1087 cp "${REXKEY}.pub
" "$PUBEXPIREBAK"
1088 local SECUNEXPIRED="${REXKEY}.sec.unexpired
"
1089 local PUBUNEXPIRED="${REXKEY}.pub.unexpired
"
1090 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1091 cp "$SECUNEXPIRED" "${REXKEY}.sec
"
1092 cp "$PUBUNEXPIRED" "${REXKEY}.pub
"
1094 if ! printf "expire
\n1w
\nsave
\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then
1098 cp "${REXKEY}.sec
" "$SECUNEXPIRED"
1099 cp "${REXKEY}.pub
" "$PUBUNEXPIRED"
1102 for RELEASE in $(find "${REPODIR}/" -name Release); do
1103 testsuccess $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output "${RELEASE}.gpg
" "${RELEASE}"
1104 local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
1105 testsuccess $GPG --default-key "$SIGNER" --clearsign --output "$INRELEASE" "$RELEASE"
1106 # we might have set a specific date for the Release file, so copy it
1107 touch -d "$(stat --format "%y" ${RELEASE})" "${RELEASE}.gpg
" "${INRELEASE}"
1109 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1110 mv -f "$SECEXPIREBAK" "${REXKEY}.sec
"
1111 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub
"
1116 redatereleasefiles() {
1117 local DATE="$(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
1118 for release in $(find aptarchive/ -name 'Release'); do
1119 sed -i "s
/^Date
: .
*$
/Date
: ${DATE}/" "$release"
1120 touch -d "$DATE" "$release"
1122 signreleasefiles "${2:-Joe Sixpack}"
1126 local WEBSERVER="${3:-http://localhost:${APTHTTPPORT}}"
1128 if [ "$1" = '--no-check' ]; then
1132 local DOWNLOG='rootdir/tmp/download-testfile.log'
1133 local STATUS='downloaded/webserverconfig.status'
1134 rm -f "$STATUS" "$DOWNLOG"
1135 # very very basic URI encoding
1137 if [ -n "$2" ]; then
1138 msgtest "Set webserver config option
'${1}' to
" "$2"
1139 URI="${WEBSERVER}/_config
/set
/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1141 msgtest 'Clear webserver config option' "${1}"
1142 URI="${WEBSERVER}/_config
/clear
/$(echo "${1}" | sed -e 's/\//%2f/g')"
1144 if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then
1147 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir
/tmp
/webserverconfig.output
"
1148 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1149 msgfailoutput '' "$OUTPUT"
1151 $NOCHECK || testwebserverlaststatuscode '200'
1154 rewritesourceslist() {
1155 local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1156 local APTARCHIVE2="copy
://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1157 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1158 sed -i $LIST -e "s
#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
1159 -e "s#http://localhost:${APTHTTPPORT}/#${1}#" \
1160 -e "s#https://localhost:${APTHTTPSPORT}/#${1}#"
1164 # wait for up to 10s for a pid file to appear to avoid possible race
1165 # when a helper is started and dosn't write the PID quick enough
1168 for i
in $(seq 10); do
1169 if test -s "$PIDFILE"; then
1174 msgdie
"waiting for $PIDFILE failed"
1178 changetowebserver
() {
1180 if [ "$1" != '--no-rewrite' ]; then
1185 if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
1187 local LOG
="webserver.log"
1188 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1192 waitforpidfile aptwebserver.pid
1193 local PID
="$(cat aptwebserver.pid)"
1194 if [ -z "$PID" ]; then
1195 msgdie
'Could not fork aptwebserver successfully'
1197 addtrap
"kill $PID;"
1198 waitforpidfile aptwebserver.port
1199 APTHTTPPORT
="$(cat aptwebserver.port)"
1200 if [ -z "$APTHTTPPORT" ]; then
1201 msgdie
'Could not get port for aptwebserver successfully'
1205 msgdie
'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver'
1207 if [ "$REWRTE" != 'yes' ]; then
1208 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1212 changetohttpswebserver
() {
1213 if ! command -v stunnel4
>/dev
/null
2>&1; then
1214 msgdie
'You need to install stunnel4 for https testcases'
1216 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1217 changetowebserver
--no-rewrite "$@"
1219 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1220 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1225 connect = $APTHTTPPORT
1226 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1227 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1228 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1229 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1230 if [ -z "$PID" ]; then
1231 msgdie
'Could not fork stunnel4 successfully'
1233 addtrap
'prefix' "kill ${PID};"
1234 APTHTTPSPORT
="$(lsof -i | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1235 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1236 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1240 mkdir -p rootdir
/media
/cdrom
/.disk
1241 local CD
="$(readlink -f rootdir/media/cdrom)"
1242 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1243 acquire::cdrom::mount "${CD}";
1244 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1245 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1246 acquire::cdrom::autodetect 0;
1248 echo -n "$1" > "${CD}/.disk/info"
1249 if [ ! -d aptarchive
/dists
]; then
1250 msgdie
'Flat file archive cdroms can not be created currently'
1253 mv aptarchive
/dists
"$CD"
1254 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1255 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1256 # start with an unmounted disk
1257 mv "${CD}" "${CD}-unmounted"
1258 # we don't want the disk to be modifiable
1259 addtrap
'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;"
1260 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1264 local PROTO
="${1%%:*}"
1265 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1266 download
-file "$1" "$2" "$3" 2>&1 ; then
1269 # only if the file exists the download was successful
1270 if [ -r "$2" ]; then
1278 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1279 if [ -n "$DIFFTEXT" ]; then
1281 echo >&2 "$DIFFTEXT"
1289 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1290 local COMPAREFILE
="$1"
1292 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1295 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1296 cat "$COMPAREFILE" >>"${OUTPUT}"
1297 msgfailoutput
'' "$OUTPUT" "$@"
1302 msggroup
'testfileequal'
1303 local MSG
='Test for correctness of file'
1304 if [ "$1" = '--nomsg' ]; then
1310 if [ -n "$MSG" ]; then
1311 msgtest
"$MSG" "$FILE"
1313 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1314 if [ -z "$*" ]; then
1315 testoutputequal
"$FILE" echo -n ''
1317 testoutputequal
"$FILE" echo "$*"
1323 msggroup
'testempty'
1324 if [ "$1" = '--nomsg' ]; then
1327 msgtest
"Test for no output of" "$*"
1329 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1330 if "$@" >"$COMPAREFILE" 2>&1 && test ! -s "$COMPAREFILE"; then
1333 msgfailoutput
'' "$COMPAREFILE" "$@"
1335 aptautotest
'testempty' "$@"
1339 msggroup
'testnotempty'
1340 msgtest
"Test for some output of" "$*"
1341 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
1342 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then
1345 msgfailoutput
'' "$COMPAREFILE" "$@"
1347 aptautotest
'testnotempty' "$@"
1352 msggroup
'testequal'
1353 local MSG
='Test of equality of'
1354 if [ "$1" = '--nomsg' ]; then
1359 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1360 echo "$1" > "$COMPAREFILE"
1363 if [ -n "$MSG" ]; then
1366 testoutputequal
"$COMPAREFILE" "$@"
1367 aptautotest
'testequal' "$@"
1372 msggroup
'testequalor2'
1373 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1374 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1375 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1376 echo "$1" > "$COMPAREFILE1"
1377 echo "$2" > "$COMPAREFILE2"
1379 msgtest
"Test for equality OR of" "$*"
1380 "$@" >"$COMPAREAGAINST" 2>&1 || true
1381 if checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null
2>&1 || \
1382 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null
2>&1
1386 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1387 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1388 checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1389 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1390 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1391 msgfailoutput
'' "$OUTPUT"
1393 aptautotest
'testequalor2' "$@"
1398 msggroup
'testshowvirtual'
1399 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1402 while [ -n "$1" ]; do
1404 N: Can't select versions from package '$1' as it is purely virtual"
1405 PACKAGE
="${PACKAGE} $1"
1408 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1410 N: No packages found"
1411 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1412 local ARCH
="$(getarchitecture 'native')"
1413 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1414 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1415 testoutputequal
"$COMPAREFILE" aptcache show
"$PACKAGE"
1420 msggroup
'testnopackage'
1421 msgtest
"Test for non-existent packages" "apt-cache show $*"
1422 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1423 if [ -n "$SHOWPKG" ]; then
1424 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1425 echo "$SHOWPKG" >"$OUTPUT"
1426 msgfailoutput
'' "$OUTPUT"
1432 testnosrcpackage
() {
1433 msggroup
'testnosrcpackage'
1434 msgtest
"Test for non-existent source packages" "apt-cache showsrc $*"
1435 local SHOWPKG
="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')"
1436 if [ -n "$SHOWPKG" ]; then
1437 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output"
1438 echo "$SHOWPKG" >"$OUTPUT"
1439 msgfailoutput
'' "$OUTPUT"
1447 msggroup
'testdpkgstatus'
1451 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1452 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1453 if [ "$PKGS" != $NR ]; then
1454 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1455 echo "$PKGS" >"$OUTPUT"
1456 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1457 msgfailoutput
'' "$OUTPUT"
1464 testdpkginstalled
() {
1465 msggroup
'testdpkginstalled'
1466 testdpkgstatus
'ii' "$#" "$@"
1470 testdpkgnotinstalled
() {
1471 msggroup
'testdpkgnotinstalled'
1472 testdpkgstatus
'ii' '0' "$@"
1477 msggroup
'testmarkedauto'
1478 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1479 if [ -n "$1" ]; then
1480 msgtest
'Test for correctly marked as auto-installed' "$*"
1481 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1483 msgtest
'Test for correctly marked as auto-installed' 'no package'
1484 echo -n > "$COMPAREFILE"
1486 testoutputequal
"$COMPAREFILE" aptmark showauto
1489 testmarkedmanual
() {
1490 msggroup
'testmarkedmanual'
1491 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1492 if [ -n "$1" ]; then
1493 msgtest
'Test for correctly marked as manually installed' "$*"
1494 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1496 msgtest
'Test for correctly marked as manually installed' 'no package'
1497 echo -n > "$COMPAREFILE"
1499 testoutputequal
"$COMPAREFILE" aptmark showmanual
1504 msgreportheader
'msgfailoutput'
1508 if [ "$1" = 'grep' ]; then
1510 while [ -n "$2" ]; do shift; done
1511 echo "#### Complete file: $1 ####"
1512 cat >&2 "$1" || true
1513 echo '#### grep output ####'
1514 elif [ "$1" = 'test' ]; then
1516 # doesn't support ! or non-file flags
1517 msgfailoutputstatfile
() {
1518 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1519 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1520 echo "#### stat(2) of file: $2 ####"
1522 if test -d "$2"; then
1523 echo "#### The directory contains: $2 ####"
1525 elif test -e "$2"; then
1526 echo "#### Complete file: $2 ####"
1527 cat >&2 "$2" || true
1531 msgfailoutputstatfile
"$2" "$3"
1532 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1534 msgfailoutputstatfile
"$2" "$3"
1536 echo '#### test output ####'
1537 elif [ "$1" = 'cmp' ]; then
1539 while [ -n "$2" ]; do
1540 echo "#### Complete file: $2 ####"
1541 cat >&2 "$2" || true
1544 echo '#### cmp output ####'
1550 testsuccesswithglobalerror
() {
1555 if [ "$1" = '--nomsg' ]; then
1558 msgtest
'Test for successful execution of' "$*"
1560 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output"
1561 if "$@" >"${OUTPUT}" 2>&1; then
1562 if expr match
"$1" '^apt.*' >/dev
/null
; then
1563 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1564 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1565 elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1566 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1567 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1568 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1571 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1574 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1576 elif [ "$TYPE" = 'testsuccesswithnotice' ]; then
1577 if grep -q -E "^N: " "$OUTPUT"; then
1580 msgfailoutput
'successful run, but output had no notices' "$OUTPUT" "$@"
1590 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1592 aptautotest
"$TYPE" "$@"
1595 testsuccesswithnotice
() {
1596 testsuccesswithglobalerror
'testsuccesswithnotice' 'WE' "$@"
1599 testsuccesswithglobalerror
'testsuccess' 'NWE' "$@"
1602 msggroup
'testwarning'
1603 if [ "$1" = '--nomsg' ]; then
1606 msgtest
'Test for successful execution with warnings of' "$*"
1608 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1609 if "$@" >"${OUTPUT}" 2>&1; then
1610 if expr match
"$1" '^apt.*' >/dev
/null
; then
1611 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1612 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1613 elif grep -q -E '^E: ' "$OUTPUT"; then
1614 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1615 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1616 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1625 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1627 aptautotest
'testwarning' "$@"
1631 msggroup
'testfailure'
1632 if [ "$1" = '--nomsg' ]; then
1635 msgtest
'Test for failure in execution of' "$*"
1637 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1638 if "$@" >"${OUTPUT}" 2>&1; then
1640 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1643 if expr match
"$1" '^apt.*' >/dev
/null
; then
1644 if [ "$1" = 'aptkey' ]; then
1645 if grep -q -E " Can't check signature: " "$OUTPUT" || \
1646 grep -q -E " BAD signature from " "$OUTPUT"; then
1649 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1652 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1653 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1654 elif grep -q -E '==ERROR' "$OUTPUT"; then
1655 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1656 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1657 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1666 aptautotest
'testfailure' "$@"
1670 testreturnstateequal
() {
1672 if [ "$STATE" = 'testsuccesswithglobalerror' ]; then
1676 msggroup
"${STATE}equal"
1677 if [ "$1" != '--nomsg' ]; then
1680 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1681 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1685 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1686 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1689 msggroup
"${STATE}equal"
1690 if [ "$2" != '--nomsg' ]; then
1694 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1698 "$STATE" --nomsg "$@"
1699 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1704 testsuccessequal
() {
1705 # we compare output, so we know perfectly well about N:
1706 testreturnstateequal
'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@"
1708 testwarningequal
() {
1709 testreturnstateequal
'testwarning' "$@"
1711 testfailureequal
() {
1712 testreturnstateequal
'testfailure' "$@"
1716 msggroup
'testfailuremsg'
1720 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1721 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1722 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1723 testoutputequal
"$COMPAREFILE" echo "$CMP"
1727 msggroup
'testwarningmsg'
1731 msgtest
'Check that the output of the previous warned command has expected' 'warnings'
1732 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
1733 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
1734 testoutputequal
"$COMPAREFILE" echo "$CMP"
1739 msggroup
'testfilestats'
1740 msgtest
"Test that file $1 has $2 $3" "$4"
1741 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1744 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1747 echo -n "stat(1) reports for $2: "
1748 stat
--format "$2" "$1" || true
1750 msgfailoutput
'' "$OUTPUT"
1754 testaccessrights
() {
1755 msggroup
'testaccessrights'
1756 testfilestats
"$1" '%a' '=' "$2"
1760 testwebserverlaststatuscode
() {
1761 msggroup
'testwebserverlaststatuscode'
1762 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1763 local STATUS
='downloaded/webserverstatus-statusfile.log'
1764 rm -f "$DOWNLOG" "$STATUS"
1765 msgtest
'Test last status code from the webserver was' "$1"
1766 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1769 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1771 if [ -n "$2" ]; then
1773 echo >&2 '#### Additionally provided output files contain:'
1776 echo >&2 '#### Download log of the status code:'
1779 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1784 createlistofkeys
() {
1787 while [ -n "$1" ]; do
1788 # gpg 2.1.something starts printing [SC] at some point
1789 if grep -q ' rsa2048/' "$OUTPUT" && grep -qF '[SC]' "$OUTPUT"; then
1791 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';;
1792 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [SC] [expired: 2013-07-13]';;
1793 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16 [SC]';;
1794 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19 [SC]';;
1795 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';;
1796 *) echo 'UNKNOWN KEY';;
1798 # gpg 2.1 has a slightly different output format
1799 elif grep -q ' rsa2048/' "$OUTPUT"; then
1801 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1802 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1803 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16';;
1804 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19';;
1805 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1806 *) echo 'UNKNOWN KEY';;
1810 *Joe
*|*Sixpack
*) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1811 *Rex
*|*Expired
*) echo 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1812 *Marvin
*|*Paranoid
*) echo 'pub 2048R/528144E2 2011-01-16';;
1813 oldarchive
) echo 'pub 1024R/F68C85A3 2013-12-19';;
1814 newarchive
) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1815 *) echo 'UNKNOWN KEY';;
1822 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output"
1823 if ! aptkey list
| grep '^pub' > "$OUTPUT"; then
1826 testfileequal
"$OUTPUT" "$(createlistofkeys "$OUTPUT" "$@")"
1830 echo "STOPPED execution. Press enter to continue"
1835 listcurrentlistsdirectory
() {
1837 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1838 stat
--format '%U:%G:%a:%n' "$line"
1840 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1841 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1845 forallsupportedcompressors
() {
1846 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
1847 if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi
1852 ### convenience hacks ###
1854 # creating some directories by hand is a tedious task, so make it look simple
1856 if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then
1857 # only the last directory created by mkdir is effected by the -m !
1858 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1859 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1860 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1861 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1862 if [ "$(id -u)" = '0' ]; then
1863 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1870 ### The following tests are run by most test methods automatically to check
1871 ### general things about commands executed without writing the test every time.
1877 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')"
1878 if command -v $AUTOTEST >/dev
/null
; then
1880 # save and restore the *.output files from other tests
1881 # as we might otherwise override them in these automatic tests
1882 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1883 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1884 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1885 $AUTOTEST "$TESTCALL" "$@"
1886 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1887 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1888 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1892 aptautotest_aptget_update
() {
1894 while [ -n "$2" ]; do
1895 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1898 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1899 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1900 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1901 # all copied files are properly chmodded
1902 local backupIFS
="$IFS"
1903 IFS
="$(printf "\n\b")"
1904 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1905 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1908 if [ "$TESTCALL" = 'testsuccess' ]; then
1909 # failure cases can retain partial files and such
1910 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
1913 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1914 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
1916 testaptautotestnodpkgwarning
() {
1918 while [ -n "$2" ]; do
1919 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
1920 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
1923 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1926 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
1927 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
1928 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
1929 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
1930 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
1931 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }