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
"${APTTESTHELPERSBINDIR}/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 APTTESTHELPERSBINDIR
="${APT_INTEGRATION_TESTS_HELPERS_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
528 # Add an empty line to the end if there is none
529 if tail -1 rootdir
/var
/lib
/dpkg
/status
| grep -q .
; then
530 echo >> rootdir
/var
/lib
/dpkg
/status
533 echo -n > rootdir
/var
/lib
/dpkg
/status
536 rm -f rootdir
/etc
/apt
/apt.conf.d
/00foreigndpkg
537 # make sure dpkg can detect itself as capable of it
538 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
539 # dpkg doesn't really check the version as long as it is fully installed,
540 # but just to be sure we choose one above the required version
541 insertinstalledpackage
'dpkg' "all" '1.16.2+fake'
543 if dpkg
--assert-multi-arch >/dev
/null
2>&1 ; then
544 local ARCHS
="$(getarchitectures)"
545 local DPKGARCH
="$(dpkg --print-architecture)"
546 # this ensures that even if multi-arch isn't active in the view
547 # of apt, given that dpkg can't be told which arch is native
548 # the arch apt treats as native might be foreign for dpkg
549 for ARCH
in ${ARCHS}; do
550 if [ "${ARCH}" != "${DPKGARCH}" ]; then
551 if ! dpkg
--add-architecture ${ARCH} >/dev
/null
2>&1; then
552 # old-style used e.g. in Ubuntu-P – and as it seems travis
553 echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir
/etc
/apt
/apt.conf.d
/00foreigndpkg
554 echo "DPKG::options:: \"${ARCH}\";" >> rootdir
/etc
/apt
/apt.conf.d
/00foreigndpkg
561 configdpkgnoopchroot
() {
562 # create a library to noop chroot() and rewrite maintainer script executions
563 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
564 # chroot directory dpkg could chroot into to execute the maintainer scripts
565 msgtest
'Building library to preload to make maintainerscript work in' 'dpkg'
566 cat > noopchroot.c
<< EOF
573 static char * chrootdir = NULL;
575 int chroot(const char *path) {
576 printf("WARNING: CHROOTing to %s was ignored!\n", path);
578 chrootdir = strdup(path);
581 int execvp(const char *file, char *const argv[]) {
582 static int (*func_execvp) (const char *, char * const []) = NULL;
583 if (func_execvp == NULL)
584 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp");
585 if (chrootdir == NULL || strncmp(file, "/var/lib/dpkg/", strlen("/var/lib/dpkg/")) != 0)
586 return func_execvp(file, argv);
587 printf("REWRITE execvp call %s into %s\n", file, chrootdir);
589 if (asprintf(&newfile, "%s%s", chrootdir, file) == -1) {
593 char const * const baseadmindir = "/var/lib/dpkg";
595 if (asprintf(&admindir, "%s%s", chrootdir, baseadmindir) == -1) {
599 setenv("DPKG_ADMINDIR", admindir, 1);
600 return func_execvp(newfile, argv);
603 if cc
-ldl 2>&1 | grep -q dl
; then
604 testempty
--nomsg cc
-Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c
606 testempty
--nomsg cc
-Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c
-ldl
609 configcompression
() {
610 if [ "$1" = 'ALL' ]; then
611 configcompression
'.' $(aptconfig dump APT::Compressor --format '%t %v%n' | sed -n 's#^Extension \.\(.*\)$#\
1#p')
614 local CMD
='apthelper cat-file -C'
615 while [ -n "$1" ]; do
617 '.') printf ".\t.\tcat\n";;
618 'gz') printf "gzip\tgz\t$CMD $1\n";;
619 'bz2') printf "bzip2\tbz2\t$CMD $1\n";;
620 *) printf "$1\t$1\t$CMD $1\n";;
623 done > "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf"
627 echo 'APT::FTPArchive {'
629 while [ -n "$1" ]; do
630 printf "$1" | tr 'a-z' 'A-Z'
631 printf "\t\"true\";\n"
634 for h
in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
635 printf "$h\t\"false\";\n"
639 } >> "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/ftparchive-hashes.conf"
644 COMPRESSOR_CMD
="apthelper cat-file -C $1"
646 gzip) COMPRESS
='gz';;
647 bzip2) COMPRESS
='bz2';;
649 local CONFFILE
="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
650 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
651 Dir::Bin::uncompressed \"/does/not/exist\";" > "$CONFFILE"
652 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
653 if [ -z "$COMP" -o "$COMP" = '.' -o "$COMP" = "$COMPRESSOR" ]; then continue; fi
654 echo "Dir::Bin::${COMP} \"/does/not/exist\";" >> "$CONFFILE"
655 echo "APT::Compressor::${COMP}::Name \"${COMP}-disabled\";" >> "$CONFFILE"
659 _setupsimplenativepackage
() {
663 local RELEASE
="${4:-unstable}"
664 local DEPENDENCIES
="$5"
665 local DESCRIPTION
="${6:-an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
666 If you find such a package installed on your system,
667 something went horribly wrong! They are autogenerated
668 und used only by testcases and serve no other purpose…}"
670 local SECTION
="${7:-others}"
671 local PRIORITY
="${8:-optional}"
673 local COMPRESS_TYPE
="${10:-gzip}"
675 if [ "$SECTION" = "${SECTION#*/}" ]; then
678 DISTSECTION
="${SECTION%/*}"
680 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
682 mkdir -p "$BUILDDIR/debian/source"
683 echo "* most suckless software product ever" > "${BUILDDIR}/FEATURES"
685 echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}"
687 echo "Copyleft by Joe Sixpack $(date -u +%Y)" > "${BUILDDIR}/debian/copyright"
688 echo "$NAME ($VERSION) $RELEASE; urgency=low
692 -- Joe Sixpack <joe@example.org> $(date -u -R)" > "${BUILDDIR}/debian/changelog"
696 Maintainer: Joe Sixpack <joe@example.org>
697 Standards-Version: 3.9.3"
698 if [ "$SECTION" != '<none>' ]; then
699 echo "Section: $SECTION"
701 local BUILDDEPS
="$(printf "%b\n" "$DEPENDENCIES" | grep '^Build-')"
702 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
706 if [ "$ARCH" = 'all' ]; then
707 echo "Architecture: all"
709 echo "Architecture: any"
711 local DEPS
="$(printf "%b\n" "$DEPENDENCIES" | grep -v '^Build-')"
712 test -z "$DEPS" || echo "$DEPS"
713 printf "%b\n" "Description: $DESCRIPTION"
714 } > "${BUILDDIR}/debian/control"
716 echo '3.0 (native)' > "${BUILDDIR}/debian/source/format"
721 if command -v gmake
>/dev
/null
2>&1; then
722 [ -e ${TMPWORKINGDIRECTORY}/bin
/make ] || ln -s $(command -v gmake) ${TMPWORKINGDIRECTORY}/bin
/make
723 echo "#!${TMPWORKINGDIRECTORY}/bin/make -f" > "$OUT"
725 echo '#!/usr/bin/make -f' > "$OUT"
728 echo ' dh $@' >> "$OUT"
731 setupsimplenativepackage
() {
732 _setupsimplenativepackage
"$@"
735 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
736 test -e "${BUILDDIR}/debian/compat" || echo '7' > "${BUILDDIR}/debian/compat"
737 test -e "${BUILDDIR}/debian/rules" || make_tiny_rules
"${BUILDDIR}/debian/rules"
740 buildsimplenativepackage
() {
744 local RELEASE
="${4:-unstable}"
745 local DEPENDENCIES
="$5"
746 local DESCRIPTION
="$6"
747 local SECTION
="${7:-others}"
748 local PRIORITY
="${8:-optional}"
750 local COMPRESS_TYPE
="${10:-gzip}"
752 if [ "$SECTION" = "${SECTION#*/}" ]; then
755 DISTSECTION
="${SECTION%/*}"
757 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
758 msgtest
"Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
759 _setupsimplenativepackage
"$@"
761 testsuccess
--nomsg dpkg
-source -b ${NAME}-${VERSION}
763 sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" \
765 echo "pool/${SRC}" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist"
766 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
767 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
768 # adv --yes --default-key 'Joe Sixpack' \
769 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
770 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
774 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
775 msgtest
"Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
776 rm -rf "${BUILDDIR}/debian/tmp"
777 mkdir -p "${BUILDDIR}/debian/tmp/DEBIAN" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin"
778 cp "${BUILDDIR}/debian/copyright" "${BUILDDIR}/debian/changelog" "${BUILDDIR}/FEATURES" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}"
779 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}"
780 if [ -n "$FILE_TREE" ]; then
781 cp -ar "$FILE_TREE" "${BUILDDIR}/debian/tmp"
784 (cd "${BUILDDIR}"; dpkg
-gencontrol -DArchitecture=$arch)
785 (cd "${BUILDDIR}/debian/tmp"; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
786 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
787 # ensure the right permissions as dpkg-deb insists
788 chmod 755 "${BUILDDIR}/debian/tmp/DEBIAN"
789 testsuccess
--nomsg dpkg
-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian/tmp" "${BUILDDIR}/.."
790 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist"
794 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then
795 NM
="$(echo "$NAME" | cut -c 1-4)"
797 NM
="$(echo "$NAME" | cut -c 1)"
799 local CHANGEPATH
="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}"
800 mkdir -p "$CHANGEPATH"
801 cp "${BUILDDIR}/debian/changelog" "$CHANGEPATH"
810 local ARCH
=$(getarchitecture $4)
811 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
812 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
813 msgtest
"Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
815 if [ "$ARCH" = "all" ]; then
816 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
818 testsuccess
--nomsg dpkg
-buildpackage -uc -us -a$ARCH -d
819 cp "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$BUILDLOG"
820 local PKGS
="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
821 local SRCS
="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
824 echo "pool/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist"
827 echo "pool/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist"
832 if [ -d incoming
]; then
833 buildaptarchivefromincoming
"$@"
835 buildaptarchivefromfiles
"$@"
839 createaptftparchiveconfig
() {
840 local COMPRESSORS
="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
841 local COMPRESSORS
="${COMPRESSORS%* }"
842 local ARCHS
="$(getarchitectures)"
843 cat > ftparchive.conf
<<EOF
845 ArchiveDir "$(readlink -f .)";
846 CacheDir "$(readlink -f ..)";
847 FileListDir "$(readlink -f pool/)";
850 Packages::Compress "$COMPRESSORS";
851 Sources::Compress "$COMPRESSORS";
852 Contents::Compress "$COMPRESSORS";
853 Translation::Compress "$COMPRESSORS";
854 LongDescription "false";
858 SrcDirectory "pool/";
861 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
864 Architectures "$ARCHS all source";
865 FileList "${DIST}.\$(SECTION).pkglist";
866 SourceFileList "${DIST}.\$(SECTION).srclist";
867 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
870 done >> ftparchive.conf
873 buildaptftparchivedirectorystructure
() {
874 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
875 for DIST
in $DISTS; do
876 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
877 for SECTION
in $SECTIONS; do
878 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
879 for ARCH
in $ARCHS; do
880 mkdir -p "dists/${DIST}/${SECTION}/binary-${ARCH}"
882 mkdir -p "dists/${DIST}/${SECTION}/source"
883 mkdir -p "dists/${DIST}/${SECTION}/i18n"
893 local DEPENDENCIES
="$5"
894 local PRIORITY
="${6:-optional}"
895 local DESCRIPTION
="${7:-an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
896 If you find such a package installed on your system,
897 something went horribly wrong! They are autogenerated
898 und used only by testcases and serve no other purpose…}"
900 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
901 if [ "$RELEASE" = 'installed' ]; then
902 insertinstalledpackage
"$2" "$3" "$4" "$5" "$6" "$7"
905 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
906 if [ "$arch" = 'none' ]; then
907 ARCHS
="$(getarchitectures)"
911 for BUILDARCH
in $ARCHS; do
912 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
919 Maintainer: Joe Sixpack <joe@example.org>"
920 test "$arch" = 'none' || echo "Architecture: $arch"
921 echo "Version: $VERSION
922 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb"
923 test -z "$DEPENDENCIES" || printf "%b\n" "$DEPENDENCIES"
924 echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)"
925 echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
926 echo "SHA256: 0000000000000000000000000000000000000000000000000000000000000000"
928 } >> "${PPATH}/Packages"
931 mkdir -p "aptarchive/dists/${RELEASE}/main/source" "aptarchive/dists/${RELEASE}/main/i18n"
932 touch "aptarchive/dists/${RELEASE}/main/source/Sources"
934 Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
935 Description-en: $DESCRIPTION
936 " >> "aptarchive/dists/${RELEASE}/main/i18n/Translation-en"
945 local DEPENDENCIES
="$5"
946 local BINARY
="${6:-$NAME}"
948 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
949 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
951 local FILE
="${SPATH}/Sources"
952 local DSCFILE
="${NAME}_${VERSION}.dsc"
953 local TARFILE
="${NAME}_${VERSION}.tar.gz"
957 Maintainer: Joe Sixpack <joe@example.org>
958 Architecture: $ARCH" >> $FILE
959 test -z "$DEPENDENCIES" || printf "%b\n" "$DEPENDENCIES" >> "$FILE"
961 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
962 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
964 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
965 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
970 insertinstalledpackage
() {
974 local DEPENDENCIES
="$4"
975 local PRIORITY
="${5:-optional}"
976 local STATUS
="${6:-install ok installed}"
977 local DESCRIPTION
="${7:-an autogenerated dummy ${NAME}=${VERSION}/installed
978 If you find such a package installed on your system,
979 something went horribly wrong! They are autogenerated
980 und used only by testcases and serve no other purpose…}"
982 local FILE
='rootdir/var/lib/dpkg/status'
983 local INFO
='rootdir/var/lib/dpkg/info'
984 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
990 Maintainer: Joe Sixpack <joe@example.org>
991 Version: $VERSION" >> "$FILE"
992 test "$arch" = 'none' || echo "Architecture: $arch" >> "$FILE"
993 test -z "$DEPENDENCIES" || printf "%b\n" "$DEPENDENCIES" >> "$FILE"
994 printf "%b\n" "Description: $DESCRIPTION" >> "$FILE"
996 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
997 echo -n > "${INFO}/${NAME}:${arch}.list"
999 echo -n > "${INFO}/${NAME}.list"
1005 buildaptarchivefromincoming
() {
1006 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on incoming packages…"
1008 [ -e pool
] || ln -s ..
/incoming pool
1009 [ -e ftparchive.conf
] || createaptftparchiveconfig
1010 [ -e dists
] || buildaptftparchivedirectorystructure
1011 msgninfo
"\tGenerate Packages, Sources and Contents files… "
1012 testsuccess aptftparchive generate ftparchive.conf
1015 generatereleasefiles
"$@"
1018 buildaptarchivefromfiles
() {
1019 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on prebuild files…"
1020 local DIR
='aptarchive'
1021 if [ -d "${DIR}/dists" ]; then DIR
="${DIR}/dists"; fi
1022 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
1023 msgninfo
"\t${line} file… "
1024 compressfile
"$line" "$1"
1027 generatereleasefiles
"$@"
1031 while read compressor extension
command; do
1032 if [ "$compressor" = '.' ]; then
1033 if [ -n "$2" ]; then
1038 cat "$1" | $command > "${1}.${extension}"
1039 if [ -n "$2" ]; then
1040 touch -d "$2" "${1}.${extension}"
1042 done < "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf"
1045 # can be overridden by testcases for their pleasure
1046 getcodenamefromsuite
() {
1048 unstable
) echo 'sid';;
1052 getreleaseversionfromsuite
() { true
; }
1053 getlabelfromsuite
() { true
; }
1054 getoriginfromsuite
() { true
; }
1055 getarchitecturesfromreleasefile
() { echo "all $(getarchitectures)"; }
1056 getnotautomaticfromsuite
() {
1058 experimental
|experimental2
) echo "yes";;
1061 getbutautomaticupgradesfromsuite
() { true
; }
1063 aptftparchiverelease
() {
1064 aptftparchive
-qq release
"$@" | sed -e '/0 Release$/ d' # remove the self reference
1066 generatereleasefiles
() {
1067 # $1 is the Date header and $2 is the ValidUntil header to be set
1068 # both should be given in notation date/touch can understand
1070 local VALIDUNTIL
="$2"
1071 if [ -e aptarchive
/dists
]; then
1072 msgninfo
"\tGenerate Release files for dists… "
1073 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
1074 local ARCHITECTURES
="$(getarchitecturesfromreleasefile "$dir")"
1075 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
1076 local CODENAME
="$(getcodenamefromsuite $SUITE)"
1077 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
1078 local LABEL
="$(getlabelfromsuite $SUITE)"
1079 local ORIGIN
="$(getoriginfromsuite $SUITE)"
1080 local NOTAUTOMATIC
="$(getnotautomaticfromsuite $SUITE)"
1081 local BUTAUTOMATICUPGRADES
="$(getbutautomaticupgradesfromsuite $SUITE)"
1082 aptftparchiverelease
"$dir" \
1083 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
1084 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
1085 -o APT
::FTPArchive
::Release
::Architectures
="${ARCHITECTURES}" \
1086 -o APT
::FTPArchive
::Release
::Label
="${LABEL}" \
1087 -o APT
::FTPArchive
::Release
::Origin
="${ORIGIN}" \
1088 -o APT
::FTPArchive
::Release
::Version
="${VERSION}" \
1089 -o APT
::FTPArchive
::Release
::NotAutomatic
="${NOTAUTOMATIC}" \
1090 -o APT
::FTPArchive
::Release
::ButAutomaticUpgrades
="${BUTAUTOMATICUPGRADES}" \
1094 msgninfo
"\tGenerate Release files for flat… "
1095 aptftparchiverelease .
/aptarchive
> aptarchive
/Release
1097 if [ -n "$DATE" -a "$DATE" != "now" ]; then
1098 for release
in $(find ./aptarchive -name 'Release'); do
1099 sed -i "s/^Date: .*$/Date: $(date -u -d "$DATE" -R)/" "$release"
1100 touch -d "$DATE" "$release"
1103 if [ -n "$VALIDUNTIL" ]; then
1104 sed -i "/^Date: / a\
1105 Valid-Until: $(date -u -d "$VALIDUNTIL" -R)" $(find ./aptarchive -name 'Release')
1110 setupdistsaptarchive
() {
1111 local APTARCHIVE
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1112 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
1113 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
1114 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1115 SECTIONS
=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1116 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
1117 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list"
1118 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list"
1123 setupflataptarchive
() {
1124 local APTARCHIVE
="$(readlink -f ./aptarchive)"
1125 local APTARCHIVEURI
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1126 if [ -f "${APTARCHIVE}/Packages" ]; then
1127 msgninfo
"\tadd deb sources.list line… "
1128 echo "deb file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1131 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1133 if [ -f "${APTARCHIVE}/Sources" ]; then
1134 msgninfo
"\tadd deb-src sources.list line… "
1135 echo "deb-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1138 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1144 if [ "$1" = '--no-update' ]; then
1148 buildaptarchive
"$@"
1149 if [ -e aptarchive
/dists
]; then
1150 setupdistsaptarchive
1154 signreleasefiles
'Joe Sixpack'
1155 if [ "1" != "$NOUPDATE" ]; then
1156 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
1160 signreleasefiles
() {
1161 local SIGNERS
="${1:-Joe Sixpack}"
1162 local REPODIR
="${2:-aptarchive}"
1163 if [ -n "$1" ]; then shift; fi
1164 if [ -n "$1" ]; then shift; fi
1165 local KEY
="keys/$(echo "$SIGNERS" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1166 msgninfo
"\tSign archive with $SIGNERS key $KEY… "
1167 local REXKEY
='keys/rexexpired'
1168 local SECEXPIREBAK
="${REXKEY}.sec.bak"
1169 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
1171 while [ -n "${SIGNERS%%,*}" ]; do
1172 local SIGNER
="${SIGNERS%%,*}"
1173 if [ "${SIGNERS}" = "${SIGNER}" ]; then
1176 SIGNERS
="${SIGNERS#*,}"
1177 # FIXME: This should be the full name, but we can't encode the space properly currently
1178 SIGUSERS
="${SIGUSERS} -u ${SIGNER#* }"
1179 if [ "${SIGNER}" = 'Rex Expired' ]; then
1180 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1181 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1182 # therefore we 'temporary' make the key not expired and restore a backup after signing
1183 cp "${REXKEY}.sec" "$SECEXPIREBAK"
1184 cp "${REXKEY}.pub" "$PUBEXPIREBAK"
1185 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
1186 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
1187 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1188 cp "$SECUNEXPIRED" "${REXKEY}.sec"
1189 cp "$PUBUNEXPIRED" "${REXKEY}.pub"
1191 if ! printf "expire\n1w\nsave\n" | aptkey
--quiet --keyring "${REXKEY}.pub" --secret-keyring "${REXKEY}.sec" \
1192 --readonly adv
--batch --yes --digest-algo "${APT_TESTS_DIGEST_ALGO:-SHA512}" \
1193 --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
1197 cp "${REXKEY}.sec" "$SECUNEXPIRED"
1198 cp "${REXKEY}.pub" "$PUBUNEXPIRED"
1201 if [ ! -e "${KEY}.pub" ]; then
1202 local K
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1203 cat "${K}.pub" >> "${KEY}.new.pub"
1204 cat "${K}.sec" >> "${KEY}.new.sec"
1207 if [ ! -e "${KEY}.pub" ]; then
1208 mv "${KEY}.new.pub" "${KEY}.pub"
1209 mv "${KEY}.new.sec" "${KEY}.sec"
1211 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes --digest-algo ${APT_TESTS_DIGEST_ALGO:-SHA512}"
1212 for RELEASE
in $(find "${REPODIR}/" -name Release); do
1213 # we might have set a specific date for the Release file, so copy it
1214 local DATE
="$(stat --format "%y" "${RELEASE}")"
1215 if [ "$APT_DONT_SIGN" = 'Release.gpg' ]; then
1216 rm -f "${RELEASE}.gpg"
1218 testsuccess
$GPG "$@" $SIGUSERS --armor --detach-sign --sign --output "${RELEASE}.gpg" "${RELEASE}"
1219 touch -d "$DATE" "${RELEASE}.gpg"
1221 local INRELEASE
="${RELEASE%/*}/InRelease"
1222 if [ "$APT_DONT_SIGN" = 'InRelease' ]; then
1225 testsuccess
$GPG "$@" $SIGUSERS --clearsign --output "$INRELEASE" "$RELEASE"
1226 touch -d "$DATE" "${INRELEASE}"
1229 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1230 mv -f "$SECEXPIREBAK" "${REXKEY}.sec"
1231 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub"
1236 redatereleasefiles
() {
1237 local DATE
="$(date -u -d "$1" -R)"
1238 for release
in $(find aptarchive/ -name 'Release'); do
1239 sed -i "s/^Date: .*$/Date: ${DATE}/" "$release"
1240 touch -d "$DATE" "$release"
1242 signreleasefiles
"${2:-Joe Sixpack}"
1246 local WEBSERVER
="${3:-http://localhost:${APTHTTPPORT}}"
1248 if [ "$1" = '--no-check' ]; then
1252 local DOWNLOG
='rootdir/tmp/download-testfile.log'
1253 local STATUS
='downloaded/webserverconfig.status'
1254 rm -f "$STATUS" "$DOWNLOG"
1255 # very very basic URI encoding
1257 if [ -n "$2" ]; then
1258 msgtest
"Set webserver config option '${1}' to" "$2"
1259 URI
="${WEBSERVER}/_config/set/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1261 msgtest
'Clear webserver config option' "${1}"
1262 URI
="${WEBSERVER}/_config/clear/$(echo "${1}" | sed -e 's/\//%2f/g')"
1264 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
1267 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.output"
1268 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1269 msgfailoutput
'' "$OUTPUT"
1271 $NOCHECK || testwebserverlaststatuscode
'200'
1274 rewritesourceslist
() {
1275 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1276 local APTARCHIVE2
="copy://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1277 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1278 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
1279 -e "s#http://[^@]*@\?localhost:${APTHTTPPORT}/\?#${1}#" \
1280 -e "s#https://[^@]*@\?localhost:${APTHTTPSPORT}/\?#${1}#"
1284 # wait for up to 10s for a pid file to appear to avoid possible race
1285 # when a helper is started and dosn't write the PID quick enough
1288 for i
in $(seq 10); do
1289 if test -s "$PIDFILE"; then
1294 msgdie
"waiting for $PIDFILE failed"
1298 changetowebserver
() {
1300 if [ "$1" != '--no-rewrite' ]; then
1305 if test -x "${APTTESTHELPERSBINDIR}/aptwebserver"; then
1307 local LOG
="webserver.log"
1308 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1312 waitforpidfile aptwebserver.pid
1313 local PID
="$(cat aptwebserver.pid)"
1314 if [ -z "$PID" ]; then
1315 msgdie
'Could not fork aptwebserver successfully'
1317 addtrap
"kill $PID;"
1318 waitforpidfile aptwebserver.port
1319 APTHTTPPORT
="$(cat aptwebserver.port)"
1320 if [ -z "$APTHTTPPORT" ]; then
1321 msgdie
'Could not get port for aptwebserver successfully'
1325 msgdie
'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver'
1327 if [ "$REWRTE" != 'yes' ]; then
1328 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1332 changetohttpswebserver
() {
1334 if command -v stunnel4
>/dev
/null
2>&1; then
1336 elif command -v stunnel
>/dev
/null
2>&1; then
1339 msgdie
'You need to install stunnel4 for https testcases'
1341 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1342 changetowebserver
--no-rewrite "$@"
1344 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1345 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1350 connect = $APTHTTPPORT
1351 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1352 $stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
1353 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1354 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1355 if [ -z "$PID" ]; then
1356 msgdie
'Could not fork $stunnel4 successfully'
1358 addtrap
'prefix' "kill ${PID};"
1359 APTHTTPSPORT
="$(lsof -i -n | awk "/^$stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1360 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1361 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1365 mkdir -p rootdir
/media
/cdrom
/.disk
1366 local CD
="$(readlink -f rootdir/media/cdrom)"
1367 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1368 acquire::cdrom::mount "${CD}";
1369 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1370 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1371 acquire::cdrom::autodetect 0;
1373 echo -n "$1" > "${CD}/.disk/info"
1374 if [ ! -d aptarchive
/dists
]; then
1375 msgdie
'Flat file archive cdroms can not be created currently'
1378 mv aptarchive
/dists
"$CD"
1379 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1380 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1381 # start with an unmounted disk
1382 mv "${CD}" "${CD}-unmounted"
1383 # we don't want the disk to be modifiable
1384 addtrap
'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;"
1385 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1389 local PROTO
="${1%%:*}"
1390 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1391 download
-file "$1" "$2" "$3" 2>&1 ; then
1394 # only if the file exists the download was successful
1395 if [ -r "$2" ]; then
1403 local TMPFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/checkdiff.1.tmp"
1404 local TMPFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/checkdiff.2.tmp"
1405 touch "$TMPFILE1" "$TMPFILE2"
1406 if [ "$1" != '-' ]; then
1407 sed -e '/^profiling:/ d' < "$1" >"$TMPFILE1"
1411 if [ "$2" != '-' ]; then
1412 sed -e '/^profiling:/ d' < "$2" >"$TMPFILE2"
1416 local DIFFTEXT
="$(command diff -u "$TMPFILE1" "$TMPFILE2" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1417 if [ -n "$DIFFTEXT" ]; then
1419 echo >&2 "$DIFFTEXT"
1427 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1428 local COMPAREFILE
="$1"
1430 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1433 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1434 cat "$COMPAREFILE" >>"${OUTPUT}"
1435 msgfailoutput
'' "$OUTPUT" "$@"
1440 msggroup
'testfileequal'
1441 local MSG
='Test for correctness of file'
1442 if [ "$1" = '--nomsg' ]; then
1448 if [ -n "$MSG" ]; then
1449 msgtest
"$MSG" "$FILE"
1451 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1452 if [ -z "$*" ]; then
1453 testoutputequal
"$FILE" echo -n ''
1455 testoutputequal
"$FILE" echo "$*"
1461 msggroup
'testempty'
1462 if [ "$1" = '--nomsg' ]; then
1465 msgtest
"Test for no output of" "$*"
1467 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1468 if "$@" >"$COMPAREFILE" 2>&1 && test ! -s "$COMPAREFILE"; then
1471 msgfailoutput
'' "$COMPAREFILE" "$@"
1473 aptautotest
'testempty' "$@"
1477 msggroup
'testnotempty'
1478 msgtest
"Test for some output of" "$*"
1479 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
1480 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then
1483 msgfailoutput
'' "$COMPAREFILE" "$@"
1485 aptautotest
'testnotempty' "$@"
1490 msggroup
'testequal'
1491 local MSG
='Test of equality of'
1492 if [ "$1" = '--nomsg' ]; then
1497 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1498 echo "$1" > "$COMPAREFILE"
1501 if [ -n "$MSG" ]; then
1504 testoutputequal
"$COMPAREFILE" "$@"
1505 aptautotest
'testequal' "$@"
1510 msggroup
'testequalor2'
1511 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1512 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1513 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1514 echo "$1" > "$COMPAREFILE1"
1515 echo "$2" > "$COMPAREFILE2"
1517 msgtest
"Test for equality OR of" "$*"
1518 "$@" >"$COMPAREAGAINST" 2>&1 || true
1519 if checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null
2>&1 || \
1520 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null
2>&1
1524 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1525 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1526 checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1527 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1528 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1529 msgfailoutput
'' "$OUTPUT"
1531 aptautotest
'testequalor2' "$@"
1536 msggroup
'testshowvirtual'
1537 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1540 while [ -n "$1" ]; do
1542 N: Can't select versions from package '$1' as it is purely virtual"
1543 PACKAGE
="${PACKAGE} $1"
1546 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1548 N: No packages found"
1549 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1550 local ARCH
="$(getarchitecture 'native')"
1551 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1552 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1553 testoutputequal
"$COMPAREFILE" aptcache show
"$PACKAGE"
1558 msggroup
'testnopackage'
1559 msgtest
"Test for non-existent packages" "apt-cache show $*"
1560 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1561 if [ -n "$SHOWPKG" ]; then
1562 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1563 echo "$SHOWPKG" >"$OUTPUT"
1564 msgfailoutput
'' "$OUTPUT"
1570 testnosrcpackage
() {
1571 msggroup
'testnosrcpackage'
1572 msgtest
"Test for non-existent source packages" "apt-cache showsrc $*"
1573 local SHOWPKG
="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')"
1574 if [ -n "$SHOWPKG" ]; then
1575 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output"
1576 echo "$SHOWPKG" >"$OUTPUT"
1577 msgfailoutput
'' "$OUTPUT"
1585 msggroup
'testdpkgstatus'
1589 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1590 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1591 if [ "$PKGS" != $NR ]; then
1592 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1593 echo "$PKGS" >"$OUTPUT"
1594 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1595 msgfailoutput
'' "$OUTPUT"
1602 testdpkginstalled
() {
1603 msggroup
'testdpkginstalled'
1604 testdpkgstatus
'ii' "$#" "$@"
1608 testdpkgnotinstalled
() {
1609 msggroup
'testdpkgnotinstalled'
1610 testdpkgstatus
'ii' '0' "$@"
1615 msggroup
'testmarkedauto'
1616 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1617 if [ -n "$1" ]; then
1618 msgtest
'Test for correctly marked as auto-installed' "$*"
1619 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1621 msgtest
'Test for correctly marked as auto-installed' 'no package'
1622 echo -n > "$COMPAREFILE"
1624 testoutputequal
"$COMPAREFILE" aptmark showauto
1627 testmarkedmanual
() {
1628 msggroup
'testmarkedmanual'
1629 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1630 if [ -n "$1" ]; then
1631 msgtest
'Test for correctly marked as manually installed' "$*"
1632 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1634 msgtest
'Test for correctly marked as manually installed' 'no package'
1635 echo -n > "$COMPAREFILE"
1637 testoutputequal
"$COMPAREFILE" aptmark showmanual
1642 if [ "${1##*.}" = 'deb' ]; then
1643 stat
>&2 "$1" || true
1644 file >&2 "$1" || true
1646 cat >&2 "$1" || true
1650 msgreportheader
'msgfailoutput'
1655 if [ "$1" = 'grep' -o "$1" = 'tail' -o "$1" = 'head' ]; then
1657 while [ -n "$2" ]; do shift; done
1658 echo "#### Complete file: $1 ####"
1660 echo "#### $CMD output ####"
1661 elif [ "$1" = 'test' ]; then
1663 # doesn't support ! or non-file flags
1664 msgfailoutputstatfile
() {
1665 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1666 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1667 echo "#### stat(2) of file: $2 ####"
1669 if test -d "$2"; then
1670 echo "#### The directory contains: $2 ####"
1672 elif test -e "$2"; then
1673 echo "#### Complete file: $2 ####"
1678 msgfailoutputstatfile
"$2" "$3"
1679 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1681 msgfailoutputstatfile
"$2" "$3"
1683 echo '#### test output ####'
1684 elif [ "$1" = 'cmp' ]; then
1686 while [ -n "$2" ]; do
1687 echo "#### Complete file: $2 ####"
1691 echo '#### cmp output ####'
1697 testsuccesswithglobalerror
() {
1702 if [ "$1" = '--nomsg' ]; then
1705 msgtest
'Test for successful execution of' "$*"
1707 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output"
1708 if "$@" >"${OUTPUT}" 2>&1; then
1709 if expr match
"$1" '^apt.*' >/dev
/null
; then
1710 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1711 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1712 elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1713 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1714 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1715 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1718 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1721 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1723 elif [ "$TYPE" = 'testsuccesswithnotice' ]; then
1724 if grep -q -E "^N: " "$OUTPUT"; then
1727 msgfailoutput
'successful run, but output had no notices' "$OUTPUT" "$@"
1737 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1739 aptautotest
"$TYPE" "$@"
1742 testsuccesswithnotice
() {
1743 testsuccesswithglobalerror
'testsuccesswithnotice' 'WE' "$@"
1746 testsuccesswithglobalerror
'testsuccess' 'NWE' "$@"
1749 msggroup
'testwarning'
1750 if [ "$1" = '--nomsg' ]; then
1753 msgtest
'Test for successful execution with warnings of' "$*"
1755 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1756 if "$@" >"${OUTPUT}" 2>&1; then
1757 if expr match
"$1" '^apt.*' >/dev
/null
; then
1758 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1759 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1760 elif grep -q -E '^E: ' "$OUTPUT"; then
1761 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1762 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1763 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1772 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1774 aptautotest
'testwarning' "$@"
1778 msggroup
'testfailure'
1779 if [ "$1" = '--nomsg' ]; then
1782 msgtest
'Test for failure in execution of' "$*"
1784 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1785 if "$@" >"${OUTPUT}" 2>&1; then
1787 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1790 if expr match
"$1" '^apt.*' >/dev
/null
; then
1791 if [ "$1" = 'aptkey' ]; then
1792 if grep -q " Can't check signature:
1794 signature could not be verified" "$OUTPUT"; then
1797 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1800 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1801 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1802 elif grep -q -E '==ERROR' "$OUTPUT"; then
1803 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1804 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1805 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1814 aptautotest
'testfailure' "$@"
1818 testreturnstateequal
() {
1820 if [ "$STATE" = 'testsuccesswithglobalerror' ]; then
1824 msggroup
"${STATE}equal"
1825 if [ "$1" != '--nomsg' ]; then
1828 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1829 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1833 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1834 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1837 msggroup
"${STATE}equal"
1838 if [ "$2" != '--nomsg' ]; then
1842 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1846 "$STATE" --nomsg "$@"
1847 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1852 testsuccessequal
() {
1853 # we compare output, so we know perfectly well about N:
1854 testreturnstateequal
'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@"
1856 testwarningequal
() {
1857 testreturnstateequal
'testwarning' "$@"
1859 testfailureequal
() {
1860 testreturnstateequal
'testfailure' "$@"
1864 msggroup
'testfailuremsg'
1868 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1869 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1870 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1871 testoutputequal
"$COMPAREFILE" echo "$CMP"
1875 msggroup
'testwarningmsg'
1879 msgtest
'Check that the output of the previous warned command has expected' 'warnings'
1880 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
1881 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
1882 testoutputequal
"$COMPAREFILE" echo "$CMP"
1887 msggroup
'testfilestats'
1888 msgtest
"Test that file $1 has $2 $3" "$4"
1889 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1892 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1895 echo -n "stat(1) reports for $2: "
1896 stat
--format "$2" "$1" || true
1898 msgfailoutput
'' "$OUTPUT"
1902 testaccessrights
() {
1903 msggroup
'testaccessrights'
1904 testfilestats
"$1" '%a' '=' "$2"
1908 testwebserverlaststatuscode
() {
1909 msggroup
'testwebserverlaststatuscode'
1910 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1911 local STATUS
='downloaded/webserverstatus-statusfile.log'
1912 rm -f "$DOWNLOG" "$STATUS"
1913 msgtest
'Test last status code from the webserver was' "$1"
1914 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1917 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1919 if [ -n "$2" ]; then
1921 echo >&2 '#### Additionally provided output files contain:'
1924 echo >&2 '#### Download log of the status code:'
1927 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1932 mapkeynametokeyid
() {
1933 while [ -n "$1" ]; do
1935 *Joe
*|*Sixpack
*|newarchive
) echo '5A90D141DBAC8DAE';;
1936 *Rex
*|*Expired
*) echo '4BC0A39C27CE74F9';;
1937 *Marvin
*|*Paranoid
*) echo 'E8525D47528144E2';;
1938 oldarchive
) echo 'FDD2DB85F68C85A3';;
1939 *) echo 'UNKNOWN KEY';;
1945 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output"
1946 if ! aptkey list
--with-colon | grep '^pub' | cut
-d':' -f 5 > "$OUTPUT"; then
1949 testfileequal
"$OUTPUT" "$(mapkeynametokeyid "$@")"
1953 echo "STOPPED execution. Press enter to continue"
1958 logcurrentarchivedirectory
() {
1959 find "${TMPWORKINGDIRECTORY}/aptarchive/dists" -type f
| while read line
; do
1960 stat
--format '%U:%G:%a:%n' "$line"
1961 done | sort > "${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst"
1963 listcurrentlistsdirectory
() {
1965 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1966 stat
--format '%U:%G:%a:%n' "$line"
1968 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1969 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1973 forallsupportedcompressors
() {
1974 rm -f "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
1975 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
1976 if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi
1981 ### convenience hacks ###
1983 # creating some directories by hand is a tedious task, so make it look simple
1985 if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then
1986 # only the last directory created by mkdir is effected by the -m !
1987 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1988 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1989 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1990 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1991 if [ "$(id -u)" = '0' ]; then
1992 chown _apt
:$(id -gn) "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1999 ### The following tests are run by most test methods automatically to check
2000 ### general things about commands executed without writing the test every time.
2003 if [ $# -lt 3 ]; then return; fi
2009 if ! expr match
"$i" '^-' >/dev
/null
2>&1; then
2015 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')"
2016 if command -v $AUTOTEST >/dev
/null
; then
2017 # save and restore the *.output files from other tests
2018 # as we might otherwise override them in these automatic tests
2019 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
2020 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
2021 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
2022 $AUTOTEST "$TESTCALL" "$@"
2023 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
2024 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
2025 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
2029 aptautotest_aptget_update
() {
2031 while [ -n "$2" ]; do
2032 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
2035 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
2036 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
2037 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
2038 # all copied files are properly chmodded
2039 local backupIFS
="$IFS"
2040 IFS
="$(printf "\n\b")"
2041 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
2042 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
2045 if [ "$TESTCALL" = 'testsuccess' ]; then
2046 # failure cases can retain partial files and such
2047 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
2049 if [ -s "${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" ]; then
2050 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" \
2051 "$(find "${TMPWORKINGDIRECTORY}/aptarchive/dists" -type f | while read line; do stat --format '%U:%G:%a:%n' "$line"; done | sort)"
2054 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
2055 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
2057 testaptautotestnodpkgwarning
() {
2059 while [ -n "$2" ]; do
2060 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
2061 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
2064 testfailure
grep '^dpkg: warning:.*\(ignor\|unknown\).*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
2067 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
2068 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
2069 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
2070 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
2071 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
2072 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }
2074 testaptmarknodefaultsections
() {
2075 testfailure
grep '^Auto-Installed: 0$' "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/extended_states"
2077 aptautotest_aptmark_auto
() { testaptmarknodefaultsections
"$@"; }
2078 aptautotest_aptmark_manual
() { testaptmarknodefaultsections
"$@"; }
2079 aptautotest_aptget_markauto
() { testaptmarknodefaultsections
"$@"; }
2080 aptautotest_aptget_markmanual
() { testaptmarknodefaultsections
"$@"; }