1 #!/bin/sh -- # no runable script, just for vi
6 if [ "$1" = "-q" ]; then
8 elif [ "$1" = "-v" ]; then
10 elif [ "$1" = '--color=no' ]; then
12 elif [ "$1" = '--color=yes' ]; then
14 elif [ "$1" = '--color' ]; then
15 export MSGCOLOR
="$(echo "$2" | tr 'a-z' 'A-Z')"
17 elif [ "$1" = '--level' ]; then
21 echo >&2 "WARNING: Unknown parameter »$1« will be ignored"
25 export MSGLEVEL
="${MSGLEVEL:-3}"
27 # we all like colorful messages
28 if [ "${MSGCOLOR:-YES}" = 'YES' ]; then
29 if [ ! -t 1 ]; then # but check that we output to a terminal
35 if [ "$MSGCOLOR" != 'NO' ]; then
36 CERROR
="\033[1;31m" # red
37 CWARNING
="\033[1;33m" # yellow
38 CMSG
="\033[1;32m" # green
39 CINFO
="\033[1;96m" # light blue
40 CDEBUG
="\033[1;94m" # blue
41 CNORMAL
="\033[0;39m" # default system console color
42 CDONE
="\033[1;32m" # green
43 CPASS
="\033[1;32m" # green
44 CFAIL
="\033[1;31m" # red
45 CCMD
="\033[1;35m" # pink
57 printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghks]\)#apt-\1#')"
63 msgdie
() { msgprintf
"${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; }
64 msgwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; }
65 msgmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; }
66 msginfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; }
67 msgdebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; }
68 msgdone
() { msgprintf
"${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; }
69 msgnwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; }
70 msgnmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}" "$@"; }
71 msgninfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
72 msgndebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
73 msgtest
() { msgprintf
"${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
74 msgpass
() { printf "${CPASS}PASS${CNORMAL}\n"; }
76 if [ -n "$MSGTEST_MSG" ]; then
77 test "$1" != 'msgfailoutput' || echo
78 if [ -n "$MSGTEST_MSGMSG" ]; then
79 echo "$MSGTEST_MSGMSG"
81 if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then
82 echo "${CFAIL}Part of the test group: $MSGTEST_GRP"
84 echo -n "$MSGTEST_MSG"
89 msgreportheader
'msgskip'
90 if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
91 else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
94 msgreportheader
'msgfail'
95 if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
96 else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
97 if [ -n "$APT_DEBUG_TESTS" ]; then
100 EXIT_CODE
=$((EXIT_CODE+1));
105 if [ $MSGGROUP_LEVEL = 0 ]; then
108 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL+1));
110 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL-1));
111 if [ $MSGGROUP_LEVEL = 0 ]; then
117 # enable / disable Debugging
118 if [ $MSGLEVEL -le 0 ]; then
121 if [ $MSGLEVEL -le 1 ]; then
125 if [ $MSGLEVEL -le 2 ]; then
127 MSGTEST_MSGMSG
="$(msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@")"
131 MSGTEST_MSG
="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")"
132 if [ "$MSGTEST_GRP" = 'NEXT' ]; then
133 MSGTEST_GRP
="$MSGTEST_MSG"
136 msgpass
() { printf " ${CPASS}P${CNORMAL}"; }
138 if [ $MSGLEVEL -le 3 ]; then
142 if [ $MSGLEVEL -le 4 ]; then
144 msgndebug
() { true
; }
147 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
148 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
149 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
150 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
151 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
154 printf "${CDONE}DONE${CNORMAL}\n";
158 if [ -f .
/aptconfig.conf
]; then
159 echo "$(readlink -f ./aptconfig.conf)"
160 elif [ -f ..
/aptconfig.conf
]; then
161 echo "$(readlink -f ../aptconfig.conf)"
162 elif [ -f ..
/..
/aptconfig.conf
]; then
163 echo "$(readlink -f ../../aptconfig.conf)"
164 elif [ -f "${TMPWORKINGDIRECTORY}/aptconfig.conf" ]; then
165 echo "$(readlink -f "${TMPWORKINGDIRECTORY}/aptconfig.conf")"
169 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
173 sh
|aptitude
|*/*|command) ;;
174 *) CMD
="${BUILDDIRECTORY}/$CMD";;
176 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
="${LIBRARYPATH}:${LD_LIBRARY_PATH}" "$CMD" "$@"
178 runpython3
() { runapt
command python3
"$@"; }
179 aptconfig
() { runapt apt
-config "$@"; }
180 aptcache
() { runapt apt
-cache "$@"; }
181 aptcdrom
() { runapt apt
-cdrom "$@"; }
182 aptget
() { runapt apt
-get "$@"; }
183 aptftparchive
() { runapt apt
-ftparchive "$@"; }
184 aptkey
() { runapt apt
-key "$@"; }
185 aptmark
() { runapt apt
-mark "$@"; }
186 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; }
187 apt
() { runapt apt
"$@"; }
188 apthelper
() { runapt
"${APTHELPERBINDIR}/apt-helper" "$@"; }
189 aptwebserver
() { runapt
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
190 aptitude
() { runapt aptitude
"$@"; }
191 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; }
192 aptinternalsolver
() { runapt
"${APTINTERNALSOLVER}" "$@"; }
193 aptdumpsolver
() { runapt
"${APTDUMPSOLVER}" "$@"; }
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/bin"}"
287 LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}"
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}"}"
291 APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}"
292 APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}"
293 APTINTERNALPLANNER="${APT_INTEGRATION_TESTS_INTERNAL_PLANNER:-"${BUILDDIRECTORY}/apt-internal-planner"}"
294 test -x "${BUILDDIRECTORY}/apt
-get" || msgdie "You need to build tree first
"
297 cd "$TMPWORKINGDIRECTORY"
298 mkdir rootdir aptarchive keys
300 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
301 mkdir -p usr/bin var/cache var/lib var/log tmp
302 mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
303 mkdir -p usr/lib/apt/solvers usr/lib/apt/planners
304 touch var/lib/dpkg/available
305 ln -s "${METHODSDIR}" usr/lib/apt/methods
306 ln -s "${APTDUMPSOLVER}" usr/lib/apt/solvers/dump
307 ln -s "${APTDUMPSOLVER}" usr/lib/apt/planners/dump
308 ln -s "${APTINTERNALSOLVER}" usr/lib/apt/solvers/apt
309 ln -s "${APTINTERNALPLANNER}" usr/lib/apt/planners/apt
310 echo "Dir
::Bin
::Solvers
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/solvers
\";" >> ../aptconfig.conf
311 echo "Dir
::Bin
::Planners
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/planners
\";" >> ../aptconfig.conf
312 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
314 if [ -e "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" ]; then
315 ln -s "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" etc/apt/apt.conf.d/01autoremove
317 ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
320 local BASENAME="${0##*/}"
321 local PACKAGESFILE="Packages
-${BASENAME#*-}"
322 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
323 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
325 local SOURCESSFILE="Sources
-${BASENAME#*-}"
326 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
327 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
329 find "$TESTDIRECTORY" \( -name '*.pub' -o -name '*.sec' \) -exec cp '{}' keys/ \;
331 ln -s "${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub
" rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
333 echo "Dir
\"${TMPWORKINGDIRECTORY}/rootdir
\";" >> aptconfig.conf
334 echo "Dir
::state
::status
\"${TMPWORKINGDIRECTORY}/rootdir
/var
/lib
/dpkg
/status
\";" >> 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 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
486 DPKGARCH="$(dpkg --print-architecture)"
487 for ARCH in ${ARCHS}; do
488 if [ "${ARCH}" != "${DPKGARCH}" ]; then
489 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
490 # old-style used e.g. in Ubuntu-P – and as it seems travis
491 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
492 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
496 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
497 # dpkg doesn't really check the version as long as it is fully installed,
498 # but just to be sure we choose one above the required version
499 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
505 configdpkgnoopchroot() {
506 # create a library to noop chroot() and rewrite maintainer script executions
507 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
508 # chroot directory dpkg could chroot into to execute the maintainer scripts
509 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
510 cat > noopchroot.c << EOF
517 static char * chrootdir = NULL;
519 int chroot(const char *path) {
520 printf("WARNING
: CHROOTing to
%s was ignored
!\n", path);
522 chrootdir = strdup(path);
525 int execvp(const char *file, char *const argv[]) {
526 static int (*func_execvp) (const char *, char * const []) = NULL;
527 if (func_execvp == NULL)
528 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
");
529 if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0)
530 return func_execvp(file, argv);
531 printf("REWRITE execvp call
%s into
%s
\n", file, chrootdir);
533 if (asprintf(&newfile, "%s
%s
", chrootdir, file) == -1) {
537 char const * const baseadmindir = "/var
/lib
/dpkg
";
539 if (asprintf(&admindir, "%s
%s
", chrootdir, baseadmindir) == -1) {
543 setenv("DPKG_ADMINDIR
", admindir, 1);
544 return func_execvp(newfile, argv);
547 testempty --nomsg gcc -Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c -ldl
549 configcompression() {
550 if [ "$1" = 'ALL' ]; then
551 configcompression '.' $(aptconfig dump APT::Compressor --format '%t %v%n' | sed -n 's#^Extension \.\(.*\)$#\1#p')
554 local CMD='apthelper cat-file -C'
555 while [ -n "$1" ]; do
557 '.') printf ".
\t.
\tcat
\n";;
558 'gz') printf "gzip\tgz
\t$CMD $1\n";;
559 'bz2') printf "bzip2\tbz
2\t$CMD $1\n";;
560 *) printf "$1\t$1\t$CMD $1\n";;
563 done > "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
"
567 echo 'APT::FTPArchive {'
569 while [ -n "$1" ]; do
570 printf "$1" | tr 'a-z' 'A-Z'
571 printf "\t\"true
\";\n"
574 for h in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
575 printf "$h\t\"false
\";\n"
579 } >> "${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/ftparchive
-hashes.conf
"
584 COMPRESSOR_CMD="apthelper
cat-file -C $1"
586 gzip) COMPRESS='gz';;
587 bzip2) COMPRESS='bz2';;
589 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/00force
-compressor"
590 echo "Acquire
::CompressionTypes
::Order
{ \"${COMPRESS}\"; };
591 Dir
::Bin
::uncompressed
\"/does
/not
/exist
\";" > "$CONFFILE"
592 for COMP in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
593 if [ -z "$COMP" -o "$COMP" = '.' -o "$COMP" = "$COMPRESSOR" ]; then continue; fi
594 echo "Dir
::Bin
::${COMP} \"/does
/not
/exist
\";" >> "$CONFFILE"
595 echo "APT
::Compressor
::${COMP}::Name
\"${COMP}-disabled\";" >> "$CONFFILE"
599 _setupsimplenativepackage() {
603 local RELEASE="${4:-unstable}"
604 local DEPENDENCIES="$5"
605 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
606 If you
find such a package installed on your system
,
607 something went horribly wrong
! They are autogenerated
608 und used only by testcases and serve no other purpose…
"}"
610 local SECTION
="${7:-others}"
611 local PRIORITY
="${8:-optional}"
613 local COMPRESS_TYPE
="${10:-gzip}"
615 if [ "$SECTION" = "${SECTION#*/}" ]; then
618 DISTSECTION
="${SECTION%/*}"
620 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
622 mkdir -p "$BUILDDIR/debian/source"
623 echo "* most suckless software product ever" > "${BUILDDIR}/FEATURES"
625 echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}"
627 echo "Copyleft by Joe Sixpack $(date -u +%Y)" > "${BUILDDIR}/debian/copyright"
628 echo "$NAME ($VERSION) $RELEASE; urgency=low
632 -- Joe Sixpack <joe@example.org> $(date -u -R)" > "${BUILDDIR}/debian/changelog"
636 Maintainer: Joe Sixpack <joe@example.org>
637 Standards-Version: 3.9.3"
638 if [ "$SECTION" != '<none>' ]; then
639 echo "Section: $SECTION"
641 local BUILDDEPS
="$(echo "$DEPENDENCIES" | grep '^Build-')"
642 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
646 if [ "$ARCH" = 'all' ]; then
647 echo "Architecture: all"
649 echo "Architecture: any"
651 local DEPS
="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
652 test -z "$DEPS" || echo "$DEPS"
653 echo "Description: $DESCRIPTION"
654 } > "${BUILDDIR}/debian/control"
656 echo '3.0 (native)' > "${BUILDDIR}/debian/source/format"
659 setupsimplenativepackage
() {
660 _setupsimplenativepackage
"$@"
663 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
664 test -e "${BUILDDIR}/debian/compat" || echo '7' > "${BUILDDIR}/debian/compat"
665 test -e "${BUILDDIR}/debian/rules" || cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny
"${BUILDDIR}/debian/rules"
668 buildsimplenativepackage
() {
672 local RELEASE
="${4:-unstable}"
673 local DEPENDENCIES
="$5"
674 local DESCRIPTION
="$6"
675 local SECTION
="${7:-others}"
676 local PRIORITY
="${8:-optional}"
678 local COMPRESS_TYPE
="${10:-gzip}"
680 if [ "$SECTION" = "${SECTION#*/}" ]; then
683 DISTSECTION
="${SECTION%/*}"
685 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
686 msgtest
"Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
687 _setupsimplenativepackage
"$@"
689 testsuccess
--nomsg dpkg
-source -b ${NAME}-${VERSION}
691 sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" \
693 echo "pool/${SRC}" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist"
694 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
695 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
696 # adv --yes --default-key 'Joe Sixpack' \
697 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
698 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
702 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
703 msgtest
"Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
704 rm -rf "${BUILDDIR}/debian/tmp"
705 mkdir -p "${BUILDDIR}/debian/tmp/DEBIAN" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin"
706 cp "${BUILDDIR}/debian/copyright" "${BUILDDIR}/debian/changelog" "${BUILDDIR}/FEATURES" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}"
707 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}"
708 if [ -n "$FILE_TREE" ]; then
709 cp -ar "$FILE_TREE" "${BUILDDIR}/debian/tmp"
712 (cd "${BUILDDIR}"; dpkg
-gencontrol -DArchitecture=$arch)
713 (cd "${BUILDDIR}/debian/tmp"; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
714 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
715 # ensure the right permissions as dpkg-deb insists
716 chmod 755 "${BUILDDIR}/debian/tmp/DEBIAN"
717 testsuccess
--nomsg dpkg
-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian/tmp" "${BUILDDIR}/.."
718 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist"
722 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then
723 NM
="$(echo "$NAME" | cut -c 1-4)"
725 NM
="$(echo "$NAME" | cut -c 1)"
727 local CHANGEPATH
="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}"
728 mkdir -p "$CHANGEPATH"
729 cp "${BUILDDIR}/debian/changelog" "$CHANGEPATH"
738 local ARCH
=$(getarchitecture $4)
739 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
740 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
741 msgtest
"Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
743 if [ "$ARCH" = "all" ]; then
744 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
746 testsuccess
--nomsg dpkg
-buildpackage -uc -us -a$ARCH
747 cp "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$BUILDLOG"
748 local PKGS
="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
749 local SRCS
="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
752 echo "pool/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist"
755 echo "pool/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist"
760 if [ -d incoming
]; then
761 buildaptarchivefromincoming
"$@"
763 buildaptarchivefromfiles
"$@"
767 createaptftparchiveconfig
() {
768 local COMPRESSORS
="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
769 local COMPRESSORS
="${COMPRESSORS%* }"
770 local ARCHS
="$(getarchitectures)"
771 cat > ftparchive.conf
<<EOF
773 ArchiveDir "$(readlink -f .)";
774 CacheDir "$(readlink -f ..)";
775 FileListDir "$(readlink -f pool/)";
778 Packages::Compress "$COMPRESSORS";
779 Sources::Compress "$COMPRESSORS";
780 Contents::Compress "$COMPRESSORS";
781 Translation::Compress "$COMPRESSORS";
782 LongDescription "false";
786 SrcDirectory "pool/";
789 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
792 Architectures "$ARCHS all source";
793 FileList "${DIST}.\$(SECTION).pkglist";
794 SourceFileList "${DIST}.\$(SECTION).srclist";
795 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
798 done >> ftparchive.conf
801 buildaptftparchivedirectorystructure
() {
802 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
803 for DIST
in $DISTS; do
804 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
805 for SECTION
in $SECTIONS; do
806 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
807 for ARCH
in $ARCHS; do
808 mkdir -p "dists/${DIST}/${SECTION}/binary-${ARCH}"
810 mkdir -p "dists/${DIST}/${SECTION}/source"
811 mkdir -p "dists/${DIST}/${SECTION}/i18n"
821 local DEPENDENCIES
="$5"
822 local PRIORITY
="${6:-optional}"
823 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
824 If you find such a package installed on your system,
825 something went horribly wrong! They are autogenerated
826 und used only by testcases and serve no other purpose…"}"
828 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
829 if [ "$RELEASE" = 'installed' ]; then
830 insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
833 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
834 if [ "$arch" = 'none' ]; then
835 ARCHS="$(getarchitectures)"
839 for BUILDARCH in $ARCHS; do
840 local PPATH="aptarchive
/dists
/${RELEASE}/main
/binary
-${BUILDARCH}"
847 Maintainer
: Joe Sixpack
<joe@example.org
>"
848 test "$arch" = 'none' || echo "Architecture
: $arch"
849 echo "Version
: $VERSION
850 Filename
: pool
/main
/${NAME}/${NAME}_
${VERSION}_
${arch}.deb
"
851 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES"
852 echo "Description
: $(printf '%s' "$DESCRIPTION" | head -n 1)"
853 echo "Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
855 } >> "${PPATH}/Packages
"
858 mkdir -p "aptarchive
/dists
/${RELEASE}/main
/source" "aptarchive
/dists
/${RELEASE}/main
/i18n
"
859 touch "aptarchive
/dists
/${RELEASE}/main
/source
/Sources
"
861 Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
862 Description
-en: $DESCRIPTION
863 " >> "aptarchive
/dists
/${RELEASE}/main
/i
18n
/Translation
-en"
872 local DEPENDENCIES="$5"
873 local BINARY="${6:-$NAME}"
875 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
876 local SPATH="aptarchive
/dists
/${RELEASE}/main
/source"
878 local FILE="${SPATH}/Sources
"
879 local DSCFILE="${NAME}_
${VERSION}.dsc
"
880 local TARFILE="${NAME}_
${VERSION}.
tar.gz
"
884 Maintainer
: Joe Sixpack
<joe@example.org
>
885 Architecture
: $ARCH" >> $FILE
886 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
888 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
889 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
891 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
892 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
897 insertinstalledpackage() {
901 local DEPENDENCIES="$4"
902 local PRIORITY="${5:-optional}"
903 local STATUS="${6:-install ok installed}"
904 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
905 If you
find such a package installed on your system
,
906 something went horribly wrong
! They are autogenerated
907 und used only by testcases and serve no other purpose…
"}"
909 local FILE
='rootdir/var/lib/dpkg/status'
910 local INFO
='rootdir/var/lib/dpkg/info'
911 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
917 Maintainer: Joe Sixpack <joe@example.org>
918 Version: $VERSION" >> "$FILE"
919 test "$arch" = 'none' || echo "Architecture: $arch" >> "$FILE"
920 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
921 echo "Description: $DESCRIPTION" >> "$FILE"
923 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
924 echo -n > "${INFO}/${NAME}:${arch}.list"
926 echo -n > "${INFO}/${NAME}.list"
932 buildaptarchivefromincoming
() {
933 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on incoming packages…"
935 [ -e pool
] || ln -s ..
/incoming pool
936 [ -e ftparchive.conf
] || createaptftparchiveconfig
937 [ -e dists
] || buildaptftparchivedirectorystructure
938 msgninfo
"\tGenerate Packages, Sources and Contents files… "
939 testsuccess aptftparchive generate ftparchive.conf
942 generatereleasefiles
"$@"
945 buildaptarchivefromfiles
() {
946 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on prebuild files…"
947 local DIR
='aptarchive'
948 if [ -d "${DIR}/dists" ]; then DIR
="${DIR}/dists"; fi
949 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
950 msgninfo
"\t${line} file… "
951 compressfile
"$line" "$1"
954 generatereleasefiles
"$@"
958 while read compressor extension
command; do
959 if [ "$compressor" = '.' ]; then
965 cat "$1" | $command > "${1}.${extension}"
967 touch -d "$2" "${1}.${extension}"
969 done < "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf"
972 # can be overridden by testcases for their pleasure
973 getcodenamefromsuite
() {
975 unstable
) echo 'sid';;
979 getreleaseversionfromsuite
() { true
; }
980 getlabelfromsuite
() { true
; }
981 getoriginfromsuite
() { true
; }
982 getarchitecturesfromreleasefile
() { echo "all $(getarchitectures)"; }
984 aptftparchiverelease
() {
985 aptftparchive
-qq release
"$@" | sed -e '/0 Release$/ d' # remove the self reference
987 generatereleasefiles
() {
988 # $1 is the Date header and $2 is the ValidUntil header to be set
989 # both should be given in notation date/touch can understand
991 local VALIDUNTIL
="$2"
992 if [ -e aptarchive
/dists
]; then
993 msgninfo
"\tGenerate Release files for dists… "
994 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
995 local ARCHITECTURES
="$(getarchitecturesfromreleasefile "$dir")"
996 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
997 local CODENAME
="$(getcodenamefromsuite $SUITE)"
998 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
999 local LABEL
="$(getlabelfromsuite $SUITE)"
1000 local ORIGIN
="$(getoriginfromsuite $SUITE)"
1001 aptftparchiverelease
"$dir" \
1002 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
1003 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
1004 -o APT
::FTPArchive
::Release
::Architectures
="${ARCHITECTURES}" \
1005 -o APT
::FTPArchive
::Release
::Label
="${LABEL}" \
1006 -o APT
::FTPArchive
::Release
::Origin
="${ORIGIN}" \
1007 -o APT
::FTPArchive
::Release
::Version
="${VERSION}" \
1009 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
1010 sed -i '/^Date: / a\
1011 NotAutomatic: yes' "$dir/Release"
1015 msgninfo
"\tGenerate Release files for flat… "
1016 aptftparchiverelease .
/aptarchive
> aptarchive
/Release
1018 if [ -n "$DATE" -a "$DATE" != "now" ]; then
1019 for release
in $(find ./aptarchive -name 'Release'); do
1020 sed -i "s/^Date: .*$/Date: $(date -u -d "$DATE" -R)/" "$release"
1021 touch -d "$DATE" "$release"
1024 if [ -n "$VALIDUNTIL" ]; then
1025 sed -i "/^Date: / a\
1026 Valid-Until: $(date -u -d "$VALIDUNTIL" -R)" $(find ./aptarchive -name 'Release')
1031 setupdistsaptarchive
() {
1032 local APTARCHIVE
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1033 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
1034 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
1035 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1036 SECTIONS
=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1037 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
1038 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list"
1039 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list"
1044 setupflataptarchive
() {
1045 local APTARCHIVE
="$(readlink -f ./aptarchive)"
1046 local APTARCHIVEURI
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1047 if [ -f "${APTARCHIVE}/Packages" ]; then
1048 msgninfo
"\tadd deb sources.list line… "
1049 echo "deb file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1052 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1054 if [ -f "${APTARCHIVE}/Sources" ]; then
1055 msgninfo
"\tadd deb-src sources.list line… "
1056 echo "deb-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1059 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1065 if [ "$1" = '--no-update' ]; then
1069 buildaptarchive
"$@"
1070 if [ -e aptarchive
/dists
]; then
1071 setupdistsaptarchive
1075 signreleasefiles
'Joe Sixpack'
1076 if [ "1" != "$NOUPDATE" ]; then
1077 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
1081 signreleasefiles
() {
1082 local SIGNERS
="${1:-Joe Sixpack}"
1083 local REPODIR
="${2:-aptarchive}"
1084 if [ -n "$1" ]; then shift; fi
1085 if [ -n "$1" ]; then shift; fi
1086 local KEY
="keys/$(echo "$SIGNERS" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1087 msgninfo
"\tSign archive with $SIGNERS key $KEY… "
1088 local REXKEY
='keys/rexexpired'
1089 local SECEXPIREBAK
="${REXKEY}.sec.bak"
1090 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
1092 while [ -n "${SIGNERS%%,*}" ]; do
1093 local SIGNER
="${SIGNERS%%,*}"
1094 if [ "${SIGNERS}" = "${SIGNER}" ]; then
1097 SIGNERS
="${SIGNERS#*,}"
1098 # FIXME: This should be the full name, but we can't encode the space properly currently
1099 SIGUSERS
="${SIGUSERS} -u ${SIGNER#* }"
1100 if [ "${SIGNER}" = 'Rex Expired' ]; then
1101 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1102 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1103 # therefore we 'temporary' make the key not expired and restore a backup after signing
1104 cp "${REXKEY}.sec" "$SECEXPIREBAK"
1105 cp "${REXKEY}.pub" "$PUBEXPIREBAK"
1106 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
1107 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
1108 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1109 cp "$SECUNEXPIRED" "${REXKEY}.sec"
1110 cp "$PUBUNEXPIRED" "${REXKEY}.pub"
1112 if ! printf "expire\n1w\nsave\n" | aptkey
--quiet --keyring "${REXKEY}.pub" --secret-keyring "${REXKEY}.sec" \
1113 --readonly adv
--batch --yes --digest-algo "${APT_TESTS_DIGEST_ALGO:-SHA512}" \
1114 --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
1118 cp "${REXKEY}.sec" "$SECUNEXPIRED"
1119 cp "${REXKEY}.pub" "$PUBUNEXPIRED"
1122 if [ ! -e "${KEY}.pub" ]; then
1123 local K
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1124 cat "${K}.pub" >> "${KEY}.new.pub"
1125 cat "${K}.sec" >> "${KEY}.new.sec"
1128 if [ ! -e "${KEY}.pub" ]; then
1129 mv "${KEY}.new.pub" "${KEY}.pub"
1130 mv "${KEY}.new.sec" "${KEY}.sec"
1132 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes --digest-algo ${APT_TESTS_DIGEST_ALGO:-SHA512}"
1133 for RELEASE
in $(find "${REPODIR}/" -name Release); do
1134 # we might have set a specific date for the Release file, so copy it
1135 local DATE
="$(stat --format "%y" "${RELEASE}")"
1136 if [ "$APT_DONT_SIGN" = 'Release.gpg' ]; then
1137 rm -f "${RELEASE}.gpg"
1139 testsuccess
$GPG "$@" $SIGUSERS --armor --detach-sign --sign --output "${RELEASE}.gpg" "${RELEASE}"
1140 touch -d "$DATE" "${RELEASE}.gpg"
1142 local INRELEASE
="${RELEASE%/*}/InRelease"
1143 if [ "$APT_DONT_SIGN" = 'InRelease' ]; then
1146 testsuccess
$GPG "$@" $SIGUSERS --clearsign --output "$INRELEASE" "$RELEASE"
1147 touch -d "$DATE" "${INRELEASE}"
1150 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1151 mv -f "$SECEXPIREBAK" "${REXKEY}.sec"
1152 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub"
1157 redatereleasefiles
() {
1158 local DATE
="$(date -u -d "$1" -R)"
1159 for release
in $(find aptarchive/ -name 'Release'); do
1160 sed -i "s/^Date: .*$/Date: ${DATE}/" "$release"
1161 touch -d "$DATE" "$release"
1163 signreleasefiles
"${2:-Joe Sixpack}"
1167 local WEBSERVER
="${3:-http://localhost:${APTHTTPPORT}}"
1169 if [ "$1" = '--no-check' ]; then
1173 local DOWNLOG
='rootdir/tmp/download-testfile.log'
1174 local STATUS
='downloaded/webserverconfig.status'
1175 rm -f "$STATUS" "$DOWNLOG"
1176 # very very basic URI encoding
1178 if [ -n "$2" ]; then
1179 msgtest
"Set webserver config option '${1}' to" "$2"
1180 URI
="${WEBSERVER}/_config/set/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1182 msgtest
'Clear webserver config option' "${1}"
1183 URI
="${WEBSERVER}/_config/clear/$(echo "${1}" | sed -e 's/\//%2f/g')"
1185 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
1188 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.output"
1189 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1190 msgfailoutput
'' "$OUTPUT"
1192 $NOCHECK || testwebserverlaststatuscode
'200'
1195 rewritesourceslist
() {
1196 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1197 local APTARCHIVE2
="copy://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1198 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1199 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
1200 -e "s#http://[^@]*@\?localhost:${APTHTTPPORT}/\?#${1}#" \
1201 -e "s#https://[^@]*@\?localhost:${APTHTTPSPORT}/\?#${1}#"
1205 # wait for up to 10s for a pid file to appear to avoid possible race
1206 # when a helper is started and dosn't write the PID quick enough
1209 for i
in $(seq 10); do
1210 if test -s "$PIDFILE"; then
1215 msgdie
"waiting for $PIDFILE failed"
1219 changetowebserver
() {
1221 if [ "$1" != '--no-rewrite' ]; then
1226 if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
1228 local LOG
="webserver.log"
1229 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1233 waitforpidfile aptwebserver.pid
1234 local PID
="$(cat aptwebserver.pid)"
1235 if [ -z "$PID" ]; then
1236 msgdie
'Could not fork aptwebserver successfully'
1238 addtrap
"kill $PID;"
1239 waitforpidfile aptwebserver.port
1240 APTHTTPPORT
="$(cat aptwebserver.port)"
1241 if [ -z "$APTHTTPPORT" ]; then
1242 msgdie
'Could not get port for aptwebserver successfully'
1246 msgdie
'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver'
1248 if [ "$REWRTE" != 'yes' ]; then
1249 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1253 changetohttpswebserver
() {
1254 if ! command -v stunnel4
>/dev
/null
2>&1; then
1255 msgdie
'You need to install stunnel4 for https testcases'
1257 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1258 changetowebserver
--no-rewrite "$@"
1260 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1261 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1266 connect = $APTHTTPPORT
1267 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1268 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1269 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1270 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1271 if [ -z "$PID" ]; then
1272 msgdie
'Could not fork stunnel4 successfully'
1274 addtrap
'prefix' "kill ${PID};"
1275 APTHTTPSPORT
="$(lsof -i -n | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1276 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1277 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1281 mkdir -p rootdir
/media
/cdrom
/.disk
1282 local CD
="$(readlink -f rootdir/media/cdrom)"
1283 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1284 acquire::cdrom::mount "${CD}";
1285 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1286 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1287 acquire::cdrom::autodetect 0;
1289 echo -n "$1" > "${CD}/.disk/info"
1290 if [ ! -d aptarchive
/dists
]; then
1291 msgdie
'Flat file archive cdroms can not be created currently'
1294 mv aptarchive
/dists
"$CD"
1295 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1296 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1297 # start with an unmounted disk
1298 mv "${CD}" "${CD}-unmounted"
1299 # we don't want the disk to be modifiable
1300 addtrap
'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;"
1301 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1305 local PROTO
="${1%%:*}"
1306 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1307 download
-file "$1" "$2" "$3" 2>&1 ; then
1310 # only if the file exists the download was successful
1311 if [ -r "$2" ]; then
1319 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1320 if [ -n "$DIFFTEXT" ]; then
1322 echo >&2 "$DIFFTEXT"
1330 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1331 local COMPAREFILE
="$1"
1333 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1336 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1337 cat "$COMPAREFILE" >>"${OUTPUT}"
1338 msgfailoutput
'' "$OUTPUT" "$@"
1343 msggroup
'testfileequal'
1344 local MSG
='Test for correctness of file'
1345 if [ "$1" = '--nomsg' ]; then
1351 if [ -n "$MSG" ]; then
1352 msgtest
"$MSG" "$FILE"
1354 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1355 if [ -z "$*" ]; then
1356 testoutputequal
"$FILE" echo -n ''
1358 testoutputequal
"$FILE" echo "$*"
1364 msggroup
'testempty'
1365 if [ "$1" = '--nomsg' ]; then
1368 msgtest
"Test for no output of" "$*"
1370 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1371 if "$@" >"$COMPAREFILE" 2>&1 && test ! -s "$COMPAREFILE"; then
1374 msgfailoutput
'' "$COMPAREFILE" "$@"
1376 aptautotest
'testempty' "$@"
1380 msggroup
'testnotempty'
1381 msgtest
"Test for some output of" "$*"
1382 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
1383 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then
1386 msgfailoutput
'' "$COMPAREFILE" "$@"
1388 aptautotest
'testnotempty' "$@"
1393 msggroup
'testequal'
1394 local MSG
='Test of equality of'
1395 if [ "$1" = '--nomsg' ]; then
1400 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1401 echo "$1" > "$COMPAREFILE"
1404 if [ -n "$MSG" ]; then
1407 testoutputequal
"$COMPAREFILE" "$@"
1408 aptautotest
'testequal' "$@"
1413 msggroup
'testequalor2'
1414 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1415 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1416 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1417 echo "$1" > "$COMPAREFILE1"
1418 echo "$2" > "$COMPAREFILE2"
1420 msgtest
"Test for equality OR of" "$*"
1421 "$@" >"$COMPAREAGAINST" 2>&1 || true
1422 if checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null
2>&1 || \
1423 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null
2>&1
1427 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1428 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1429 checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1430 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1431 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1432 msgfailoutput
'' "$OUTPUT"
1434 aptautotest
'testequalor2' "$@"
1439 msggroup
'testshowvirtual'
1440 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1443 while [ -n "$1" ]; do
1445 N: Can't select versions from package '$1' as it is purely virtual"
1446 PACKAGE
="${PACKAGE} $1"
1449 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1451 N: No packages found"
1452 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1453 local ARCH
="$(getarchitecture 'native')"
1454 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1455 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1456 testoutputequal
"$COMPAREFILE" aptcache show
"$PACKAGE"
1461 msggroup
'testnopackage'
1462 msgtest
"Test for non-existent packages" "apt-cache show $*"
1463 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1464 if [ -n "$SHOWPKG" ]; then
1465 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1466 echo "$SHOWPKG" >"$OUTPUT"
1467 msgfailoutput
'' "$OUTPUT"
1473 testnosrcpackage
() {
1474 msggroup
'testnosrcpackage'
1475 msgtest
"Test for non-existent source packages" "apt-cache showsrc $*"
1476 local SHOWPKG
="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')"
1477 if [ -n "$SHOWPKG" ]; then
1478 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output"
1479 echo "$SHOWPKG" >"$OUTPUT"
1480 msgfailoutput
'' "$OUTPUT"
1488 msggroup
'testdpkgstatus'
1492 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1493 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1494 if [ "$PKGS" != $NR ]; then
1495 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1496 echo "$PKGS" >"$OUTPUT"
1497 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1498 msgfailoutput
'' "$OUTPUT"
1505 testdpkginstalled
() {
1506 msggroup
'testdpkginstalled'
1507 testdpkgstatus
'ii' "$#" "$@"
1511 testdpkgnotinstalled
() {
1512 msggroup
'testdpkgnotinstalled'
1513 testdpkgstatus
'ii' '0' "$@"
1518 msggroup
'testmarkedauto'
1519 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1520 if [ -n "$1" ]; then
1521 msgtest
'Test for correctly marked as auto-installed' "$*"
1522 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1524 msgtest
'Test for correctly marked as auto-installed' 'no package'
1525 echo -n > "$COMPAREFILE"
1527 testoutputequal
"$COMPAREFILE" aptmark showauto
1530 testmarkedmanual
() {
1531 msggroup
'testmarkedmanual'
1532 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1533 if [ -n "$1" ]; then
1534 msgtest
'Test for correctly marked as manually installed' "$*"
1535 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1537 msgtest
'Test for correctly marked as manually installed' 'no package'
1538 echo -n > "$COMPAREFILE"
1540 testoutputequal
"$COMPAREFILE" aptmark showmanual
1545 if [ "${1##*.}" = 'deb' ]; then
1546 stat
>&2 "$1" || true
1547 file >&2 "$1" || true
1549 cat >&2 "$1" || true
1553 msgreportheader
'msgfailoutput'
1558 if [ "$1" = 'grep' -o "$1" = 'tail' -o "$1" = 'head' ]; then
1560 while [ -n "$2" ]; do shift; done
1561 echo "#### Complete file: $1 ####"
1563 echo "#### $CMD output ####"
1564 elif [ "$1" = 'test' ]; then
1566 # doesn't support ! or non-file flags
1567 msgfailoutputstatfile
() {
1568 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1569 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1570 echo "#### stat(2) of file: $2 ####"
1572 if test -d "$2"; then
1573 echo "#### The directory contains: $2 ####"
1575 elif test -e "$2"; then
1576 echo "#### Complete file: $2 ####"
1581 msgfailoutputstatfile
"$2" "$3"
1582 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1584 msgfailoutputstatfile
"$2" "$3"
1586 echo '#### test output ####'
1587 elif [ "$1" = 'cmp' ]; then
1589 while [ -n "$2" ]; do
1590 echo "#### Complete file: $2 ####"
1594 echo '#### cmp output ####'
1600 testsuccesswithglobalerror
() {
1605 if [ "$1" = '--nomsg' ]; then
1608 msgtest
'Test for successful execution of' "$*"
1610 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output"
1611 if "$@" >"${OUTPUT}" 2>&1; then
1612 if expr match
"$1" '^apt.*' >/dev
/null
; then
1613 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1614 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1615 elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1616 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1617 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1618 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1621 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1624 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1626 elif [ "$TYPE" = 'testsuccesswithnotice' ]; then
1627 if grep -q -E "^N: " "$OUTPUT"; then
1630 msgfailoutput
'successful run, but output had no notices' "$OUTPUT" "$@"
1640 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1642 aptautotest
"$TYPE" "$@"
1645 testsuccesswithnotice
() {
1646 testsuccesswithglobalerror
'testsuccesswithnotice' 'WE' "$@"
1649 testsuccesswithglobalerror
'testsuccess' 'NWE' "$@"
1652 msggroup
'testwarning'
1653 if [ "$1" = '--nomsg' ]; then
1656 msgtest
'Test for successful execution with warnings of' "$*"
1658 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1659 if "$@" >"${OUTPUT}" 2>&1; then
1660 if expr match
"$1" '^apt.*' >/dev
/null
; then
1661 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1662 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1663 elif grep -q -E '^E: ' "$OUTPUT"; then
1664 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1665 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1666 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1675 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1677 aptautotest
'testwarning' "$@"
1681 msggroup
'testfailure'
1682 if [ "$1" = '--nomsg' ]; then
1685 msgtest
'Test for failure in execution of' "$*"
1687 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1688 if "$@" >"${OUTPUT}" 2>&1; then
1690 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1693 if expr match
"$1" '^apt.*' >/dev
/null
; then
1694 if [ "$1" = 'aptkey' ]; then
1695 if grep -q " Can't check signature:
1697 signature could not be verified" "$OUTPUT"; then
1700 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1703 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1704 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1705 elif grep -q -E '==ERROR' "$OUTPUT"; then
1706 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1707 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1708 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1717 aptautotest
'testfailure' "$@"
1721 testreturnstateequal
() {
1723 if [ "$STATE" = 'testsuccesswithglobalerror' ]; then
1727 msggroup
"${STATE}equal"
1728 if [ "$1" != '--nomsg' ]; then
1731 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1732 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1736 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1737 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1740 msggroup
"${STATE}equal"
1741 if [ "$2" != '--nomsg' ]; then
1745 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1749 "$STATE" --nomsg "$@"
1750 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1755 testsuccessequal
() {
1756 # we compare output, so we know perfectly well about N:
1757 testreturnstateequal
'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@"
1759 testwarningequal
() {
1760 testreturnstateequal
'testwarning' "$@"
1762 testfailureequal
() {
1763 testreturnstateequal
'testfailure' "$@"
1767 msggroup
'testfailuremsg'
1771 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1772 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1773 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1774 testoutputequal
"$COMPAREFILE" echo "$CMP"
1778 msggroup
'testwarningmsg'
1782 msgtest
'Check that the output of the previous warned command has expected' 'warnings'
1783 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
1784 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
1785 testoutputequal
"$COMPAREFILE" echo "$CMP"
1790 msggroup
'testfilestats'
1791 msgtest
"Test that file $1 has $2 $3" "$4"
1792 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1795 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1798 echo -n "stat(1) reports for $2: "
1799 stat
--format "$2" "$1" || true
1801 msgfailoutput
'' "$OUTPUT"
1805 testaccessrights
() {
1806 msggroup
'testaccessrights'
1807 testfilestats
"$1" '%a' '=' "$2"
1811 testwebserverlaststatuscode
() {
1812 msggroup
'testwebserverlaststatuscode'
1813 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1814 local STATUS
='downloaded/webserverstatus-statusfile.log'
1815 rm -f "$DOWNLOG" "$STATUS"
1816 msgtest
'Test last status code from the webserver was' "$1"
1817 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1820 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1822 if [ -n "$2" ]; then
1824 echo >&2 '#### Additionally provided output files contain:'
1827 echo >&2 '#### Download log of the status code:'
1830 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1835 createlistofkeys
() {
1838 while [ -n "$1" ]; do
1839 # gpg 2.1.something starts printing [SC] at some point
1840 if grep -q ' rsa2048/' "$OUTPUT" && grep -qF '[SC]' "$OUTPUT"; then
1842 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';;
1843 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [SC] [expired: 2013-07-13]';;
1844 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16 [SC]';;
1845 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19 [SC]';;
1846 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';;
1847 *) echo 'UNKNOWN KEY';;
1849 # gpg 2.1 has a slightly different output format
1850 elif grep -q ' rsa2048/' "$OUTPUT"; then
1852 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1853 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1854 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16';;
1855 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19';;
1856 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1857 *) echo 'UNKNOWN KEY';;
1861 *Joe
*|*Sixpack
*) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1862 *Rex
*|*Expired
*) echo 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1863 *Marvin
*|*Paranoid
*) echo 'pub 2048R/528144E2 2011-01-16';;
1864 oldarchive
) echo 'pub 1024R/F68C85A3 2013-12-19';;
1865 newarchive
) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1866 *) echo 'UNKNOWN KEY';;
1873 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output"
1874 if ! aptkey list
| grep '^pub' > "$OUTPUT"; then
1877 testfileequal
"$OUTPUT" "$(createlistofkeys "$OUTPUT" "$@")"
1881 echo "STOPPED execution. Press enter to continue"
1886 logcurrentarchivedirectory
() {
1887 find "${TMPWORKINGDIRECTORY}/aptarchive/dists" -type f
| while read line
; do
1888 stat
--format '%U:%G:%a:%n' "$line"
1889 done | sort > "${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst"
1891 listcurrentlistsdirectory
() {
1893 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1894 stat
--format '%U:%G:%a:%n' "$line"
1896 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1897 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1901 forallsupportedcompressors
() {
1902 rm -f "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
1903 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
1904 if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi
1909 ### convenience hacks ###
1911 # creating some directories by hand is a tedious task, so make it look simple
1913 if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then
1914 # only the last directory created by mkdir is effected by the -m !
1915 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1916 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1917 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1918 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1919 if [ "$(id -u)" = '0' ]; then
1920 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1927 ### The following tests are run by most test methods automatically to check
1928 ### general things about commands executed without writing the test every time.
1934 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')"
1935 if command -v $AUTOTEST >/dev
/null
; then
1937 # save and restore the *.output files from other tests
1938 # as we might otherwise override them in these automatic tests
1939 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1940 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1941 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1942 $AUTOTEST "$TESTCALL" "$@"
1943 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1944 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1945 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1949 aptautotest_aptget_update
() {
1951 while [ -n "$2" ]; do
1952 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1955 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1956 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1957 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1958 # all copied files are properly chmodded
1959 local backupIFS
="$IFS"
1960 IFS
="$(printf "\n\b")"
1961 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1962 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1965 if [ "$TESTCALL" = 'testsuccess' ]; then
1966 # failure cases can retain partial files and such
1967 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
1969 if [ -s "${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" ]; then
1970 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" \
1971 "$(find "${TMPWORKINGDIRECTORY}/aptarchive/dists" -type f | while read line; do stat --format '%U:%G:%a:%n' "$line"; done | sort)"
1974 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1975 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
1977 testaptautotestnodpkgwarning
() {
1979 while [ -n "$2" ]; do
1980 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
1981 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
1984 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1987 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
1988 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
1989 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
1990 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
1991 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
1992 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }