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 # Acquire::AllowInsecureRepositories=false is not yet the default
392 # but we want it to be the default soon
393 configallowinsecurerepositories "false
";
395 # cleanup the environment a bit
396 # prefer our apt binaries over the system apt binaries
397 export PATH="${BUILDDIRECTORY}:${PATH}:/usr
/local
/sbin
:/usr
/sbin
:/sbin
"
398 export LC_ALL=C.UTF-8
399 unset LANGUAGE APT_CONFIG
400 unset GREP_OPTIONS DEB_BUILD_PROFILES
405 if [ "$1" = "native
" -o -z "$1" ]; then
406 eval `aptconfig shell ARCH APT::Architecture`
407 if [ -n "$ARCH" ]; then
410 dpkg --print-architecture
418 aptconfig dump --no-empty --format '%v%n' APT::Architecture APT::Architectures | sort -u | tr '\n' ' '
421 getarchitecturesfromcommalist() {
422 echo "$1" | sed -e 's#,#\n#g' | sed -e "s
/^native\$
/$(getarchitecture 'native')/"
425 configarchitecture() {
427 echo "APT
::Architecture
\"$(getarchitecture $1)\";"
428 while [ -n "$1" ]; do
429 echo "APT
::Architectures
:: \"$(getarchitecture $1)\";"
432 } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
437 if [ ! -e rootdir/var/lib/dpkg/status ]; then
438 local BASENAME="${0##*/}"
439 local STATUSFILE="status
-${BASENAME#*-}"
440 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
441 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
443 echo -n > rootdir/var/lib/dpkg/status
446 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
447 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
448 local ARCHS="$(getarchitectures)"
449 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
450 DPKGARCH="$(dpkg --print-architecture)"
451 for ARCH in ${ARCHS}; do
452 if [ "${ARCH}" != "${DPKGARCH}" ]; then
453 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
454 # old-style used e.g. in Ubuntu-P – and as it seems travis
455 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
456 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
460 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
461 # dpkg doesn't really check the version as long as it is fully installed,
462 # but just to be sure we choose one above the required version
463 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
469 configdpkgnoopchroot() {
470 # create a library to noop chroot() and rewrite maintainer script executions
471 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
472 # chroot directory dpkg could chroot into to execute the maintainer scripts
473 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
474 cat > noopchroot.c << EOF
481 static char * chrootdir = NULL;
483 int chroot(const char *path) {
484 printf("WARNING
: CHROOTing to
%s was ignored
!\n", path);
486 chrootdir = strdup(path);
489 int execvp(const char *file, char *const argv[]) {
490 static int (*func_execvp) (const char *, char * const []) = NULL;
491 if (func_execvp == NULL)
492 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
");
493 if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0)
494 return func_execvp(file, argv);
495 printf("REWRITE execvp call
%s into
%s
\n", file, chrootdir);
496 char newfile[strlen(chrootdir) + strlen(file)];
497 strcpy(newfile, chrootdir);
498 strcat(newfile, file);
499 char const * const baseadmindir = "/var
/lib
/dpkg
";
500 char admindir[strlen(chrootdir) + strlen(baseadmindir)];
501 strcpy(admindir, chrootdir);
502 strcat(admindir, baseadmindir);
503 setenv("DPKG_ADMINDIR
", admindir, 1);
504 return func_execvp(newfile, argv);
507 testsuccess --nomsg gcc -fPIC -shared -o noopchroot.so noopchroot.c -ldl
510 configallowinsecurerepositories() {
511 echo "Acquire
::AllowInsecureRepositories
\"$1\";" > rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf
515 configcompression() {
516 while [ -n "$1" ]; do
518 '.') printf ".
\t.
\tcat
\n";;
519 'gz') printf "gzip\tgz
\tgzip
\n";;
520 'bz2') printf "bzip2\tbz
2\tbzip
2\n";;
521 'lzma') printf "lzma
\tlzma
\txz
--format=lzma
\n";;
522 'xz') printf "xz
\txz
\txz
\n";;
523 *) printf "$1\t$1\t$1\n";;
526 done > "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
"
530 echo 'APT::FTPArchive {'
532 while [ -n "$1" ]; do
533 printf "$1" | tr 'a-z' 'A-Z'
534 printf "\t\"true
\";\n"
537 for h in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
538 printf "$h\t\"false
\";\n"
542 } >> "${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/ftparchive
-hashes.conf
"
548 gzip) COMPRESS='gz';;
549 bzip2) COMPRESS='bz2';;
550 lzma) COMPRESS='lzma';;
552 *) msgdie "Compressor
$COMPRESSOR is unknown to framework
, so can
't be forced by forcecompressor!";;
554 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
555 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
556 Dir::Bin::uncompressed \"/does/not/exist\";
557 Dir::Bin::gzip \"/does/not/exist\";
558 Dir::Bin::bzip2 \"/does/not/exist\";
559 Dir::Bin::lzma \"/does/not/exist\";
560 Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
561 if [ -e "/bin/${COMPRESSOR}" ]; then
562 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
563 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
564 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
565 elif [ "${COMPRESSOR}" = 'lzma
' ]; then
566 echo 'Dir
::Bin
::xz
"/usr/bin/xz";' >> "$CONFFILE"
567 COMPRESSOR_CMD='xz
--format=lzma
'
569 msgtest 'Test
for availability of compressor
' "${COMPRESSOR}"
570 msgfail "${COMPRESSOR} not available"
574 setupsimplenativepackage() {
578 local RELEASE="${4:-unstable}"
579 local DEPENDENCIES="$5"
580 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
581 If you find such a package installed on your system,
582 something went horribly wrong! They are autogenerated
583 und used only by testcases and surf no other propose…"}"
585 local SECTION="${7:-others}"
587 if [ "$SECTION" = "${SECTION#*/}" ]; then
590 DISTSECTION="${SECTION%/*}"
592 local BUILDDIR=incoming/${NAME}-${VERSION}
593 mkdir -p ${BUILDDIR}/debian/source
595 echo "* most suckless software product ever" > FEATURES
596 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
597 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
601 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
602 test -e debian/control || echo "Source: $NAME
605 Maintainer: Joe Sixpack <joe@example.org>
606 Build-Depends: debhelper (>= 7)
607 Standards-Version: 3.9.1
609 Package: $NAME" > debian/control
610 if [ "$ARCH" = 'all
' ]; then
611 echo "Architecture: all" >> debian/control
613 echo "Architecture: any" >> debian/control
615 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
616 echo "Description: $DESCRIPTION" >> debian/control
618 test -e debian/compat || echo "7" > debian/compat
619 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
620 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
624 buildsimplenativepackage() {
627 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib
' ]; then
628 NM="$(echo "$NAME" | cut -c 1-4)"
630 NM="$(echo "$NAME" | cut -c 1)"
634 local RELEASE="${4:-unstable}"
635 local DEPENDENCIES="$5"
636 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
637 If you find such a package installed on your system,
638 something went horribly wrong! They are autogenerated
639 und used only by testcases and surf no other propose…"}"
641 local SECTION="${7:-others}"
642 local PRIORITY="${8:-optional}"
644 local COMPRESS_TYPE="${10:-gzip}"
646 if [ "$SECTION" = "${SECTION#*/}" ]; then
649 DISTSECTION="${SECTION%/*}"
651 local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
653 msgtest "Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
654 mkdir -p "$BUILDDIR/debian/source"
655 echo "* most suckless software product ever" > "${BUILDDIR}/FEATURES"
657 echo '$NAME says
\"Hello
!\"'" > "${BUILDDIR}/${NAME}"
659 echo "Copyleft by Joe Sixpack $(date +%Y)" > "${BUILDDIR}/debian/copyright"
660 echo "$NAME ($VERSION) $RELEASE; urgency=low
664 -- Joe Sixpack <joe@example.org> $(date -R)" > "${BUILDDIR}/debian/changelog"
668 Maintainer: Joe Sixpack <joe@example.org>
669 Standards-Version: 3.9.3"
670 if [ "$SECTION" != '<none
>' ]; then
671 echo "Section: $SECTION"
673 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
674 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
678 if [ "$ARCH" = 'all
' ]; then
679 echo "Architecture: all"
681 echo "Architecture: any"
683 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
684 test -z "$DEPS" || echo "$DEPS"
685 echo "Description: $DESCRIPTION"
686 } > "${BUILDDIR}/debian/control"
688 echo '3.0 (native
)' > "${BUILDDIR}/debian/source/format"
690 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
692 sed -n 's
#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" \
694 echo "pool/${SRC}" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist"
695 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
696 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
697 # adv --yes --default-key 'Joe Sixpack' \
698 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
699 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
703 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
704 msgtest
"Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
705 rm -rf "${BUILDDIR}/debian/tmp"
706 mkdir -p "${BUILDDIR}/debian/tmp/DEBIAN" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin"
707 cp "${BUILDDIR}/debian/copyright" "${BUILDDIR}/debian/changelog" "${BUILDDIR}/FEATURES" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}"
708 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}"
709 if [ -n "$FILE_TREE" ]; then
710 cp -ar "$FILE_TREE" "${BUILDDIR}/debian/tmp"
713 (cd "${BUILDDIR}"; dpkg
-gencontrol -DArchitecture=$arch)
714 (cd "${BUILDDIR}/debian/tmp"; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
715 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
716 # ensure the right permissions as dpkg-deb insists
717 chmod 755 "${BUILDDIR}/debian/tmp/DEBIAN"
718 testsuccess
--nomsg dpkg
-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian/tmp" "${BUILDDIR}/.."
719 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist"
722 local CHANGEPATH
="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}"
723 mkdir -p "$CHANGEPATH"
724 cp "${BUILDDIR}/debian/changelog" "$CHANGEPATH"
733 local ARCH
=$(getarchitecture $4)
734 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
735 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
736 msgtest
"Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
738 if [ "$ARCH" = "all" ]; then
739 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
741 testsuccess
--nomsg dpkg
-buildpackage -uc -us -a$ARCH
742 cp "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$BUILDLOG"
743 local PKGS
="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
744 local SRCS
="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
747 echo "pool/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist"
750 echo "pool/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist"
755 if [ -d incoming
]; then
756 buildaptarchivefromincoming
"$@"
758 buildaptarchivefromfiles
"$@"
762 createaptftparchiveconfig
() {
763 local COMPRESSORS
="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
764 local COMPRESSORS
="${COMPRESSORS%* }"
765 local ARCHS
="$(getarchitectures)"
766 cat > ftparchive.conf
<<EOF
768 ArchiveDir "$(readlink -f .)";
769 CacheDir "$(readlink -f ..)";
770 FileListDir "$(readlink -f pool/)";
773 Packages::Compress "$COMPRESSORS";
774 Sources::Compress "$COMPRESSORS";
775 Contents::Compress "$COMPRESSORS";
776 Translation::Compress "$COMPRESSORS";
777 LongDescription "false";
781 SrcDirectory "pool/";
784 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
787 Architectures "$ARCHS source";
788 FileList "${DIST}.\$(SECTION).pkglist";
789 SourceFileList "${DIST}.\$(SECTION).srclist";
790 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
793 done >> ftparchive.conf
796 buildaptftparchivedirectorystructure
() {
797 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
798 for DIST
in $DISTS; do
799 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
800 for SECTION
in $SECTIONS; do
801 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
802 for ARCH
in $ARCHS; do
803 mkdir -p "dists/${DIST}/${SECTION}/binary-${ARCH}"
805 mkdir -p "dists/${DIST}/${SECTION}/source"
806 mkdir -p "dists/${DIST}/${SECTION}/i18n"
816 local DEPENDENCIES
="$5"
817 local PRIORITY
="${6:-optional}"
818 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
819 If you find such a package installed on your system,
820 something went horribly wrong! They are autogenerated
821 und used only by testcases and surf no other propose…"}"
823 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
824 if [ "$RELEASE" = 'installed' ]; then
825 insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
828 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
829 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
830 ARCHS="$(getarchitectures)"
834 for BUILDARCH in $ARCHS; do
835 local PPATH="aptarchive
/dists
/${RELEASE}/main
/binary
-${BUILDARCH}"
842 Maintainer
: Joe Sixpack
<joe@example.org
>"
843 test "$arch" = 'none' || echo "Architecture
: $arch"
844 echo "Version
: $VERSION
845 Filename
: pool
/main
/${NAME}/${NAME}_
${VERSION}_
${arch}.deb
"
846 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES"
847 echo "Description
: $(printf '%s' "$DESCRIPTION" | head -n 1)"
848 echo "Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
850 } >> "${PPATH}/Packages
"
853 mkdir -p "aptarchive
/dists
/${RELEASE}/main
/source" "aptarchive
/dists
/${RELEASE}/main
/i18n
"
854 touch "aptarchive
/dists
/${RELEASE}/main
/source
/Sources
"
856 Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
857 Description
-en: $DESCRIPTION
858 " >> "aptarchive
/dists
/${RELEASE}/main
/i
18n
/Translation
-en"
867 local DEPENDENCIES="$5"
868 local BINARY="${6:-$NAME}"
870 local SPATH="aptarchive
/dists
/${RELEASE}/main
/source"
872 local FILE="${SPATH}/Sources
"
873 local DSCFILE="${NAME}_
${VERSION}.dsc
"
874 local TARFILE="${NAME}_
${VERSION}.
tar.gz
"
878 Maintainer
: Joe Sixpack
<joe@example.org
>
879 Architecture
: $ARCH" >> $FILE
880 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
882 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
883 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
885 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
886 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
890 insertinstalledpackage() {
894 local DEPENDENCIES="$4"
895 local PRIORITY="${5:-optional}"
896 local STATUS="${6:-install ok installed}"
897 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
898 If you
find such a package installed on your system
,
899 something went horribly wrong
! They are autogenerated
900 und used only by testcases and surf no other propose…
"}"
902 local FILE
='rootdir/var/lib/dpkg/status'
903 local INFO
='rootdir/var/lib/dpkg/info'
904 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
910 Maintainer: Joe Sixpack <joe@example.org>
911 Version: $VERSION" >> "$FILE"
912 test "$arch" = 'none' || echo "Architecture: $arch" >> "$FILE"
913 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
914 echo "Description: $DESCRIPTION" >> "$FILE"
916 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
917 echo -n > "${INFO}/${NAME}:${arch}.list"
919 echo -n > "${INFO}/${NAME}.list"
925 buildaptarchivefromincoming
() {
926 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on incoming packages…"
928 [ -e pool
] || ln -s ..
/incoming pool
929 [ -e ftparchive.conf
] || createaptftparchiveconfig
930 [ -e dists
] || buildaptftparchivedirectorystructure
931 msgninfo
"\tGenerate Packages, Sources and Contents files… "
932 testsuccess aptftparchive generate ftparchive.conf
935 generatereleasefiles
"$@"
938 buildaptarchivefromfiles
() {
939 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on prebuild files…"
940 local DIR
='aptarchive'
941 if [ -d "${DIR}/dists" ]; then DIR
="${DIR}/dists"; fi
942 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
943 msgninfo
"\t${line} file… "
944 compressfile
"$line" "$1"
947 generatereleasefiles
"$@"
951 cat "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | while read compressor extension
command; do
952 if [ "$compressor" = '.' ]; then
958 cat "$1" | $command > "${1}.${extension}"
960 touch -d "$2" "${1}.${extension}"
965 # can be overridden by testcases for their pleasure
966 getcodenamefromsuite
() {
968 unstable
) echo 'sid';;
972 getreleaseversionfromsuite
() { true
; }
973 getlabelfromsuite
() { true
; }
974 getoriginfromsuite
() { true
; }
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
982 msgninfo
"\tGenerate Release files… "
983 if [ -e aptarchive
/dists
]; then
984 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
985 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
986 local CODENAME
="$(getcodenamefromsuite $SUITE)"
987 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
988 local LABEL
="$(getlabelfromsuite $SUITE)"
989 local ORIGIN
="$(getoriginfromsuite $SUITE)"
990 if [ -n "$VERSION" ]; then
991 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
993 if [ -n "$LABEL" ]; then
994 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
996 if [ -n "$ORIGIN" ]; then
997 ORIGIN
="-o APT::FTPArchive::Release::Origin=${ORIGIN}"
999 aptftparchiverelease
"$dir" \
1000 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
1001 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
1006 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
1007 sed -i '/^Date: / a\
1008 NotAutomatic: yes' "$dir/Release"
1012 aptftparchiverelease .
/aptarchive
> aptarchive
/Release
1014 if [ -n "$1" -a "$1" != "now" ]; then
1015 for release
in $(find ./aptarchive -name 'Release'); do
1016 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" "$release"
1017 touch -d "$1" "$release"
1020 if [ -n "$2" ]; then
1021 sed -i "/^Date: / a\
1022 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release')
1027 setupdistsaptarchive
() {
1028 local APTARCHIVE
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1029 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
1030 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
1031 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1032 SECTIONS
=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1033 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
1034 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list"
1035 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list"
1040 setupflataptarchive
() {
1041 local APTARCHIVE
="$(readlink -f ./aptarchive)"
1042 local APTARCHIVEURI
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1043 if [ -f "${APTARCHIVE}/Packages" ]; then
1044 msgninfo
"\tadd deb sources.list line… "
1045 echo "deb file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1048 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1050 if [ -f "${APTARCHIVE}/Sources" ]; then
1051 msgninfo
"\tadd deb-src sources.list line… "
1052 echo "deb-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1055 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1061 if [ "$1" = '--no-update' ]; then
1065 buildaptarchive
"$@"
1066 if [ -e aptarchive
/dists
]; then
1067 setupdistsaptarchive
1071 signreleasefiles
'Joe Sixpack'
1072 if [ "1" != "$NOUPDATE" ]; then
1073 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
1077 signreleasefiles
() {
1078 local SIGNER
="${1:-Joe Sixpack}"
1079 local REPODIR
="${2:-aptarchive}"
1080 local KEY
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
1081 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
1082 msgninfo
"\tSign archive with $SIGNER key $KEY… "
1083 local REXKEY
='keys/rexexpired'
1084 local SECEXPIREBAK
="${REXKEY}.sec.bak"
1085 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
1086 if [ "${SIGNER}" = 'Rex Expired' ]; then
1087 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1088 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1089 # therefore we 'temporary' make the key not expired and restore a backup after signing
1090 cp "${REXKEY}.sec" "$SECEXPIREBAK"
1091 cp "${REXKEY}.pub" "$PUBEXPIREBAK"
1092 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
1093 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
1094 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1095 cp "$SECUNEXPIRED" "${REXKEY}.sec"
1096 cp "$PUBUNEXPIRED" "${REXKEY}.pub"
1098 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
1102 cp "${REXKEY}.sec" "$SECUNEXPIRED"
1103 cp "${REXKEY}.pub" "$PUBUNEXPIRED"
1106 for RELEASE
in $(find "${REPODIR}/" -name Release); do
1107 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output "${RELEASE}.gpg" "${RELEASE}"
1108 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
1109 $GPG --default-key "$SIGNER" --clearsign --output "$INRELEASE" "$RELEASE"
1110 # we might have set a specific date for the Release file, so copy it
1111 touch -d "$(stat --format "%y" ${RELEASE})" "${RELEASE}.gpg" "${INRELEASE}"
1113 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1114 mv -f "$SECEXPIREBAK" "${REXKEY}.sec"
1115 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub"
1120 redatereleasefiles
() {
1121 local DATE
="$(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
1122 for release
in $(find aptarchive/ -name 'Release'); do
1123 sed -i "s/^Date: .*$/Date: ${DATE}/" "$release"
1124 touch -d "$DATE" "$release"
1126 signreleasefiles
"${2:-Joe Sixpack}"
1130 local WEBSERVER
="${3:-http://localhost:${APTHTTPPORT}}"
1132 if [ "$1" = '--no-check' ]; then
1136 local DOWNLOG
='rootdir/tmp/download-testfile.log'
1137 local STATUS
='downloaded/webserverconfig.status'
1138 rm -f "$STATUS" "$DOWNLOG"
1139 # very very basic URI encoding
1141 if [ -n "$2" ]; then
1142 msgtest
"Set webserver config option '${1}' to" "$2"
1143 URI
="${WEBSERVER}/_config/set/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1145 msgtest
'Clear webserver config option' "${1}"
1146 URI
="${WEBSERVER}/_config/clear/$(echo "${1}" | sed -e 's/\//%2f/g')"
1148 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
1151 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.output"
1152 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1153 msgfailoutput
'' "$OUTPUT"
1155 $NOCHECK || testwebserverlaststatuscode
'200'
1158 rewritesourceslist
() {
1159 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1160 local APTARCHIVE2
="copy://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1161 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1162 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
1163 -e "s#http://localhost:${APTHTTPPORT}/#${1}#" \
1164 -e "s#https://localhost:${APTHTTPSPORT}/#${1}#"
1168 # wait for up to 10s for a pid file to appear to avoid possible race
1169 # when a helper is started and dosn't write the PID quick enough
1172 for i
in $(seq 10); do
1173 if test -s "$PIDFILE"; then
1178 msgdie
"waiting for $PIDFILE failed"
1182 changetowebserver
() {
1184 if [ "$1" != '--no-rewrite' ]; then
1189 if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
1191 local LOG
="webserver.log"
1192 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1196 waitforpidfile aptwebserver.pid
1197 local PID
="$(cat aptwebserver.pid)"
1198 if [ -z "$PID" ]; then
1199 msgdie
'Could not fork aptwebserver successfully'
1201 addtrap
"kill $PID;"
1202 waitforpidfile aptwebserver.port
1203 APTHTTPPORT
="$(cat aptwebserver.port)"
1204 if [ -z "$APTHTTPPORT" ]; then
1205 msgdie
'Could not get port for aptwebserver successfully'
1209 msgdie
'You have to build aptwerbserver or install a webserver'
1211 if [ "$REWRTE" != 'yes' ]; then
1212 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1216 changetohttpswebserver
() {
1217 if ! which stunnel4
>/dev
/null
; then
1218 msgdie
'You need to install stunnel4 for https testcases'
1220 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1221 changetowebserver
--no-rewrite "$@"
1223 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1224 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1229 connect = $APTHTTPPORT
1230 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1231 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1232 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1233 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1234 if [ -z "$PID" ]; then
1235 msgdie
'Could not fork stunnel4 successfully'
1237 addtrap
'prefix' "kill ${PID};"
1238 APTHTTPSPORT
="$(lsof -i | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1239 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1240 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1244 mkdir -p rootdir
/media
/cdrom
/.disk
1245 local CD
="$(readlink -f rootdir/media/cdrom)"
1246 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1247 acquire::cdrom::mount "${CD}";
1248 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1249 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1250 acquire::cdrom::autodetect 0;
1252 echo -n "$1" > "${CD}/.disk/info"
1253 if [ ! -d aptarchive
/dists
]; then
1254 msgdie
'Flat file archive cdroms can not be created currently'
1257 mv aptarchive
/dists
"$CD"
1258 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1259 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1260 # start with an unmounted disk
1261 mv "${CD}" "${CD}-unmounted"
1262 # we don't want the disk to be modifiable
1263 addtrap
'prefix' "chmod -f -R +w \"$PWD/rootdir/media/cdrom/dists/\" \"$PWD/rootdir/media/cdrom-unmounted/dists/\" || true;"
1264 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1268 local PROTO
="${1%%:*}"
1269 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1270 download
-file "$1" "$2" "$3" 2>&1 ; then
1273 # only if the file exists the download was successful
1274 if [ -r "$2" ]; then
1282 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1283 if [ -n "$DIFFTEXT" ]; then
1285 echo >&2 "$DIFFTEXT"
1293 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1294 local COMPAREFILE
="$1"
1296 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1299 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1300 cat "$COMPAREFILE" >>"${OUTPUT}"
1301 msgfailoutput
'' "$OUTPUT" "$@"
1306 msggroup
'testfileequal'
1307 local MSG
='Test for correctness of file'
1308 if [ "$1" = '--nomsg' ]; then
1314 if [ -n "$MSG" ]; then
1315 msgtest
"$MSG" "$FILE"
1317 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1318 if [ -z "$*" ]; then
1319 testoutputequal
"$FILE" echo -n ''
1321 testoutputequal
"$FILE" echo "$*"
1327 msggroup
'testempty'
1328 msgtest
"Test for no output of" "$*"
1329 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1330 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && 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
-q=0 "$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"
1434 msggroup
'testdpkgstatus'
1438 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1439 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1440 if [ "$PKGS" != $NR ]; then
1441 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1442 echo "$PKGS" >"$OUTPUT"
1443 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1444 msgfailoutput
'' "$OUTPUT"
1451 testdpkginstalled
() {
1452 msggroup
'testdpkginstalled'
1453 testdpkgstatus
'ii' "$#" "$@"
1457 testdpkgnotinstalled
() {
1458 msggroup
'testdpkgnotinstalled'
1459 testdpkgstatus
'ii' '0' "$@"
1464 msggroup
'testmarkedauto'
1465 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1466 if [ -n "$1" ]; then
1467 msgtest
'Test for correctly marked as auto-installed' "$*"
1468 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1470 msgtest
'Test for correctly marked as auto-installed' 'no package'
1471 echo -n > "$COMPAREFILE"
1473 testoutputequal
"$COMPAREFILE" aptmark showauto
1476 testmarkedmanual
() {
1477 msggroup
'testmarkedmanual'
1478 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1479 if [ -n "$1" ]; then
1480 msgtest
'Test for correctly marked as manually installed' "$*"
1481 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1483 msgtest
'Test for correctly marked as manually installed' 'no package'
1484 echo -n > "$COMPAREFILE"
1486 testoutputequal
"$COMPAREFILE" aptmark showmanual
1491 msgreportheader
'msgfailoutput'
1495 if [ "$1" = 'grep' ]; then
1497 while [ -n "$2" ]; do shift; done
1498 echo "#### Complete file: $1 ####"
1499 cat >&2 "$1" || true
1500 echo '#### grep output ####'
1501 elif [ "$1" = 'test' ]; then
1503 # doesn't support ! or non-file flags
1504 msgfailoutputstatfile
() {
1505 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1506 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1507 echo "#### stat(2) of file: $2 ####"
1509 if test -e "$2"; then
1510 echo "#### Complete file: $2 ####"
1511 cat >&2 "$2" || true
1515 msgfailoutputstatfile
"$2" "$3"
1516 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1518 msgfailoutputstatfile
"$2" "$3"
1520 echo '#### test output ####'
1527 msggroup
'testsuccess'
1528 if [ "$1" = '--nomsg' ]; then
1531 msgtest
'Test for successful execution of' "$*"
1533 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1534 if "$@" >"${OUTPUT}" 2>&1; then
1535 if expr match
"$1" '^apt.*' >/dev
/null
; then
1536 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1537 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1538 elif grep -E '^[WE]: ' "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1539 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1540 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1541 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1544 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1547 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1557 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1559 aptautotest
'testsuccess' "$@"
1563 msggroup
'testwarning'
1564 if [ "$1" = '--nomsg' ]; then
1567 msgtest
'Test for successful execution with warnings of' "$*"
1569 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1570 if "$@" >"${OUTPUT}" 2>&1; then
1571 if expr match
"$1" '^apt.*' >/dev
/null
; then
1572 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1573 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1574 elif grep -q -E '^E: ' "$OUTPUT"; then
1575 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1576 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1577 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1586 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1588 aptautotest
'testwarning' "$@"
1592 msggroup
'testfailure'
1593 if [ "$1" = '--nomsg' ]; then
1596 msgtest
'Test for failure in execution of' "$*"
1598 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1599 if "$@" >"${OUTPUT}" 2>&1; then
1601 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1604 if expr match
"$1" '^apt.*' >/dev
/null
; then
1605 if [ "$1" = 'aptkey' ]; then
1606 if grep -q -E " Can't check signature: " "$OUTPUT" || \
1607 grep -q -E " BAD signature from " "$OUTPUT"; then
1610 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1613 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1614 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1615 elif grep -q -E '==ERROR' "$OUTPUT"; then
1616 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1617 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1618 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1627 aptautotest
'testfailure' "$@"
1631 testreturnstateequal
() {
1633 msggroup
"${STATE}equal"
1634 if [ "$2" != '--nomsg' ]; then
1638 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1642 "$STATE" --nomsg "$@"
1643 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1647 testsuccessequal
() {
1648 testreturnstateequal
'testsuccess' "$@"
1650 testwarningequal
() {
1651 testreturnstateequal
'testwarning' "$@"
1653 testfailureequal
() {
1654 testreturnstateequal
'testfailure' "$@"
1658 msggroup
'testfailuremsg'
1662 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1663 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1664 grep '^\(W\|E\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1665 testoutputequal
"$COMPAREFILE" echo "$CMP"
1670 msggroup
'testfilestats'
1671 msgtest
"Test that file $1 has $2 $3" "$4"
1672 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1675 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1678 echo -n "stat(1) reports for $2: "
1679 stat
--format "$2" "$1" || true
1681 msgfailoutput
'' "$OUTPUT"
1685 testaccessrights
() {
1686 msggroup
'testaccessrights'
1687 testfilestats
"$1" '%a' '=' "$2"
1691 testwebserverlaststatuscode
() {
1692 msggroup
'testwebserverlaststatuscode'
1693 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1694 local STATUS
='downloaded/webserverstatus-statusfile.log'
1695 rm -f "$DOWNLOG" "$STATUS"
1696 msgtest
'Test last status code from the webserver was' "$1"
1697 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1700 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1702 if [ -n "$2" ]; then
1704 echo >&2 '#### Additionally provided output files contain:'
1707 echo >&2 '#### Download log of the status code:'
1710 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1716 echo "STOPPED execution. Press enter to continue"
1721 listcurrentlistsdirectory
() {
1723 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1724 stat
--format '%U:%G:%a:%n' "$line"
1726 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1727 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1732 ### convenience hacks ###
1734 # creating some directories by hand is a tedious task, so make it look simple
1735 if [ "$*" = '-p rootdir/var/lib/apt/lists' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" ] ||
1736 [ "$*" = '-p rootdir/var/lib/apt/lists/partial' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" ]; then
1737 # only the last directory created by mkdir is effected by the -m !
1738 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1739 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1740 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1741 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1742 if [ "$(id -u)" = '0' ]; then
1743 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1750 ### The following tests are run by most test methods automatically to check
1751 ### general things about commands executed without writing the test every time.
1757 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d '-')"
1758 if command -v $AUTOTEST >/dev
/null
; then
1760 # save and restore the *.output files from other tests
1761 # as we might otherwise override them in these automatic tests
1762 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1763 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1764 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1765 $AUTOTEST "$TESTCALL" "$@"
1766 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1767 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1768 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1772 aptautotest_aptget_update
() {
1774 while [ -n "$2" ]; do
1775 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1778 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1779 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1780 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1781 # all copied files are properly chmodded
1782 local backupIFS
="$IFS"
1783 IFS
="$(printf "\n\b")"
1784 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1785 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1788 if [ "$TESTCALL" = 'testsuccess' ]; then
1789 # failure cases can retain partial files and such
1790 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
1793 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1794 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
1796 testaptautotestnodpkgwarning
() {
1798 while [ -n "$2" ]; do
1799 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
1800 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
1803 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1806 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
1807 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
1808 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
1809 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
1810 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
1811 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }