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
34 if [ "$MSGCOLOR" != 'NO' ]; then
35 CERROR
="\033[1;31m" # red
36 CWARNING
="\033[1;33m" # yellow
37 CMSG
="\033[1;32m" # green
38 CINFO
="\033[1;96m" # light blue
39 CDEBUG
="\033[1;94m" # blue
40 CNORMAL
="\033[0;39m" # default system console color
41 CDONE
="\033[1;32m" # green
42 CPASS
="\033[1;32m" # green
43 CFAIL
="\033[1;31m" # red
44 CCMD
="\033[1;35m" # pink
56 printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghks]\)#apt-\1#')"
62 msgdie
() { msgprintf
"${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; }
63 msgwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; }
64 msgmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; }
65 msginfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; }
66 msgdebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; }
67 msgdone
() { msgprintf
"${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; }
68 msgnwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; }
69 msgnmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}" "$@"; }
70 msgninfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
71 msgndebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
72 msgtest
() { msgprintf
"${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
73 msgpass
() { printf "${CPASS}PASS${CNORMAL}\n"; }
75 if [ -n "$MSGTEST_MSG" ]; then
76 test "$1" != 'msgfailoutput' || echo
77 if [ -n "$MSGTEST_MSGMSG" ]; then
78 echo "$MSGTEST_MSGMSG"
80 if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then
81 echo "${CFAIL}Part of the test group: $MSGTEST_GRP"
83 echo -n "$MSGTEST_MSG"
88 msgreportheader
'msgskip'
89 if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
90 else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
93 msgreportheader
'msgfail'
94 if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
95 else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
96 if [ -n "$APT_DEBUG_TESTS" ]; then
99 EXIT_CODE
=$((EXIT_CODE+1));
104 if [ $MSGGROUP_LEVEL = 0 ]; then
107 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL+1));
109 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL-1));
110 if [ $MSGGROUP_LEVEL = 0 ]; then
116 # enable / disable Debugging
117 if [ $MSGLEVEL -le 0 ]; then
120 if [ $MSGLEVEL -le 1 ]; then
124 if [ $MSGLEVEL -le 2 ]; then
126 MSGTEST_MSGMSG
="$(msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@")"
130 MSGTEST_MSG
="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")"
131 if [ "$MSGTEST_GRP" = 'NEXT' ]; then
132 MSGTEST_GRP
="$MSGTEST_MSG"
135 msgpass
() { printf " ${CPASS}P${CNORMAL}"; }
137 if [ $MSGLEVEL -le 3 ]; then
141 if [ $MSGLEVEL -le 4 ]; then
143 msgndebug
() { true
; }
146 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
147 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
148 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
149 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
150 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
153 printf "${CDONE}DONE${CNORMAL}\n";
157 if [ -f .
/aptconfig.conf
]; then
158 echo "$(readlink -f ./aptconfig.conf)"
159 elif [ -f ..
/aptconfig.conf
]; then
160 echo "$(readlink -f ../aptconfig.conf)"
161 elif [ -f ..
/..
/aptconfig.conf
]; then
162 echo "$(readlink -f ../../aptconfig.conf)"
163 elif [ -f "${TMPWORKINGDIRECTORY}/aptconfig.conf" ]; then
164 echo "$(readlink -f "${TMPWORKINGDIRECTORY}/aptconfig.conf")"
168 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
172 sh
|aptitude
|*/*|command) ;;
173 *) CMD
="${BUILDDIRECTORY}/$CMD";;
175 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
="${LIBRARYPATH}:${LD_LIBRARY_PATH}" "$CMD" "$@"
177 runpython3
() { runapt
command python3
"$@"; }
178 aptconfig
() { runapt apt
-config "$@"; }
179 aptcache
() { runapt apt
-cache "$@"; }
180 aptcdrom
() { runapt apt
-cdrom "$@"; }
181 aptget
() { runapt apt
-get "$@"; }
182 aptftparchive
() { runapt
"${APTFTPARCHIVEBINDIR}/apt-ftparchive" "$@"; }
183 aptkey
() { runapt apt
-key "$@"; }
184 aptmark
() { runapt apt
-mark "$@"; }
185 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; }
186 apt
() { runapt apt
"$@"; }
187 apthelper
() { runapt
"${APTHELPERBINDIR}/apt-helper" "$@"; }
188 aptwebserver
() { runapt
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
189 aptitude
() { runapt aptitude
"$@"; }
190 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; }
191 aptinternalsolver
() { runapt
"${APTINTERNALSOLVER}" "$@"; }
192 aptdumpsolver
() { runapt
"${APTDUMPSOLVER}" "$@"; }
193 aptinternalplanner
() { runapt
"${APTINTERNALPLANNER}" "$@"; }
196 "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@"
199 command perl
-MDpkg -E 'say $Dpkg::PROGVERSION'
201 dpkgcheckbuilddeps
() {
202 command dpkg
-checkbuilddeps --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" "$@"
207 aptget
) CMD
="apt-get";;
208 aptcache
) CMD
="apt-cache";;
209 aptcdrom
) CMD
="apt-cdrom";;
210 aptconfig
) CMD
="apt-config";;
211 aptmark
) CMD
="apt-mark";;
212 apthelper
) CMD
="apt-helper";;
213 aptftparchive
) CMD
="apt-ftparchive";;
214 dpkg
) shift; runapt
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" "$@"; return;;
218 if [ "${CMD##*/}" = "$CMD" ]; then
219 CMD
="${BUILDDIRECTORY}/${CMD}"
221 runapt
command gdb
--quiet -ex "directory '$SOURCEDIRECTORY'" -ex run
"$CMD" --args "$CMD" "$@"
224 date -u -d "@$(stat -c '%Y' "${TMPWORKINGDIRECTORY}/$1")" -R
227 grep "^${2:-Date}:" "$1" | cut
-d' ' -f 2-
231 # error if we about to overflow, but ...
232 # "255 failures ought to be enough for everybody"
233 if [ $EXIT_CODE -gt 255 ]; then
234 msgdie
"Total failure count $EXIT_CODE too big"
236 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
239 shellsetedetector
() {
241 if [ "$exit_status" != '0' ]; then
242 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
243 if [ "$EXIT_CODE" = '0' ]; then
244 EXIT_CODE
="$exit_status"
250 if [ "$1" = 'prefix' ]; then
251 CURRENTTRAP
="$2 $CURRENTTRAP"
253 CURRENTTRAP
="$CURRENTTRAP $1"
255 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
259 echo "$@" | sed -e "s#'#'\"'\"'#g"
262 find_project_binary_dir
() {
263 local TESTDIRECTORY
="$(readlink -f "$(dirname $0)")"
264 if [ -z "$PROJECT_BINARY_DIR" ]; then
266 for dir in ${TESTDIRECTORY}/../../ ${TESTDIRECTORY}/../../*; do
267 test -e "$dir/CMakeCache.txt
" || continue
268 if [ -z "$PROJECT_BINARY_DIR" ] ||
269 [ "$dir/CMakeCache.txt
" -nt "$PROJECT_BINARY_DIR/CMakeCache.txt
" ]; then
270 PROJECT_BINARY_DIR="$dir"
273 if [ -z "$PROJECT_BINARY_DIR" ]; then
274 echo "Cannot
find build directory
, you might want to
set PROJECT_BINARY_DIR
" >&2
277 export PROJECT_BINARY_DIR
281 # Next check needs a gnu stat, let's figure that out early.
283 if command -v gnustat >/dev/null 2>&1; then
286 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
287 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$($stat --format '%a' "$TMPDIR")" != '1777' ]; then
290 TMPWORKINGDIRECTORY="$(mktemp -d)"
291 addtrap "cd /; rm -rf '$(escape_shell "$TMPWORKINGDIRECTORY")';"
292 if [ -n "$TMPDIR_ADD" ]; then
293 TMPWORKINGDIRECTORY="${TMPWORKINGDIRECTORY}/${TMPDIR_ADD}"
294 mkdir -p "$TMPWORKINGDIRECTORY"
296 export TMPDIR="$TMPWORKINGDIRECTORY"
298 msgninfo "Preparing environment
for ${0##*/} in ${TMPWORKINGDIRECTORY}…
"
300 # Setup coreutils on BSD systems
301 mkdir "${TMPWORKINGDIRECTORY}/bin
"
302 for prefix in gnu g; do
303 for command in stat touch sed cp tr sha1sum sha256sum md5sum sha512sum grep date wc chmod head readlink tar expr base64; do
304 if command -v $prefix$command 2>/dev/null >/dev/null; then
305 [ -e "${TMPWORKINGDIRECTORY}/bin
/$command" ] || ln -sf $(command -v $prefix$command) "${TMPWORKINGDIRECTORY}/bin
/$command"
309 export PATH="${TMPWORKINGDIRECTORY}/bin
/:$PATH"
312 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded
"
313 if [ "$(id -u)" = '0' ]; then
314 # relax permissions so that running as root with user switching works
316 chmod 711 "$TMPWORKINGDIRECTORY"
317 chown _apt:root "${TMPWORKINGDIRECTORY}/downloaded
"
320 TESTDIRECTORY="$(readlink -f "$(dirname $0)")"
321 # Find the newest build directory (sets PROJECT_BINARY_DIR)
322 find_project_binary_dir
323 # allow overriding the default BUILDDIR location
324 SOURCEDIRECTORY
="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}"
325 BUILDDIRECTORY
="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${PROJECT_BINARY_DIR}/cmdline"}"
326 LIBRARYPATH
="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}/../apt-pkg"}"
327 METHODSDIR
="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/../methods"}"
328 APTHELPERBINDIR
="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}"
329 APTWEBSERVERBINDIR
="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}/../test/interactive-helper"}"
330 APTFTPARCHIVEBINDIR
="${APT_INTEGRATION_TESTS_FTPARCHIVE_BIN_DIR:-"${BUILDDIRECTORY}/../ftparchive"}"
331 APTINTERNALSOLVER
="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/solvers/apt"}"
332 APTDUMPSOLVER
="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/solvers/dump"}"
333 APTINTERNALPLANNER
="${APT_INTEGRATION_TESTS_INTERNAL_PLANNER:-"${BUILDDIRECTORY}/planners/apt"}"
334 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
337 cd "$TMPWORKINGDIRECTORY"
338 mkdir rootdir aptarchive keys
340 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
341 mkdir -p usr
/bin var
/cache var
/lib var
/log var
/crash tmp
342 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
343 mkdir -p usr
/lib
/apt
/solvers usr
/lib
/apt
/planners
344 touch var
/lib
/dpkg
/available
345 ln -s "${METHODSDIR}" usr
/lib
/apt
/methods
346 ln -s "${APTDUMPSOLVER}" usr
/lib
/apt
/solvers
/dump
347 ln -s "${APTDUMPSOLVER}" usr
/lib
/apt
/planners
/dump
348 ln -s "${APTINTERNALSOLVER}" usr
/lib
/apt
/solvers
/apt
349 ln -s "${APTINTERNALPLANNER}" usr
/lib
/apt
/planners
/apt
350 echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" >> ..
/aptconfig.conf
351 echo "Dir::Bin::Planners \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/planners\";" >> ..
/aptconfig.conf
352 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
354 if [ -z "${APT_INTEGRATION_TESTS_SOURCE_DIR}" ]; then
355 ln -s "${SOURCEDIRECTORY}/debian/apt.conf.autoremove" etc
/apt
/apt.conf.d
/01autoremove
357 ln -s /etc
/apt
/apt.conf.d
/01autoremove etc
/apt
/apt.conf.d
/01autoremove
360 local BASENAME
="${0##*/}"
361 local PACKAGESFILE
="Packages-${BASENAME#*-}"
362 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
363 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive
/Packages
365 local SOURCESSFILE
="Sources-${BASENAME#*-}"
366 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
367 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
369 find "$TESTDIRECTORY" \
( -name '*.pub' -o -name '*.sec' \
) -exec cp '{}' keys
/ \
;
371 ln -s "${TMPWORKINGDIRECTORY}/keys/joesixpack.pub" rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
373 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
374 echo "Dir::Etc \"etc\";" >> aptconfig.conf
375 echo "Dir::State \"var/lib/apt\";" >> aptconfig.conf
376 echo "Dir::Cache \"var/cache/apt\";" >> aptconfig.conf
377 echo "Dir::Etc \"etc/apt\";" >> aptconfig.conf
378 echo "Dir::Log \"var/log/apt\";" >> aptconfig.conf
379 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
380 echo "Dir::Bin::Methods \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/methods\";" >> aptconfig.conf
381 # either store apt-key were we can access it, even if we run it as a different user
382 #cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
383 #chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
384 #echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
385 # destroys coverage reporting though, so we disable changing user for the calling gpgv
386 echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
387 if [ "$(id -u)" = '0' ]; then
388 echo 'Binary::gpgv::APT::Sandbox::User "root";' >> aptconfig.conf
389 # same for the solver executables
390 echo 'APT::Solver::RunAsUser "root";' >> aptconfig.conf
391 echo 'APT::Planner::RunAsUser "root";' >> aptconfig.conf
394 cat > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" <<EOF
397 if [ -r '${TMPWORKINGDIRECTORY}/noopchroot.so' ]; then
398 if [ -n "\$LD_LIBRARY_PATH" ]; then
399 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}:'"\${LD_LIBRARY_PATH}"
401 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}'
403 if [ -n "\$LD_PRELOAD" ]; then
404 export LD_PRELOAD="noopchroot.so \${LD_PRELOAD}"
406 export LD_PRELOAD="noopchroot.so"
410 cp "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg"
411 cat >> "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" <<EOF
412 exec fakeroot '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
413 --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" \\
414 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
415 --force-not-root --force-bad-path "\$@"
417 cat >> "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" <<EOF
418 exec fakeroot gdb --quiet -ex run '${DPKG:-dpkg}' --args '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
419 --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" \\
420 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
421 --force-not-root --force-bad-path "\$@"
423 chmod +x
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg"
424 echo "Dir::Bin::dpkg \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg\";" > rootdir
/etc
/apt
/apt.conf.d
/99dpkg
427 if ! command dpkg
--assert-multi-arch >/dev
/null
2>&1; then
428 echo "DPKG::options:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
431 echo 'quiet::NoUpdate "true";'
432 echo 'quiet::NoStatistic "true";'
433 # too distracting for users, but helpful to detect changes
434 echo 'Acquire::Progress::Ignore::ShowErrorText "true";'
435 echo 'Acquire::Progress::Diffpercent "true";'
436 # in testcases, it can appear as if localhost has a rotation setup,
437 # hide this as we can't really deal with it properly
438 echo 'Acquire::Failure::ShowIP "false";'
439 # fakeroot can't fake everything, so disabled in production but good for tests
440 echo 'APT::Sandbox::Verify "true";'
443 cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
444 if [ "$(id -u)" = '0' ]; then
445 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
447 echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
448 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary
449 export APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE
=no
450 echo 'Acquire::Connect::AddrConfig "false";' > rootdir
/etc
/apt
/apt.conf.d
/connect
-addrconfig
452 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
453 confighashes
'SHA256' # these are tests, not security best-practices
455 # create some files in /tmp and look at user/group to get what this means
456 TEST_DEFAULT_USER
="$(id -un)"
457 touch "${TMPWORKINGDIRECTORY}/test-file"
458 TEST_DEFAULT_GROUP
=$(stat --format '%G' "${TMPWORKINGDIRECTORY}/test-file")
460 # cleanup the environment a bit
461 # prefer our apt binaries over the system apt binaries
462 export PATH
="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
464 unset LANGUAGE APT_CONFIG
465 unset GREP_OPTIONS DEB_BUILD_PROFILES
466 unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy
468 # If gpgv supports --weak-digest, pass it to make sure we can disable SHA1
469 if aptkey verify
--weak-digest SHA1
--help 2>/dev
/null
>/dev
/null
; then
470 echo 'Acquire::gpgv::Options { "--weak-digest"; "sha1"; };' > rootdir
/etc
/apt
/apt.conf.d
/no
-sha1
473 # most tests just need one signed Release file, not both
474 export APT_DONT_SIGN
='Release.gpg'
476 if [ -r "${TESTDIRECTORY}/extra-environment" ]; then
477 .
"${TESTDIRECTORY}/extra-environment"
484 if [ "$1" = "native" -o -z "$1" ]; then
485 eval `aptconfig shell ARCH APT::Architecture`
486 if [ -n "$ARCH" ]; then
489 dpkg
--print-architecture
497 aptconfig dump
--no-empty --format '%v%n' APT
::Architecture APT
::Architectures
| sort -u | tr '\n' ' '
500 getarchitecturesfromcommalist
() {
501 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
504 configarchitecture
() {
506 echo "APT::Architecture \"$(getarchitecture $1)\";"
507 while [ -n "$1" ]; do
508 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
511 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
516 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
517 local BASENAME
="${0##*/}"
518 local STATUSFILE
="status-${BASENAME#*-}"
519 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
520 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir
/var
/lib
/dpkg
/status
522 echo -n > rootdir
/var
/lib
/dpkg
/status
525 rm -f rootdir
/etc
/apt
/apt.conf.d
/00foreigndpkg
526 # if multi-arch make sure dpkg can detect itself as capable of it
527 if getarchitectures
| grep -E -q '[^ ]+ [^ ]+'; then
528 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
529 # dpkg doesn't really check the version as long as it is fully installed,
530 # but just to be sure we choose one above the required version
531 insertinstalledpackage
'dpkg' "all" '1.16.2+fake'
534 if dpkg
--assert-multi-arch >/dev
/null
2>&1 ; then
535 local ARCHS
="$(getarchitectures)"
536 local DPKGARCH
="$(dpkg --print-architecture)"
537 # this ensures that even if multi-arch isn't active in the view
538 # of apt, given that dpkg can't be told which arch is native
539 # the arch apt treats as native might be foreign for dpkg
540 for ARCH
in ${ARCHS}; do
541 if [ "${ARCH}" != "${DPKGARCH}" ]; then
542 if ! dpkg
--add-architecture ${ARCH} >/dev
/null
2>&1; then
543 # old-style used e.g. in Ubuntu-P – and as it seems travis
544 echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir
/etc
/apt
/apt.conf.d
/00foreigndpkg
545 echo "DPKG::options:: \"${ARCH}\";" >> rootdir
/etc
/apt
/apt.conf.d
/00foreigndpkg
552 configdpkgnoopchroot
() {
553 # create a library to noop chroot() and rewrite maintainer script executions
554 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
555 # chroot directory dpkg could chroot into to execute the maintainer scripts
556 msgtest
'Building library to preload to make maintainerscript work in' 'dpkg'
557 cat > noopchroot.c
<< EOF
564 static char * chrootdir = NULL;
566 int chroot(const char *path) {
567 printf("WARNING: CHROOTing to %s was ignored!\n", path);
569 chrootdir = strdup(path);
572 int execvp(const char *file, char *const argv[]) {
573 static int (*func_execvp) (const char *, char * const []) = NULL;
574 if (func_execvp == NULL)
575 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp");
576 if (chrootdir == NULL || strncmp(file, "/var/lib/dpkg/", strlen("/var/lib/dpkg/")) != 0)
577 return func_execvp(file, argv);
578 printf("REWRITE execvp call %s into %s\n", file, chrootdir);
580 if (asprintf(&newfile, "%s%s", chrootdir, file) == -1) {
584 char const * const baseadmindir = "/var/lib/dpkg";
586 if (asprintf(&admindir, "%s%s", chrootdir, baseadmindir) == -1) {
590 setenv("DPKG_ADMINDIR", admindir, 1);
591 return func_execvp(newfile, argv);
594 if cc
-ldl 2>&1 | grep -q dl
; then
595 testempty
--nomsg cc
-Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c
597 testempty
--nomsg cc
-Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c
-ldl
600 configcompression
() {
601 if [ "$1" = 'ALL' ]; then
602 configcompression
'.' $(aptconfig dump APT::Compressor --format '%t %v%n' | sed -n 's#^Extension \.\(.*\)$#\
1#p')
605 local CMD
='apthelper cat-file -C'
606 while [ -n "$1" ]; do
608 '.') printf ".\t.\tcat\n";;
609 'gz') printf "gzip\tgz\t$CMD $1\n";;
610 'bz2') printf "bzip2\tbz2\t$CMD $1\n";;
611 *) printf "$1\t$1\t$CMD $1\n";;
614 done > "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf"
618 echo 'APT::FTPArchive {'
620 while [ -n "$1" ]; do
621 printf "$1" | tr 'a-z' 'A-Z'
622 printf "\t\"true\";\n"
625 for h
in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
626 printf "$h\t\"false\";\n"
630 } >> "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/ftparchive-hashes.conf"
635 COMPRESSOR_CMD
="apthelper cat-file -C $1"
637 gzip) COMPRESS
='gz';;
638 bzip2) COMPRESS
='bz2';;
640 local CONFFILE
="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
641 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
642 Dir::Bin::uncompressed \"/does/not/exist\";" > "$CONFFILE"
643 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
644 if [ -z "$COMP" -o "$COMP" = '.' -o "$COMP" = "$COMPRESSOR" ]; then continue; fi
645 echo "Dir::Bin::${COMP} \"/does/not/exist\";" >> "$CONFFILE"
646 echo "APT::Compressor::${COMP}::Name \"${COMP}-disabled\";" >> "$CONFFILE"
650 _setupsimplenativepackage
() {
654 local RELEASE
="${4:-unstable}"
655 local DEPENDENCIES
="$5"
656 local DESCRIPTION
="${6:-an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
657 If you find such a package installed on your system,
658 something went horribly wrong! They are autogenerated
659 und used only by testcases and serve no other purpose…}"
661 local SECTION
="${7:-others}"
662 local PRIORITY
="${8:-optional}"
664 local COMPRESS_TYPE
="${10:-gzip}"
666 if [ "$SECTION" = "${SECTION#*/}" ]; then
669 DISTSECTION
="${SECTION%/*}"
671 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
673 mkdir -p "$BUILDDIR/debian/source"
674 echo "* most suckless software product ever" > "${BUILDDIR}/FEATURES"
676 echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}"
678 echo "Copyleft by Joe Sixpack $(date -u +%Y)" > "${BUILDDIR}/debian/copyright"
679 echo "$NAME ($VERSION) $RELEASE; urgency=low
683 -- Joe Sixpack <joe@example.org> $(date -u -R)" > "${BUILDDIR}/debian/changelog"
687 Maintainer: Joe Sixpack <joe@example.org>
688 Standards-Version: 3.9.3"
689 if [ "$SECTION" != '<none>' ]; then
690 echo "Section: $SECTION"
692 local BUILDDEPS
="$(printf "%b\n" "$DEPENDENCIES" | grep '^Build-')"
693 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
697 if [ "$ARCH" = 'all' ]; then
698 echo "Architecture: all"
700 echo "Architecture: any"
702 local DEPS
="$(printf "%b\n" "$DEPENDENCIES" | grep -v '^Build-')"
703 test -z "$DEPS" || echo "$DEPS"
704 printf "%b\n" "Description: $DESCRIPTION"
705 } > "${BUILDDIR}/debian/control"
707 echo '3.0 (native)' > "${BUILDDIR}/debian/source/format"
712 if command -v gmake
>/dev
/null
2>&1; then
713 [ -e ${TMPWORKINGDIRECTORY}/bin
/make ] || ln -s $(command -v gmake) ${TMPWORKINGDIRECTORY}/bin
/make
714 echo "#!${TMPWORKINGDIRECTORY}/bin/make -f" > "$OUT"
716 echo '#!/usr/bin/make -f' > "$OUT"
719 echo ' dh $@' >> "$OUT"
722 setupsimplenativepackage
() {
723 _setupsimplenativepackage
"$@"
726 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
727 test -e "${BUILDDIR}/debian/compat" || echo '7' > "${BUILDDIR}/debian/compat"
728 test -e "${BUILDDIR}/debian/rules" || make_tiny_rules
"${BUILDDIR}/debian/rules"
731 buildsimplenativepackage
() {
735 local RELEASE
="${4:-unstable}"
736 local DEPENDENCIES
="$5"
737 local DESCRIPTION
="$6"
738 local SECTION
="${7:-others}"
739 local PRIORITY
="${8:-optional}"
741 local COMPRESS_TYPE
="${10:-gzip}"
743 if [ "$SECTION" = "${SECTION#*/}" ]; then
746 DISTSECTION
="${SECTION%/*}"
748 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
749 msgtest
"Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
750 _setupsimplenativepackage
"$@"
752 testsuccess
--nomsg dpkg
-source -b ${NAME}-${VERSION}
754 sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" \
756 echo "pool/${SRC}" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist"
757 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
758 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
759 # adv --yes --default-key 'Joe Sixpack' \
760 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
761 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
765 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
766 msgtest
"Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
767 rm -rf "${BUILDDIR}/debian/tmp"
768 mkdir -p "${BUILDDIR}/debian/tmp/DEBIAN" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin"
769 cp "${BUILDDIR}/debian/copyright" "${BUILDDIR}/debian/changelog" "${BUILDDIR}/FEATURES" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}"
770 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}"
771 if [ -n "$FILE_TREE" ]; then
772 cp -ar "$FILE_TREE" "${BUILDDIR}/debian/tmp"
775 (cd "${BUILDDIR}"; dpkg
-gencontrol -DArchitecture=$arch)
776 (cd "${BUILDDIR}/debian/tmp"; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
777 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
778 # ensure the right permissions as dpkg-deb insists
779 chmod 755 "${BUILDDIR}/debian/tmp/DEBIAN"
780 testsuccess
--nomsg dpkg
-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian/tmp" "${BUILDDIR}/.."
781 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist"
785 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then
786 NM
="$(echo "$NAME" | cut -c 1-4)"
788 NM
="$(echo "$NAME" | cut -c 1)"
790 local CHANGEPATH
="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}"
791 mkdir -p "$CHANGEPATH"
792 cp "${BUILDDIR}/debian/changelog" "$CHANGEPATH"
801 local ARCH
=$(getarchitecture $4)
802 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
803 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
804 msgtest
"Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
806 if [ "$ARCH" = "all" ]; then
807 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
809 testsuccess
--nomsg dpkg
-buildpackage -uc -us -a$ARCH
810 cp "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$BUILDLOG"
811 local PKGS
="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
812 local SRCS
="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
815 echo "pool/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist"
818 echo "pool/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist"
823 if [ -d incoming
]; then
824 buildaptarchivefromincoming
"$@"
826 buildaptarchivefromfiles
"$@"
830 createaptftparchiveconfig
() {
831 local COMPRESSORS
="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
832 local COMPRESSORS
="${COMPRESSORS%* }"
833 local ARCHS
="$(getarchitectures)"
834 cat > ftparchive.conf
<<EOF
836 ArchiveDir "$(readlink -f .)";
837 CacheDir "$(readlink -f ..)";
838 FileListDir "$(readlink -f pool/)";
841 Packages::Compress "$COMPRESSORS";
842 Sources::Compress "$COMPRESSORS";
843 Contents::Compress "$COMPRESSORS";
844 Translation::Compress "$COMPRESSORS";
845 LongDescription "false";
849 SrcDirectory "pool/";
852 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
855 Architectures "$ARCHS all source";
856 FileList "${DIST}.\$(SECTION).pkglist";
857 SourceFileList "${DIST}.\$(SECTION).srclist";
858 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
861 done >> ftparchive.conf
864 buildaptftparchivedirectorystructure
() {
865 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
866 for DIST
in $DISTS; do
867 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
868 for SECTION
in $SECTIONS; do
869 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
870 for ARCH
in $ARCHS; do
871 mkdir -p "dists/${DIST}/${SECTION}/binary-${ARCH}"
873 mkdir -p "dists/${DIST}/${SECTION}/source"
874 mkdir -p "dists/${DIST}/${SECTION}/i18n"
884 local DEPENDENCIES
="$5"
885 local PRIORITY
="${6:-optional}"
886 local DESCRIPTION
="${7:-an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
887 If you find such a package installed on your system,
888 something went horribly wrong! They are autogenerated
889 und used only by testcases and serve no other purpose…}"
891 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
892 if [ "$RELEASE" = 'installed' ]; then
893 insertinstalledpackage
"$2" "$3" "$4" "$5" "$6" "$7"
896 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
897 if [ "$arch" = 'none' ]; then
898 ARCHS
="$(getarchitectures)"
902 for BUILDARCH
in $ARCHS; do
903 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
910 Maintainer: Joe Sixpack <joe@example.org>"
911 test "$arch" = 'none' || echo "Architecture: $arch"
912 echo "Version: $VERSION
913 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb"
914 test -z "$DEPENDENCIES" || printf "%b\n" "$DEPENDENCIES"
915 echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)"
916 echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
918 } >> "${PPATH}/Packages"
921 mkdir -p "aptarchive/dists/${RELEASE}/main/source" "aptarchive/dists/${RELEASE}/main/i18n"
922 touch "aptarchive/dists/${RELEASE}/main/source/Sources"
924 Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
925 Description-en: $DESCRIPTION
926 " >> "aptarchive/dists/${RELEASE}/main/i18n/Translation-en"
935 local DEPENDENCIES
="$5"
936 local BINARY
="${6:-$NAME}"
938 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
939 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
941 local FILE
="${SPATH}/Sources"
942 local DSCFILE
="${NAME}_${VERSION}.dsc"
943 local TARFILE
="${NAME}_${VERSION}.tar.gz"
947 Maintainer: Joe Sixpack <joe@example.org>
948 Architecture: $ARCH" >> $FILE
949 test -z "$DEPENDENCIES" || printf "%b\n" "$DEPENDENCIES" >> "$FILE"
951 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
952 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
954 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
955 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
960 insertinstalledpackage
() {
964 local DEPENDENCIES
="$4"
965 local PRIORITY
="${5:-optional}"
966 local STATUS
="${6:-install ok installed}"
967 local DESCRIPTION
="${7:-an autogenerated dummy ${NAME}=${VERSION}/installed
968 If you find such a package installed on your system,
969 something went horribly wrong! They are autogenerated
970 und used only by testcases and serve no other purpose…}"
972 local FILE
='rootdir/var/lib/dpkg/status'
973 local INFO
='rootdir/var/lib/dpkg/info'
974 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
980 Maintainer: Joe Sixpack <joe@example.org>
981 Version: $VERSION" >> "$FILE"
982 test "$arch" = 'none' || echo "Architecture: $arch" >> "$FILE"
983 test -z "$DEPENDENCIES" || printf "%b\n" "$DEPENDENCIES" >> "$FILE"
984 printf "%b\n" "Description: $DESCRIPTION" >> "$FILE"
986 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
987 echo -n > "${INFO}/${NAME}:${arch}.list"
989 echo -n > "${INFO}/${NAME}.list"
995 buildaptarchivefromincoming
() {
996 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on incoming packages…"
998 [ -e pool
] || ln -s ..
/incoming pool
999 [ -e ftparchive.conf
] || createaptftparchiveconfig
1000 [ -e dists
] || buildaptftparchivedirectorystructure
1001 msgninfo
"\tGenerate Packages, Sources and Contents files… "
1002 testsuccess aptftparchive generate ftparchive.conf
1005 generatereleasefiles
"$@"
1008 buildaptarchivefromfiles
() {
1009 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on prebuild files…"
1010 local DIR
='aptarchive'
1011 if [ -d "${DIR}/dists" ]; then DIR
="${DIR}/dists"; fi
1012 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
1013 msgninfo
"\t${line} file… "
1014 compressfile
"$line" "$1"
1017 generatereleasefiles
"$@"
1021 while read compressor extension
command; do
1022 if [ "$compressor" = '.' ]; then
1023 if [ -n "$2" ]; then
1028 cat "$1" | $command > "${1}.${extension}"
1029 if [ -n "$2" ]; then
1030 touch -d "$2" "${1}.${extension}"
1032 done < "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf"
1035 # can be overridden by testcases for their pleasure
1036 getcodenamefromsuite
() {
1038 unstable
) echo 'sid';;
1042 getreleaseversionfromsuite
() { true
; }
1043 getlabelfromsuite
() { true
; }
1044 getoriginfromsuite
() { true
; }
1045 getarchitecturesfromreleasefile
() { echo "all $(getarchitectures)"; }
1047 aptftparchiverelease
() {
1048 aptftparchive
-qq release
"$@" | sed -e '/0 Release$/ d' # remove the self reference
1050 generatereleasefiles
() {
1051 # $1 is the Date header and $2 is the ValidUntil header to be set
1052 # both should be given in notation date/touch can understand
1054 local VALIDUNTIL
="$2"
1055 if [ -e aptarchive
/dists
]; then
1056 msgninfo
"\tGenerate Release files for dists… "
1057 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
1058 local ARCHITECTURES
="$(getarchitecturesfromreleasefile "$dir")"
1059 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
1060 local CODENAME
="$(getcodenamefromsuite $SUITE)"
1061 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
1062 local LABEL
="$(getlabelfromsuite $SUITE)"
1063 local ORIGIN
="$(getoriginfromsuite $SUITE)"
1064 aptftparchiverelease
"$dir" \
1065 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
1066 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
1067 -o APT
::FTPArchive
::Release
::Architectures
="${ARCHITECTURES}" \
1068 -o APT
::FTPArchive
::Release
::Label
="${LABEL}" \
1069 -o APT
::FTPArchive
::Release
::Origin
="${ORIGIN}" \
1070 -o APT
::FTPArchive
::Release
::Version
="${VERSION}" \
1072 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
1073 sed -i '/^Date: / a\
1074 NotAutomatic: yes' "$dir/Release"
1078 msgninfo
"\tGenerate Release files for flat… "
1079 aptftparchiverelease .
/aptarchive
> aptarchive
/Release
1081 if [ -n "$DATE" -a "$DATE" != "now" ]; then
1082 for release
in $(find ./aptarchive -name 'Release'); do
1083 sed -i "s/^Date: .*$/Date: $(date -u -d "$DATE" -R)/" "$release"
1084 touch -d "$DATE" "$release"
1087 if [ -n "$VALIDUNTIL" ]; then
1088 sed -i "/^Date: / a\
1089 Valid-Until: $(date -u -d "$VALIDUNTIL" -R)" $(find ./aptarchive -name 'Release')
1094 setupdistsaptarchive
() {
1095 local APTARCHIVE
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1096 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
1097 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
1098 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1099 SECTIONS
=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1100 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
1101 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list"
1102 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list"
1107 setupflataptarchive
() {
1108 local APTARCHIVE
="$(readlink -f ./aptarchive)"
1109 local APTARCHIVEURI
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1110 if [ -f "${APTARCHIVE}/Packages" ]; then
1111 msgninfo
"\tadd deb sources.list line… "
1112 echo "deb file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1115 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1117 if [ -f "${APTARCHIVE}/Sources" ]; then
1118 msgninfo
"\tadd deb-src sources.list line… "
1119 echo "deb-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1122 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1128 if [ "$1" = '--no-update' ]; then
1132 buildaptarchive
"$@"
1133 if [ -e aptarchive
/dists
]; then
1134 setupdistsaptarchive
1138 signreleasefiles
'Joe Sixpack'
1139 if [ "1" != "$NOUPDATE" ]; then
1140 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
1144 signreleasefiles
() {
1145 local SIGNERS
="${1:-Joe Sixpack}"
1146 local REPODIR
="${2:-aptarchive}"
1147 if [ -n "$1" ]; then shift; fi
1148 if [ -n "$1" ]; then shift; fi
1149 local KEY
="keys/$(echo "$SIGNERS" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1150 msgninfo
"\tSign archive with $SIGNERS key $KEY… "
1151 local REXKEY
='keys/rexexpired'
1152 local SECEXPIREBAK
="${REXKEY}.sec.bak"
1153 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
1155 while [ -n "${SIGNERS%%,*}" ]; do
1156 local SIGNER
="${SIGNERS%%,*}"
1157 if [ "${SIGNERS}" = "${SIGNER}" ]; then
1160 SIGNERS
="${SIGNERS#*,}"
1161 # FIXME: This should be the full name, but we can't encode the space properly currently
1162 SIGUSERS
="${SIGUSERS} -u ${SIGNER#* }"
1163 if [ "${SIGNER}" = 'Rex Expired' ]; then
1164 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1165 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1166 # therefore we 'temporary' make the key not expired and restore a backup after signing
1167 cp "${REXKEY}.sec" "$SECEXPIREBAK"
1168 cp "${REXKEY}.pub" "$PUBEXPIREBAK"
1169 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
1170 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
1171 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1172 cp "$SECUNEXPIRED" "${REXKEY}.sec"
1173 cp "$PUBUNEXPIRED" "${REXKEY}.pub"
1175 if ! printf "expire\n1w\nsave\n" | aptkey
--quiet --keyring "${REXKEY}.pub" --secret-keyring "${REXKEY}.sec" \
1176 --readonly adv
--batch --yes --digest-algo "${APT_TESTS_DIGEST_ALGO:-SHA512}" \
1177 --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
1181 cp "${REXKEY}.sec" "$SECUNEXPIRED"
1182 cp "${REXKEY}.pub" "$PUBUNEXPIRED"
1185 if [ ! -e "${KEY}.pub" ]; then
1186 local K
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1187 cat "${K}.pub" >> "${KEY}.new.pub"
1188 cat "${K}.sec" >> "${KEY}.new.sec"
1191 if [ ! -e "${KEY}.pub" ]; then
1192 mv "${KEY}.new.pub" "${KEY}.pub"
1193 mv "${KEY}.new.sec" "${KEY}.sec"
1195 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes --digest-algo ${APT_TESTS_DIGEST_ALGO:-SHA512}"
1196 for RELEASE
in $(find "${REPODIR}/" -name Release); do
1197 # we might have set a specific date for the Release file, so copy it
1198 local DATE
="$(stat --format "%y" "${RELEASE}")"
1199 if [ "$APT_DONT_SIGN" = 'Release.gpg' ]; then
1200 rm -f "${RELEASE}.gpg"
1202 testsuccess
$GPG "$@" $SIGUSERS --armor --detach-sign --sign --output "${RELEASE}.gpg" "${RELEASE}"
1203 touch -d "$DATE" "${RELEASE}.gpg"
1205 local INRELEASE
="${RELEASE%/*}/InRelease"
1206 if [ "$APT_DONT_SIGN" = 'InRelease' ]; then
1209 testsuccess
$GPG "$@" $SIGUSERS --clearsign --output "$INRELEASE" "$RELEASE"
1210 touch -d "$DATE" "${INRELEASE}"
1213 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1214 mv -f "$SECEXPIREBAK" "${REXKEY}.sec"
1215 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub"
1220 redatereleasefiles
() {
1221 local DATE
="$(date -u -d "$1" -R)"
1222 for release
in $(find aptarchive/ -name 'Release'); do
1223 sed -i "s/^Date: .*$/Date: ${DATE}/" "$release"
1224 touch -d "$DATE" "$release"
1226 signreleasefiles
"${2:-Joe Sixpack}"
1230 local WEBSERVER
="${3:-http://localhost:${APTHTTPPORT}}"
1232 if [ "$1" = '--no-check' ]; then
1236 local DOWNLOG
='rootdir/tmp/download-testfile.log'
1237 local STATUS
='downloaded/webserverconfig.status'
1238 rm -f "$STATUS" "$DOWNLOG"
1239 # very very basic URI encoding
1241 if [ -n "$2" ]; then
1242 msgtest
"Set webserver config option '${1}' to" "$2"
1243 URI
="${WEBSERVER}/_config/set/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1245 msgtest
'Clear webserver config option' "${1}"
1246 URI
="${WEBSERVER}/_config/clear/$(echo "${1}" | sed -e 's/\//%2f/g')"
1248 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
1251 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.output"
1252 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1253 msgfailoutput
'' "$OUTPUT"
1255 $NOCHECK || testwebserverlaststatuscode
'200'
1258 rewritesourceslist
() {
1259 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1260 local APTARCHIVE2
="copy://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1261 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1262 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
1263 -e "s#http://[^@]*@\?localhost:${APTHTTPPORT}/\?#${1}#" \
1264 -e "s#https://[^@]*@\?localhost:${APTHTTPSPORT}/\?#${1}#"
1268 # wait for up to 10s for a pid file to appear to avoid possible race
1269 # when a helper is started and dosn't write the PID quick enough
1272 for i
in $(seq 10); do
1273 if test -s "$PIDFILE"; then
1278 msgdie
"waiting for $PIDFILE failed"
1282 changetowebserver
() {
1284 if [ "$1" != '--no-rewrite' ]; then
1289 if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
1291 local LOG
="webserver.log"
1292 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1296 waitforpidfile aptwebserver.pid
1297 local PID
="$(cat aptwebserver.pid)"
1298 if [ -z "$PID" ]; then
1299 msgdie
'Could not fork aptwebserver successfully'
1301 addtrap
"kill $PID;"
1302 waitforpidfile aptwebserver.port
1303 APTHTTPPORT
="$(cat aptwebserver.port)"
1304 if [ -z "$APTHTTPPORT" ]; then
1305 msgdie
'Could not get port for aptwebserver successfully'
1309 msgdie
'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver'
1311 if [ "$REWRTE" != 'yes' ]; then
1312 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1316 changetohttpswebserver
() {
1318 if command -v stunnel4
>/dev
/null
2>&1; then
1320 elif command -v stunnel
>/dev
/null
2>&1; then
1323 msgdie
'You need to install stunnel4 for https testcases'
1325 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1326 changetowebserver
--no-rewrite "$@"
1328 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1329 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1334 connect = $APTHTTPPORT
1335 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1336 $stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
1337 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1338 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1339 if [ -z "$PID" ]; then
1340 msgdie
'Could not fork $stunnel4 successfully'
1342 addtrap
'prefix' "kill ${PID};"
1343 APTHTTPSPORT
="$(lsof -i -n | awk "/^$stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1344 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1345 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1349 mkdir -p rootdir
/media
/cdrom
/.disk
1350 local CD
="$(readlink -f rootdir/media/cdrom)"
1351 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1352 acquire::cdrom::mount "${CD}";
1353 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1354 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1355 acquire::cdrom::autodetect 0;
1357 echo -n "$1" > "${CD}/.disk/info"
1358 if [ ! -d aptarchive
/dists
]; then
1359 msgdie
'Flat file archive cdroms can not be created currently'
1362 mv aptarchive
/dists
"$CD"
1363 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1364 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1365 # start with an unmounted disk
1366 mv "${CD}" "${CD}-unmounted"
1367 # we don't want the disk to be modifiable
1368 addtrap
'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;"
1369 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1373 local PROTO
="${1%%:*}"
1374 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1375 download
-file "$1" "$2" "$3" 2>&1 ; then
1378 # only if the file exists the download was successful
1379 if [ -r "$2" ]; then
1387 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1388 if [ -n "$DIFFTEXT" ]; then
1390 echo >&2 "$DIFFTEXT"
1398 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1399 local COMPAREFILE
="$1"
1401 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1404 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1405 cat "$COMPAREFILE" >>"${OUTPUT}"
1406 msgfailoutput
'' "$OUTPUT" "$@"
1411 msggroup
'testfileequal'
1412 local MSG
='Test for correctness of file'
1413 if [ "$1" = '--nomsg' ]; then
1419 if [ -n "$MSG" ]; then
1420 msgtest
"$MSG" "$FILE"
1422 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1423 if [ -z "$*" ]; then
1424 testoutputequal
"$FILE" echo -n ''
1426 testoutputequal
"$FILE" echo "$*"
1432 msggroup
'testempty'
1433 if [ "$1" = '--nomsg' ]; then
1436 msgtest
"Test for no output of" "$*"
1438 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1439 if "$@" >"$COMPAREFILE" 2>&1 && test ! -s "$COMPAREFILE"; then
1442 msgfailoutput
'' "$COMPAREFILE" "$@"
1444 aptautotest
'testempty' "$@"
1448 msggroup
'testnotempty'
1449 msgtest
"Test for some output of" "$*"
1450 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
1451 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then
1454 msgfailoutput
'' "$COMPAREFILE" "$@"
1456 aptautotest
'testnotempty' "$@"
1461 msggroup
'testequal'
1462 local MSG
='Test of equality of'
1463 if [ "$1" = '--nomsg' ]; then
1468 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1469 echo "$1" > "$COMPAREFILE"
1472 if [ -n "$MSG" ]; then
1475 testoutputequal
"$COMPAREFILE" "$@"
1476 aptautotest
'testequal' "$@"
1481 msggroup
'testequalor2'
1482 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1483 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1484 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1485 echo "$1" > "$COMPAREFILE1"
1486 echo "$2" > "$COMPAREFILE2"
1488 msgtest
"Test for equality OR of" "$*"
1489 "$@" >"$COMPAREAGAINST" 2>&1 || true
1490 if checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null
2>&1 || \
1491 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null
2>&1
1495 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1496 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1497 checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1498 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1499 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1500 msgfailoutput
'' "$OUTPUT"
1502 aptautotest
'testequalor2' "$@"
1507 msggroup
'testshowvirtual'
1508 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1511 while [ -n "$1" ]; do
1513 N: Can't select versions from package '$1' as it is purely virtual"
1514 PACKAGE
="${PACKAGE} $1"
1517 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1519 N: No packages found"
1520 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1521 local ARCH
="$(getarchitecture 'native')"
1522 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1523 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1524 testoutputequal
"$COMPAREFILE" aptcache show
"$PACKAGE"
1529 msggroup
'testnopackage'
1530 msgtest
"Test for non-existent packages" "apt-cache show $*"
1531 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1532 if [ -n "$SHOWPKG" ]; then
1533 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1534 echo "$SHOWPKG" >"$OUTPUT"
1535 msgfailoutput
'' "$OUTPUT"
1541 testnosrcpackage
() {
1542 msggroup
'testnosrcpackage'
1543 msgtest
"Test for non-existent source packages" "apt-cache showsrc $*"
1544 local SHOWPKG
="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')"
1545 if [ -n "$SHOWPKG" ]; then
1546 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output"
1547 echo "$SHOWPKG" >"$OUTPUT"
1548 msgfailoutput
'' "$OUTPUT"
1556 msggroup
'testdpkgstatus'
1560 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1561 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1562 if [ "$PKGS" != $NR ]; then
1563 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1564 echo "$PKGS" >"$OUTPUT"
1565 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1566 msgfailoutput
'' "$OUTPUT"
1573 testdpkginstalled
() {
1574 msggroup
'testdpkginstalled'
1575 testdpkgstatus
'ii' "$#" "$@"
1579 testdpkgnotinstalled
() {
1580 msggroup
'testdpkgnotinstalled'
1581 testdpkgstatus
'ii' '0' "$@"
1586 msggroup
'testmarkedauto'
1587 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1588 if [ -n "$1" ]; then
1589 msgtest
'Test for correctly marked as auto-installed' "$*"
1590 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1592 msgtest
'Test for correctly marked as auto-installed' 'no package'
1593 echo -n > "$COMPAREFILE"
1595 testoutputequal
"$COMPAREFILE" aptmark showauto
1598 testmarkedmanual
() {
1599 msggroup
'testmarkedmanual'
1600 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1601 if [ -n "$1" ]; then
1602 msgtest
'Test for correctly marked as manually installed' "$*"
1603 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1605 msgtest
'Test for correctly marked as manually installed' 'no package'
1606 echo -n > "$COMPAREFILE"
1608 testoutputequal
"$COMPAREFILE" aptmark showmanual
1613 if [ "${1##*.}" = 'deb' ]; then
1614 stat
>&2 "$1" || true
1615 file >&2 "$1" || true
1617 cat >&2 "$1" || true
1621 msgreportheader
'msgfailoutput'
1626 if [ "$1" = 'grep' -o "$1" = 'tail' -o "$1" = 'head' ]; then
1628 while [ -n "$2" ]; do shift; done
1629 echo "#### Complete file: $1 ####"
1631 echo "#### $CMD output ####"
1632 elif [ "$1" = 'test' ]; then
1634 # doesn't support ! or non-file flags
1635 msgfailoutputstatfile
() {
1636 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1637 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1638 echo "#### stat(2) of file: $2 ####"
1640 if test -d "$2"; then
1641 echo "#### The directory contains: $2 ####"
1643 elif test -e "$2"; then
1644 echo "#### Complete file: $2 ####"
1649 msgfailoutputstatfile
"$2" "$3"
1650 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1652 msgfailoutputstatfile
"$2" "$3"
1654 echo '#### test output ####'
1655 elif [ "$1" = 'cmp' ]; then
1657 while [ -n "$2" ]; do
1658 echo "#### Complete file: $2 ####"
1662 echo '#### cmp output ####'
1668 testsuccesswithglobalerror
() {
1673 if [ "$1" = '--nomsg' ]; then
1676 msgtest
'Test for successful execution of' "$*"
1678 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output"
1679 if "$@" >"${OUTPUT}" 2>&1; then
1680 if expr match
"$1" '^apt.*' >/dev
/null
; then
1681 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1682 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1683 elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1684 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1685 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1686 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1689 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1692 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1694 elif [ "$TYPE" = 'testsuccesswithnotice' ]; then
1695 if grep -q -E "^N: " "$OUTPUT"; then
1698 msgfailoutput
'successful run, but output had no notices' "$OUTPUT" "$@"
1708 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1710 aptautotest
"$TYPE" "$@"
1713 testsuccesswithnotice
() {
1714 testsuccesswithglobalerror
'testsuccesswithnotice' 'WE' "$@"
1717 testsuccesswithglobalerror
'testsuccess' 'NWE' "$@"
1720 msggroup
'testwarning'
1721 if [ "$1" = '--nomsg' ]; then
1724 msgtest
'Test for successful execution with warnings of' "$*"
1726 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1727 if "$@" >"${OUTPUT}" 2>&1; then
1728 if expr match
"$1" '^apt.*' >/dev
/null
; then
1729 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1730 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1731 elif grep -q -E '^E: ' "$OUTPUT"; then
1732 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1733 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1734 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1743 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1745 aptautotest
'testwarning' "$@"
1749 msggroup
'testfailure'
1750 if [ "$1" = '--nomsg' ]; then
1753 msgtest
'Test for failure in execution of' "$*"
1755 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1756 if "$@" >"${OUTPUT}" 2>&1; then
1758 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1761 if expr match
"$1" '^apt.*' >/dev
/null
; then
1762 if [ "$1" = 'aptkey' ]; then
1763 if grep -q " Can't check signature:
1765 signature could not be verified" "$OUTPUT"; then
1768 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1771 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1772 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1773 elif grep -q -E '==ERROR' "$OUTPUT"; then
1774 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1775 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1776 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1785 aptautotest
'testfailure' "$@"
1789 testreturnstateequal
() {
1791 if [ "$STATE" = 'testsuccesswithglobalerror' ]; then
1795 msggroup
"${STATE}equal"
1796 if [ "$1" != '--nomsg' ]; then
1799 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1800 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1804 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1805 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1808 msggroup
"${STATE}equal"
1809 if [ "$2" != '--nomsg' ]; then
1813 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1817 "$STATE" --nomsg "$@"
1818 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1823 testsuccessequal
() {
1824 # we compare output, so we know perfectly well about N:
1825 testreturnstateequal
'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@"
1827 testwarningequal
() {
1828 testreturnstateequal
'testwarning' "$@"
1830 testfailureequal
() {
1831 testreturnstateequal
'testfailure' "$@"
1835 msggroup
'testfailuremsg'
1839 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1840 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1841 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1842 testoutputequal
"$COMPAREFILE" echo "$CMP"
1846 msggroup
'testwarningmsg'
1850 msgtest
'Check that the output of the previous warned command has expected' 'warnings'
1851 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
1852 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
1853 testoutputequal
"$COMPAREFILE" echo "$CMP"
1858 msggroup
'testfilestats'
1859 msgtest
"Test that file $1 has $2 $3" "$4"
1860 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1863 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1866 echo -n "stat(1) reports for $2: "
1867 stat
--format "$2" "$1" || true
1869 msgfailoutput
'' "$OUTPUT"
1873 testaccessrights
() {
1874 msggroup
'testaccessrights'
1875 testfilestats
"$1" '%a' '=' "$2"
1879 testwebserverlaststatuscode
() {
1880 msggroup
'testwebserverlaststatuscode'
1881 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1882 local STATUS
='downloaded/webserverstatus-statusfile.log'
1883 rm -f "$DOWNLOG" "$STATUS"
1884 msgtest
'Test last status code from the webserver was' "$1"
1885 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1888 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1890 if [ -n "$2" ]; then
1892 echo >&2 '#### Additionally provided output files contain:'
1895 echo >&2 '#### Download log of the status code:'
1898 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1903 mapkeynametokeyid
() {
1904 while [ -n "$1" ]; do
1906 *Joe
*|*Sixpack
*|newarchive
) echo '5A90D141DBAC8DAE';;
1907 *Rex
*|*Expired
*) echo '4BC0A39C27CE74F9';;
1908 *Marvin
*|*Paranoid
*) echo 'E8525D47528144E2';;
1909 oldarchive
) echo 'FDD2DB85F68C85A3';;
1910 *) echo 'UNKNOWN KEY';;
1916 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output"
1917 if ! aptkey list
--with-colon | grep '^pub' | cut
-d':' -f 5 > "$OUTPUT"; then
1920 testfileequal
"$OUTPUT" "$(mapkeynametokeyid "$@")"
1924 echo "STOPPED execution. Press enter to continue"
1929 logcurrentarchivedirectory
() {
1930 find "${TMPWORKINGDIRECTORY}/aptarchive/dists" -type f
| while read line
; do
1931 stat
--format '%U:%G:%a:%n' "$line"
1932 done | sort > "${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst"
1934 listcurrentlistsdirectory
() {
1936 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1937 stat
--format '%U:%G:%a:%n' "$line"
1939 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1940 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1944 forallsupportedcompressors
() {
1945 rm -f "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
1946 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
1947 if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi
1952 ### convenience hacks ###
1954 # creating some directories by hand is a tedious task, so make it look simple
1956 if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then
1957 # only the last directory created by mkdir is effected by the -m !
1958 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1959 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1960 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1961 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1962 if [ "$(id -u)" = '0' ]; then
1963 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1970 ### The following tests are run by most test methods automatically to check
1971 ### general things about commands executed without writing the test every time.
1974 if [ $# -lt 3 ]; then return; fi
1980 if ! expr match
"$i" '^-' >/dev
/null
2>&1; then
1986 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')"
1987 if command -v $AUTOTEST >/dev
/null
; then
1988 # save and restore the *.output files from other tests
1989 # as we might otherwise override them in these automatic tests
1990 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1991 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1992 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1993 $AUTOTEST "$TESTCALL" "$@"
1994 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1995 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1996 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
2000 aptautotest_aptget_update
() {
2002 while [ -n "$2" ]; do
2003 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
2006 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
2007 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
2008 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
2009 # all copied files are properly chmodded
2010 local backupIFS
="$IFS"
2011 IFS
="$(printf "\n\b")"
2012 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
2013 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
2016 if [ "$TESTCALL" = 'testsuccess' ]; then
2017 # failure cases can retain partial files and such
2018 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
2020 if [ -s "${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" ]; then
2021 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" \
2022 "$(find "${TMPWORKINGDIRECTORY}/aptarchive/dists" -type f | while read line; do stat --format '%U:%G:%a:%n' "$line"; done | sort)"
2025 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
2026 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
2028 testaptautotestnodpkgwarning
() {
2030 while [ -n "$2" ]; do
2031 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
2032 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
2035 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
2038 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
2039 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
2040 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
2041 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
2042 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
2043 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }
2045 testaptmarknodefaultsections
() {
2046 testfailure
grep '^Auto-Installed: 0$' "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/extended_states"
2048 aptautotest_aptmark_auto
() { testaptmarknodefaultsections
"$@"; }
2049 aptautotest_aptmark_manual
() { testaptmarknodefaultsections
"$@"; }
2050 aptautotest_aptget_markauto
() { testaptmarknodefaultsections
"$@"; }
2051 aptautotest_aptget_markmanual
() { testaptmarknodefaultsections
"$@"; }