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:$(id -gn) "${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 # randomess and tests don't play well together
440 echo 'Acquire::IndexTargets::Randomized "false";'
441 # fakeroot can't fake everything, so disabled in production but good for tests
442 echo 'APT::Sandbox::Verify "true";'
445 cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
446 if [ "$(id -u)" = '0' ]; then
447 chown _apt
:$(id -gn) "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
449 echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
450 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary
451 export APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE
=no
452 echo 'Acquire::Connect::AddrConfig "false";' > rootdir
/etc
/apt
/apt.conf.d
/connect
-addrconfig
454 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
455 confighashes
'SHA256' # these are tests, not security best-practices
457 # create some files in /tmp and look at user/group to get what this means
458 TEST_DEFAULT_USER
="$(id -un)"
459 touch "${TMPWORKINGDIRECTORY}/test-file"
460 TEST_DEFAULT_GROUP
=$(stat --format '%G' "${TMPWORKINGDIRECTORY}/test-file")
462 # cleanup the environment a bit
463 # prefer our apt binaries over the system apt binaries
464 export PATH
="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
466 unset LANGUAGE APT_CONFIG
467 unset GREP_OPTIONS DEB_BUILD_PROFILES
468 unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy
470 # If gpgv supports --weak-digest, pass it to make sure we can disable SHA1
471 if aptkey verify
--weak-digest SHA1
--help 2>/dev
/null
>/dev
/null
; then
472 echo 'Acquire::gpgv::Options { "--weak-digest"; "sha1"; };' > rootdir
/etc
/apt
/apt.conf.d
/no
-sha1
475 # most tests just need one signed Release file, not both
476 export APT_DONT_SIGN
='Release.gpg'
478 if [ -r "${TESTDIRECTORY}/extra-environment" ]; then
479 .
"${TESTDIRECTORY}/extra-environment"
486 if [ "$1" = "native" -o -z "$1" ]; then
487 eval `aptconfig shell ARCH APT::Architecture`
488 if [ -n "$ARCH" ]; then
491 dpkg
--print-architecture
499 aptconfig dump
--no-empty --format '%v%n' APT
::Architecture APT
::Architectures
| sort -u | tr '\n' ' '
502 getarchitecturesfromcommalist
() {
503 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
506 configarchitecture
() {
508 echo "APT::Architecture \"$(getarchitecture $1)\";"
509 while [ -n "$1" ]; do
510 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
513 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
518 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
519 local BASENAME
="${0##*/}"
520 local STATUSFILE
="status-${BASENAME#*-}"
521 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
522 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir
/var
/lib
/dpkg
/status
524 echo -n > rootdir
/var
/lib
/dpkg
/status
527 rm -f rootdir
/etc
/apt
/apt.conf.d
/00foreigndpkg
528 # if multi-arch make sure dpkg can detect itself as capable of it
529 if getarchitectures
| grep -E -q '[^ ]+ [^ ]+'; then
530 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
531 # dpkg doesn't really check the version as long as it is fully installed,
532 # but just to be sure we choose one above the required version
533 insertinstalledpackage
'dpkg' "all" '1.16.2+fake'
536 if dpkg
--assert-multi-arch >/dev
/null
2>&1 ; then
537 local ARCHS
="$(getarchitectures)"
538 local DPKGARCH
="$(dpkg --print-architecture)"
539 # this ensures that even if multi-arch isn't active in the view
540 # of apt, given that dpkg can't be told which arch is native
541 # the arch apt treats as native might be foreign for dpkg
542 for ARCH
in ${ARCHS}; do
543 if [ "${ARCH}" != "${DPKGARCH}" ]; then
544 if ! dpkg
--add-architecture ${ARCH} >/dev
/null
2>&1; then
545 # old-style used e.g. in Ubuntu-P – and as it seems travis
546 echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir
/etc
/apt
/apt.conf.d
/00foreigndpkg
547 echo "DPKG::options:: \"${ARCH}\";" >> rootdir
/etc
/apt
/apt.conf.d
/00foreigndpkg
554 configdpkgnoopchroot
() {
555 # create a library to noop chroot() and rewrite maintainer script executions
556 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
557 # chroot directory dpkg could chroot into to execute the maintainer scripts
558 msgtest
'Building library to preload to make maintainerscript work in' 'dpkg'
559 cat > noopchroot.c
<< EOF
566 static char * chrootdir = NULL;
568 int chroot(const char *path) {
569 printf("WARNING: CHROOTing to %s was ignored!\n", path);
571 chrootdir = strdup(path);
574 int execvp(const char *file, char *const argv[]) {
575 static int (*func_execvp) (const char *, char * const []) = NULL;
576 if (func_execvp == NULL)
577 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp");
578 if (chrootdir == NULL || strncmp(file, "/var/lib/dpkg/", strlen("/var/lib/dpkg/")) != 0)
579 return func_execvp(file, argv);
580 printf("REWRITE execvp call %s into %s\n", file, chrootdir);
582 if (asprintf(&newfile, "%s%s", chrootdir, file) == -1) {
586 char const * const baseadmindir = "/var/lib/dpkg";
588 if (asprintf(&admindir, "%s%s", chrootdir, baseadmindir) == -1) {
592 setenv("DPKG_ADMINDIR", admindir, 1);
593 return func_execvp(newfile, argv);
596 if cc
-ldl 2>&1 | grep -q dl
; then
597 testempty
--nomsg cc
-Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c
599 testempty
--nomsg cc
-Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c
-ldl
602 configcompression
() {
603 if [ "$1" = 'ALL' ]; then
604 configcompression
'.' $(aptconfig dump APT::Compressor --format '%t %v%n' | sed -n 's#^Extension \.\(.*\)$#\
1#p')
607 local CMD
='apthelper cat-file -C'
608 while [ -n "$1" ]; do
610 '.') printf ".\t.\tcat\n";;
611 'gz') printf "gzip\tgz\t$CMD $1\n";;
612 'bz2') printf "bzip2\tbz2\t$CMD $1\n";;
613 *) printf "$1\t$1\t$CMD $1\n";;
616 done > "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf"
620 echo 'APT::FTPArchive {'
622 while [ -n "$1" ]; do
623 printf "$1" | tr 'a-z' 'A-Z'
624 printf "\t\"true\";\n"
627 for h
in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
628 printf "$h\t\"false\";\n"
632 } >> "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/ftparchive-hashes.conf"
637 COMPRESSOR_CMD
="apthelper cat-file -C $1"
639 gzip) COMPRESS
='gz';;
640 bzip2) COMPRESS
='bz2';;
642 local CONFFILE
="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
643 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
644 Dir::Bin::uncompressed \"/does/not/exist\";" > "$CONFFILE"
645 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
646 if [ -z "$COMP" -o "$COMP" = '.' -o "$COMP" = "$COMPRESSOR" ]; then continue; fi
647 echo "Dir::Bin::${COMP} \"/does/not/exist\";" >> "$CONFFILE"
648 echo "APT::Compressor::${COMP}::Name \"${COMP}-disabled\";" >> "$CONFFILE"
652 _setupsimplenativepackage
() {
656 local RELEASE
="${4:-unstable}"
657 local DEPENDENCIES
="$5"
658 local DESCRIPTION
="${6:-an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
659 If you find such a package installed on your system,
660 something went horribly wrong! They are autogenerated
661 und used only by testcases and serve no other purpose…}"
663 local SECTION
="${7:-others}"
664 local PRIORITY
="${8:-optional}"
666 local COMPRESS_TYPE
="${10:-gzip}"
668 if [ "$SECTION" = "${SECTION#*/}" ]; then
671 DISTSECTION
="${SECTION%/*}"
673 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
675 mkdir -p "$BUILDDIR/debian/source"
676 echo "* most suckless software product ever" > "${BUILDDIR}/FEATURES"
678 echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}"
680 echo "Copyleft by Joe Sixpack $(date -u +%Y)" > "${BUILDDIR}/debian/copyright"
681 echo "$NAME ($VERSION) $RELEASE; urgency=low
685 -- Joe Sixpack <joe@example.org> $(date -u -R)" > "${BUILDDIR}/debian/changelog"
689 Maintainer: Joe Sixpack <joe@example.org>
690 Standards-Version: 3.9.3"
691 if [ "$SECTION" != '<none>' ]; then
692 echo "Section: $SECTION"
694 local BUILDDEPS
="$(printf "%b\n" "$DEPENDENCIES" | grep '^Build-')"
695 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
699 if [ "$ARCH" = 'all' ]; then
700 echo "Architecture: all"
702 echo "Architecture: any"
704 local DEPS
="$(printf "%b\n" "$DEPENDENCIES" | grep -v '^Build-')"
705 test -z "$DEPS" || echo "$DEPS"
706 printf "%b\n" "Description: $DESCRIPTION"
707 } > "${BUILDDIR}/debian/control"
709 echo '3.0 (native)' > "${BUILDDIR}/debian/source/format"
714 if command -v gmake
>/dev
/null
2>&1; then
715 [ -e ${TMPWORKINGDIRECTORY}/bin
/make ] || ln -s $(command -v gmake) ${TMPWORKINGDIRECTORY}/bin
/make
716 echo "#!${TMPWORKINGDIRECTORY}/bin/make -f" > "$OUT"
718 echo '#!/usr/bin/make -f' > "$OUT"
721 echo ' dh $@' >> "$OUT"
724 setupsimplenativepackage
() {
725 _setupsimplenativepackage
"$@"
728 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
729 test -e "${BUILDDIR}/debian/compat" || echo '7' > "${BUILDDIR}/debian/compat"
730 test -e "${BUILDDIR}/debian/rules" || make_tiny_rules
"${BUILDDIR}/debian/rules"
733 buildsimplenativepackage
() {
737 local RELEASE
="${4:-unstable}"
738 local DEPENDENCIES
="$5"
739 local DESCRIPTION
="$6"
740 local SECTION
="${7:-others}"
741 local PRIORITY
="${8:-optional}"
743 local COMPRESS_TYPE
="${10:-gzip}"
745 if [ "$SECTION" = "${SECTION#*/}" ]; then
748 DISTSECTION
="${SECTION%/*}"
750 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
751 msgtest
"Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
752 _setupsimplenativepackage
"$@"
754 testsuccess
--nomsg dpkg
-source -b ${NAME}-${VERSION}
756 sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" \
758 echo "pool/${SRC}" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist"
759 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
760 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
761 # adv --yes --default-key 'Joe Sixpack' \
762 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
763 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
767 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
768 msgtest
"Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
769 rm -rf "${BUILDDIR}/debian/tmp"
770 mkdir -p "${BUILDDIR}/debian/tmp/DEBIAN" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin"
771 cp "${BUILDDIR}/debian/copyright" "${BUILDDIR}/debian/changelog" "${BUILDDIR}/FEATURES" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}"
772 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}"
773 if [ -n "$FILE_TREE" ]; then
774 cp -ar "$FILE_TREE" "${BUILDDIR}/debian/tmp"
777 (cd "${BUILDDIR}"; dpkg
-gencontrol -DArchitecture=$arch)
778 (cd "${BUILDDIR}/debian/tmp"; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
779 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
780 # ensure the right permissions as dpkg-deb insists
781 chmod 755 "${BUILDDIR}/debian/tmp/DEBIAN"
782 testsuccess
--nomsg dpkg
-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian/tmp" "${BUILDDIR}/.."
783 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist"
787 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then
788 NM
="$(echo "$NAME" | cut -c 1-4)"
790 NM
="$(echo "$NAME" | cut -c 1)"
792 local CHANGEPATH
="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}"
793 mkdir -p "$CHANGEPATH"
794 cp "${BUILDDIR}/debian/changelog" "$CHANGEPATH"
803 local ARCH
=$(getarchitecture $4)
804 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
805 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
806 msgtest
"Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
808 if [ "$ARCH" = "all" ]; then
809 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
811 testsuccess
--nomsg dpkg
-buildpackage -uc -us -a$ARCH
812 cp "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$BUILDLOG"
813 local PKGS
="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
814 local SRCS
="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
817 echo "pool/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist"
820 echo "pool/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist"
825 if [ -d incoming
]; then
826 buildaptarchivefromincoming
"$@"
828 buildaptarchivefromfiles
"$@"
832 createaptftparchiveconfig
() {
833 local COMPRESSORS
="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
834 local COMPRESSORS
="${COMPRESSORS%* }"
835 local ARCHS
="$(getarchitectures)"
836 cat > ftparchive.conf
<<EOF
838 ArchiveDir "$(readlink -f .)";
839 CacheDir "$(readlink -f ..)";
840 FileListDir "$(readlink -f pool/)";
843 Packages::Compress "$COMPRESSORS";
844 Sources::Compress "$COMPRESSORS";
845 Contents::Compress "$COMPRESSORS";
846 Translation::Compress "$COMPRESSORS";
847 LongDescription "false";
851 SrcDirectory "pool/";
854 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
857 Architectures "$ARCHS all source";
858 FileList "${DIST}.\$(SECTION).pkglist";
859 SourceFileList "${DIST}.\$(SECTION).srclist";
860 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
863 done >> ftparchive.conf
866 buildaptftparchivedirectorystructure
() {
867 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
868 for DIST
in $DISTS; do
869 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
870 for SECTION
in $SECTIONS; do
871 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
872 for ARCH
in $ARCHS; do
873 mkdir -p "dists/${DIST}/${SECTION}/binary-${ARCH}"
875 mkdir -p "dists/${DIST}/${SECTION}/source"
876 mkdir -p "dists/${DIST}/${SECTION}/i18n"
886 local DEPENDENCIES
="$5"
887 local PRIORITY
="${6:-optional}"
888 local DESCRIPTION
="${7:-an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
889 If you find such a package installed on your system,
890 something went horribly wrong! They are autogenerated
891 und used only by testcases and serve no other purpose…}"
893 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
894 if [ "$RELEASE" = 'installed' ]; then
895 insertinstalledpackage
"$2" "$3" "$4" "$5" "$6" "$7"
898 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
899 if [ "$arch" = 'none' ]; then
900 ARCHS
="$(getarchitectures)"
904 for BUILDARCH
in $ARCHS; do
905 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
912 Maintainer: Joe Sixpack <joe@example.org>"
913 test "$arch" = 'none' || echo "Architecture: $arch"
914 echo "Version: $VERSION
915 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb"
916 test -z "$DEPENDENCIES" || printf "%b\n" "$DEPENDENCIES"
917 echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)"
918 echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
919 echo "SHA256: 0000000000000000000000000000000000000000000000000000000000000000"
921 } >> "${PPATH}/Packages"
924 mkdir -p "aptarchive/dists/${RELEASE}/main/source" "aptarchive/dists/${RELEASE}/main/i18n"
925 touch "aptarchive/dists/${RELEASE}/main/source/Sources"
927 Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
928 Description-en: $DESCRIPTION
929 " >> "aptarchive/dists/${RELEASE}/main/i18n/Translation-en"
938 local DEPENDENCIES
="$5"
939 local BINARY
="${6:-$NAME}"
941 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
942 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
944 local FILE
="${SPATH}/Sources"
945 local DSCFILE
="${NAME}_${VERSION}.dsc"
946 local TARFILE
="${NAME}_${VERSION}.tar.gz"
950 Maintainer: Joe Sixpack <joe@example.org>
951 Architecture: $ARCH" >> $FILE
952 test -z "$DEPENDENCIES" || printf "%b\n" "$DEPENDENCIES" >> "$FILE"
954 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
955 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
957 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
958 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
963 insertinstalledpackage
() {
967 local DEPENDENCIES
="$4"
968 local PRIORITY
="${5:-optional}"
969 local STATUS
="${6:-install ok installed}"
970 local DESCRIPTION
="${7:-an autogenerated dummy ${NAME}=${VERSION}/installed
971 If you find such a package installed on your system,
972 something went horribly wrong! They are autogenerated
973 und used only by testcases and serve no other purpose…}"
975 local FILE
='rootdir/var/lib/dpkg/status'
976 local INFO
='rootdir/var/lib/dpkg/info'
977 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
983 Maintainer: Joe Sixpack <joe@example.org>
984 Version: $VERSION" >> "$FILE"
985 test "$arch" = 'none' || echo "Architecture: $arch" >> "$FILE"
986 test -z "$DEPENDENCIES" || printf "%b\n" "$DEPENDENCIES" >> "$FILE"
987 printf "%b\n" "Description: $DESCRIPTION" >> "$FILE"
989 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
990 echo -n > "${INFO}/${NAME}:${arch}.list"
992 echo -n > "${INFO}/${NAME}.list"
998 buildaptarchivefromincoming
() {
999 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on incoming packages…"
1001 [ -e pool
] || ln -s ..
/incoming pool
1002 [ -e ftparchive.conf
] || createaptftparchiveconfig
1003 [ -e dists
] || buildaptftparchivedirectorystructure
1004 msgninfo
"\tGenerate Packages, Sources and Contents files… "
1005 testsuccess aptftparchive generate ftparchive.conf
1008 generatereleasefiles
"$@"
1011 buildaptarchivefromfiles
() {
1012 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on prebuild files…"
1013 local DIR
='aptarchive'
1014 if [ -d "${DIR}/dists" ]; then DIR
="${DIR}/dists"; fi
1015 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
1016 msgninfo
"\t${line} file… "
1017 compressfile
"$line" "$1"
1020 generatereleasefiles
"$@"
1024 while read compressor extension
command; do
1025 if [ "$compressor" = '.' ]; then
1026 if [ -n "$2" ]; then
1031 cat "$1" | $command > "${1}.${extension}"
1032 if [ -n "$2" ]; then
1033 touch -d "$2" "${1}.${extension}"
1035 done < "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf"
1038 # can be overridden by testcases for their pleasure
1039 getcodenamefromsuite
() {
1041 unstable
) echo 'sid';;
1045 getreleaseversionfromsuite
() { true
; }
1046 getlabelfromsuite
() { true
; }
1047 getoriginfromsuite
() { true
; }
1048 getarchitecturesfromreleasefile
() { echo "all $(getarchitectures)"; }
1050 aptftparchiverelease
() {
1051 aptftparchive
-qq release
"$@" | sed -e '/0 Release$/ d' # remove the self reference
1053 generatereleasefiles
() {
1054 # $1 is the Date header and $2 is the ValidUntil header to be set
1055 # both should be given in notation date/touch can understand
1057 local VALIDUNTIL
="$2"
1058 if [ -e aptarchive
/dists
]; then
1059 msgninfo
"\tGenerate Release files for dists… "
1060 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
1061 local ARCHITECTURES
="$(getarchitecturesfromreleasefile "$dir")"
1062 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
1063 local CODENAME
="$(getcodenamefromsuite $SUITE)"
1064 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
1065 local LABEL
="$(getlabelfromsuite $SUITE)"
1066 local ORIGIN
="$(getoriginfromsuite $SUITE)"
1067 aptftparchiverelease
"$dir" \
1068 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
1069 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
1070 -o APT
::FTPArchive
::Release
::Architectures
="${ARCHITECTURES}" \
1071 -o APT
::FTPArchive
::Release
::Label
="${LABEL}" \
1072 -o APT
::FTPArchive
::Release
::Origin
="${ORIGIN}" \
1073 -o APT
::FTPArchive
::Release
::Version
="${VERSION}" \
1075 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
1076 sed -i '/^Date: / a\
1077 NotAutomatic: yes' "$dir/Release"
1081 msgninfo
"\tGenerate Release files for flat… "
1082 aptftparchiverelease .
/aptarchive
> aptarchive
/Release
1084 if [ -n "$DATE" -a "$DATE" != "now" ]; then
1085 for release
in $(find ./aptarchive -name 'Release'); do
1086 sed -i "s/^Date: .*$/Date: $(date -u -d "$DATE" -R)/" "$release"
1087 touch -d "$DATE" "$release"
1090 if [ -n "$VALIDUNTIL" ]; then
1091 sed -i "/^Date: / a\
1092 Valid-Until: $(date -u -d "$VALIDUNTIL" -R)" $(find ./aptarchive -name 'Release')
1097 setupdistsaptarchive
() {
1098 local APTARCHIVE
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1099 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
1100 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
1101 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1102 SECTIONS
=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1103 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
1104 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list"
1105 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list"
1110 setupflataptarchive
() {
1111 local APTARCHIVE
="$(readlink -f ./aptarchive)"
1112 local APTARCHIVEURI
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1113 if [ -f "${APTARCHIVE}/Packages" ]; then
1114 msgninfo
"\tadd deb sources.list line… "
1115 echo "deb file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1118 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1120 if [ -f "${APTARCHIVE}/Sources" ]; then
1121 msgninfo
"\tadd deb-src sources.list line… "
1122 echo "deb-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1125 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1131 if [ "$1" = '--no-update' ]; then
1135 buildaptarchive
"$@"
1136 if [ -e aptarchive
/dists
]; then
1137 setupdistsaptarchive
1141 signreleasefiles
'Joe Sixpack'
1142 if [ "1" != "$NOUPDATE" ]; then
1143 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
1147 signreleasefiles
() {
1148 local SIGNERS
="${1:-Joe Sixpack}"
1149 local REPODIR
="${2:-aptarchive}"
1150 if [ -n "$1" ]; then shift; fi
1151 if [ -n "$1" ]; then shift; fi
1152 local KEY
="keys/$(echo "$SIGNERS" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1153 msgninfo
"\tSign archive with $SIGNERS key $KEY… "
1154 local REXKEY
='keys/rexexpired'
1155 local SECEXPIREBAK
="${REXKEY}.sec.bak"
1156 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
1158 while [ -n "${SIGNERS%%,*}" ]; do
1159 local SIGNER
="${SIGNERS%%,*}"
1160 if [ "${SIGNERS}" = "${SIGNER}" ]; then
1163 SIGNERS
="${SIGNERS#*,}"
1164 # FIXME: This should be the full name, but we can't encode the space properly currently
1165 SIGUSERS
="${SIGUSERS} -u ${SIGNER#* }"
1166 if [ "${SIGNER}" = 'Rex Expired' ]; then
1167 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1168 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1169 # therefore we 'temporary' make the key not expired and restore a backup after signing
1170 cp "${REXKEY}.sec" "$SECEXPIREBAK"
1171 cp "${REXKEY}.pub" "$PUBEXPIREBAK"
1172 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
1173 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
1174 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1175 cp "$SECUNEXPIRED" "${REXKEY}.sec"
1176 cp "$PUBUNEXPIRED" "${REXKEY}.pub"
1178 if ! printf "expire\n1w\nsave\n" | aptkey
--quiet --keyring "${REXKEY}.pub" --secret-keyring "${REXKEY}.sec" \
1179 --readonly adv
--batch --yes --digest-algo "${APT_TESTS_DIGEST_ALGO:-SHA512}" \
1180 --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
1184 cp "${REXKEY}.sec" "$SECUNEXPIRED"
1185 cp "${REXKEY}.pub" "$PUBUNEXPIRED"
1188 if [ ! -e "${KEY}.pub" ]; then
1189 local K
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1190 cat "${K}.pub" >> "${KEY}.new.pub"
1191 cat "${K}.sec" >> "${KEY}.new.sec"
1194 if [ ! -e "${KEY}.pub" ]; then
1195 mv "${KEY}.new.pub" "${KEY}.pub"
1196 mv "${KEY}.new.sec" "${KEY}.sec"
1198 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes --digest-algo ${APT_TESTS_DIGEST_ALGO:-SHA512}"
1199 for RELEASE
in $(find "${REPODIR}/" -name Release); do
1200 # we might have set a specific date for the Release file, so copy it
1201 local DATE
="$(stat --format "%y" "${RELEASE}")"
1202 if [ "$APT_DONT_SIGN" = 'Release.gpg' ]; then
1203 rm -f "${RELEASE}.gpg"
1205 testsuccess
$GPG "$@" $SIGUSERS --armor --detach-sign --sign --output "${RELEASE}.gpg" "${RELEASE}"
1206 touch -d "$DATE" "${RELEASE}.gpg"
1208 local INRELEASE
="${RELEASE%/*}/InRelease"
1209 if [ "$APT_DONT_SIGN" = 'InRelease' ]; then
1212 testsuccess
$GPG "$@" $SIGUSERS --clearsign --output "$INRELEASE" "$RELEASE"
1213 touch -d "$DATE" "${INRELEASE}"
1216 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1217 mv -f "$SECEXPIREBAK" "${REXKEY}.sec"
1218 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub"
1223 redatereleasefiles
() {
1224 local DATE
="$(date -u -d "$1" -R)"
1225 for release
in $(find aptarchive/ -name 'Release'); do
1226 sed -i "s/^Date: .*$/Date: ${DATE}/" "$release"
1227 touch -d "$DATE" "$release"
1229 signreleasefiles
"${2:-Joe Sixpack}"
1233 local WEBSERVER
="${3:-http://localhost:${APTHTTPPORT}}"
1235 if [ "$1" = '--no-check' ]; then
1239 local DOWNLOG
='rootdir/tmp/download-testfile.log'
1240 local STATUS
='downloaded/webserverconfig.status'
1241 rm -f "$STATUS" "$DOWNLOG"
1242 # very very basic URI encoding
1244 if [ -n "$2" ]; then
1245 msgtest
"Set webserver config option '${1}' to" "$2"
1246 URI
="${WEBSERVER}/_config/set/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1248 msgtest
'Clear webserver config option' "${1}"
1249 URI
="${WEBSERVER}/_config/clear/$(echo "${1}" | sed -e 's/\//%2f/g')"
1251 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
1254 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.output"
1255 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1256 msgfailoutput
'' "$OUTPUT"
1258 $NOCHECK || testwebserverlaststatuscode
'200'
1261 rewritesourceslist
() {
1262 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1263 local APTARCHIVE2
="copy://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1264 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1265 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
1266 -e "s#http://[^@]*@\?localhost:${APTHTTPPORT}/\?#${1}#" \
1267 -e "s#https://[^@]*@\?localhost:${APTHTTPSPORT}/\?#${1}#"
1271 # wait for up to 10s for a pid file to appear to avoid possible race
1272 # when a helper is started and dosn't write the PID quick enough
1275 for i
in $(seq 10); do
1276 if test -s "$PIDFILE"; then
1281 msgdie
"waiting for $PIDFILE failed"
1285 changetowebserver
() {
1287 if [ "$1" != '--no-rewrite' ]; then
1292 if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
1294 local LOG
="webserver.log"
1295 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1299 waitforpidfile aptwebserver.pid
1300 local PID
="$(cat aptwebserver.pid)"
1301 if [ -z "$PID" ]; then
1302 msgdie
'Could not fork aptwebserver successfully'
1304 addtrap
"kill $PID;"
1305 waitforpidfile aptwebserver.port
1306 APTHTTPPORT
="$(cat aptwebserver.port)"
1307 if [ -z "$APTHTTPPORT" ]; then
1308 msgdie
'Could not get port for aptwebserver successfully'
1312 msgdie
'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver'
1314 if [ "$REWRTE" != 'yes' ]; then
1315 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1319 changetohttpswebserver
() {
1321 if command -v stunnel4
>/dev
/null
2>&1; then
1323 elif command -v stunnel
>/dev
/null
2>&1; then
1326 msgdie
'You need to install stunnel4 for https testcases'
1328 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1329 changetowebserver
--no-rewrite "$@"
1331 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1332 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1337 connect = $APTHTTPPORT
1338 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1339 $stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
1340 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1341 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1342 if [ -z "$PID" ]; then
1343 msgdie
'Could not fork $stunnel4 successfully'
1345 addtrap
'prefix' "kill ${PID};"
1346 APTHTTPSPORT
="$(lsof -i -n | awk "/^$stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1347 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1348 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1352 mkdir -p rootdir
/media
/cdrom
/.disk
1353 local CD
="$(readlink -f rootdir/media/cdrom)"
1354 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1355 acquire::cdrom::mount "${CD}";
1356 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1357 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1358 acquire::cdrom::autodetect 0;
1360 echo -n "$1" > "${CD}/.disk/info"
1361 if [ ! -d aptarchive
/dists
]; then
1362 msgdie
'Flat file archive cdroms can not be created currently'
1365 mv aptarchive
/dists
"$CD"
1366 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1367 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1368 # start with an unmounted disk
1369 mv "${CD}" "${CD}-unmounted"
1370 # we don't want the disk to be modifiable
1371 addtrap
'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;"
1372 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1376 local PROTO
="${1%%:*}"
1377 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1378 download
-file "$1" "$2" "$3" 2>&1 ; then
1381 # only if the file exists the download was successful
1382 if [ -r "$2" ]; then
1390 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1391 if [ -n "$DIFFTEXT" ]; then
1393 echo >&2 "$DIFFTEXT"
1401 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1402 local COMPAREFILE
="$1"
1404 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1407 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1408 cat "$COMPAREFILE" >>"${OUTPUT}"
1409 msgfailoutput
'' "$OUTPUT" "$@"
1414 msggroup
'testfileequal'
1415 local MSG
='Test for correctness of file'
1416 if [ "$1" = '--nomsg' ]; then
1422 if [ -n "$MSG" ]; then
1423 msgtest
"$MSG" "$FILE"
1425 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1426 if [ -z "$*" ]; then
1427 testoutputequal
"$FILE" echo -n ''
1429 testoutputequal
"$FILE" echo "$*"
1435 msggroup
'testempty'
1436 if [ "$1" = '--nomsg' ]; then
1439 msgtest
"Test for no output of" "$*"
1441 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1442 if "$@" >"$COMPAREFILE" 2>&1 && test ! -s "$COMPAREFILE"; then
1445 msgfailoutput
'' "$COMPAREFILE" "$@"
1447 aptautotest
'testempty' "$@"
1451 msggroup
'testnotempty'
1452 msgtest
"Test for some output of" "$*"
1453 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
1454 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then
1457 msgfailoutput
'' "$COMPAREFILE" "$@"
1459 aptautotest
'testnotempty' "$@"
1464 msggroup
'testequal'
1465 local MSG
='Test of equality of'
1466 if [ "$1" = '--nomsg' ]; then
1471 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1472 echo "$1" > "$COMPAREFILE"
1475 if [ -n "$MSG" ]; then
1478 testoutputequal
"$COMPAREFILE" "$@"
1479 aptautotest
'testequal' "$@"
1484 msggroup
'testequalor2'
1485 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1486 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1487 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1488 echo "$1" > "$COMPAREFILE1"
1489 echo "$2" > "$COMPAREFILE2"
1491 msgtest
"Test for equality OR of" "$*"
1492 "$@" >"$COMPAREAGAINST" 2>&1 || true
1493 if checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null
2>&1 || \
1494 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null
2>&1
1498 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1499 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1500 checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1501 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1502 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1503 msgfailoutput
'' "$OUTPUT"
1505 aptautotest
'testequalor2' "$@"
1510 msggroup
'testshowvirtual'
1511 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1514 while [ -n "$1" ]; do
1516 N: Can't select versions from package '$1' as it is purely virtual"
1517 PACKAGE
="${PACKAGE} $1"
1520 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1522 N: No packages found"
1523 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1524 local ARCH
="$(getarchitecture 'native')"
1525 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1526 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1527 testoutputequal
"$COMPAREFILE" aptcache show
"$PACKAGE"
1532 msggroup
'testnopackage'
1533 msgtest
"Test for non-existent packages" "apt-cache show $*"
1534 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1535 if [ -n "$SHOWPKG" ]; then
1536 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1537 echo "$SHOWPKG" >"$OUTPUT"
1538 msgfailoutput
'' "$OUTPUT"
1544 testnosrcpackage
() {
1545 msggroup
'testnosrcpackage'
1546 msgtest
"Test for non-existent source packages" "apt-cache showsrc $*"
1547 local SHOWPKG
="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')"
1548 if [ -n "$SHOWPKG" ]; then
1549 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output"
1550 echo "$SHOWPKG" >"$OUTPUT"
1551 msgfailoutput
'' "$OUTPUT"
1559 msggroup
'testdpkgstatus'
1563 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1564 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1565 if [ "$PKGS" != $NR ]; then
1566 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1567 echo "$PKGS" >"$OUTPUT"
1568 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1569 msgfailoutput
'' "$OUTPUT"
1576 testdpkginstalled
() {
1577 msggroup
'testdpkginstalled'
1578 testdpkgstatus
'ii' "$#" "$@"
1582 testdpkgnotinstalled
() {
1583 msggroup
'testdpkgnotinstalled'
1584 testdpkgstatus
'ii' '0' "$@"
1589 msggroup
'testmarkedauto'
1590 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1591 if [ -n "$1" ]; then
1592 msgtest
'Test for correctly marked as auto-installed' "$*"
1593 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1595 msgtest
'Test for correctly marked as auto-installed' 'no package'
1596 echo -n > "$COMPAREFILE"
1598 testoutputequal
"$COMPAREFILE" aptmark showauto
1601 testmarkedmanual
() {
1602 msggroup
'testmarkedmanual'
1603 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1604 if [ -n "$1" ]; then
1605 msgtest
'Test for correctly marked as manually installed' "$*"
1606 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1608 msgtest
'Test for correctly marked as manually installed' 'no package'
1609 echo -n > "$COMPAREFILE"
1611 testoutputequal
"$COMPAREFILE" aptmark showmanual
1616 if [ "${1##*.}" = 'deb' ]; then
1617 stat
>&2 "$1" || true
1618 file >&2 "$1" || true
1620 cat >&2 "$1" || true
1624 msgreportheader
'msgfailoutput'
1629 if [ "$1" = 'grep' -o "$1" = 'tail' -o "$1" = 'head' ]; then
1631 while [ -n "$2" ]; do shift; done
1632 echo "#### Complete file: $1 ####"
1634 echo "#### $CMD output ####"
1635 elif [ "$1" = 'test' ]; then
1637 # doesn't support ! or non-file flags
1638 msgfailoutputstatfile
() {
1639 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1640 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1641 echo "#### stat(2) of file: $2 ####"
1643 if test -d "$2"; then
1644 echo "#### The directory contains: $2 ####"
1646 elif test -e "$2"; then
1647 echo "#### Complete file: $2 ####"
1652 msgfailoutputstatfile
"$2" "$3"
1653 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1655 msgfailoutputstatfile
"$2" "$3"
1657 echo '#### test output ####'
1658 elif [ "$1" = 'cmp' ]; then
1660 while [ -n "$2" ]; do
1661 echo "#### Complete file: $2 ####"
1665 echo '#### cmp output ####'
1671 testsuccesswithglobalerror
() {
1676 if [ "$1" = '--nomsg' ]; then
1679 msgtest
'Test for successful execution of' "$*"
1681 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output"
1682 if "$@" >"${OUTPUT}" 2>&1; then
1683 if expr match
"$1" '^apt.*' >/dev
/null
; then
1684 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1685 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1686 elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1687 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1688 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1689 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1692 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1695 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1697 elif [ "$TYPE" = 'testsuccesswithnotice' ]; then
1698 if grep -q -E "^N: " "$OUTPUT"; then
1701 msgfailoutput
'successful run, but output had no notices' "$OUTPUT" "$@"
1711 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1713 aptautotest
"$TYPE" "$@"
1716 testsuccesswithnotice
() {
1717 testsuccesswithglobalerror
'testsuccesswithnotice' 'WE' "$@"
1720 testsuccesswithglobalerror
'testsuccess' 'NWE' "$@"
1723 msggroup
'testwarning'
1724 if [ "$1" = '--nomsg' ]; then
1727 msgtest
'Test for successful execution with warnings of' "$*"
1729 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1730 if "$@" >"${OUTPUT}" 2>&1; then
1731 if expr match
"$1" '^apt.*' >/dev
/null
; then
1732 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1733 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1734 elif grep -q -E '^E: ' "$OUTPUT"; then
1735 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1736 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1737 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1746 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1748 aptautotest
'testwarning' "$@"
1752 msggroup
'testfailure'
1753 if [ "$1" = '--nomsg' ]; then
1756 msgtest
'Test for failure in execution of' "$*"
1758 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1759 if "$@" >"${OUTPUT}" 2>&1; then
1761 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1764 if expr match
"$1" '^apt.*' >/dev
/null
; then
1765 if [ "$1" = 'aptkey' ]; then
1766 if grep -q " Can't check signature:
1768 signature could not be verified" "$OUTPUT"; then
1771 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1774 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1775 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1776 elif grep -q -E '==ERROR' "$OUTPUT"; then
1777 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1778 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1779 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1788 aptautotest
'testfailure' "$@"
1792 testreturnstateequal
() {
1794 if [ "$STATE" = 'testsuccesswithglobalerror' ]; then
1798 msggroup
"${STATE}equal"
1799 if [ "$1" != '--nomsg' ]; then
1802 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1803 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1807 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1808 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1811 msggroup
"${STATE}equal"
1812 if [ "$2" != '--nomsg' ]; then
1816 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1820 "$STATE" --nomsg "$@"
1821 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1826 testsuccessequal
() {
1827 # we compare output, so we know perfectly well about N:
1828 testreturnstateequal
'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@"
1830 testwarningequal
() {
1831 testreturnstateequal
'testwarning' "$@"
1833 testfailureequal
() {
1834 testreturnstateequal
'testfailure' "$@"
1838 msggroup
'testfailuremsg'
1842 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1843 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1844 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1845 testoutputequal
"$COMPAREFILE" echo "$CMP"
1849 msggroup
'testwarningmsg'
1853 msgtest
'Check that the output of the previous warned command has expected' 'warnings'
1854 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
1855 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
1856 testoutputequal
"$COMPAREFILE" echo "$CMP"
1861 msggroup
'testfilestats'
1862 msgtest
"Test that file $1 has $2 $3" "$4"
1863 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1866 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1869 echo -n "stat(1) reports for $2: "
1870 stat
--format "$2" "$1" || true
1872 msgfailoutput
'' "$OUTPUT"
1876 testaccessrights
() {
1877 msggroup
'testaccessrights'
1878 testfilestats
"$1" '%a' '=' "$2"
1882 testwebserverlaststatuscode
() {
1883 msggroup
'testwebserverlaststatuscode'
1884 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1885 local STATUS
='downloaded/webserverstatus-statusfile.log'
1886 rm -f "$DOWNLOG" "$STATUS"
1887 msgtest
'Test last status code from the webserver was' "$1"
1888 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1891 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1893 if [ -n "$2" ]; then
1895 echo >&2 '#### Additionally provided output files contain:'
1898 echo >&2 '#### Download log of the status code:'
1901 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1906 mapkeynametokeyid
() {
1907 while [ -n "$1" ]; do
1909 *Joe
*|*Sixpack
*|newarchive
) echo '5A90D141DBAC8DAE';;
1910 *Rex
*|*Expired
*) echo '4BC0A39C27CE74F9';;
1911 *Marvin
*|*Paranoid
*) echo 'E8525D47528144E2';;
1912 oldarchive
) echo 'FDD2DB85F68C85A3';;
1913 *) echo 'UNKNOWN KEY';;
1919 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output"
1920 if ! aptkey list
--with-colon | grep '^pub' | cut
-d':' -f 5 > "$OUTPUT"; then
1923 testfileequal
"$OUTPUT" "$(mapkeynametokeyid "$@")"
1927 echo "STOPPED execution. Press enter to continue"
1932 logcurrentarchivedirectory
() {
1933 find "${TMPWORKINGDIRECTORY}/aptarchive/dists" -type f
| while read line
; do
1934 stat
--format '%U:%G:%a:%n' "$line"
1935 done | sort > "${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst"
1937 listcurrentlistsdirectory
() {
1939 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1940 stat
--format '%U:%G:%a:%n' "$line"
1942 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1943 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1947 forallsupportedcompressors
() {
1948 rm -f "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
1949 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
1950 if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi
1955 ### convenience hacks ###
1957 # creating some directories by hand is a tedious task, so make it look simple
1959 if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then
1960 # only the last directory created by mkdir is effected by the -m !
1961 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1962 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1963 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1964 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1965 if [ "$(id -u)" = '0' ]; then
1966 chown _apt
:$(id -gn) "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1973 ### The following tests are run by most test methods automatically to check
1974 ### general things about commands executed without writing the test every time.
1977 if [ $# -lt 3 ]; then return; fi
1983 if ! expr match
"$i" '^-' >/dev
/null
2>&1; then
1989 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')"
1990 if command -v $AUTOTEST >/dev
/null
; then
1991 # save and restore the *.output files from other tests
1992 # as we might otherwise override them in these automatic tests
1993 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1994 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1995 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1996 $AUTOTEST "$TESTCALL" "$@"
1997 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1998 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1999 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
2003 aptautotest_aptget_update
() {
2005 while [ -n "$2" ]; do
2006 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
2009 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
2010 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
2011 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
2012 # all copied files are properly chmodded
2013 local backupIFS
="$IFS"
2014 IFS
="$(printf "\n\b")"
2015 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
2016 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
2019 if [ "$TESTCALL" = 'testsuccess' ]; then
2020 # failure cases can retain partial files and such
2021 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
2023 if [ -s "${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" ]; then
2024 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" \
2025 "$(find "${TMPWORKINGDIRECTORY}/aptarchive/dists" -type f | while read line; do stat --format '%U:%G:%a:%n' "$line"; done | sort)"
2028 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
2029 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
2031 testaptautotestnodpkgwarning
() {
2033 while [ -n "$2" ]; do
2034 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
2035 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
2038 testfailure
grep '^dpkg: warning:.*\(ignor\|unknown\).*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
2041 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
2042 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
2043 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
2044 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
2045 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
2046 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }
2048 testaptmarknodefaultsections
() {
2049 testfailure
grep '^Auto-Installed: 0$' "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/extended_states"
2051 aptautotest_aptmark_auto
() { testaptmarknodefaultsections
"$@"; }
2052 aptautotest_aptmark_manual
() { testaptmarknodefaultsections
"$@"; }
2053 aptautotest_aptget_markauto
() { testaptmarknodefaultsections
"$@"; }
2054 aptautotest_aptget_markmanual
() { testaptmarknodefaultsections
"$@"; }