1 #!/bin/sh -- # no runable script, just for vi
6 if [ "$1" = "-q" ]; then
8 elif [ "$1" = "-qq" ]; then
10 elif [ "$1" = "-v" ]; then
12 elif [ "$1" = '--color=no' ]; then
14 elif [ "$1" = '--color=yes' ]; then
16 elif [ "$1" = '--color' ]; then
17 export MSGCOLOR
="$(echo "$2" | tr 'a-z' 'A-Z')"
19 elif [ "$1" = '--level' ]; then
23 echo >&2 "WARNING: Unknown parameter »$1« will be ignored"
27 export MSGLEVEL
="${MSGLEVEL:-3}"
29 # we all like colorful messages
30 if [ "${MSGCOLOR:-YES}" = 'YES' ]; then
31 if [ ! -t 1 ]; then # but check that we output to a terminal
36 if [ "$MSGCOLOR" != 'NO' ]; then
37 CERROR
="\033[1;31m" # red
38 CWARNING
="\033[1;33m" # yellow
39 CMSG
="\033[1;32m" # green
40 CINFO
="\033[1;96m" # light blue
41 CDEBUG
="\033[1;94m" # blue
42 CNORMAL
="\033[0;39m" # default system console color
43 CDONE
="\033[1;32m" # green
44 CPASS
="\033[1;32m" # green
45 CFAIL
="\033[1;31m" # red
46 CCMD
="\033[1;35m" # pink
58 printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghks]\)#apt-\1#')"
64 msgdie
() { msgprintf
"${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; }
65 msgwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; }
66 msgmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; }
67 msginfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; }
68 msgdebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; }
69 msgdone
() { msgprintf
"${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; }
70 msgnwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; }
71 msgnmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}" "$@"; }
72 msgninfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
73 msgndebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
74 msgtest
() { msgprintf
"${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
75 msgpass
() { printf "${CPASS}PASS${CNORMAL}\n"; }
77 if [ -n "$MSGTEST_MSG" ]; then
78 test "$1" != 'msgfailoutput' || echo
79 if [ -n "$MSGTEST_MSGMSG" ]; then
80 echo "$MSGTEST_MSGMSG"
82 if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then
83 echo "${CFAIL}Part of the test group: $MSGTEST_GRP"
85 echo -n "$MSGTEST_MSG"
90 msgreportheader
'msgskip'
91 if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
92 else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
95 msgreportheader
'msgfail'
96 if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
97 else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
98 if [ -n "$APT_DEBUG_TESTS" ]; then
101 EXIT_CODE
=$((EXIT_CODE+1));
106 if [ $MSGGROUP_LEVEL = 0 ]; then
109 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL+1));
111 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL-1));
112 if [ $MSGGROUP_LEVEL = 0 ]; then
118 # enable / disable Debugging
119 if [ $MSGLEVEL -le 0 ]; then
122 if [ $MSGLEVEL -le 1 ]; then
126 if [ $MSGLEVEL -le 2 ]; then
128 MSGTEST_MSGMSG
="$(msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@")"
132 MSGTEST_MSG
="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")"
133 if [ "$MSGTEST_GRP" = 'NEXT' ]; then
134 MSGTEST_GRP
="$MSGTEST_MSG"
137 msgpass
() { printf " ${CPASS}P${CNORMAL}"; }
139 if [ $MSGLEVEL -le 3 ]; then
143 if [ $MSGLEVEL -le 4 ]; then
145 msgndebug
() { true
; }
147 if [ $MSGLEVEL -le 1 ]; then
151 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
152 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
153 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
154 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
155 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
158 printf "${CDONE}DONE${CNORMAL}\n";
162 if [ -f .
/aptconfig.conf
]; then
163 echo "$(readlink -f ./aptconfig.conf)"
164 elif [ -f ..
/aptconfig.conf
]; then
165 echo "$(readlink -f ../aptconfig.conf)"
166 elif [ -f ..
/..
/aptconfig.conf
]; then
167 echo "$(readlink -f ../../aptconfig.conf)"
168 elif [ -f "${TMPWORKINGDIRECTORY}/aptconfig.conf" ]; then
169 echo "$(readlink -f "${TMPWORKINGDIRECTORY}/aptconfig.conf")"
173 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
177 sh
|aptitude
|*/*|command) ;;
178 *) CMD
="${BUILDDIRECTORY}/$CMD";;
180 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
="${LIBRARYPATH}:${LD_LIBRARY_PATH}" "$CMD" "$@"
182 runpython3
() { runapt
command python3
"$@"; }
183 aptconfig
() { runapt apt
-config "$@"; }
184 aptcache
() { runapt apt
-cache "$@"; }
185 aptcdrom
() { runapt apt
-cdrom "$@"; }
186 aptget
() { runapt apt
-get "$@"; }
187 aptftparchive
() { runapt
"${APTFTPARCHIVEBINDIR}/apt-ftparchive" "$@"; }
188 aptkey
() { runapt apt
-key "$@"; }
189 aptmark
() { runapt apt
-mark "$@"; }
190 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; }
191 apt
() { runapt apt
"$@"; }
192 apthelper
() { runapt
"${APTHELPERBINDIR}/apt-helper" "$@"; }
193 aptwebserver
() { runapt
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
194 aptitude
() { runapt aptitude
"$@"; }
195 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; }
196 aptinternalsolver
() { runapt
"${APTINTERNALSOLVER}" "$@"; }
197 aptdumpsolver
() { runapt
"${APTDUMPSOLVER}" "$@"; }
198 aptinternalplanner
() { runapt
"${APTINTERNALPLANNER}" "$@"; }
201 "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@"
204 command perl
-MDpkg -E 'say $Dpkg::PROGVERSION'
206 dpkgcheckbuilddeps
() {
207 command dpkg
-checkbuilddeps --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" "$@"
212 aptget
) CMD
="apt-get";;
213 aptcache
) CMD
="apt-cache";;
214 aptcdrom
) CMD
="apt-cdrom";;
215 aptconfig
) CMD
="apt-config";;
216 aptmark
) CMD
="apt-mark";;
217 apthelper
) CMD
="apt-helper";;
218 aptftparchive
) CMD
="apt-ftparchive";;
219 dpkg
) shift; runapt
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" "$@"; return;;
223 if [ "${CMD##*/}" = "$CMD" ]; then
224 CMD
="${BUILDDIRECTORY}/${CMD}"
226 runapt
command gdb
--quiet -ex "directory '$SOURCEDIRECTORY'" -ex run
"$CMD" --args "$CMD" "$@"
229 date -u -d "@$(stat -c '%Y' "${TMPWORKINGDIRECTORY}/$1")" -R
232 grep "^${2:-Date}:" "$1" | cut
-d' ' -f 2-
236 # error if we about to overflow, but ...
237 # "255 failures ought to be enough for everybody"
238 if [ $EXIT_CODE -gt 255 ]; then
239 msgdie
"Total failure count $EXIT_CODE too big"
241 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
244 shellsetedetector
() {
246 if [ "$exit_status" != '0' ]; then
247 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
248 if [ "$EXIT_CODE" = '0' ]; then
249 EXIT_CODE
="$exit_status"
255 if [ "$1" = 'prefix' ]; then
256 CURRENTTRAP
="$2 $CURRENTTRAP"
258 CURRENTTRAP
="$CURRENTTRAP $1"
260 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
264 echo "$@" | sed -e "s#'#'\"'\"'#g"
267 find_project_binary_dir
() {
268 local TESTDIRECTORY
="$(readlink -f "$(dirname $0)")"
269 if [ -z "$PROJECT_BINARY_DIR" ]; then
271 for dir in ${TESTDIRECTORY}/../../ ${TESTDIRECTORY}/../../*; do
272 test -e "$dir/CMakeCache.txt
" || continue
273 if [ -z "$PROJECT_BINARY_DIR" ] ||
274 [ "$dir/CMakeCache.txt
" -nt "$PROJECT_BINARY_DIR/CMakeCache.txt
" ]; then
275 PROJECT_BINARY_DIR="$dir"
278 if [ -z "$PROJECT_BINARY_DIR" ]; then
279 echo "Cannot
find build directory
, you might want to
set PROJECT_BINARY_DIR
" >&2
282 export PROJECT_BINARY_DIR
286 # Next check needs a gnu stat, let's figure that out early.
288 if command -v gnustat >/dev/null 2>&1; then
291 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
292 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$($stat --format '%a' "$TMPDIR")" != '1777' ]; then
295 TMPWORKINGDIRECTORY="$(mktemp -d)"
296 addtrap "cd /; rm -rf '$(escape_shell "$TMPWORKINGDIRECTORY")';"
297 if [ -n "$TMPDIR_ADD" ]; then
298 TMPWORKINGDIRECTORY="${TMPWORKINGDIRECTORY}/${TMPDIR_ADD}"
299 mkdir -p "$TMPWORKINGDIRECTORY"
301 export TMPDIR="$TMPWORKINGDIRECTORY"
303 msgninfo "Preparing environment
for ${0##*/} in ${TMPWORKINGDIRECTORY}…
"
305 # Setup coreutils on BSD systems
306 mkdir "${TMPWORKINGDIRECTORY}/bin
"
307 for prefix in gnu g; do
308 for command in stat touch sed cp tr sha1sum sha256sum md5sum sha512sum grep date wc chmod head readlink tar expr base64; do
309 if command -v $prefix$command 2>/dev/null >/dev/null; then
310 [ -e "${TMPWORKINGDIRECTORY}/bin
/$command" ] || ln -sf $(command -v $prefix$command) "${TMPWORKINGDIRECTORY}/bin
/$command"
314 export PATH="${TMPWORKINGDIRECTORY}/bin
/:$PATH"
317 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded
"
318 if [ "$(id -u)" = '0' ]; then
319 # relax permissions so that running as root with user switching works
321 chmod 711 "$TMPWORKINGDIRECTORY"
322 chown _apt:$(id -gn) "${TMPWORKINGDIRECTORY}/downloaded
"
325 TESTDIRECTORY="$(readlink -f "$(dirname $0)")"
326 # Find the newest build directory (sets PROJECT_BINARY_DIR)
327 find_project_binary_dir
328 # allow overriding the default BUILDDIR location
329 SOURCEDIRECTORY
="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}"
330 BUILDDIRECTORY
="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${PROJECT_BINARY_DIR}/cmdline"}"
331 LIBRARYPATH
="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}/../apt-pkg"}"
332 METHODSDIR
="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/../methods"}"
333 APTHELPERBINDIR
="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}"
334 APTWEBSERVERBINDIR
="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}/../test/interactive-helper"}"
335 APTFTPARCHIVEBINDIR
="${APT_INTEGRATION_TESTS_FTPARCHIVE_BIN_DIR:-"${BUILDDIRECTORY}/../ftparchive"}"
336 APTINTERNALSOLVER
="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/solvers/apt"}"
337 APTDUMPSOLVER
="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/solvers/dump"}"
338 APTINTERNALPLANNER
="${APT_INTEGRATION_TESTS_INTERNAL_PLANNER:-"${BUILDDIRECTORY}/planners/apt"}"
339 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
342 cd "$TMPWORKINGDIRECTORY"
343 mkdir rootdir aptarchive keys
345 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
346 mkdir -p usr
/bin var
/cache var
/lib var
/log var
/crash tmp
347 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
348 mkdir -p usr
/lib
/apt
/solvers usr
/lib
/apt
/planners
349 touch var
/lib
/dpkg
/available
350 ln -s "${METHODSDIR}" usr
/lib
/apt
/methods
351 ln -s "${APTDUMPSOLVER}" usr
/lib
/apt
/solvers
/dump
352 ln -s "${APTDUMPSOLVER}" usr
/lib
/apt
/planners
/dump
353 ln -s "${APTINTERNALSOLVER}" usr
/lib
/apt
/solvers
/apt
354 ln -s "${APTINTERNALPLANNER}" usr
/lib
/apt
/planners
/apt
355 echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" >> ..
/aptconfig.conf
356 echo "Dir::Bin::Planners \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/planners\";" >> ..
/aptconfig.conf
357 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
359 if [ -z "${APT_INTEGRATION_TESTS_SOURCE_DIR}" ]; then
360 ln -s "${SOURCEDIRECTORY}/debian/apt.conf.autoremove" etc
/apt
/apt.conf.d
/01autoremove
362 ln -s /etc
/apt
/apt.conf.d
/01autoremove etc
/apt
/apt.conf.d
/01autoremove
365 local BASENAME
="${0##*/}"
366 local PACKAGESFILE
="Packages-${BASENAME#*-}"
367 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
368 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive
/Packages
370 local SOURCESSFILE
="Sources-${BASENAME#*-}"
371 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
372 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
374 find "$TESTDIRECTORY" \
( -name '*.pub' -o -name '*.sec' \
) -exec cp '{}' keys
/ \
;
376 ln -s "${TMPWORKINGDIRECTORY}/keys/joesixpack.pub" rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
378 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
379 echo "Dir::Etc \"etc\";" >> aptconfig.conf
380 echo "Dir::State \"var/lib/apt\";" >> aptconfig.conf
381 echo "Dir::Cache \"var/cache/apt\";" >> aptconfig.conf
382 echo "Dir::Etc \"etc/apt\";" >> aptconfig.conf
383 echo "Dir::Log \"var/log/apt\";" >> aptconfig.conf
384 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
385 echo "Dir::Bin::Methods \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/methods\";" >> aptconfig.conf
386 # either store apt-key were we can access it, even if we run it as a different user
387 #cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
388 #chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
389 #echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
390 # destroys coverage reporting though, so we disable changing user for the calling gpgv
391 echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
392 if [ "$(id -u)" = '0' ]; then
393 echo 'Binary::gpgv::APT::Sandbox::User "root";' >> aptconfig.conf
394 # same for the solver executables
395 echo 'APT::Solver::RunAsUser "root";' >> aptconfig.conf
396 echo 'APT::Planner::RunAsUser "root";' >> aptconfig.conf
399 cat > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" <<EOF
402 if [ -r '${TMPWORKINGDIRECTORY}/noopchroot.so' ]; then
403 if [ -n "\$LD_LIBRARY_PATH" ]; then
404 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}:'"\${LD_LIBRARY_PATH}"
406 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}'
408 if [ -n "\$LD_PRELOAD" ]; then
409 export LD_PRELOAD="noopchroot.so \${LD_PRELOAD}"
411 export LD_PRELOAD="noopchroot.so"
415 cp "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg"
416 cat >> "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" <<EOF
417 exec fakeroot '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
418 --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" \\
419 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
420 --force-not-root --force-bad-path "\$@"
422 cat >> "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" <<EOF
423 exec fakeroot gdb --quiet -ex run '${DPKG:-dpkg}' --args '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
424 --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" \\
425 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
426 --force-not-root --force-bad-path "\$@"
428 chmod +x
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg"
429 echo "Dir::Bin::dpkg \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg\";" > rootdir
/etc
/apt
/apt.conf.d
/99dpkg
432 if ! command dpkg
--assert-multi-arch >/dev
/null
2>&1; then
433 echo "DPKG::options:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
436 echo 'quiet::NoUpdate "true";'
437 echo 'quiet::NoStatistic "true";'
438 # too distracting for users, but helpful to detect changes
439 echo 'Acquire::Progress::Ignore::ShowErrorText "true";'
440 echo 'Acquire::Progress::Diffpercent "true";'
441 # in testcases, it can appear as if localhost has a rotation setup,
442 # hide this as we can't really deal with it properly
443 echo 'Acquire::Failure::ShowIP "false";'
444 # randomess and tests don't play well together
445 echo 'Acquire::IndexTargets::Randomized "false";'
446 # fakeroot can't fake everything, so disabled in production but good for tests
447 echo 'APT::Sandbox::Verify "true";'
450 cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
451 if [ "$(id -u)" = '0' ]; then
452 chown _apt
:$(id -gn) "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
454 echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
455 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary
456 export APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE
=no
457 echo 'Acquire::Connect::AddrConfig "false";' > rootdir
/etc
/apt
/apt.conf.d
/connect
-addrconfig
459 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
460 confighashes
'SHA256' # these are tests, not security best-practices
462 # create some files in /tmp and look at user/group to get what this means
463 TEST_DEFAULT_USER
="$(id -un)"
464 touch "${TMPWORKINGDIRECTORY}/test-file"
465 TEST_DEFAULT_GROUP
=$(stat --format '%G' "${TMPWORKINGDIRECTORY}/test-file")
467 # cleanup the environment a bit
468 # prefer our apt binaries over the system apt binaries
469 export PATH
="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
471 unset LANGUAGE APT_CONFIG
472 unset GREP_OPTIONS DEB_BUILD_PROFILES
473 unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy
475 # If gpgv supports --weak-digest, pass it to make sure we can disable SHA1
476 if aptkey verify
--weak-digest SHA1
--help 2>/dev
/null
>/dev
/null
; then
477 echo 'Acquire::gpgv::Options { "--weak-digest"; "sha1"; };' > rootdir
/etc
/apt
/apt.conf.d
/no
-sha1
480 # most tests just need one signed Release file, not both
481 export APT_DONT_SIGN
='Release.gpg'
483 if [ -r "${TESTDIRECTORY}/extra-environment" ]; then
484 .
"${TESTDIRECTORY}/extra-environment"
491 if [ "$1" = "native" -o -z "$1" ]; then
492 eval `aptconfig shell ARCH APT::Architecture`
493 if [ -n "$ARCH" ]; then
496 dpkg
--print-architecture
504 aptconfig dump
--no-empty --format '%v%n' APT
::Architecture APT
::Architectures
| sort -u | tr '\n' ' '
507 getarchitecturesfromcommalist
() {
508 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
511 configarchitecture
() {
513 echo "APT::Architecture \"$(getarchitecture $1)\";"
514 while [ -n "$1" ]; do
515 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
518 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
523 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
524 local BASENAME
="${0##*/}"
525 local STATUSFILE
="status-${BASENAME#*-}"
526 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
527 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir
/var
/lib
/dpkg
/status
529 echo -n > rootdir
/var
/lib
/dpkg
/status
532 rm -f rootdir
/etc
/apt
/apt.conf.d
/00foreigndpkg
533 # if multi-arch make sure dpkg can detect itself as capable of it
534 if getarchitectures
| grep -E -q '[^ ]+ [^ ]+'; then
535 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
536 # dpkg doesn't really check the version as long as it is fully installed,
537 # but just to be sure we choose one above the required version
538 insertinstalledpackage
'dpkg' "all" '1.16.2+fake'
541 if dpkg
--assert-multi-arch >/dev
/null
2>&1 ; then
542 local ARCHS
="$(getarchitectures)"
543 local DPKGARCH
="$(dpkg --print-architecture)"
544 # this ensures that even if multi-arch isn't active in the view
545 # of apt, given that dpkg can't be told which arch is native
546 # the arch apt treats as native might be foreign for dpkg
547 for ARCH
in ${ARCHS}; do
548 if [ "${ARCH}" != "${DPKGARCH}" ]; then
549 if ! dpkg
--add-architecture ${ARCH} >/dev
/null
2>&1; then
550 # old-style used e.g. in Ubuntu-P – and as it seems travis
551 echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir
/etc
/apt
/apt.conf.d
/00foreigndpkg
552 echo "DPKG::options:: \"${ARCH}\";" >> rootdir
/etc
/apt
/apt.conf.d
/00foreigndpkg
559 configdpkgnoopchroot
() {
560 # create a library to noop chroot() and rewrite maintainer script executions
561 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
562 # chroot directory dpkg could chroot into to execute the maintainer scripts
563 msgtest
'Building library to preload to make maintainerscript work in' 'dpkg'
564 cat > noopchroot.c
<< EOF
571 static char * chrootdir = NULL;
573 int chroot(const char *path) {
574 printf("WARNING: CHROOTing to %s was ignored!\n", path);
576 chrootdir = strdup(path);
579 int execvp(const char *file, char *const argv[]) {
580 static int (*func_execvp) (const char *, char * const []) = NULL;
581 if (func_execvp == NULL)
582 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp");
583 if (chrootdir == NULL || strncmp(file, "/var/lib/dpkg/", strlen("/var/lib/dpkg/")) != 0)
584 return func_execvp(file, argv);
585 printf("REWRITE execvp call %s into %s\n", file, chrootdir);
587 if (asprintf(&newfile, "%s%s", chrootdir, file) == -1) {
591 char const * const baseadmindir = "/var/lib/dpkg";
593 if (asprintf(&admindir, "%s%s", chrootdir, baseadmindir) == -1) {
597 setenv("DPKG_ADMINDIR", admindir, 1);
598 return func_execvp(newfile, argv);
601 if cc
-ldl 2>&1 | grep -q dl
; then
602 testempty
--nomsg cc
-Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c
604 testempty
--nomsg cc
-Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c
-ldl
607 configcompression
() {
608 if [ "$1" = 'ALL' ]; then
609 configcompression
'.' $(aptconfig dump APT::Compressor --format '%t %v%n' | sed -n 's#^Extension \.\(.*\)$#\
1#p')
612 local CMD
='apthelper cat-file -C'
613 while [ -n "$1" ]; do
615 '.') printf ".\t.\tcat\n";;
616 'gz') printf "gzip\tgz\t$CMD $1\n";;
617 'bz2') printf "bzip2\tbz2\t$CMD $1\n";;
618 *) printf "$1\t$1\t$CMD $1\n";;
621 done > "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf"
625 echo 'APT::FTPArchive {'
627 while [ -n "$1" ]; do
628 printf "$1" | tr 'a-z' 'A-Z'
629 printf "\t\"true\";\n"
632 for h
in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
633 printf "$h\t\"false\";\n"
637 } >> "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/ftparchive-hashes.conf"
642 COMPRESSOR_CMD
="apthelper cat-file -C $1"
644 gzip) COMPRESS
='gz';;
645 bzip2) COMPRESS
='bz2';;
647 local CONFFILE
="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
648 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
649 Dir::Bin::uncompressed \"/does/not/exist\";" > "$CONFFILE"
650 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
651 if [ -z "$COMP" -o "$COMP" = '.' -o "$COMP" = "$COMPRESSOR" ]; then continue; fi
652 echo "Dir::Bin::${COMP} \"/does/not/exist\";" >> "$CONFFILE"
653 echo "APT::Compressor::${COMP}::Name \"${COMP}-disabled\";" >> "$CONFFILE"
657 _setupsimplenativepackage
() {
661 local RELEASE
="${4:-unstable}"
662 local DEPENDENCIES
="$5"
663 local DESCRIPTION
="${6:-an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
664 If you find such a package installed on your system,
665 something went horribly wrong! They are autogenerated
666 und used only by testcases and serve no other purpose…}"
668 local SECTION
="${7:-others}"
669 local PRIORITY
="${8:-optional}"
671 local COMPRESS_TYPE
="${10:-gzip}"
673 if [ "$SECTION" = "${SECTION#*/}" ]; then
676 DISTSECTION
="${SECTION%/*}"
678 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
680 mkdir -p "$BUILDDIR/debian/source"
681 echo "* most suckless software product ever" > "${BUILDDIR}/FEATURES"
683 echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}"
685 echo "Copyleft by Joe Sixpack $(date -u +%Y)" > "${BUILDDIR}/debian/copyright"
686 echo "$NAME ($VERSION) $RELEASE; urgency=low
690 -- Joe Sixpack <joe@example.org> $(date -u -R)" > "${BUILDDIR}/debian/changelog"
694 Maintainer: Joe Sixpack <joe@example.org>
695 Standards-Version: 3.9.3"
696 if [ "$SECTION" != '<none>' ]; then
697 echo "Section: $SECTION"
699 local BUILDDEPS
="$(printf "%b\n" "$DEPENDENCIES" | grep '^Build-')"
700 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
704 if [ "$ARCH" = 'all' ]; then
705 echo "Architecture: all"
707 echo "Architecture: any"
709 local DEPS
="$(printf "%b\n" "$DEPENDENCIES" | grep -v '^Build-')"
710 test -z "$DEPS" || echo "$DEPS"
711 printf "%b\n" "Description: $DESCRIPTION"
712 } > "${BUILDDIR}/debian/control"
714 echo '3.0 (native)' > "${BUILDDIR}/debian/source/format"
719 if command -v gmake
>/dev
/null
2>&1; then
720 [ -e ${TMPWORKINGDIRECTORY}/bin
/make ] || ln -s $(command -v gmake) ${TMPWORKINGDIRECTORY}/bin
/make
721 echo "#!${TMPWORKINGDIRECTORY}/bin/make -f" > "$OUT"
723 echo '#!/usr/bin/make -f' > "$OUT"
726 echo ' dh $@' >> "$OUT"
729 setupsimplenativepackage
() {
730 _setupsimplenativepackage
"$@"
733 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
734 test -e "${BUILDDIR}/debian/compat" || echo '7' > "${BUILDDIR}/debian/compat"
735 test -e "${BUILDDIR}/debian/rules" || make_tiny_rules
"${BUILDDIR}/debian/rules"
738 buildsimplenativepackage
() {
742 local RELEASE
="${4:-unstable}"
743 local DEPENDENCIES
="$5"
744 local DESCRIPTION
="$6"
745 local SECTION
="${7:-others}"
746 local PRIORITY
="${8:-optional}"
748 local COMPRESS_TYPE
="${10:-gzip}"
750 if [ "$SECTION" = "${SECTION#*/}" ]; then
753 DISTSECTION
="${SECTION%/*}"
755 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
756 msgtest
"Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
757 _setupsimplenativepackage
"$@"
759 testsuccess
--nomsg dpkg
-source -b ${NAME}-${VERSION}
761 sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" \
763 echo "pool/${SRC}" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist"
764 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
765 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
766 # adv --yes --default-key 'Joe Sixpack' \
767 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
768 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
772 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
773 msgtest
"Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
774 rm -rf "${BUILDDIR}/debian/tmp"
775 mkdir -p "${BUILDDIR}/debian/tmp/DEBIAN" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin"
776 cp "${BUILDDIR}/debian/copyright" "${BUILDDIR}/debian/changelog" "${BUILDDIR}/FEATURES" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}"
777 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}"
778 if [ -n "$FILE_TREE" ]; then
779 cp -ar "$FILE_TREE" "${BUILDDIR}/debian/tmp"
782 (cd "${BUILDDIR}"; dpkg
-gencontrol -DArchitecture=$arch)
783 (cd "${BUILDDIR}/debian/tmp"; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
784 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
785 # ensure the right permissions as dpkg-deb insists
786 chmod 755 "${BUILDDIR}/debian/tmp/DEBIAN"
787 testsuccess
--nomsg dpkg
-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian/tmp" "${BUILDDIR}/.."
788 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist"
792 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then
793 NM
="$(echo "$NAME" | cut -c 1-4)"
795 NM
="$(echo "$NAME" | cut -c 1)"
797 local CHANGEPATH
="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}"
798 mkdir -p "$CHANGEPATH"
799 cp "${BUILDDIR}/debian/changelog" "$CHANGEPATH"
808 local ARCH
=$(getarchitecture $4)
809 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
810 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
811 msgtest
"Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
813 if [ "$ARCH" = "all" ]; then
814 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
816 testsuccess
--nomsg dpkg
-buildpackage -uc -us -a$ARCH -d
817 cp "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$BUILDLOG"
818 local PKGS
="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
819 local SRCS
="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
822 echo "pool/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist"
825 echo "pool/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist"
830 if [ -d incoming
]; then
831 buildaptarchivefromincoming
"$@"
833 buildaptarchivefromfiles
"$@"
837 createaptftparchiveconfig
() {
838 local COMPRESSORS
="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
839 local COMPRESSORS
="${COMPRESSORS%* }"
840 local ARCHS
="$(getarchitectures)"
841 cat > ftparchive.conf
<<EOF
843 ArchiveDir "$(readlink -f .)";
844 CacheDir "$(readlink -f ..)";
845 FileListDir "$(readlink -f pool/)";
848 Packages::Compress "$COMPRESSORS";
849 Sources::Compress "$COMPRESSORS";
850 Contents::Compress "$COMPRESSORS";
851 Translation::Compress "$COMPRESSORS";
852 LongDescription "false";
856 SrcDirectory "pool/";
859 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
862 Architectures "$ARCHS all source";
863 FileList "${DIST}.\$(SECTION).pkglist";
864 SourceFileList "${DIST}.\$(SECTION).srclist";
865 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
868 done >> ftparchive.conf
871 buildaptftparchivedirectorystructure
() {
872 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
873 for DIST
in $DISTS; do
874 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
875 for SECTION
in $SECTIONS; do
876 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
877 for ARCH
in $ARCHS; do
878 mkdir -p "dists/${DIST}/${SECTION}/binary-${ARCH}"
880 mkdir -p "dists/${DIST}/${SECTION}/source"
881 mkdir -p "dists/${DIST}/${SECTION}/i18n"
891 local DEPENDENCIES
="$5"
892 local PRIORITY
="${6:-optional}"
893 local DESCRIPTION
="${7:-an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
894 If you find such a package installed on your system,
895 something went horribly wrong! They are autogenerated
896 und used only by testcases and serve no other purpose…}"
898 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
899 if [ "$RELEASE" = 'installed' ]; then
900 insertinstalledpackage
"$2" "$3" "$4" "$5" "$6" "$7"
903 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
904 if [ "$arch" = 'none' ]; then
905 ARCHS
="$(getarchitectures)"
909 for BUILDARCH
in $ARCHS; do
910 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
917 Maintainer: Joe Sixpack <joe@example.org>"
918 test "$arch" = 'none' || echo "Architecture: $arch"
919 echo "Version: $VERSION
920 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb"
921 test -z "$DEPENDENCIES" || printf "%b\n" "$DEPENDENCIES"
922 echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)"
923 echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
924 echo "SHA256: 0000000000000000000000000000000000000000000000000000000000000000"
926 } >> "${PPATH}/Packages"
929 mkdir -p "aptarchive/dists/${RELEASE}/main/source" "aptarchive/dists/${RELEASE}/main/i18n"
930 touch "aptarchive/dists/${RELEASE}/main/source/Sources"
932 Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
933 Description-en: $DESCRIPTION
934 " >> "aptarchive/dists/${RELEASE}/main/i18n/Translation-en"
943 local DEPENDENCIES
="$5"
944 local BINARY
="${6:-$NAME}"
946 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
947 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
949 local FILE
="${SPATH}/Sources"
950 local DSCFILE
="${NAME}_${VERSION}.dsc"
951 local TARFILE
="${NAME}_${VERSION}.tar.gz"
955 Maintainer: Joe Sixpack <joe@example.org>
956 Architecture: $ARCH" >> $FILE
957 test -z "$DEPENDENCIES" || printf "%b\n" "$DEPENDENCIES" >> "$FILE"
959 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
960 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
962 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
963 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
968 insertinstalledpackage
() {
972 local DEPENDENCIES
="$4"
973 local PRIORITY
="${5:-optional}"
974 local STATUS
="${6:-install ok installed}"
975 local DESCRIPTION
="${7:-an autogenerated dummy ${NAME}=${VERSION}/installed
976 If you find such a package installed on your system,
977 something went horribly wrong! They are autogenerated
978 und used only by testcases and serve no other purpose…}"
980 local FILE
='rootdir/var/lib/dpkg/status'
981 local INFO
='rootdir/var/lib/dpkg/info'
982 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
988 Maintainer: Joe Sixpack <joe@example.org>
989 Version: $VERSION" >> "$FILE"
990 test "$arch" = 'none' || echo "Architecture: $arch" >> "$FILE"
991 test -z "$DEPENDENCIES" || printf "%b\n" "$DEPENDENCIES" >> "$FILE"
992 printf "%b\n" "Description: $DESCRIPTION" >> "$FILE"
994 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
995 echo -n > "${INFO}/${NAME}:${arch}.list"
997 echo -n > "${INFO}/${NAME}.list"
1003 buildaptarchivefromincoming
() {
1004 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on incoming packages…"
1006 [ -e pool
] || ln -s ..
/incoming pool
1007 [ -e ftparchive.conf
] || createaptftparchiveconfig
1008 [ -e dists
] || buildaptftparchivedirectorystructure
1009 msgninfo
"\tGenerate Packages, Sources and Contents files… "
1010 testsuccess aptftparchive generate ftparchive.conf
1013 generatereleasefiles
"$@"
1016 buildaptarchivefromfiles
() {
1017 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on prebuild files…"
1018 local DIR
='aptarchive'
1019 if [ -d "${DIR}/dists" ]; then DIR
="${DIR}/dists"; fi
1020 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
1021 msgninfo
"\t${line} file… "
1022 compressfile
"$line" "$1"
1025 generatereleasefiles
"$@"
1029 while read compressor extension
command; do
1030 if [ "$compressor" = '.' ]; then
1031 if [ -n "$2" ]; then
1036 cat "$1" | $command > "${1}.${extension}"
1037 if [ -n "$2" ]; then
1038 touch -d "$2" "${1}.${extension}"
1040 done < "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf"
1043 # can be overridden by testcases for their pleasure
1044 getcodenamefromsuite
() {
1046 unstable
) echo 'sid';;
1050 getreleaseversionfromsuite
() { true
; }
1051 getlabelfromsuite
() { true
; }
1052 getoriginfromsuite
() { true
; }
1053 getarchitecturesfromreleasefile
() { echo "all $(getarchitectures)"; }
1055 aptftparchiverelease
() {
1056 aptftparchive
-qq release
"$@" | sed -e '/0 Release$/ d' # remove the self reference
1058 generatereleasefiles
() {
1059 # $1 is the Date header and $2 is the ValidUntil header to be set
1060 # both should be given in notation date/touch can understand
1062 local VALIDUNTIL
="$2"
1063 if [ -e aptarchive
/dists
]; then
1064 msgninfo
"\tGenerate Release files for dists… "
1065 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
1066 local ARCHITECTURES
="$(getarchitecturesfromreleasefile "$dir")"
1067 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
1068 local CODENAME
="$(getcodenamefromsuite $SUITE)"
1069 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
1070 local LABEL
="$(getlabelfromsuite $SUITE)"
1071 local ORIGIN
="$(getoriginfromsuite $SUITE)"
1072 aptftparchiverelease
"$dir" \
1073 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
1074 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
1075 -o APT
::FTPArchive
::Release
::Architectures
="${ARCHITECTURES}" \
1076 -o APT
::FTPArchive
::Release
::Label
="${LABEL}" \
1077 -o APT
::FTPArchive
::Release
::Origin
="${ORIGIN}" \
1078 -o APT
::FTPArchive
::Release
::Version
="${VERSION}" \
1080 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
1081 sed -i '/^Date: / a\
1082 NotAutomatic: yes' "$dir/Release"
1086 msgninfo
"\tGenerate Release files for flat… "
1087 aptftparchiverelease .
/aptarchive
> aptarchive
/Release
1089 if [ -n "$DATE" -a "$DATE" != "now" ]; then
1090 for release
in $(find ./aptarchive -name 'Release'); do
1091 sed -i "s/^Date: .*$/Date: $(date -u -d "$DATE" -R)/" "$release"
1092 touch -d "$DATE" "$release"
1095 if [ -n "$VALIDUNTIL" ]; then
1096 sed -i "/^Date: / a\
1097 Valid-Until: $(date -u -d "$VALIDUNTIL" -R)" $(find ./aptarchive -name 'Release')
1102 setupdistsaptarchive
() {
1103 local APTARCHIVE
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1104 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
1105 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
1106 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1107 SECTIONS
=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1108 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
1109 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list"
1110 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list"
1115 setupflataptarchive
() {
1116 local APTARCHIVE
="$(readlink -f ./aptarchive)"
1117 local APTARCHIVEURI
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1118 if [ -f "${APTARCHIVE}/Packages" ]; then
1119 msgninfo
"\tadd deb sources.list line… "
1120 echo "deb file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1123 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1125 if [ -f "${APTARCHIVE}/Sources" ]; then
1126 msgninfo
"\tadd deb-src sources.list line… "
1127 echo "deb-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1130 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1136 if [ "$1" = '--no-update' ]; then
1140 buildaptarchive
"$@"
1141 if [ -e aptarchive
/dists
]; then
1142 setupdistsaptarchive
1146 signreleasefiles
'Joe Sixpack'
1147 if [ "1" != "$NOUPDATE" ]; then
1148 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
1152 signreleasefiles
() {
1153 local SIGNERS
="${1:-Joe Sixpack}"
1154 local REPODIR
="${2:-aptarchive}"
1155 if [ -n "$1" ]; then shift; fi
1156 if [ -n "$1" ]; then shift; fi
1157 local KEY
="keys/$(echo "$SIGNERS" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1158 msgninfo
"\tSign archive with $SIGNERS key $KEY… "
1159 local REXKEY
='keys/rexexpired'
1160 local SECEXPIREBAK
="${REXKEY}.sec.bak"
1161 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
1163 while [ -n "${SIGNERS%%,*}" ]; do
1164 local SIGNER
="${SIGNERS%%,*}"
1165 if [ "${SIGNERS}" = "${SIGNER}" ]; then
1168 SIGNERS
="${SIGNERS#*,}"
1169 # FIXME: This should be the full name, but we can't encode the space properly currently
1170 SIGUSERS
="${SIGUSERS} -u ${SIGNER#* }"
1171 if [ "${SIGNER}" = 'Rex Expired' ]; then
1172 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1173 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1174 # therefore we 'temporary' make the key not expired and restore a backup after signing
1175 cp "${REXKEY}.sec" "$SECEXPIREBAK"
1176 cp "${REXKEY}.pub" "$PUBEXPIREBAK"
1177 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
1178 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
1179 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1180 cp "$SECUNEXPIRED" "${REXKEY}.sec"
1181 cp "$PUBUNEXPIRED" "${REXKEY}.pub"
1183 if ! printf "expire\n1w\nsave\n" | aptkey
--quiet --keyring "${REXKEY}.pub" --secret-keyring "${REXKEY}.sec" \
1184 --readonly adv
--batch --yes --digest-algo "${APT_TESTS_DIGEST_ALGO:-SHA512}" \
1185 --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
1189 cp "${REXKEY}.sec" "$SECUNEXPIRED"
1190 cp "${REXKEY}.pub" "$PUBUNEXPIRED"
1193 if [ ! -e "${KEY}.pub" ]; then
1194 local K
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1195 cat "${K}.pub" >> "${KEY}.new.pub"
1196 cat "${K}.sec" >> "${KEY}.new.sec"
1199 if [ ! -e "${KEY}.pub" ]; then
1200 mv "${KEY}.new.pub" "${KEY}.pub"
1201 mv "${KEY}.new.sec" "${KEY}.sec"
1203 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes --digest-algo ${APT_TESTS_DIGEST_ALGO:-SHA512}"
1204 for RELEASE
in $(find "${REPODIR}/" -name Release); do
1205 # we might have set a specific date for the Release file, so copy it
1206 local DATE
="$(stat --format "%y" "${RELEASE}")"
1207 if [ "$APT_DONT_SIGN" = 'Release.gpg' ]; then
1208 rm -f "${RELEASE}.gpg"
1210 testsuccess
$GPG "$@" $SIGUSERS --armor --detach-sign --sign --output "${RELEASE}.gpg" "${RELEASE}"
1211 touch -d "$DATE" "${RELEASE}.gpg"
1213 local INRELEASE
="${RELEASE%/*}/InRelease"
1214 if [ "$APT_DONT_SIGN" = 'InRelease' ]; then
1217 testsuccess
$GPG "$@" $SIGUSERS --clearsign --output "$INRELEASE" "$RELEASE"
1218 touch -d "$DATE" "${INRELEASE}"
1221 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1222 mv -f "$SECEXPIREBAK" "${REXKEY}.sec"
1223 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub"
1228 redatereleasefiles
() {
1229 local DATE
="$(date -u -d "$1" -R)"
1230 for release
in $(find aptarchive/ -name 'Release'); do
1231 sed -i "s/^Date: .*$/Date: ${DATE}/" "$release"
1232 touch -d "$DATE" "$release"
1234 signreleasefiles
"${2:-Joe Sixpack}"
1238 local WEBSERVER
="${3:-http://localhost:${APTHTTPPORT}}"
1240 if [ "$1" = '--no-check' ]; then
1244 local DOWNLOG
='rootdir/tmp/download-testfile.log'
1245 local STATUS
='downloaded/webserverconfig.status'
1246 rm -f "$STATUS" "$DOWNLOG"
1247 # very very basic URI encoding
1249 if [ -n "$2" ]; then
1250 msgtest
"Set webserver config option '${1}' to" "$2"
1251 URI
="${WEBSERVER}/_config/set/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1253 msgtest
'Clear webserver config option' "${1}"
1254 URI
="${WEBSERVER}/_config/clear/$(echo "${1}" | sed -e 's/\//%2f/g')"
1256 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
1259 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.output"
1260 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1261 msgfailoutput
'' "$OUTPUT"
1263 $NOCHECK || testwebserverlaststatuscode
'200'
1266 rewritesourceslist
() {
1267 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1268 local APTARCHIVE2
="copy://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1269 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1270 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
1271 -e "s#http://[^@]*@\?localhost:${APTHTTPPORT}/\?#${1}#" \
1272 -e "s#https://[^@]*@\?localhost:${APTHTTPSPORT}/\?#${1}#"
1276 # wait for up to 10s for a pid file to appear to avoid possible race
1277 # when a helper is started and dosn't write the PID quick enough
1280 for i
in $(seq 10); do
1281 if test -s "$PIDFILE"; then
1286 msgdie
"waiting for $PIDFILE failed"
1290 changetowebserver
() {
1292 if [ "$1" != '--no-rewrite' ]; then
1297 if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
1299 local LOG
="webserver.log"
1300 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1304 waitforpidfile aptwebserver.pid
1305 local PID
="$(cat aptwebserver.pid)"
1306 if [ -z "$PID" ]; then
1307 msgdie
'Could not fork aptwebserver successfully'
1309 addtrap
"kill $PID;"
1310 waitforpidfile aptwebserver.port
1311 APTHTTPPORT
="$(cat aptwebserver.port)"
1312 if [ -z "$APTHTTPPORT" ]; then
1313 msgdie
'Could not get port for aptwebserver successfully'
1317 msgdie
'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver'
1319 if [ "$REWRTE" != 'yes' ]; then
1320 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1324 changetohttpswebserver
() {
1326 if command -v stunnel4
>/dev
/null
2>&1; then
1328 elif command -v stunnel
>/dev
/null
2>&1; then
1331 msgdie
'You need to install stunnel4 for https testcases'
1333 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1334 changetowebserver
--no-rewrite "$@"
1336 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1337 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1342 connect = $APTHTTPPORT
1343 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1344 $stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
1345 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1346 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1347 if [ -z "$PID" ]; then
1348 msgdie
'Could not fork $stunnel4 successfully'
1350 addtrap
'prefix' "kill ${PID};"
1351 APTHTTPSPORT
="$(lsof -i -n | awk "/^$stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1352 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1353 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1357 mkdir -p rootdir
/media
/cdrom
/.disk
1358 local CD
="$(readlink -f rootdir/media/cdrom)"
1359 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1360 acquire::cdrom::mount "${CD}";
1361 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1362 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1363 acquire::cdrom::autodetect 0;
1365 echo -n "$1" > "${CD}/.disk/info"
1366 if [ ! -d aptarchive
/dists
]; then
1367 msgdie
'Flat file archive cdroms can not be created currently'
1370 mv aptarchive
/dists
"$CD"
1371 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1372 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1373 # start with an unmounted disk
1374 mv "${CD}" "${CD}-unmounted"
1375 # we don't want the disk to be modifiable
1376 addtrap
'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;"
1377 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1381 local PROTO
="${1%%:*}"
1382 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1383 download
-file "$1" "$2" "$3" 2>&1 ; then
1386 # only if the file exists the download was successful
1387 if [ -r "$2" ]; then
1395 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1396 if [ -n "$DIFFTEXT" ]; then
1398 echo >&2 "$DIFFTEXT"
1406 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1407 local COMPAREFILE
="$1"
1409 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1412 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1413 cat "$COMPAREFILE" >>"${OUTPUT}"
1414 msgfailoutput
'' "$OUTPUT" "$@"
1419 msggroup
'testfileequal'
1420 local MSG
='Test for correctness of file'
1421 if [ "$1" = '--nomsg' ]; then
1427 if [ -n "$MSG" ]; then
1428 msgtest
"$MSG" "$FILE"
1430 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1431 if [ -z "$*" ]; then
1432 testoutputequal
"$FILE" echo -n ''
1434 testoutputequal
"$FILE" echo "$*"
1440 msggroup
'testempty'
1441 if [ "$1" = '--nomsg' ]; then
1444 msgtest
"Test for no output of" "$*"
1446 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1447 if "$@" >"$COMPAREFILE" 2>&1 && test ! -s "$COMPAREFILE"; then
1450 msgfailoutput
'' "$COMPAREFILE" "$@"
1452 aptautotest
'testempty' "$@"
1456 msggroup
'testnotempty'
1457 msgtest
"Test for some output of" "$*"
1458 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
1459 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then
1462 msgfailoutput
'' "$COMPAREFILE" "$@"
1464 aptautotest
'testnotempty' "$@"
1469 msggroup
'testequal'
1470 local MSG
='Test of equality of'
1471 if [ "$1" = '--nomsg' ]; then
1476 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1477 echo "$1" > "$COMPAREFILE"
1480 if [ -n "$MSG" ]; then
1483 testoutputequal
"$COMPAREFILE" "$@"
1484 aptautotest
'testequal' "$@"
1489 msggroup
'testequalor2'
1490 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1491 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1492 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1493 echo "$1" > "$COMPAREFILE1"
1494 echo "$2" > "$COMPAREFILE2"
1496 msgtest
"Test for equality OR of" "$*"
1497 "$@" >"$COMPAREAGAINST" 2>&1 || true
1498 if checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null
2>&1 || \
1499 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null
2>&1
1503 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1504 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1505 checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1506 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1507 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1508 msgfailoutput
'' "$OUTPUT"
1510 aptautotest
'testequalor2' "$@"
1515 msggroup
'testshowvirtual'
1516 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1519 while [ -n "$1" ]; do
1521 N: Can't select versions from package '$1' as it is purely virtual"
1522 PACKAGE
="${PACKAGE} $1"
1525 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1527 N: No packages found"
1528 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1529 local ARCH
="$(getarchitecture 'native')"
1530 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1531 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1532 testoutputequal
"$COMPAREFILE" aptcache show
"$PACKAGE"
1537 msggroup
'testnopackage'
1538 msgtest
"Test for non-existent packages" "apt-cache show $*"
1539 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1540 if [ -n "$SHOWPKG" ]; then
1541 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1542 echo "$SHOWPKG" >"$OUTPUT"
1543 msgfailoutput
'' "$OUTPUT"
1549 testnosrcpackage
() {
1550 msggroup
'testnosrcpackage'
1551 msgtest
"Test for non-existent source packages" "apt-cache showsrc $*"
1552 local SHOWPKG
="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')"
1553 if [ -n "$SHOWPKG" ]; then
1554 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output"
1555 echo "$SHOWPKG" >"$OUTPUT"
1556 msgfailoutput
'' "$OUTPUT"
1564 msggroup
'testdpkgstatus'
1568 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1569 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1570 if [ "$PKGS" != $NR ]; then
1571 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1572 echo "$PKGS" >"$OUTPUT"
1573 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1574 msgfailoutput
'' "$OUTPUT"
1581 testdpkginstalled
() {
1582 msggroup
'testdpkginstalled'
1583 testdpkgstatus
'ii' "$#" "$@"
1587 testdpkgnotinstalled
() {
1588 msggroup
'testdpkgnotinstalled'
1589 testdpkgstatus
'ii' '0' "$@"
1594 msggroup
'testmarkedauto'
1595 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1596 if [ -n "$1" ]; then
1597 msgtest
'Test for correctly marked as auto-installed' "$*"
1598 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1600 msgtest
'Test for correctly marked as auto-installed' 'no package'
1601 echo -n > "$COMPAREFILE"
1603 testoutputequal
"$COMPAREFILE" aptmark showauto
1606 testmarkedmanual
() {
1607 msggroup
'testmarkedmanual'
1608 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1609 if [ -n "$1" ]; then
1610 msgtest
'Test for correctly marked as manually installed' "$*"
1611 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1613 msgtest
'Test for correctly marked as manually installed' 'no package'
1614 echo -n > "$COMPAREFILE"
1616 testoutputequal
"$COMPAREFILE" aptmark showmanual
1621 if [ "${1##*.}" = 'deb' ]; then
1622 stat
>&2 "$1" || true
1623 file >&2 "$1" || true
1625 cat >&2 "$1" || true
1629 msgreportheader
'msgfailoutput'
1634 if [ "$1" = 'grep' -o "$1" = 'tail' -o "$1" = 'head' ]; then
1636 while [ -n "$2" ]; do shift; done
1637 echo "#### Complete file: $1 ####"
1639 echo "#### $CMD output ####"
1640 elif [ "$1" = 'test' ]; then
1642 # doesn't support ! or non-file flags
1643 msgfailoutputstatfile
() {
1644 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1645 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1646 echo "#### stat(2) of file: $2 ####"
1648 if test -d "$2"; then
1649 echo "#### The directory contains: $2 ####"
1651 elif test -e "$2"; then
1652 echo "#### Complete file: $2 ####"
1657 msgfailoutputstatfile
"$2" "$3"
1658 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1660 msgfailoutputstatfile
"$2" "$3"
1662 echo '#### test output ####'
1663 elif [ "$1" = 'cmp' ]; then
1665 while [ -n "$2" ]; do
1666 echo "#### Complete file: $2 ####"
1670 echo '#### cmp output ####'
1676 testsuccesswithglobalerror
() {
1681 if [ "$1" = '--nomsg' ]; then
1684 msgtest
'Test for successful execution of' "$*"
1686 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output"
1687 if "$@" >"${OUTPUT}" 2>&1; then
1688 if expr match
"$1" '^apt.*' >/dev
/null
; then
1689 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1690 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1691 elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1692 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1693 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1694 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1697 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1700 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1702 elif [ "$TYPE" = 'testsuccesswithnotice' ]; then
1703 if grep -q -E "^N: " "$OUTPUT"; then
1706 msgfailoutput
'successful run, but output had no notices' "$OUTPUT" "$@"
1716 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1718 aptautotest
"$TYPE" "$@"
1721 testsuccesswithnotice
() {
1722 testsuccesswithglobalerror
'testsuccesswithnotice' 'WE' "$@"
1725 testsuccesswithglobalerror
'testsuccess' 'NWE' "$@"
1728 msggroup
'testwarning'
1729 if [ "$1" = '--nomsg' ]; then
1732 msgtest
'Test for successful execution with warnings of' "$*"
1734 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1735 if "$@" >"${OUTPUT}" 2>&1; then
1736 if expr match
"$1" '^apt.*' >/dev
/null
; then
1737 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1738 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1739 elif grep -q -E '^E: ' "$OUTPUT"; then
1740 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1741 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1742 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1751 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1753 aptautotest
'testwarning' "$@"
1757 msggroup
'testfailure'
1758 if [ "$1" = '--nomsg' ]; then
1761 msgtest
'Test for failure in execution of' "$*"
1763 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1764 if "$@" >"${OUTPUT}" 2>&1; then
1766 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1769 if expr match
"$1" '^apt.*' >/dev
/null
; then
1770 if [ "$1" = 'aptkey' ]; then
1771 if grep -q " Can't check signature:
1773 signature could not be verified" "$OUTPUT"; then
1776 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1779 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1780 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1781 elif grep -q -E '==ERROR' "$OUTPUT"; then
1782 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1783 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1784 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1793 aptautotest
'testfailure' "$@"
1797 testreturnstateequal
() {
1799 if [ "$STATE" = 'testsuccesswithglobalerror' ]; then
1803 msggroup
"${STATE}equal"
1804 if [ "$1" != '--nomsg' ]; then
1807 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1808 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1812 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1813 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1816 msggroup
"${STATE}equal"
1817 if [ "$2" != '--nomsg' ]; then
1821 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1825 "$STATE" --nomsg "$@"
1826 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1831 testsuccessequal
() {
1832 # we compare output, so we know perfectly well about N:
1833 testreturnstateequal
'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@"
1835 testwarningequal
() {
1836 testreturnstateequal
'testwarning' "$@"
1838 testfailureequal
() {
1839 testreturnstateequal
'testfailure' "$@"
1843 msggroup
'testfailuremsg'
1847 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1848 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1849 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1850 testoutputequal
"$COMPAREFILE" echo "$CMP"
1854 msggroup
'testwarningmsg'
1858 msgtest
'Check that the output of the previous warned command has expected' 'warnings'
1859 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
1860 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
1861 testoutputequal
"$COMPAREFILE" echo "$CMP"
1866 msggroup
'testfilestats'
1867 msgtest
"Test that file $1 has $2 $3" "$4"
1868 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1871 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1874 echo -n "stat(1) reports for $2: "
1875 stat
--format "$2" "$1" || true
1877 msgfailoutput
'' "$OUTPUT"
1881 testaccessrights
() {
1882 msggroup
'testaccessrights'
1883 testfilestats
"$1" '%a' '=' "$2"
1887 testwebserverlaststatuscode
() {
1888 msggroup
'testwebserverlaststatuscode'
1889 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1890 local STATUS
='downloaded/webserverstatus-statusfile.log'
1891 rm -f "$DOWNLOG" "$STATUS"
1892 msgtest
'Test last status code from the webserver was' "$1"
1893 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1896 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1898 if [ -n "$2" ]; then
1900 echo >&2 '#### Additionally provided output files contain:'
1903 echo >&2 '#### Download log of the status code:'
1906 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1911 mapkeynametokeyid
() {
1912 while [ -n "$1" ]; do
1914 *Joe
*|*Sixpack
*|newarchive
) echo '5A90D141DBAC8DAE';;
1915 *Rex
*|*Expired
*) echo '4BC0A39C27CE74F9';;
1916 *Marvin
*|*Paranoid
*) echo 'E8525D47528144E2';;
1917 oldarchive
) echo 'FDD2DB85F68C85A3';;
1918 *) echo 'UNKNOWN KEY';;
1924 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output"
1925 if ! aptkey list
--with-colon | grep '^pub' | cut
-d':' -f 5 > "$OUTPUT"; then
1928 testfileequal
"$OUTPUT" "$(mapkeynametokeyid "$@")"
1932 echo "STOPPED execution. Press enter to continue"
1937 logcurrentarchivedirectory
() {
1938 find "${TMPWORKINGDIRECTORY}/aptarchive/dists" -type f
| while read line
; do
1939 stat
--format '%U:%G:%a:%n' "$line"
1940 done | sort > "${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst"
1942 listcurrentlistsdirectory
() {
1944 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1945 stat
--format '%U:%G:%a:%n' "$line"
1947 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1948 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1952 forallsupportedcompressors
() {
1953 rm -f "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
1954 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
1955 if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi
1960 ### convenience hacks ###
1962 # creating some directories by hand is a tedious task, so make it look simple
1964 if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then
1965 # only the last directory created by mkdir is effected by the -m !
1966 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1967 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1968 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1969 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1970 if [ "$(id -u)" = '0' ]; then
1971 chown _apt
:$(id -gn) "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1978 ### The following tests are run by most test methods automatically to check
1979 ### general things about commands executed without writing the test every time.
1982 if [ $# -lt 3 ]; then return; fi
1988 if ! expr match
"$i" '^-' >/dev
/null
2>&1; then
1994 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')"
1995 if command -v $AUTOTEST >/dev
/null
; then
1996 # save and restore the *.output files from other tests
1997 # as we might otherwise override them in these automatic tests
1998 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1999 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
2000 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
2001 $AUTOTEST "$TESTCALL" "$@"
2002 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
2003 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
2004 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
2008 aptautotest_aptget_update
() {
2010 while [ -n "$2" ]; do
2011 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
2014 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
2015 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
2016 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
2017 # all copied files are properly chmodded
2018 local backupIFS
="$IFS"
2019 IFS
="$(printf "\n\b")"
2020 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
2021 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
2024 if [ "$TESTCALL" = 'testsuccess' ]; then
2025 # failure cases can retain partial files and such
2026 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
2028 if [ -s "${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" ]; then
2029 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" \
2030 "$(find "${TMPWORKINGDIRECTORY}/aptarchive/dists" -type f | while read line; do stat --format '%U:%G:%a:%n' "$line"; done | sort)"
2033 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
2034 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
2036 testaptautotestnodpkgwarning
() {
2038 while [ -n "$2" ]; do
2039 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
2040 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
2043 testfailure
grep '^dpkg: warning:.*\(ignor\|unknown\).*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
2046 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
2047 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
2048 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
2049 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
2050 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
2051 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }
2053 testaptmarknodefaultsections
() {
2054 testfailure
grep '^Auto-Installed: 0$' "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/extended_states"
2056 aptautotest_aptmark_auto
() { testaptmarknodefaultsections
"$@"; }
2057 aptautotest_aptmark_manual
() { testaptmarknodefaultsections
"$@"; }
2058 aptautotest_aptget_markauto
() { testaptmarknodefaultsections
"$@"; }
2059 aptautotest_aptget_markmanual
() { testaptmarknodefaultsections
"$@"; }