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\([cfghs]\)#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} $CMD "$@"
178 aptconfig
() { runapt apt
-config "$@"; }
179 aptcache
() { runapt apt
-cache "$@"; }
180 aptcdrom
() { runapt apt
-cdrom "$@"; }
181 aptget
() { runapt apt
-get "$@"; }
182 aptftparchive
() { runapt apt
-ftparchive "$@"; }
183 aptkey
() { runapt apt
-key "$@"; }
184 aptmark
() { runapt apt
-mark "$@"; }
185 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; }
186 apt
() { runapt apt
"$@"; }
187 apthelper
() { runapt
"${APTHELPERBINDIR}/apt-helper" "$@"; }
188 aptwebserver
() { runapt
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
189 aptitude
() { runapt aptitude
"$@"; }
190 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; }
191 aptinternalsolver
() { runapt
"${APTINTERNALSOLVER}" "$@"; }
192 aptdumpsolver
() { runapt
"${APTDUMPSOLVER}" "$@"; }
195 "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@"
197 dpkgcheckbuilddeps
() {
198 command dpkg
-checkbuilddeps --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" "$@"
203 aptget
) CMD
="apt-get";;
204 aptcache
) CMD
="apt-cache";;
205 aptcdrom
) CMD
="apt-cdrom";;
206 aptconfig
) CMD
="apt-config";;
207 aptmark
) CMD
="apt-mark";;
208 apthelper
) CMD
="apt-helper";;
209 aptftparchive
) CMD
="apt-ftparchive";;
210 dpkg
) shift; runapt
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" "$@"; return;;
214 if [ "${CMD##*/}" = "$CMD" ]; then
215 CMD
="${BUILDDIRECTORY}/${CMD}"
217 runapt
command gdb
--quiet -ex run
"$CMD" --args "$CMD" "$@"
221 # error if we about to overflow, but ...
222 # "255 failures ought to be enough for everybody"
223 if [ $EXIT_CODE -gt 255 ]; then
224 msgdie
"Total failure count $EXIT_CODE too big"
226 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
229 shellsetedetector
() {
231 if [ "$exit_status" != '0' ]; then
232 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
233 if [ "$EXIT_CODE" = '0' ]; then
234 EXIT_CODE
="$exit_status"
240 if [ "$1" = 'prefix' ]; then
241 CURRENTTRAP
="$2 $CURRENTTRAP"
243 CURRENTTRAP
="$CURRENTTRAP $1"
245 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
249 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
250 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
253 TMPWORKINGDIRECTORY
="$(mktemp -d)"
254 addtrap
"cd /; rm -rf \"$TMPWORKINGDIRECTORY\";"
255 msgninfo
"Preparing environment for ${0##*/} in ${TMPWORKINGDIRECTORY}…"
257 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
258 if [ "$(id -u)" = '0' ]; then
259 # relax permissions so that running as root with user switching works
261 chmod 711 "$TMPWORKINGDIRECTORY"
262 chown _apt
:root
"${TMPWORKINGDIRECTORY}/downloaded"
265 TESTDIRECTORY
="$(readlink -f "$(dirname $0)")"
266 # allow overriding the default BUILDDIR location
267 SOURCEDIRECTORY="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}"
268 BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}"
269 LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}"
270 METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}"
271 APTHELPERBINDIR="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}"
272 APTWEBSERVERBINDIR="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}"
273 APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}"
274 APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}"
275 test -x "${BUILDDIRECTORY}/apt
-get" || msgdie "You need to build tree first
"
278 cd "$TMPWORKINGDIRECTORY"
279 mkdir rootdir aptarchive keys
281 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
282 mkdir -p usr/bin var/cache var/lib var/log tmp
283 mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
284 touch var/lib/dpkg/available
286 ln -s "${METHODSDIR}" usr/lib/apt/methods
287 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
288 mkdir -p usr/lib/apt/solvers
289 ln -s "${BUILDDIRECTORY}/apt
-dump-solver" usr/lib/apt/solvers/dump
290 ln -s "${BUILDDIRECTORY}/apt
-internal-solver" usr/lib/apt/solvers/apt
291 echo "Dir
::Bin
::Solvers
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/solvers
\";" > etc/apt/apt.conf.d/externalsolver.conf
293 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
295 if [ -e "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" ]; then
296 ln -s "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" etc/apt/apt.conf.d/01autoremove
298 ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
301 local BASENAME="${0##*/}"
302 local PACKAGESFILE="Packages
-${BASENAME#*-}"
303 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
304 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
306 local SOURCESSFILE="Sources
-${BASENAME#*-}"
307 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
308 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
310 for key in $(find "$TESTDIRECTORY" -name '*.pub' -o -name '*.sec'); do
314 ln -s "${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub
" rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
316 echo "Dir
\"${TMPWORKINGDIRECTORY}/rootdir
\";" > aptconfig.conf
317 echo "Dir
::state
::status
\"${TMPWORKINGDIRECTORY}/rootdir
/var
/lib
/dpkg
/status
\";" >> aptconfig.conf
318 echo "APT
::Get
::Show
-User-Simulation-Note \"false
\";" >> aptconfig.conf
319 echo "Dir
::Bin
::Methods
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/methods
\";" >> aptconfig.conf
320 # store apt-key were we can access it, even if we run it as a different user
321 # destroys coverage reporting though, so just do it for root for now
322 if [ "$(id -u)" = '0' ]; then
323 cp "${BUILDDIRECTORY}/apt
-key" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/"
324 chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key"
325 echo "Dir
::Bin
::apt
-key \"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key\";" >> aptconfig.conf
327 echo "Dir
::Bin
::apt
-key \"${BUILDDIRECTORY}/apt
-key\";" >> aptconfig.conf
330 cat > "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
333 if [ -r "${TMPWORKINGDIRECTORY}/noopchroot.so
" ]; then
334 if [ -n "\
$LD_LIBRARY_PATH" ]; then
335 export LD_LIBRARY_PATH="${TMPWORKINGDIRECTORY}:${LD_LIBRARY_PATH}"
337 export LD_LIBRARY_PATH="${TMPWORKINGDIRECTORY}"
339 if [ -n "\
$LD_PRELOAD" ]; then
340 export LD_PRELOAD="noopchroot.so \
${LD_PRELOAD}"
342 export LD_PRELOAD="noopchroot.so
"
346 cp "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
347 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
348 exec fakeroot "${DPKG:-dpkg}" --root="${TMPWORKINGDIRECTORY}/rootdir
" \\
349 --log="${TMPWORKINGDIRECTORY}/rootdir
/var
/log
/dpkg.log
" \\
350 --force-not-root --force-bad-path "\$@
"
352 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg" <<EOF
353 exec fakeroot gdb --quiet -ex run "${DPKG:-dpkg}" --args "${DPKG:-dpkg}" --root="${TMPWORKINGDIRECTORY}/rootdir
" \\
354 --log="${TMPWORKINGDIRECTORY}/rootdir
/var
/log
/dpkg.log
" \\
355 --force-not-root --force-bad-path "\$@
"
357 chmod +x "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
358 echo "Dir
::Bin
::dpkg
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
\";" > rootdir/etc/apt/apt.conf.d/99dpkg
361 if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
362 echo "DPKG
::options
:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
364 echo 'quiet::NoUpdate "true
";'
365 echo 'quiet::NoStatistic "true
";'
366 # too distracting for users, but helpful to detect changes
367 echo 'Acquire::Progress::Ignore::ShowErrorText "true
";'
368 echo 'Acquire::Progress::Diffpercent "true
";'
369 # in testcases, it can appear as if localhost has a rotation setup,
370 # hide this as we can't really deal with it properly
371 echo 'Acquire::Failure::ShowIP "false
";'
374 cp "${TESTDIRECTORY}/apt.pem
" "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
375 if [ "$(id -u)" = '0' ]; then
376 chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
378 echo "Acquire
::https
::CaInfo
\"${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
\";" > rootdir/etc/apt/apt.conf.d/99https
379 echo "Apt
::Cmd
::Disable
-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
380 configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
381 confighashes 'SHA1' # these are tests, not security best-practices
383 # create some files in /tmp and look at user/group to get what this means
384 TEST_DEFAULT_USER="$USER"
385 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
386 TEST_DEFAULT_GROUP='root'
388 TEST_DEFAULT_GROUP="$USER"
391 # cleanup the environment a bit
392 # prefer our apt binaries over the system apt binaries
393 export PATH="${BUILDDIRECTORY}:${PATH}:/usr
/local
/sbin
:/usr
/sbin
:/sbin
"
394 export LC_ALL=C.UTF-8
395 unset LANGUAGE APT_CONFIG
396 unset GREP_OPTIONS DEB_BUILD_PROFILES
401 if [ "$1" = "native
" -o -z "$1" ]; then
402 eval `aptconfig shell ARCH APT::Architecture`
403 if [ -n "$ARCH" ]; then
406 dpkg --print-architecture
414 aptconfig dump --no-empty --format '%v%n' APT::Architecture APT::Architectures | sort -u | tr '\n' ' '
417 getarchitecturesfromcommalist() {
418 echo "$1" | sed -e 's#,#\n#g' | sed -e "s
/^native\$
/$(getarchitecture 'native')/"
421 configarchitecture() {
423 echo "APT
::Architecture
\"$(getarchitecture $1)\";"
424 while [ -n "$1" ]; do
425 echo "APT
::Architectures
:: \"$(getarchitecture $1)\";"
428 } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
433 if [ ! -e rootdir/var/lib/dpkg/status ]; then
434 local BASENAME="${0##*/}"
435 local STATUSFILE="status
-${BASENAME#*-}"
436 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
437 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
439 echo -n > rootdir/var/lib/dpkg/status
442 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
443 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
444 local ARCHS="$(getarchitectures)"
445 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
446 DPKGARCH="$(dpkg --print-architecture)"
447 for ARCH in ${ARCHS}; do
448 if [ "${ARCH}" != "${DPKGARCH}" ]; then
449 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
450 # old-style used e.g. in Ubuntu-P – and as it seems travis
451 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
452 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
456 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
457 # dpkg doesn't really check the version as long as it is fully installed,
458 # but just to be sure we choose one above the required version
459 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
465 configdpkgnoopchroot() {
466 # create a library to noop chroot() and rewrite maintainer script executions
467 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
468 # chroot directory dpkg could chroot into to execute the maintainer scripts
469 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
470 cat > noopchroot.c << EOF
477 static char * chrootdir = NULL;
479 int chroot(const char *path) {
480 printf("WARNING
: CHROOTing to
%s was ignored
!\n", path);
482 chrootdir = strdup(path);
485 int execvp(const char *file, char *const argv[]) {
486 static int (*func_execvp) (const char *, char * const []) = NULL;
487 if (func_execvp == NULL)
488 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
");
489 if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0)
490 return func_execvp(file, argv);
491 printf("REWRITE execvp call
%s into
%s
\n", file, chrootdir);
492 char newfile[strlen(chrootdir) + strlen(file)];
493 strcpy(newfile, chrootdir);
494 strcat(newfile, file);
495 char const * const baseadmindir = "/var
/lib
/dpkg
";
496 char admindir[strlen(chrootdir) + strlen(baseadmindir)];
497 strcpy(admindir, chrootdir);
498 strcat(admindir, baseadmindir);
499 setenv("DPKG_ADMINDIR
", admindir, 1);
500 return func_execvp(newfile, argv);
503 testsuccess --nomsg gcc -fPIC -shared -o noopchroot.so noopchroot.c -ldl
505 configcompression() {
506 while [ -n "$1" ]; do
508 '.') printf ".
\t.
\tcat
\n";;
509 'gz') printf "gzip\tgz
\tgzip
\n";;
510 'bz2') printf "bzip2\tbz
2\tbzip
2\n";;
511 'lzma') printf "lzma
\tlzma
\txz
--format=lzma
\n";;
512 'xz') printf "xz
\txz
\txz
\n";;
513 *) printf "$1\t$1\t$1\n";;
516 done > "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
"
520 echo 'APT::FTPArchive {'
522 while [ -n "$1" ]; do
523 printf "$1" | tr 'a-z' 'A-Z'
524 printf "\t\"true
\";\n"
527 for h in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
528 printf "$h\t\"false
\";\n"
532 } >> "${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/ftparchive
-hashes.conf
"
538 gzip) COMPRESS='gz';;
539 bzip2) COMPRESS='bz2';;
540 lzma) COMPRESS='lzma';;
542 *) msgdie "Compressor
$COMPRESSOR is unknown to framework
, so can
't be forced by forcecompressor!";;
544 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
545 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
546 Dir::Bin::uncompressed \"/does/not/exist\";
547 Dir::Bin::gzip \"/does/not/exist\";
548 Dir::Bin::bzip2 \"/does/not/exist\";
549 Dir::Bin::lzma \"/does/not/exist\";
550 Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
551 if [ -e "/bin/${COMPRESSOR}" ]; then
552 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
553 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
554 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
555 elif [ "${COMPRESSOR}" = 'lzma
' ]; then
556 echo 'Dir
::Bin
::xz
"/usr/bin/xz";' >> "$CONFFILE"
557 COMPRESSOR_CMD='xz
--format=lzma
'
559 msgtest 'Test
for availability of compressor
' "${COMPRESSOR}"
560 msgfail "${COMPRESSOR} not available"
564 setupsimplenativepackage() {
568 local RELEASE="${4:-unstable}"
569 local DEPENDENCIES="$5"
570 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
571 If you find such a package installed on your system,
572 something went horribly wrong! They are autogenerated
573 und used only by testcases and surf no other propose…"}"
575 local SECTION="${7:-others}"
577 if [ "$SECTION" = "${SECTION#*/}" ]; then
580 DISTSECTION="${SECTION%/*}"
582 local BUILDDIR=incoming/${NAME}-${VERSION}
583 mkdir -p ${BUILDDIR}/debian/source
585 echo "* most suckless software product ever" > FEATURES
586 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
587 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
591 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
592 test -e debian/control || echo "Source: $NAME
595 Maintainer: Joe Sixpack <joe@example.org>
596 Build-Depends: debhelper (>= 7)
597 Standards-Version: 3.9.1
599 Package: $NAME" > debian/control
600 if [ "$ARCH" = 'all
' ]; then
601 echo "Architecture: all" >> debian/control
603 echo "Architecture: any" >> debian/control
605 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
606 echo "Description: $DESCRIPTION" >> debian/control
608 test -e debian/compat || echo "7" > debian/compat
609 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
610 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
614 buildsimplenativepackage() {
617 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib
' ]; then
618 NM="$(echo "$NAME" | cut -c 1-4)"
620 NM="$(echo "$NAME" | cut -c 1)"
624 local RELEASE="${4:-unstable}"
625 local DEPENDENCIES="$5"
626 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
627 If you find such a package installed on your system,
628 something went horribly wrong! They are autogenerated
629 und used only by testcases and surf no other propose…"}"
631 local SECTION="${7:-others}"
632 local PRIORITY="${8:-optional}"
634 local COMPRESS_TYPE="${10:-gzip}"
636 if [ "$SECTION" = "${SECTION#*/}" ]; then
639 DISTSECTION="${SECTION%/*}"
641 local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
643 msgtest "Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
644 mkdir -p "$BUILDDIR/debian/source"
645 echo "* most suckless software product ever" > "${BUILDDIR}/FEATURES"
647 echo '$NAME says
\"Hello
!\"'" > "${BUILDDIR}/${NAME}"
649 echo "Copyleft by Joe Sixpack $(date +%Y)" > "${BUILDDIR}/debian/copyright"
650 echo "$NAME ($VERSION) $RELEASE; urgency=low
654 -- Joe Sixpack <joe@example.org> $(date -R)" > "${BUILDDIR}/debian/changelog"
658 Maintainer: Joe Sixpack <joe@example.org>
659 Standards-Version: 3.9.3"
660 if [ "$SECTION" != '<none
>' ]; then
661 echo "Section: $SECTION"
663 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
664 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
668 if [ "$ARCH" = 'all
' ]; then
669 echo "Architecture: all"
671 echo "Architecture: any"
673 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
674 test -z "$DEPS" || echo "$DEPS"
675 echo "Description: $DESCRIPTION"
676 } > "${BUILDDIR}/debian/control"
678 echo '3.0 (native
)' > "${BUILDDIR}/debian/source/format"
680 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
682 sed -n 's
#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" \
684 echo "pool/${SRC}" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist"
685 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
686 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
687 # adv --yes --default-key 'Joe Sixpack' \
688 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
689 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
693 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
694 msgtest
"Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
695 rm -rf "${BUILDDIR}/debian/tmp"
696 mkdir -p "${BUILDDIR}/debian/tmp/DEBIAN" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin"
697 cp "${BUILDDIR}/debian/copyright" "${BUILDDIR}/debian/changelog" "${BUILDDIR}/FEATURES" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}"
698 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}"
699 if [ -n "$FILE_TREE" ]; then
700 cp -ar "$FILE_TREE" "${BUILDDIR}/debian/tmp"
703 (cd "${BUILDDIR}"; dpkg
-gencontrol -DArchitecture=$arch)
704 (cd "${BUILDDIR}/debian/tmp"; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
705 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
706 # ensure the right permissions as dpkg-deb insists
707 chmod 755 "${BUILDDIR}/debian/tmp/DEBIAN"
708 testsuccess
--nomsg dpkg
-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian/tmp" "${BUILDDIR}/.."
709 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist"
712 local CHANGEPATH
="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}"
713 mkdir -p "$CHANGEPATH"
714 cp "${BUILDDIR}/debian/changelog" "$CHANGEPATH"
723 local ARCH
=$(getarchitecture $4)
724 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
725 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
726 msgtest
"Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
728 if [ "$ARCH" = "all" ]; then
729 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
731 testsuccess
--nomsg dpkg
-buildpackage -uc -us -a$ARCH
732 cp "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$BUILDLOG"
733 local PKGS
="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
734 local SRCS
="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
737 echo "pool/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist"
740 echo "pool/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist"
745 if [ -d incoming
]; then
746 buildaptarchivefromincoming
"$@"
748 buildaptarchivefromfiles
"$@"
752 createaptftparchiveconfig
() {
753 local COMPRESSORS
="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
754 local COMPRESSORS
="${COMPRESSORS%* }"
755 local ARCHS
="$(getarchitectures)"
756 cat > ftparchive.conf
<<EOF
758 ArchiveDir "$(readlink -f .)";
759 CacheDir "$(readlink -f ..)";
760 FileListDir "$(readlink -f pool/)";
763 Packages::Compress "$COMPRESSORS";
764 Sources::Compress "$COMPRESSORS";
765 Contents::Compress "$COMPRESSORS";
766 Translation::Compress "$COMPRESSORS";
767 LongDescription "false";
771 SrcDirectory "pool/";
774 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
777 Architectures "$ARCHS source";
778 FileList "${DIST}.\$(SECTION).pkglist";
779 SourceFileList "${DIST}.\$(SECTION).srclist";
780 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
783 done >> ftparchive.conf
786 buildaptftparchivedirectorystructure
() {
787 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
788 for DIST
in $DISTS; do
789 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
790 for SECTION
in $SECTIONS; do
791 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
792 for ARCH
in $ARCHS; do
793 mkdir -p "dists/${DIST}/${SECTION}/binary-${ARCH}"
795 mkdir -p "dists/${DIST}/${SECTION}/source"
796 mkdir -p "dists/${DIST}/${SECTION}/i18n"
806 local DEPENDENCIES
="$5"
807 local PRIORITY
="${6:-optional}"
808 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
809 If you find such a package installed on your system,
810 something went horribly wrong! They are autogenerated
811 und used only by testcases and surf no other propose…"}"
813 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
814 if [ "$RELEASE" = 'installed' ]; then
815 insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
818 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
819 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
820 ARCHS="$(getarchitectures)"
824 for BUILDARCH in $ARCHS; do
825 local PPATH="aptarchive
/dists
/${RELEASE}/main
/binary
-${BUILDARCH}"
832 Maintainer
: Joe Sixpack
<joe@example.org
>"
833 test "$arch" = 'none' || echo "Architecture
: $arch"
834 echo "Version
: $VERSION
835 Filename
: pool
/main
/${NAME}/${NAME}_
${VERSION}_
${arch}.deb
"
836 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES"
837 echo "Description
: $(printf '%s' "$DESCRIPTION" | head -n 1)"
838 echo "Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
840 } >> "${PPATH}/Packages
"
843 mkdir -p "aptarchive
/dists
/${RELEASE}/main
/source" "aptarchive
/dists
/${RELEASE}/main
/i18n
"
844 touch "aptarchive
/dists
/${RELEASE}/main
/source
/Sources
"
846 Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
847 Description
-en: $DESCRIPTION
848 " >> "aptarchive
/dists
/${RELEASE}/main
/i
18n
/Translation
-en"
857 local DEPENDENCIES="$5"
858 local BINARY="${6:-$NAME}"
860 local SPATH="aptarchive
/dists
/${RELEASE}/main
/source"
862 local FILE="${SPATH}/Sources
"
863 local DSCFILE="${NAME}_
${VERSION}.dsc
"
864 local TARFILE="${NAME}_
${VERSION}.
tar.gz
"
868 Maintainer
: Joe Sixpack
<joe@example.org
>
869 Architecture
: $ARCH" >> $FILE
870 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
872 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
873 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
875 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
876 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
880 insertinstalledpackage() {
884 local DEPENDENCIES="$4"
885 local PRIORITY="${5:-optional}"
886 local STATUS="${6:-install ok installed}"
887 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
888 If you
find such a package installed on your system
,
889 something went horribly wrong
! They are autogenerated
890 und used only by testcases and surf no other propose…
"}"
892 local FILE
='rootdir/var/lib/dpkg/status'
893 local INFO
='rootdir/var/lib/dpkg/info'
894 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
900 Maintainer: Joe Sixpack <joe@example.org>
901 Version: $VERSION" >> "$FILE"
902 test "$arch" = 'none' || echo "Architecture: $arch" >> "$FILE"
903 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
904 echo "Description: $DESCRIPTION" >> "$FILE"
906 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
907 echo -n > "${INFO}/${NAME}:${arch}.list"
909 echo -n > "${INFO}/${NAME}.list"
915 buildaptarchivefromincoming
() {
916 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on incoming packages…"
918 [ -e pool
] || ln -s ..
/incoming pool
919 [ -e ftparchive.conf
] || createaptftparchiveconfig
920 [ -e dists
] || buildaptftparchivedirectorystructure
921 msgninfo
"\tGenerate Packages, Sources and Contents files… "
922 testsuccess aptftparchive generate ftparchive.conf
925 generatereleasefiles
"$@"
928 buildaptarchivefromfiles
() {
929 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on prebuild files…"
930 local DIR
='aptarchive'
931 if [ -d "${DIR}/dists" ]; then DIR
="${DIR}/dists"; fi
932 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
933 msgninfo
"\t${line} file… "
934 compressfile
"$line" "$1"
937 generatereleasefiles
"$@"
941 cat "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | while read compressor extension
command; do
942 if [ "$compressor" = '.' ]; then
948 cat "$1" | $command > "${1}.${extension}"
950 touch -d "$2" "${1}.${extension}"
955 # can be overridden by testcases for their pleasure
956 getcodenamefromsuite
() {
958 unstable
) echo 'sid';;
962 getreleaseversionfromsuite
() { true
; }
963 getlabelfromsuite
() { true
; }
964 getoriginfromsuite
() { true
; }
966 aptftparchiverelease
() {
967 aptftparchive
-qq release
"$@" | sed -e '/0 Release$/ d' # remove the self reference
969 generatereleasefiles
() {
970 # $1 is the Date header and $2 is the ValidUntil header to be set
971 # both should be given in notation date/touch can understand
972 msgninfo
"\tGenerate Release files… "
973 if [ -e aptarchive
/dists
]; then
974 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
975 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
976 local CODENAME
="$(getcodenamefromsuite $SUITE)"
977 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
978 local LABEL
="$(getlabelfromsuite $SUITE)"
979 local ORIGIN
="$(getoriginfromsuite $SUITE)"
980 if [ -n "$VERSION" ]; then
981 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
983 if [ -n "$LABEL" ]; then
984 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
986 if [ -n "$ORIGIN" ]; then
987 ORIGIN
="-o APT::FTPArchive::Release::Origin=${ORIGIN}"
989 aptftparchiverelease
"$dir" \
990 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
991 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
996 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
998 NotAutomatic: yes' "$dir/Release"
1002 aptftparchiverelease .
/aptarchive
> aptarchive
/Release
1004 if [ -n "$1" -a "$1" != "now" ]; then
1005 for release
in $(find ./aptarchive -name 'Release'); do
1006 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" "$release"
1007 touch -d "$1" "$release"
1010 if [ -n "$2" ]; then
1011 sed -i "/^Date: / a\
1012 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release')
1017 setupdistsaptarchive
() {
1018 local APTARCHIVE
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1019 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
1020 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
1021 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1022 SECTIONS
=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1023 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
1024 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list"
1025 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list"
1030 setupflataptarchive
() {
1031 local APTARCHIVE
="$(readlink -f ./aptarchive)"
1032 local APTARCHIVEURI
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1033 if [ -f "${APTARCHIVE}/Packages" ]; then
1034 msgninfo
"\tadd deb sources.list line… "
1035 echo "deb file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1038 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1040 if [ -f "${APTARCHIVE}/Sources" ]; then
1041 msgninfo
"\tadd deb-src sources.list line… "
1042 echo "deb-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1045 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1051 if [ "$1" = '--no-update' ]; then
1055 buildaptarchive
"$@"
1056 if [ -e aptarchive
/dists
]; then
1057 setupdistsaptarchive
1061 signreleasefiles
'Joe Sixpack'
1062 if [ "1" != "$NOUPDATE" ]; then
1063 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
1067 signreleasefiles
() {
1068 local SIGNER
="${1:-Joe Sixpack}"
1069 local REPODIR
="${2:-aptarchive}"
1070 local KEY
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
1071 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
1072 msgninfo
"\tSign archive with $SIGNER key $KEY… "
1073 local REXKEY
='keys/rexexpired'
1074 local SECEXPIREBAK
="${REXKEY}.sec.bak"
1075 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
1076 if [ "${SIGNER}" = 'Rex Expired' ]; then
1077 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1078 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1079 # therefore we 'temporary' make the key not expired and restore a backup after signing
1080 cp "${REXKEY}.sec" "$SECEXPIREBAK"
1081 cp "${REXKEY}.pub" "$PUBEXPIREBAK"
1082 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
1083 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
1084 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1085 cp "$SECUNEXPIRED" "${REXKEY}.sec"
1086 cp "$PUBUNEXPIRED" "${REXKEY}.pub"
1088 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
1092 cp "${REXKEY}.sec" "$SECUNEXPIRED"
1093 cp "${REXKEY}.pub" "$PUBUNEXPIRED"
1096 for RELEASE
in $(find "${REPODIR}/" -name Release); do
1097 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output "${RELEASE}.gpg" "${RELEASE}"
1098 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
1099 $GPG --default-key "$SIGNER" --clearsign --output "$INRELEASE" "$RELEASE"
1100 # we might have set a specific date for the Release file, so copy it
1101 touch -d "$(stat --format "%y" ${RELEASE})" "${RELEASE}.gpg" "${INRELEASE}"
1103 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1104 mv -f "$SECEXPIREBAK" "${REXKEY}.sec"
1105 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub"
1110 redatereleasefiles
() {
1111 local DATE
="$(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
1112 for release
in $(find aptarchive/ -name 'Release'); do
1113 sed -i "s/^Date: .*$/Date: ${DATE}/" "$release"
1114 touch -d "$DATE" "$release"
1116 signreleasefiles
"${2:-Joe Sixpack}"
1120 local WEBSERVER
="${3:-http://localhost:${APTHTTPPORT}}"
1122 if [ "$1" = '--no-check' ]; then
1126 local DOWNLOG
='rootdir/tmp/download-testfile.log'
1127 local STATUS
='downloaded/webserverconfig.status'
1128 rm -f "$STATUS" "$DOWNLOG"
1129 # very very basic URI encoding
1131 if [ -n "$2" ]; then
1132 msgtest
"Set webserver config option '${1}' to" "$2"
1133 URI
="${WEBSERVER}/_config/set/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1135 msgtest
'Clear webserver config option' "${1}"
1136 URI
="${WEBSERVER}/_config/clear/$(echo "${1}" | sed -e 's/\//%2f/g')"
1138 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
1141 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.output"
1142 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1143 msgfailoutput
'' "$OUTPUT"
1145 $NOCHECK || testwebserverlaststatuscode
'200'
1148 rewritesourceslist
() {
1149 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1150 local APTARCHIVE2
="copy://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1151 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1152 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
1153 -e "s#http://localhost:${APTHTTPPORT}/#${1}#" \
1154 -e "s#https://localhost:${APTHTTPSPORT}/#${1}#"
1158 # wait for up to 10s for a pid file to appear to avoid possible race
1159 # when a helper is started and dosn't write the PID quick enough
1162 for i
in $(seq 10); do
1163 if test -s "$PIDFILE"; then
1168 msgdie
"waiting for $PIDFILE failed"
1172 changetowebserver
() {
1174 if [ "$1" != '--no-rewrite' ]; then
1179 if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
1181 local LOG
="webserver.log"
1182 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1186 waitforpidfile aptwebserver.pid
1187 local PID
="$(cat aptwebserver.pid)"
1188 if [ -z "$PID" ]; then
1189 msgdie
'Could not fork aptwebserver successfully'
1191 addtrap
"kill $PID;"
1192 waitforpidfile aptwebserver.port
1193 APTHTTPPORT
="$(cat aptwebserver.port)"
1194 if [ -z "$APTHTTPPORT" ]; then
1195 msgdie
'Could not get port for aptwebserver successfully'
1199 msgdie
'You have to build aptwerbserver or install a webserver'
1201 if [ "$REWRTE" != 'yes' ]; then
1202 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1206 changetohttpswebserver
() {
1207 if ! which stunnel4
>/dev
/null
; then
1208 msgdie
'You need to install stunnel4 for https testcases'
1210 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1211 changetowebserver
--no-rewrite "$@"
1213 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1214 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1219 connect = $APTHTTPPORT
1220 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1221 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1222 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1223 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1224 if [ -z "$PID" ]; then
1225 msgdie
'Could not fork stunnel4 successfully'
1227 addtrap
'prefix' "kill ${PID};"
1228 APTHTTPSPORT
="$(lsof -i | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1229 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1230 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1234 mkdir -p rootdir
/media
/cdrom
/.disk
1235 local CD
="$(readlink -f rootdir/media/cdrom)"
1236 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1237 acquire::cdrom::mount "${CD}";
1238 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1239 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1240 acquire::cdrom::autodetect 0;
1242 echo -n "$1" > "${CD}/.disk/info"
1243 if [ ! -d aptarchive
/dists
]; then
1244 msgdie
'Flat file archive cdroms can not be created currently'
1247 mv aptarchive
/dists
"$CD"
1248 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1249 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1250 # start with an unmounted disk
1251 mv "${CD}" "${CD}-unmounted"
1252 # we don't want the disk to be modifiable
1253 addtrap
'prefix' "chmod -f -R +w \"$PWD/rootdir/media/cdrom/dists/\" \"$PWD/rootdir/media/cdrom-unmounted/dists/\" || true;"
1254 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1258 local PROTO
="${1%%:*}"
1259 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1260 download
-file "$1" "$2" "$3" 2>&1 ; then
1263 # only if the file exists the download was successful
1264 if [ -r "$2" ]; then
1272 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1273 if [ -n "$DIFFTEXT" ]; then
1275 echo >&2 "$DIFFTEXT"
1283 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1284 local COMPAREFILE
="$1"
1286 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1289 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1290 cat "$COMPAREFILE" >>"${OUTPUT}"
1291 msgfailoutput
'' "$OUTPUT" "$@"
1296 msggroup
'testfileequal'
1297 local MSG
='Test for correctness of file'
1298 if [ "$1" = '--nomsg' ]; then
1304 if [ -n "$MSG" ]; then
1305 msgtest
"$MSG" "$FILE"
1307 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1308 if [ -z "$*" ]; then
1309 testoutputequal
"$FILE" echo -n ''
1311 testoutputequal
"$FILE" echo "$*"
1317 msggroup
'testempty'
1318 msgtest
"Test for no output of" "$*"
1319 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1320 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test ! -s "$COMPAREFILE"; then
1323 msgfailoutput
'' "$COMPAREFILE" "$@"
1325 aptautotest
'testempty' "$@"
1329 msggroup
'testnotempty'
1330 msgtest
"Test for some output of" "$*"
1331 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
1332 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then
1335 msgfailoutput
'' "$COMPAREFILE" "$@"
1337 aptautotest
'testnotempty' "$@"
1342 msggroup
'testequal'
1343 local MSG
='Test of equality of'
1344 if [ "$1" = '--nomsg' ]; then
1349 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1350 echo "$1" > "$COMPAREFILE"
1353 if [ -n "$MSG" ]; then
1356 testoutputequal
"$COMPAREFILE" "$@"
1357 aptautotest
'testequal' "$@"
1362 msggroup
'testequalor2'
1363 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1364 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1365 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1366 echo "$1" > "$COMPAREFILE1"
1367 echo "$2" > "$COMPAREFILE2"
1369 msgtest
"Test for equality OR of" "$*"
1370 "$@" >"$COMPAREAGAINST" 2>&1 || true
1371 if checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null
2>&1 || \
1372 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null
2>&1
1376 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1377 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1378 checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1379 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1380 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1381 msgfailoutput
'' "$OUTPUT"
1383 aptautotest
'testequalor2' "$@"
1388 msggroup
'testshowvirtual'
1389 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1392 while [ -n "$1" ]; do
1394 N: Can't select versions from package '$1' as it is purely virtual"
1395 PACKAGE
="${PACKAGE} $1"
1398 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1400 N: No packages found"
1401 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1402 local ARCH
="$(getarchitecture 'native')"
1403 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1404 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1405 testoutputequal
"$COMPAREFILE" aptcache show
-q=0 "$PACKAGE"
1410 msggroup
'testnopackage'
1411 msgtest
"Test for non-existent packages" "apt-cache show $*"
1412 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1413 if [ -n "$SHOWPKG" ]; then
1414 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1415 echo "$SHOWPKG" >"$OUTPUT"
1416 msgfailoutput
'' "$OUTPUT"
1424 msggroup
'testdpkgstatus'
1428 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1429 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1430 if [ "$PKGS" != $NR ]; then
1431 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1432 echo "$PKGS" >"$OUTPUT"
1433 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1434 msgfailoutput
'' "$OUTPUT"
1441 testdpkginstalled
() {
1442 msggroup
'testdpkginstalled'
1443 testdpkgstatus
'ii' "$#" "$@"
1447 testdpkgnotinstalled
() {
1448 msggroup
'testdpkgnotinstalled'
1449 testdpkgstatus
'ii' '0' "$@"
1454 msggroup
'testmarkedauto'
1455 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1456 if [ -n "$1" ]; then
1457 msgtest
'Test for correctly marked as auto-installed' "$*"
1458 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1460 msgtest
'Test for correctly marked as auto-installed' 'no package'
1461 echo -n > "$COMPAREFILE"
1463 testoutputequal
"$COMPAREFILE" aptmark showauto
1466 testmarkedmanual
() {
1467 msggroup
'testmarkedmanual'
1468 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1469 if [ -n "$1" ]; then
1470 msgtest
'Test for correctly marked as manually installed' "$*"
1471 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1473 msgtest
'Test for correctly marked as manually installed' 'no package'
1474 echo -n > "$COMPAREFILE"
1476 testoutputequal
"$COMPAREFILE" aptmark showmanual
1481 msgreportheader
'msgfailoutput'
1485 if [ "$1" = 'grep' ]; then
1487 while [ -n "$2" ]; do shift; done
1488 echo "#### Complete file: $1 ####"
1489 cat >&2 "$1" || true
1490 echo '#### grep output ####'
1491 elif [ "$1" = 'test' ]; then
1493 # doesn't support ! or non-file flags
1494 msgfailoutputstatfile
() {
1495 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1496 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1497 echo "#### stat(2) of file: $2 ####"
1499 if test -e "$2"; then
1500 echo "#### Complete file: $2 ####"
1501 cat >&2 "$2" || true
1505 msgfailoutputstatfile
"$2" "$3"
1506 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1508 msgfailoutputstatfile
"$2" "$3"
1510 echo '#### test output ####'
1517 msggroup
'testsuccess'
1518 if [ "$1" = '--nomsg' ]; then
1521 msgtest
'Test for successful execution of' "$*"
1523 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1524 if "$@" >"${OUTPUT}" 2>&1; then
1525 if expr match
"$1" '^apt.*' >/dev
/null
; then
1526 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1527 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1528 elif grep -E '^[WE]: ' "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1529 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1530 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1531 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1534 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1537 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1547 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1549 aptautotest
'testsuccess' "$@"
1553 msggroup
'testwarning'
1554 if [ "$1" = '--nomsg' ]; then
1557 msgtest
'Test for successful execution with warnings of' "$*"
1559 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1560 if "$@" >"${OUTPUT}" 2>&1; then
1561 if expr match
"$1" '^apt.*' >/dev
/null
; then
1562 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1563 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1564 elif grep -q -E '^E: ' "$OUTPUT"; then
1565 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1566 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1567 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1576 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1578 aptautotest
'testwarning' "$@"
1582 msggroup
'testfailure'
1583 if [ "$1" = '--nomsg' ]; then
1586 msgtest
'Test for failure in execution of' "$*"
1588 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1589 if "$@" >"${OUTPUT}" 2>&1; then
1591 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1594 if expr match
"$1" '^apt.*' >/dev
/null
; then
1595 if [ "$1" = 'aptkey' ]; then
1596 if grep -q -E " Can't check signature: " "$OUTPUT" || \
1597 grep -q -E " BAD signature from " "$OUTPUT"; then
1600 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1603 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1604 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1605 elif grep -q -E '==ERROR' "$OUTPUT"; then
1606 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1607 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1608 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1617 aptautotest
'testfailure' "$@"
1621 testreturnstateequal
() {
1623 msggroup
"${STATE}equal"
1624 if [ "$2" != '--nomsg' ]; then
1628 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1632 "$STATE" --nomsg "$@"
1633 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1637 testsuccessequal
() {
1638 testreturnstateequal
'testsuccess' "$@"
1640 testwarningequal
() {
1641 testreturnstateequal
'testwarning' "$@"
1643 testfailureequal
() {
1644 testreturnstateequal
'testfailure' "$@"
1648 msggroup
'testfailuremsg'
1652 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1653 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1654 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1655 testoutputequal
"$COMPAREFILE" echo "$CMP"
1659 msggroup
'testwarningmsg'
1663 msgtest
'Check that the output of the previous warned command has expected' 'warnings'
1664 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
1665 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
1666 testoutputequal
"$COMPAREFILE" echo "$CMP"
1671 msggroup
'testfilestats'
1672 msgtest
"Test that file $1 has $2 $3" "$4"
1673 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1676 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1679 echo -n "stat(1) reports for $2: "
1680 stat
--format "$2" "$1" || true
1682 msgfailoutput
'' "$OUTPUT"
1686 testaccessrights
() {
1687 msggroup
'testaccessrights'
1688 testfilestats
"$1" '%a' '=' "$2"
1692 testwebserverlaststatuscode
() {
1693 msggroup
'testwebserverlaststatuscode'
1694 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1695 local STATUS
='downloaded/webserverstatus-statusfile.log'
1696 rm -f "$DOWNLOG" "$STATUS"
1697 msgtest
'Test last status code from the webserver was' "$1"
1698 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1701 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1703 if [ -n "$2" ]; then
1705 echo >&2 '#### Additionally provided output files contain:'
1708 echo >&2 '#### Download log of the status code:'
1711 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1717 echo "STOPPED execution. Press enter to continue"
1722 listcurrentlistsdirectory
() {
1724 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1725 stat
--format '%U:%G:%a:%n' "$line"
1727 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1728 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1733 ### convenience hacks ###
1735 # creating some directories by hand is a tedious task, so make it look simple
1736 if [ "$*" = '-p rootdir/var/lib/apt/lists' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" ] ||
1737 [ "$*" = '-p rootdir/var/lib/apt/lists/partial' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" ]; then
1738 # only the last directory created by mkdir is effected by the -m !
1739 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1740 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1741 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1742 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1743 if [ "$(id -u)" = '0' ]; then
1744 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1751 ### The following tests are run by most test methods automatically to check
1752 ### general things about commands executed without writing the test every time.
1758 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d '-')"
1759 if command -v $AUTOTEST >/dev
/null
; then
1761 # save and restore the *.output files from other tests
1762 # as we might otherwise override them in these automatic tests
1763 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1764 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1765 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1766 $AUTOTEST "$TESTCALL" "$@"
1767 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1768 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1769 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1773 aptautotest_aptget_update
() {
1775 while [ -n "$2" ]; do
1776 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1779 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1780 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1781 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1782 # all copied files are properly chmodded
1783 local backupIFS
="$IFS"
1784 IFS
="$(printf "\n\b")"
1785 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1786 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1789 if [ "$TESTCALL" = 'testsuccess' ]; then
1790 # failure cases can retain partial files and such
1791 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
1794 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1795 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
1797 testaptautotestnodpkgwarning
() {
1799 while [ -n "$2" ]; do
1800 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
1801 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
1804 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1807 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
1808 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
1809 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
1810 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
1811 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
1812 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }