1 #!/bin/sh -- # no runable script, just for vi
6 if [ "$1" = "-q" ]; then
8 elif [ "$1" = "-v" ]; then
10 elif [ "$1" = '--color=no' ]; then
12 elif [ "$1" = '--color=yes' ]; then
14 elif [ "$1" = '--color' ]; then
15 export MSGCOLOR
="$(echo "$2" | tr 'a-z' 'A-Z')"
17 elif [ "$1" = '--level' ]; then
21 echo >&2 "WARNING: Unknown parameter »$1« will be ignored"
25 export MSGLEVEL
="${MSGLEVEL:-3}"
27 # we all like colorful messages
28 if [ "${MSGCOLOR:-YES}" = 'YES' ]; then
29 if [ ! -t 1 ]; then # but check that we output to a terminal
35 if [ "$MSGCOLOR" != 'NO' ]; then
36 CERROR
="\033[1;31m" # red
37 CWARNING
="\033[1;33m" # yellow
38 CMSG
="\033[1;32m" # green
39 CINFO
="\033[1;96m" # light blue
40 CDEBUG
="\033[1;94m" # blue
41 CNORMAL
="\033[0;39m" # default system console color
42 CDONE
="\033[1;32m" # green
43 CPASS
="\033[1;32m" # green
44 CFAIL
="\033[1;31m" # red
45 CCMD
="\033[1;35m" # pink
57 printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghks]\)#apt-\1#')"
63 msgdie
() { msgprintf
"${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; }
64 msgwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; }
65 msgmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; }
66 msginfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; }
67 msgdebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; }
68 msgdone
() { msgprintf
"${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; }
69 msgnwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; }
70 msgnmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}" "$@"; }
71 msgninfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
72 msgndebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
73 msgtest
() { msgprintf
"${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
74 msgpass
() { printf "${CPASS}PASS${CNORMAL}\n"; }
76 if [ -n "$MSGTEST_MSG" ]; then
77 test "$1" != 'msgfailoutput' || echo
78 if [ -n "$MSGTEST_MSGMSG" ]; then
79 echo "$MSGTEST_MSGMSG"
81 if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then
82 echo "${CFAIL}Part of the test group: $MSGTEST_GRP"
84 echo -n "$MSGTEST_MSG"
89 msgreportheader
'msgskip'
90 if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
91 else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
94 msgreportheader
'msgfail'
95 if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
96 else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
97 if [ -n "$APT_DEBUG_TESTS" ]; then
100 EXIT_CODE
=$((EXIT_CODE+1));
105 if [ $MSGGROUP_LEVEL = 0 ]; then
108 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL+1));
110 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL-1));
111 if [ $MSGGROUP_LEVEL = 0 ]; then
117 # enable / disable Debugging
118 if [ $MSGLEVEL -le 0 ]; then
121 if [ $MSGLEVEL -le 1 ]; then
125 if [ $MSGLEVEL -le 2 ]; then
127 MSGTEST_MSGMSG
="$(msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@")"
131 MSGTEST_MSG
="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")"
132 if [ "$MSGTEST_GRP" = 'NEXT' ]; then
133 MSGTEST_GRP
="$MSGTEST_MSG"
136 msgpass
() { printf " ${CPASS}P${CNORMAL}"; }
138 if [ $MSGLEVEL -le 3 ]; then
142 if [ $MSGLEVEL -le 4 ]; then
144 msgndebug
() { true
; }
147 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
148 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
149 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
150 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
151 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
154 printf "${CDONE}DONE${CNORMAL}\n";
158 if [ -f .
/aptconfig.conf
]; then
159 echo "$(readlink -f ./aptconfig.conf)"
160 elif [ -f ..
/aptconfig.conf
]; then
161 echo "$(readlink -f ../aptconfig.conf)"
162 elif [ -f ..
/..
/aptconfig.conf
]; then
163 echo "$(readlink -f ../../aptconfig.conf)"
164 elif [ -f "${TMPWORKINGDIRECTORY}/aptconfig.conf" ]; then
165 echo "$(readlink -f "${TMPWORKINGDIRECTORY}/aptconfig.conf")"
169 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
173 sh
|aptitude
|*/*|command) ;;
174 *) CMD
="${BUILDDIRECTORY}/$CMD";;
176 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
="${LIBRARYPATH}:${LD_LIBRARY_PATH}" "$CMD" "$@"
178 runpython3
() { runapt
command python3
"$@"; }
179 aptconfig
() { runapt apt
-config "$@"; }
180 aptcache
() { runapt apt
-cache "$@"; }
181 aptcdrom
() { runapt apt
-cdrom "$@"; }
182 aptget
() { runapt apt
-get "$@"; }
183 aptftparchive
() { runapt
"${APTFTPARCHIVEBINDIR}/apt-ftparchive" "$@"; }
184 aptkey
() { runapt apt
-key "$@"; }
185 aptmark
() { runapt apt
-mark "$@"; }
186 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; }
187 apt
() { runapt apt
"$@"; }
188 apthelper
() { runapt
"${APTHELPERBINDIR}/apt-helper" "$@"; }
189 aptwebserver
() { runapt
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
190 aptitude
() { runapt aptitude
"$@"; }
191 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; }
192 aptinternalsolver
() { runapt
"${APTINTERNALSOLVER}" "$@"; }
193 aptdumpsolver
() { runapt
"${APTDUMPSOLVER}" "$@"; }
194 aptinternalplanner
() { runapt
"${APTINTERNALPLANNER}" "$@"; }
197 "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@"
199 dpkgcheckbuilddeps
() {
200 command dpkg
-checkbuilddeps --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" "$@"
205 aptget
) CMD
="apt-get";;
206 aptcache
) CMD
="apt-cache";;
207 aptcdrom
) CMD
="apt-cdrom";;
208 aptconfig
) CMD
="apt-config";;
209 aptmark
) CMD
="apt-mark";;
210 apthelper
) CMD
="apt-helper";;
211 aptftparchive
) CMD
="apt-ftparchive";;
212 dpkg
) shift; runapt
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" "$@"; return;;
216 if [ "${CMD##*/}" = "$CMD" ]; then
217 CMD
="${BUILDDIRECTORY}/${CMD}"
219 runapt
command gdb
--quiet -ex run
"$CMD" --args "$CMD" "$@"
222 date -u -d "@$(stat -c '%Y' "${TMPWORKINGDIRECTORY}/$1")" -R
225 grep "^${2:-Date}:" "$1" | cut
-d' ' -f 2-
229 # error if we about to overflow, but ...
230 # "255 failures ought to be enough for everybody"
231 if [ $EXIT_CODE -gt 255 ]; then
232 msgdie
"Total failure count $EXIT_CODE too big"
234 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
237 shellsetedetector
() {
239 if [ "$exit_status" != '0' ]; then
240 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
241 if [ "$EXIT_CODE" = '0' ]; then
242 EXIT_CODE
="$exit_status"
248 if [ "$1" = 'prefix' ]; then
249 CURRENTTRAP
="$2 $CURRENTTRAP"
251 CURRENTTRAP
="$CURRENTTRAP $1"
253 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
257 echo "$@" | sed -e "s#'#'\"'\"'#g"
261 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
262 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
265 TMPWORKINGDIRECTORY
="$(mktemp -d)"
266 addtrap
"cd /; rm -rf '$(escape_shell "$TMPWORKINGDIRECTORY")';"
267 if [ -n "$TMPDIR_ADD" ]; then
268 TMPWORKINGDIRECTORY
="${TMPWORKINGDIRECTORY}/${TMPDIR_ADD}"
269 mkdir -p "$TMPWORKINGDIRECTORY"
271 export TMPDIR
="$TMPWORKINGDIRECTORY"
273 msgninfo
"Preparing environment for ${0##*/} in ${TMPWORKINGDIRECTORY}…"
275 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
276 if [ "$(id -u)" = '0' ]; then
277 # relax permissions so that running as root with user switching works
279 chmod 711 "$TMPWORKINGDIRECTORY"
280 chown _apt
:root
"${TMPWORKINGDIRECTORY}/downloaded"
283 TESTDIRECTORY
="$(readlink -f "$(dirname $0)")"
284 # allow overriding the default BUILDDIR location
285 SOURCEDIRECTORY="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}"
286 BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/cmdline"}"
287 LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}/../apt-pkg"}"
288 METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/../methods"}"
289 APTHELPERBINDIR="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}"
290 APTWEBSERVERBINDIR="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}/../test/interactive-helper"}"
291 APTFTPARCHIVEBINDIR="${APT_INTEGRATION_TESTS_FTPARCHIVE_BIN_DIR:-"${BUILDDIRECTORY}/../ftparchive"}"
292 APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/solvers/apt"}"
293 APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/solvers/dump"}"
294 APTINTERNALPLANNER="${APT_INTEGRATION_TESTS_INTERNAL_PLANNER:-"${BUILDDIRECTORY}/planners/apt"}"
295 test -x "${BUILDDIRECTORY}/apt
-get" || msgdie "You need to build tree first
"
298 cd "$TMPWORKINGDIRECTORY"
299 mkdir rootdir aptarchive keys
301 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
302 mkdir -p usr/bin var/cache var/lib var/log var/crash tmp
303 mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
304 mkdir -p usr/lib/apt/solvers usr/lib/apt/planners
305 touch var/lib/dpkg/available
306 ln -s "${METHODSDIR}" usr/lib/apt/methods
307 ln -s "${APTDUMPSOLVER}" usr/lib/apt/solvers/dump
308 ln -s "${APTDUMPSOLVER}" usr/lib/apt/planners/dump
309 ln -s "${APTINTERNALSOLVER}" usr/lib/apt/solvers/apt
310 ln -s "${APTINTERNALPLANNER}" usr/lib/apt/planners/apt
311 echo "Dir
::Bin
::Solvers
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/solvers
\";" >> ../aptconfig.conf
312 echo "Dir
::Bin
::Planners
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/planners
\";" >> ../aptconfig.conf
313 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
315 if [ -e "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" ]; then
316 ln -s "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" etc/apt/apt.conf.d/01autoremove
318 ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
321 local BASENAME="${0##*/}"
322 local PACKAGESFILE="Packages
-${BASENAME#*-}"
323 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
324 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
326 local SOURCESSFILE="Sources
-${BASENAME#*-}"
327 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
328 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
330 find "$TESTDIRECTORY" \( -name '*.pub' -o -name '*.sec' \) -exec cp '{}' keys/ \;
332 ln -s "${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub
" rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
334 echo "Dir
\"${TMPWORKINGDIRECTORY}/rootdir
\";" >> aptconfig.conf
335 echo "APT
::Get
::Show
-User-Simulation-Note \"false
\";" >> aptconfig.conf
336 echo "Dir
::Bin
::Methods
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/methods
\";" >> aptconfig.conf
337 # either store apt-key were we can access it, even if we run it as a different user
338 #cp "${BUILDDIRECTORY}/apt
-key" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/"
339 #chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key"
340 #echo "Dir
::Bin
::apt
-key \"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key\";" >> aptconfig.conf
341 # destroys coverage reporting though, so we disable changing user for the calling gpgv
342 echo "Dir
::Bin
::apt
-key \"${BUILDDIRECTORY}/apt
-key\";" >> aptconfig.conf
343 if [ "$(id -u)" = '0' ]; then
344 echo 'Binary::gpgv::APT::Sandbox::User "root
";' >> aptconfig.conf
345 # same for the solver executables
346 echo 'APT::Solver::RunAsUser "root
";' >> aptconfig.conf
347 echo 'APT::Planner::RunAsUser "root
";' >> aptconfig.conf
350 cat > "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
353 if [ -r '${TMPWORKINGDIRECTORY}/noopchroot.so' ]; then
354 if [ -n "\
$LD_LIBRARY_PATH" ]; then
355 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}:'"\
${LD_LIBRARY_PATH}"
357 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}'
359 if [ -n "\
$LD_PRELOAD" ]; then
360 export LD_PRELOAD="noopchroot.so \
${LD_PRELOAD}"
362 export LD_PRELOAD="noopchroot.so
"
366 cp "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
367 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
368 exec fakeroot '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
369 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
370 --force-not-root --force-bad-path "\$@
"
372 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg" <<EOF
373 exec fakeroot gdb --quiet -ex run '${DPKG:-dpkg}' --args '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
374 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
375 --force-not-root --force-bad-path "\$@
"
377 chmod +x "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
378 echo "Dir
::Bin
::dpkg
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
\";" > rootdir/etc/apt/apt.conf.d/99dpkg
381 if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
382 echo "DPKG
::options
:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
385 echo 'quiet::NoUpdate "true
";'
386 echo 'quiet::NoStatistic "true
";'
387 # too distracting for users, but helpful to detect changes
388 echo 'Acquire::Progress::Ignore::ShowErrorText "true
";'
389 echo 'Acquire::Progress::Diffpercent "true
";'
390 # in testcases, it can appear as if localhost has a rotation setup,
391 # hide this as we can't really deal with it properly
392 echo 'Acquire::Failure::ShowIP "false
";'
393 # fakeroot can't fake everything, so disabled in production but good for tests
394 echo 'APT::Sandbox::Verify "true
";'
397 cp "${TESTDIRECTORY}/apt.pem
" "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
398 if [ "$(id -u)" = '0' ]; then
399 chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
401 echo "Acquire
::https
::CaInfo
\"${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
\";" > rootdir/etc/apt/apt.conf.d/99https
402 echo "Apt
::Cmd
::Disable
-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
403 export APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=no
404 echo 'Acquire::Connect::AddrConfig "false
";' > rootdir/etc/apt/apt.conf.d/connect-addrconfig
406 configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
407 confighashes 'SHA256' # these are tests, not security best-practices
409 # create some files in /tmp and look at user/group to get what this means
410 TEST_DEFAULT_USER="$(id -un)"
411 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
412 TEST_DEFAULT_GROUP='root'
414 TEST_DEFAULT_GROUP="$(id -gn)"
417 # cleanup the environment a bit
418 # prefer our apt binaries over the system apt binaries
419 export PATH="${BUILDDIRECTORY}:${PATH}:/usr
/local
/sbin
:/usr
/sbin
:/sbin
"
420 export LC_ALL=C.UTF-8
421 unset LANGUAGE APT_CONFIG
422 unset GREP_OPTIONS DEB_BUILD_PROFILES
423 unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy
425 # If gpgv supports --weak-digest, pass it to make sure we can disable SHA1
426 if aptkey verify --weak-digest SHA1 --help 2>/dev/null >/dev/null; then
427 echo 'Acquire::gpgv::Options { "--weak-digest"; "sha1
"; };' > rootdir/etc/apt/apt.conf.d/no-sha1
430 # most tests just need one signed Release file, not both
431 export APT_DONT_SIGN='Release.gpg'
433 if [ -r "${TESTDIRECTORY}/extra
-environment" ]; then
434 . "${TESTDIRECTORY}/extra
-environment"
441 if [ "$1" = "native
" -o -z "$1" ]; then
442 eval `aptconfig shell ARCH APT::Architecture`
443 if [ -n "$ARCH" ]; then
446 dpkg --print-architecture
454 aptconfig dump --no-empty --format '%v%n' APT::Architecture APT::Architectures | sort -u | tr '\n' ' '
457 getarchitecturesfromcommalist() {
458 echo "$1" | sed -e 's#,#\n#g' | sed -e "s
/^native\$
/$(getarchitecture 'native')/"
461 configarchitecture() {
463 echo "APT
::Architecture
\"$(getarchitecture $1)\";"
464 while [ -n "$1" ]; do
465 echo "APT
::Architectures
:: \"$(getarchitecture $1)\";"
468 } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
473 if [ ! -e rootdir/var/lib/dpkg/status ]; then
474 local BASENAME="${0##*/}"
475 local STATUSFILE="status
-${BASENAME#*-}"
476 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
477 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
479 echo -n > rootdir/var/lib/dpkg/status
482 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
483 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
484 local ARCHS="$(getarchitectures)"
485 local DPKGARCH="$(dpkg --print-architecture)"
486 # this ensures that even if multi-arch isn't active in the view
487 # of apt, given that dpkg can't be told which arch is native
488 # the arch apt treats as native might be foreign for dpkg
489 for ARCH in ${ARCHS}; do
490 if [ "${ARCH}" != "${DPKGARCH}" ]; then
491 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
492 # old-style used e.g. in Ubuntu-P – and as it seems travis
493 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
494 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
498 # if multi-arch make sure dpkg can detect itself as capable of it
499 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
500 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
501 # dpkg doesn't really check the version as long as it is fully installed,
502 # but just to be sure we choose one above the required version
503 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
509 configdpkgnoopchroot() {
510 # create a library to noop chroot() and rewrite maintainer script executions
511 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
512 # chroot directory dpkg could chroot into to execute the maintainer scripts
513 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
514 cat > noopchroot.c << EOF
521 static char * chrootdir = NULL;
523 int chroot(const char *path) {
524 printf("WARNING
: CHROOTing to
%s was ignored
!\n", path);
526 chrootdir = strdup(path);
529 int execvp(const char *file, char *const argv[]) {
530 static int (*func_execvp) (const char *, char * const []) = NULL;
531 if (func_execvp == NULL)
532 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
");
533 if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0)
534 return func_execvp(file, argv);
535 printf("REWRITE execvp call
%s into
%s
\n", file, chrootdir);
537 if (asprintf(&newfile, "%s
%s
", chrootdir, file) == -1) {
541 char const * const baseadmindir = "/var
/lib
/dpkg
";
543 if (asprintf(&admindir, "%s
%s
", chrootdir, baseadmindir) == -1) {
547 setenv("DPKG_ADMINDIR
", admindir, 1);
548 return func_execvp(newfile, argv);
551 testempty --nomsg gcc -Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c -ldl
553 configcompression() {
554 if [ "$1" = 'ALL' ]; then
555 configcompression '.' $(aptconfig dump APT::Compressor --format '%t %v%n' | sed -n 's#^Extension \.\(.*\)$#\1#p')
558 local CMD='apthelper cat-file -C'
559 while [ -n "$1" ]; do
561 '.') printf ".
\t.
\tcat
\n";;
562 'gz') printf "gzip\tgz
\t$CMD $1\n";;
563 'bz2') printf "bzip2\tbz
2\t$CMD $1\n";;
564 *) printf "$1\t$1\t$CMD $1\n";;
567 done > "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
"
571 echo 'APT::FTPArchive {'
573 while [ -n "$1" ]; do
574 printf "$1" | tr 'a-z' 'A-Z'
575 printf "\t\"true
\";\n"
578 for h in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
579 printf "$h\t\"false
\";\n"
583 } >> "${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/ftparchive
-hashes.conf
"
588 COMPRESSOR_CMD="apthelper
cat-file -C $1"
590 gzip) COMPRESS='gz';;
591 bzip2) COMPRESS='bz2';;
593 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/00force
-compressor"
594 echo "Acquire
::CompressionTypes
::Order
{ \"${COMPRESS}\"; };
595 Dir
::Bin
::uncompressed
\"/does
/not
/exist
\";" > "$CONFFILE"
596 for COMP in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
597 if [ -z "$COMP" -o "$COMP" = '.' -o "$COMP" = "$COMPRESSOR" ]; then continue; fi
598 echo "Dir
::Bin
::${COMP} \"/does
/not
/exist
\";" >> "$CONFFILE"
599 echo "APT
::Compressor
::${COMP}::Name
\"${COMP}-disabled\";" >> "$CONFFILE"
603 _setupsimplenativepackage() {
607 local RELEASE="${4:-unstable}"
608 local DEPENDENCIES="$5"
609 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
610 If you
find such a package installed on your system
,
611 something went horribly wrong
! They are autogenerated
612 und used only by testcases and serve no other purpose…
"}"
614 local SECTION
="${7:-others}"
615 local PRIORITY
="${8:-optional}"
617 local COMPRESS_TYPE
="${10:-gzip}"
619 if [ "$SECTION" = "${SECTION#*/}" ]; then
622 DISTSECTION
="${SECTION%/*}"
624 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
626 mkdir -p "$BUILDDIR/debian/source"
627 echo "* most suckless software product ever" > "${BUILDDIR}/FEATURES"
629 echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}"
631 echo "Copyleft by Joe Sixpack $(date -u +%Y)" > "${BUILDDIR}/debian/copyright"
632 echo "$NAME ($VERSION) $RELEASE; urgency=low
636 -- Joe Sixpack <joe@example.org> $(date -u -R)" > "${BUILDDIR}/debian/changelog"
640 Maintainer: Joe Sixpack <joe@example.org>
641 Standards-Version: 3.9.3"
642 if [ "$SECTION" != '<none>' ]; then
643 echo "Section: $SECTION"
645 local BUILDDEPS
="$(echo "$DEPENDENCIES" | grep '^Build-')"
646 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
650 if [ "$ARCH" = 'all' ]; then
651 echo "Architecture: all"
653 echo "Architecture: any"
655 local DEPS
="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
656 test -z "$DEPS" || echo "$DEPS"
657 echo "Description: $DESCRIPTION"
658 } > "${BUILDDIR}/debian/control"
660 echo '3.0 (native)' > "${BUILDDIR}/debian/source/format"
663 setupsimplenativepackage
() {
664 _setupsimplenativepackage
"$@"
667 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
668 test -e "${BUILDDIR}/debian/compat" || echo '7' > "${BUILDDIR}/debian/compat"
669 test -e "${BUILDDIR}/debian/rules" || cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny
"${BUILDDIR}/debian/rules"
672 buildsimplenativepackage
() {
676 local RELEASE
="${4:-unstable}"
677 local DEPENDENCIES
="$5"
678 local DESCRIPTION
="$6"
679 local SECTION
="${7:-others}"
680 local PRIORITY
="${8:-optional}"
682 local COMPRESS_TYPE
="${10:-gzip}"
684 if [ "$SECTION" = "${SECTION#*/}" ]; then
687 DISTSECTION
="${SECTION%/*}"
689 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
690 msgtest
"Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
691 _setupsimplenativepackage
"$@"
693 testsuccess
--nomsg dpkg
-source -b ${NAME}-${VERSION}
695 sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" \
697 echo "pool/${SRC}" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist"
698 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
699 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
700 # adv --yes --default-key 'Joe Sixpack' \
701 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
702 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
706 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
707 msgtest
"Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
708 rm -rf "${BUILDDIR}/debian/tmp"
709 mkdir -p "${BUILDDIR}/debian/tmp/DEBIAN" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin"
710 cp "${BUILDDIR}/debian/copyright" "${BUILDDIR}/debian/changelog" "${BUILDDIR}/FEATURES" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}"
711 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}"
712 if [ -n "$FILE_TREE" ]; then
713 cp -ar "$FILE_TREE" "${BUILDDIR}/debian/tmp"
716 (cd "${BUILDDIR}"; dpkg
-gencontrol -DArchitecture=$arch)
717 (cd "${BUILDDIR}/debian/tmp"; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
718 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
719 # ensure the right permissions as dpkg-deb insists
720 chmod 755 "${BUILDDIR}/debian/tmp/DEBIAN"
721 testsuccess
--nomsg dpkg
-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian/tmp" "${BUILDDIR}/.."
722 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist"
726 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then
727 NM
="$(echo "$NAME" | cut -c 1-4)"
729 NM
="$(echo "$NAME" | cut -c 1)"
731 local CHANGEPATH
="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}"
732 mkdir -p "$CHANGEPATH"
733 cp "${BUILDDIR}/debian/changelog" "$CHANGEPATH"
742 local ARCH
=$(getarchitecture $4)
743 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
744 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
745 msgtest
"Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
747 if [ "$ARCH" = "all" ]; then
748 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
750 testsuccess
--nomsg dpkg
-buildpackage -uc -us -a$ARCH
751 cp "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$BUILDLOG"
752 local PKGS
="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
753 local SRCS
="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
756 echo "pool/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist"
759 echo "pool/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist"
764 if [ -d incoming
]; then
765 buildaptarchivefromincoming
"$@"
767 buildaptarchivefromfiles
"$@"
771 createaptftparchiveconfig
() {
772 local COMPRESSORS
="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
773 local COMPRESSORS
="${COMPRESSORS%* }"
774 local ARCHS
="$(getarchitectures)"
775 cat > ftparchive.conf
<<EOF
777 ArchiveDir "$(readlink -f .)";
778 CacheDir "$(readlink -f ..)";
779 FileListDir "$(readlink -f pool/)";
782 Packages::Compress "$COMPRESSORS";
783 Sources::Compress "$COMPRESSORS";
784 Contents::Compress "$COMPRESSORS";
785 Translation::Compress "$COMPRESSORS";
786 LongDescription "false";
790 SrcDirectory "pool/";
793 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
796 Architectures "$ARCHS all source";
797 FileList "${DIST}.\$(SECTION).pkglist";
798 SourceFileList "${DIST}.\$(SECTION).srclist";
799 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
802 done >> ftparchive.conf
805 buildaptftparchivedirectorystructure
() {
806 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
807 for DIST
in $DISTS; do
808 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
809 for SECTION
in $SECTIONS; do
810 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
811 for ARCH
in $ARCHS; do
812 mkdir -p "dists/${DIST}/${SECTION}/binary-${ARCH}"
814 mkdir -p "dists/${DIST}/${SECTION}/source"
815 mkdir -p "dists/${DIST}/${SECTION}/i18n"
825 local DEPENDENCIES
="$5"
826 local PRIORITY
="${6:-optional}"
827 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
828 If you find such a package installed on your system,
829 something went horribly wrong! They are autogenerated
830 und used only by testcases and serve no other purpose…"}"
832 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
833 if [ "$RELEASE" = 'installed' ]; then
834 insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
837 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
838 if [ "$arch" = 'none' ]; then
839 ARCHS="$(getarchitectures)"
843 for BUILDARCH in $ARCHS; do
844 local PPATH="aptarchive
/dists
/${RELEASE}/main
/binary
-${BUILDARCH}"
851 Maintainer
: Joe Sixpack
<joe@example.org
>"
852 test "$arch" = 'none' || echo "Architecture
: $arch"
853 echo "Version
: $VERSION
854 Filename
: pool
/main
/${NAME}/${NAME}_
${VERSION}_
${arch}.deb
"
855 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES"
856 echo "Description
: $(printf '%s' "$DESCRIPTION" | head -n 1)"
857 echo "Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
859 } >> "${PPATH}/Packages
"
862 mkdir -p "aptarchive
/dists
/${RELEASE}/main
/source" "aptarchive
/dists
/${RELEASE}/main
/i18n
"
863 touch "aptarchive
/dists
/${RELEASE}/main
/source
/Sources
"
865 Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
866 Description
-en: $DESCRIPTION
867 " >> "aptarchive
/dists
/${RELEASE}/main
/i
18n
/Translation
-en"
876 local DEPENDENCIES="$5"
877 local BINARY="${6:-$NAME}"
879 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
880 local SPATH="aptarchive
/dists
/${RELEASE}/main
/source"
882 local FILE="${SPATH}/Sources
"
883 local DSCFILE="${NAME}_
${VERSION}.dsc
"
884 local TARFILE="${NAME}_
${VERSION}.
tar.gz
"
888 Maintainer
: Joe Sixpack
<joe@example.org
>
889 Architecture
: $ARCH" >> $FILE
890 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
892 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
893 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
895 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
896 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
901 insertinstalledpackage() {
905 local DEPENDENCIES="$4"
906 local PRIORITY="${5:-optional}"
907 local STATUS="${6:-install ok installed}"
908 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
909 If you
find such a package installed on your system
,
910 something went horribly wrong
! They are autogenerated
911 und used only by testcases and serve no other purpose…
"}"
913 local FILE
='rootdir/var/lib/dpkg/status'
914 local INFO
='rootdir/var/lib/dpkg/info'
915 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
921 Maintainer: Joe Sixpack <joe@example.org>
922 Version: $VERSION" >> "$FILE"
923 test "$arch" = 'none' || echo "Architecture: $arch" >> "$FILE"
924 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
925 echo "Description: $DESCRIPTION" >> "$FILE"
927 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
928 echo -n > "${INFO}/${NAME}:${arch}.list"
930 echo -n > "${INFO}/${NAME}.list"
936 buildaptarchivefromincoming
() {
937 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on incoming packages…"
939 [ -e pool
] || ln -s ..
/incoming pool
940 [ -e ftparchive.conf
] || createaptftparchiveconfig
941 [ -e dists
] || buildaptftparchivedirectorystructure
942 msgninfo
"\tGenerate Packages, Sources and Contents files… "
943 testsuccess aptftparchive generate ftparchive.conf
946 generatereleasefiles
"$@"
949 buildaptarchivefromfiles
() {
950 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on prebuild files…"
951 local DIR
='aptarchive'
952 if [ -d "${DIR}/dists" ]; then DIR
="${DIR}/dists"; fi
953 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
954 msgninfo
"\t${line} file… "
955 compressfile
"$line" "$1"
958 generatereleasefiles
"$@"
962 while read compressor extension
command; do
963 if [ "$compressor" = '.' ]; then
969 cat "$1" | $command > "${1}.${extension}"
971 touch -d "$2" "${1}.${extension}"
973 done < "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf"
976 # can be overridden by testcases for their pleasure
977 getcodenamefromsuite
() {
979 unstable
) echo 'sid';;
983 getreleaseversionfromsuite
() { true
; }
984 getlabelfromsuite
() { true
; }
985 getoriginfromsuite
() { true
; }
986 getarchitecturesfromreleasefile
() { echo "all $(getarchitectures)"; }
988 aptftparchiverelease
() {
989 aptftparchive
-qq release
"$@" | sed -e '/0 Release$/ d' # remove the self reference
991 generatereleasefiles
() {
992 # $1 is the Date header and $2 is the ValidUntil header to be set
993 # both should be given in notation date/touch can understand
995 local VALIDUNTIL
="$2"
996 if [ -e aptarchive
/dists
]; then
997 msgninfo
"\tGenerate Release files for dists… "
998 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
999 local ARCHITECTURES
="$(getarchitecturesfromreleasefile "$dir")"
1000 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
1001 local CODENAME
="$(getcodenamefromsuite $SUITE)"
1002 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
1003 local LABEL
="$(getlabelfromsuite $SUITE)"
1004 local ORIGIN
="$(getoriginfromsuite $SUITE)"
1005 aptftparchiverelease
"$dir" \
1006 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
1007 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
1008 -o APT
::FTPArchive
::Release
::Architectures
="${ARCHITECTURES}" \
1009 -o APT
::FTPArchive
::Release
::Label
="${LABEL}" \
1010 -o APT
::FTPArchive
::Release
::Origin
="${ORIGIN}" \
1011 -o APT
::FTPArchive
::Release
::Version
="${VERSION}" \
1013 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
1014 sed -i '/^Date: / a\
1015 NotAutomatic: yes' "$dir/Release"
1019 msgninfo
"\tGenerate Release files for flat… "
1020 aptftparchiverelease .
/aptarchive
> aptarchive
/Release
1022 if [ -n "$DATE" -a "$DATE" != "now" ]; then
1023 for release
in $(find ./aptarchive -name 'Release'); do
1024 sed -i "s/^Date: .*$/Date: $(date -u -d "$DATE" -R)/" "$release"
1025 touch -d "$DATE" "$release"
1028 if [ -n "$VALIDUNTIL" ]; then
1029 sed -i "/^Date: / a\
1030 Valid-Until: $(date -u -d "$VALIDUNTIL" -R)" $(find ./aptarchive -name 'Release')
1035 setupdistsaptarchive
() {
1036 local APTARCHIVE
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1037 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
1038 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
1039 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1040 SECTIONS
=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1041 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
1042 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list"
1043 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list"
1048 setupflataptarchive
() {
1049 local APTARCHIVE
="$(readlink -f ./aptarchive)"
1050 local APTARCHIVEURI
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1051 if [ -f "${APTARCHIVE}/Packages" ]; then
1052 msgninfo
"\tadd deb sources.list line… "
1053 echo "deb file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1056 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1058 if [ -f "${APTARCHIVE}/Sources" ]; then
1059 msgninfo
"\tadd deb-src sources.list line… "
1060 echo "deb-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1063 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1069 if [ "$1" = '--no-update' ]; then
1073 buildaptarchive
"$@"
1074 if [ -e aptarchive
/dists
]; then
1075 setupdistsaptarchive
1079 signreleasefiles
'Joe Sixpack'
1080 if [ "1" != "$NOUPDATE" ]; then
1081 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
1085 signreleasefiles
() {
1086 local SIGNERS
="${1:-Joe Sixpack}"
1087 local REPODIR
="${2:-aptarchive}"
1088 if [ -n "$1" ]; then shift; fi
1089 if [ -n "$1" ]; then shift; fi
1090 local KEY
="keys/$(echo "$SIGNERS" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1091 msgninfo
"\tSign archive with $SIGNERS key $KEY… "
1092 local REXKEY
='keys/rexexpired'
1093 local SECEXPIREBAK
="${REXKEY}.sec.bak"
1094 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
1096 while [ -n "${SIGNERS%%,*}" ]; do
1097 local SIGNER
="${SIGNERS%%,*}"
1098 if [ "${SIGNERS}" = "${SIGNER}" ]; then
1101 SIGNERS
="${SIGNERS#*,}"
1102 # FIXME: This should be the full name, but we can't encode the space properly currently
1103 SIGUSERS
="${SIGUSERS} -u ${SIGNER#* }"
1104 if [ "${SIGNER}" = 'Rex Expired' ]; then
1105 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1106 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1107 # therefore we 'temporary' make the key not expired and restore a backup after signing
1108 cp "${REXKEY}.sec" "$SECEXPIREBAK"
1109 cp "${REXKEY}.pub" "$PUBEXPIREBAK"
1110 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
1111 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
1112 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1113 cp "$SECUNEXPIRED" "${REXKEY}.sec"
1114 cp "$PUBUNEXPIRED" "${REXKEY}.pub"
1116 if ! printf "expire\n1w\nsave\n" | aptkey
--quiet --keyring "${REXKEY}.pub" --secret-keyring "${REXKEY}.sec" \
1117 --readonly adv
--batch --yes --digest-algo "${APT_TESTS_DIGEST_ALGO:-SHA512}" \
1118 --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
1122 cp "${REXKEY}.sec" "$SECUNEXPIRED"
1123 cp "${REXKEY}.pub" "$PUBUNEXPIRED"
1126 if [ ! -e "${KEY}.pub" ]; then
1127 local K
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1128 cat "${K}.pub" >> "${KEY}.new.pub"
1129 cat "${K}.sec" >> "${KEY}.new.sec"
1132 if [ ! -e "${KEY}.pub" ]; then
1133 mv "${KEY}.new.pub" "${KEY}.pub"
1134 mv "${KEY}.new.sec" "${KEY}.sec"
1136 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes --digest-algo ${APT_TESTS_DIGEST_ALGO:-SHA512}"
1137 for RELEASE
in $(find "${REPODIR}/" -name Release); do
1138 # we might have set a specific date for the Release file, so copy it
1139 local DATE
="$(stat --format "%y" "${RELEASE}")"
1140 if [ "$APT_DONT_SIGN" = 'Release.gpg' ]; then
1141 rm -f "${RELEASE}.gpg"
1143 testsuccess
$GPG "$@" $SIGUSERS --armor --detach-sign --sign --output "${RELEASE}.gpg" "${RELEASE}"
1144 touch -d "$DATE" "${RELEASE}.gpg"
1146 local INRELEASE
="${RELEASE%/*}/InRelease"
1147 if [ "$APT_DONT_SIGN" = 'InRelease' ]; then
1150 testsuccess
$GPG "$@" $SIGUSERS --clearsign --output "$INRELEASE" "$RELEASE"
1151 touch -d "$DATE" "${INRELEASE}"
1154 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1155 mv -f "$SECEXPIREBAK" "${REXKEY}.sec"
1156 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub"
1161 redatereleasefiles
() {
1162 local DATE
="$(date -u -d "$1" -R)"
1163 for release
in $(find aptarchive/ -name 'Release'); do
1164 sed -i "s/^Date: .*$/Date: ${DATE}/" "$release"
1165 touch -d "$DATE" "$release"
1167 signreleasefiles
"${2:-Joe Sixpack}"
1171 local WEBSERVER
="${3:-http://localhost:${APTHTTPPORT}}"
1173 if [ "$1" = '--no-check' ]; then
1177 local DOWNLOG
='rootdir/tmp/download-testfile.log'
1178 local STATUS
='downloaded/webserverconfig.status'
1179 rm -f "$STATUS" "$DOWNLOG"
1180 # very very basic URI encoding
1182 if [ -n "$2" ]; then
1183 msgtest
"Set webserver config option '${1}' to" "$2"
1184 URI
="${WEBSERVER}/_config/set/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1186 msgtest
'Clear webserver config option' "${1}"
1187 URI
="${WEBSERVER}/_config/clear/$(echo "${1}" | sed -e 's/\//%2f/g')"
1189 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
1192 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.output"
1193 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1194 msgfailoutput
'' "$OUTPUT"
1196 $NOCHECK || testwebserverlaststatuscode
'200'
1199 rewritesourceslist
() {
1200 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1201 local APTARCHIVE2
="copy://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1202 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1203 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
1204 -e "s#http://[^@]*@\?localhost:${APTHTTPPORT}/\?#${1}#" \
1205 -e "s#https://[^@]*@\?localhost:${APTHTTPSPORT}/\?#${1}#"
1209 # wait for up to 10s for a pid file to appear to avoid possible race
1210 # when a helper is started and dosn't write the PID quick enough
1213 for i
in $(seq 10); do
1214 if test -s "$PIDFILE"; then
1219 msgdie
"waiting for $PIDFILE failed"
1223 changetowebserver
() {
1225 if [ "$1" != '--no-rewrite' ]; then
1230 if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
1232 local LOG
="webserver.log"
1233 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1237 waitforpidfile aptwebserver.pid
1238 local PID
="$(cat aptwebserver.pid)"
1239 if [ -z "$PID" ]; then
1240 msgdie
'Could not fork aptwebserver successfully'
1242 addtrap
"kill $PID;"
1243 waitforpidfile aptwebserver.port
1244 APTHTTPPORT
="$(cat aptwebserver.port)"
1245 if [ -z "$APTHTTPPORT" ]; then
1246 msgdie
'Could not get port for aptwebserver successfully'
1250 msgdie
'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver'
1252 if [ "$REWRTE" != 'yes' ]; then
1253 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1257 changetohttpswebserver
() {
1258 if ! command -v stunnel4
>/dev
/null
2>&1; then
1259 msgdie
'You need to install stunnel4 for https testcases'
1261 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1262 changetowebserver
--no-rewrite "$@"
1264 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1265 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1270 connect = $APTHTTPPORT
1271 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1272 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1273 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1274 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1275 if [ -z "$PID" ]; then
1276 msgdie
'Could not fork stunnel4 successfully'
1278 addtrap
'prefix' "kill ${PID};"
1279 APTHTTPSPORT
="$(lsof -i -n | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1280 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1281 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1285 mkdir -p rootdir
/media
/cdrom
/.disk
1286 local CD
="$(readlink -f rootdir/media/cdrom)"
1287 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1288 acquire::cdrom::mount "${CD}";
1289 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1290 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1291 acquire::cdrom::autodetect 0;
1293 echo -n "$1" > "${CD}/.disk/info"
1294 if [ ! -d aptarchive
/dists
]; then
1295 msgdie
'Flat file archive cdroms can not be created currently'
1298 mv aptarchive
/dists
"$CD"
1299 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1300 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1301 # start with an unmounted disk
1302 mv "${CD}" "${CD}-unmounted"
1303 # we don't want the disk to be modifiable
1304 addtrap
'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;"
1305 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1309 local PROTO
="${1%%:*}"
1310 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1311 download
-file "$1" "$2" "$3" 2>&1 ; then
1314 # only if the file exists the download was successful
1315 if [ -r "$2" ]; then
1323 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1324 if [ -n "$DIFFTEXT" ]; then
1326 echo >&2 "$DIFFTEXT"
1334 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1335 local COMPAREFILE
="$1"
1337 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1340 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1341 cat "$COMPAREFILE" >>"${OUTPUT}"
1342 msgfailoutput
'' "$OUTPUT" "$@"
1347 msggroup
'testfileequal'
1348 local MSG
='Test for correctness of file'
1349 if [ "$1" = '--nomsg' ]; then
1355 if [ -n "$MSG" ]; then
1356 msgtest
"$MSG" "$FILE"
1358 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1359 if [ -z "$*" ]; then
1360 testoutputequal
"$FILE" echo -n ''
1362 testoutputequal
"$FILE" echo "$*"
1368 msggroup
'testempty'
1369 if [ "$1" = '--nomsg' ]; then
1372 msgtest
"Test for no output of" "$*"
1374 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1375 if "$@" >"$COMPAREFILE" 2>&1 && test ! -s "$COMPAREFILE"; then
1378 msgfailoutput
'' "$COMPAREFILE" "$@"
1380 aptautotest
'testempty' "$@"
1384 msggroup
'testnotempty'
1385 msgtest
"Test for some output of" "$*"
1386 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
1387 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then
1390 msgfailoutput
'' "$COMPAREFILE" "$@"
1392 aptautotest
'testnotempty' "$@"
1397 msggroup
'testequal'
1398 local MSG
='Test of equality of'
1399 if [ "$1" = '--nomsg' ]; then
1404 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1405 echo "$1" > "$COMPAREFILE"
1408 if [ -n "$MSG" ]; then
1411 testoutputequal
"$COMPAREFILE" "$@"
1412 aptautotest
'testequal' "$@"
1417 msggroup
'testequalor2'
1418 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1419 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1420 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1421 echo "$1" > "$COMPAREFILE1"
1422 echo "$2" > "$COMPAREFILE2"
1424 msgtest
"Test for equality OR of" "$*"
1425 "$@" >"$COMPAREAGAINST" 2>&1 || true
1426 if checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null
2>&1 || \
1427 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null
2>&1
1431 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1432 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1433 checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1434 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1435 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1436 msgfailoutput
'' "$OUTPUT"
1438 aptautotest
'testequalor2' "$@"
1443 msggroup
'testshowvirtual'
1444 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1447 while [ -n "$1" ]; do
1449 N: Can't select versions from package '$1' as it is purely virtual"
1450 PACKAGE
="${PACKAGE} $1"
1453 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1455 N: No packages found"
1456 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1457 local ARCH
="$(getarchitecture 'native')"
1458 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1459 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1460 testoutputequal
"$COMPAREFILE" aptcache show
"$PACKAGE"
1465 msggroup
'testnopackage'
1466 msgtest
"Test for non-existent packages" "apt-cache show $*"
1467 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1468 if [ -n "$SHOWPKG" ]; then
1469 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1470 echo "$SHOWPKG" >"$OUTPUT"
1471 msgfailoutput
'' "$OUTPUT"
1477 testnosrcpackage
() {
1478 msggroup
'testnosrcpackage'
1479 msgtest
"Test for non-existent source packages" "apt-cache showsrc $*"
1480 local SHOWPKG
="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')"
1481 if [ -n "$SHOWPKG" ]; then
1482 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output"
1483 echo "$SHOWPKG" >"$OUTPUT"
1484 msgfailoutput
'' "$OUTPUT"
1492 msggroup
'testdpkgstatus'
1496 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1497 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1498 if [ "$PKGS" != $NR ]; then
1499 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1500 echo "$PKGS" >"$OUTPUT"
1501 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1502 msgfailoutput
'' "$OUTPUT"
1509 testdpkginstalled
() {
1510 msggroup
'testdpkginstalled'
1511 testdpkgstatus
'ii' "$#" "$@"
1515 testdpkgnotinstalled
() {
1516 msggroup
'testdpkgnotinstalled'
1517 testdpkgstatus
'ii' '0' "$@"
1522 msggroup
'testmarkedauto'
1523 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1524 if [ -n "$1" ]; then
1525 msgtest
'Test for correctly marked as auto-installed' "$*"
1526 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1528 msgtest
'Test for correctly marked as auto-installed' 'no package'
1529 echo -n > "$COMPAREFILE"
1531 testoutputequal
"$COMPAREFILE" aptmark showauto
1534 testmarkedmanual
() {
1535 msggroup
'testmarkedmanual'
1536 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1537 if [ -n "$1" ]; then
1538 msgtest
'Test for correctly marked as manually installed' "$*"
1539 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1541 msgtest
'Test for correctly marked as manually installed' 'no package'
1542 echo -n > "$COMPAREFILE"
1544 testoutputequal
"$COMPAREFILE" aptmark showmanual
1549 if [ "${1##*.}" = 'deb' ]; then
1550 stat
>&2 "$1" || true
1551 file >&2 "$1" || true
1553 cat >&2 "$1" || true
1557 msgreportheader
'msgfailoutput'
1562 if [ "$1" = 'grep' -o "$1" = 'tail' -o "$1" = 'head' ]; then
1564 while [ -n "$2" ]; do shift; done
1565 echo "#### Complete file: $1 ####"
1567 echo "#### $CMD output ####"
1568 elif [ "$1" = 'test' ]; then
1570 # doesn't support ! or non-file flags
1571 msgfailoutputstatfile
() {
1572 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1573 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1574 echo "#### stat(2) of file: $2 ####"
1576 if test -d "$2"; then
1577 echo "#### The directory contains: $2 ####"
1579 elif test -e "$2"; then
1580 echo "#### Complete file: $2 ####"
1585 msgfailoutputstatfile
"$2" "$3"
1586 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1588 msgfailoutputstatfile
"$2" "$3"
1590 echo '#### test output ####'
1591 elif [ "$1" = 'cmp' ]; then
1593 while [ -n "$2" ]; do
1594 echo "#### Complete file: $2 ####"
1598 echo '#### cmp output ####'
1604 testsuccesswithglobalerror
() {
1609 if [ "$1" = '--nomsg' ]; then
1612 msgtest
'Test for successful execution of' "$*"
1614 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output"
1615 if "$@" >"${OUTPUT}" 2>&1; then
1616 if expr match
"$1" '^apt.*' >/dev
/null
; then
1617 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1618 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1619 elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1620 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1621 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1622 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1625 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1628 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1630 elif [ "$TYPE" = 'testsuccesswithnotice' ]; then
1631 if grep -q -E "^N: " "$OUTPUT"; then
1634 msgfailoutput
'successful run, but output had no notices' "$OUTPUT" "$@"
1644 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1646 aptautotest
"$TYPE" "$@"
1649 testsuccesswithnotice
() {
1650 testsuccesswithglobalerror
'testsuccesswithnotice' 'WE' "$@"
1653 testsuccesswithglobalerror
'testsuccess' 'NWE' "$@"
1656 msggroup
'testwarning'
1657 if [ "$1" = '--nomsg' ]; then
1660 msgtest
'Test for successful execution with warnings of' "$*"
1662 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1663 if "$@" >"${OUTPUT}" 2>&1; then
1664 if expr match
"$1" '^apt.*' >/dev
/null
; then
1665 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1666 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1667 elif grep -q -E '^E: ' "$OUTPUT"; then
1668 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1669 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1670 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1679 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1681 aptautotest
'testwarning' "$@"
1685 msggroup
'testfailure'
1686 if [ "$1" = '--nomsg' ]; then
1689 msgtest
'Test for failure in execution of' "$*"
1691 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1692 if "$@" >"${OUTPUT}" 2>&1; then
1694 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1697 if expr match
"$1" '^apt.*' >/dev
/null
; then
1698 if [ "$1" = 'aptkey' ]; then
1699 if grep -q " Can't check signature:
1701 signature could not be verified" "$OUTPUT"; then
1704 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1707 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1708 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1709 elif grep -q -E '==ERROR' "$OUTPUT"; then
1710 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1711 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1712 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1721 aptautotest
'testfailure' "$@"
1725 testreturnstateequal
() {
1727 if [ "$STATE" = 'testsuccesswithglobalerror' ]; then
1731 msggroup
"${STATE}equal"
1732 if [ "$1" != '--nomsg' ]; then
1735 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1736 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1740 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1741 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1744 msggroup
"${STATE}equal"
1745 if [ "$2" != '--nomsg' ]; then
1749 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1753 "$STATE" --nomsg "$@"
1754 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1759 testsuccessequal
() {
1760 # we compare output, so we know perfectly well about N:
1761 testreturnstateequal
'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@"
1763 testwarningequal
() {
1764 testreturnstateequal
'testwarning' "$@"
1766 testfailureequal
() {
1767 testreturnstateequal
'testfailure' "$@"
1771 msggroup
'testfailuremsg'
1775 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1776 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1777 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1778 testoutputequal
"$COMPAREFILE" echo "$CMP"
1782 msggroup
'testwarningmsg'
1786 msgtest
'Check that the output of the previous warned command has expected' 'warnings'
1787 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
1788 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
1789 testoutputequal
"$COMPAREFILE" echo "$CMP"
1794 msggroup
'testfilestats'
1795 msgtest
"Test that file $1 has $2 $3" "$4"
1796 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1799 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1802 echo -n "stat(1) reports for $2: "
1803 stat
--format "$2" "$1" || true
1805 msgfailoutput
'' "$OUTPUT"
1809 testaccessrights
() {
1810 msggroup
'testaccessrights'
1811 testfilestats
"$1" '%a' '=' "$2"
1815 testwebserverlaststatuscode
() {
1816 msggroup
'testwebserverlaststatuscode'
1817 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1818 local STATUS
='downloaded/webserverstatus-statusfile.log'
1819 rm -f "$DOWNLOG" "$STATUS"
1820 msgtest
'Test last status code from the webserver was' "$1"
1821 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1824 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1826 if [ -n "$2" ]; then
1828 echo >&2 '#### Additionally provided output files contain:'
1831 echo >&2 '#### Download log of the status code:'
1834 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1839 createlistofkeys
() {
1842 while [ -n "$1" ]; do
1843 # gpg 2.1.something starts printing [SC] at some point
1844 if grep -q ' rsa2048/' "$OUTPUT" && grep -qF '[SC]' "$OUTPUT"; then
1846 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';;
1847 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [SC] [expired: 2013-07-13]';;
1848 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16 [SC]';;
1849 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19 [SC]';;
1850 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';;
1851 *) echo 'UNKNOWN KEY';;
1853 # gpg 2.1 has a slightly different output format
1854 elif grep -q ' rsa2048/' "$OUTPUT"; then
1856 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1857 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1858 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16';;
1859 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19';;
1860 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1861 *) echo 'UNKNOWN KEY';;
1865 *Joe
*|*Sixpack
*) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1866 *Rex
*|*Expired
*) echo 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1867 *Marvin
*|*Paranoid
*) echo 'pub 2048R/528144E2 2011-01-16';;
1868 oldarchive
) echo 'pub 1024R/F68C85A3 2013-12-19';;
1869 newarchive
) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1870 *) echo 'UNKNOWN KEY';;
1877 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output"
1878 if ! aptkey list
| grep '^pub' > "$OUTPUT"; then
1881 testfileequal
"$OUTPUT" "$(createlistofkeys "$OUTPUT" "$@")"
1885 echo "STOPPED execution. Press enter to continue"
1890 logcurrentarchivedirectory
() {
1891 find "${TMPWORKINGDIRECTORY}/aptarchive/dists" -type f
| while read line
; do
1892 stat
--format '%U:%G:%a:%n' "$line"
1893 done | sort > "${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst"
1895 listcurrentlistsdirectory
() {
1897 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1898 stat
--format '%U:%G:%a:%n' "$line"
1900 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1901 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1905 forallsupportedcompressors
() {
1906 rm -f "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
1907 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
1908 if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi
1913 ### convenience hacks ###
1915 # creating some directories by hand is a tedious task, so make it look simple
1917 if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then
1918 # only the last directory created by mkdir is effected by the -m !
1919 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1920 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1921 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1922 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1923 if [ "$(id -u)" = '0' ]; then
1924 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1931 ### The following tests are run by most test methods automatically to check
1932 ### general things about commands executed without writing the test every time.
1935 if [ $# -lt 3 ]; then return; fi
1941 if ! expr match
"$i" '^-' >/dev
/null
2>&1; then
1947 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')"
1948 if command -v $AUTOTEST >/dev
/null
; then
1949 # save and restore the *.output files from other tests
1950 # as we might otherwise override them in these automatic tests
1951 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1952 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1953 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1954 $AUTOTEST "$TESTCALL" "$@"
1955 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1956 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1957 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1961 aptautotest_aptget_update
() {
1963 while [ -n "$2" ]; do
1964 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1967 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1968 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1969 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1970 # all copied files are properly chmodded
1971 local backupIFS
="$IFS"
1972 IFS
="$(printf "\n\b")"
1973 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1974 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1977 if [ "$TESTCALL" = 'testsuccess' ]; then
1978 # failure cases can retain partial files and such
1979 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
1981 if [ -s "${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" ]; then
1982 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" \
1983 "$(find "${TMPWORKINGDIRECTORY}/aptarchive/dists" -type f | while read line; do stat --format '%U:%G:%a:%n' "$line"; done | sort)"
1986 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1987 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
1989 testaptautotestnodpkgwarning
() {
1991 while [ -n "$2" ]; do
1992 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
1993 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
1996 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1999 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
2000 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
2001 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
2002 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
2003 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
2004 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }
2006 testaptmarknodefaultsections
() {
2007 testfailure
grep '^Auto-Installed: 0$' "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/extended_states"
2009 aptautotest_aptmark_auto
() { testaptmarknodefaultsections
"$@"; }
2010 aptautotest_aptmark_manual
() { testaptmarknodefaultsections
"$@"; }
2011 aptautotest_aptget_markauto
() { testaptmarknodefaultsections
"$@"; }
2012 aptautotest_aptget_markmanual
() { testaptmarknodefaultsections
"$@"; }