1 #!/bin/sh -- # no runable script, just for vi
6 if [ "$1" = "-q" ]; then
8 elif [ "$1" = "-v" ]; then
10 elif [ "$1" = '--color=no' ]; then
12 elif [ "$1" = '--color=yes' ]; then
14 elif [ "$1" = '--color' ]; then
15 export MSGCOLOR
="$(echo "$2" | tr 'a-z' 'A-Z')"
17 elif [ "$1" = '--level' ]; then
21 echo >&2 "WARNING: Unknown parameter »$1« will be ignored"
25 export MSGLEVEL
="${MSGLEVEL:-3}"
27 # we all like colorful messages
28 if [ "${MSGCOLOR:-YES}" = 'YES' ]; then
29 if [ ! -t 1 ]; then # but check that we output to a terminal
34 if [ "$MSGCOLOR" != 'NO' ]; then
35 CERROR
="\033[1;31m" # red
36 CWARNING
="\033[1;33m" # yellow
37 CMSG
="\033[1;32m" # green
38 CINFO
="\033[1;96m" # light blue
39 CDEBUG
="\033[1;94m" # blue
40 CNORMAL
="\033[0;39m" # default system console color
41 CDONE
="\033[1;32m" # green
42 CPASS
="\033[1;32m" # green
43 CFAIL
="\033[1;31m" # red
44 CCMD
="\033[1;35m" # pink
56 printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghks]\)#apt-\1#')"
62 msgdie
() { msgprintf
"${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; }
63 msgwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; }
64 msgmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; }
65 msginfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; }
66 msgdebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; }
67 msgdone
() { msgprintf
"${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; }
68 msgnwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; }
69 msgnmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}" "$@"; }
70 msgninfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
71 msgndebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
72 msgtest
() { msgprintf
"${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
73 msgpass
() { printf "${CPASS}PASS${CNORMAL}\n"; }
75 if [ -n "$MSGTEST_MSG" ]; then
76 test "$1" != 'msgfailoutput' || echo
77 if [ -n "$MSGTEST_MSGMSG" ]; then
78 echo "$MSGTEST_MSGMSG"
80 if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then
81 echo "${CFAIL}Part of the test group: $MSGTEST_GRP"
83 echo -n "$MSGTEST_MSG"
88 msgreportheader
'msgskip'
89 if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
90 else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
93 msgreportheader
'msgfail'
94 if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
95 else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
96 if [ -n "$APT_DEBUG_TESTS" ]; then
99 EXIT_CODE
=$((EXIT_CODE+1));
104 if [ $MSGGROUP_LEVEL = 0 ]; then
107 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL+1));
109 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL-1));
110 if [ $MSGGROUP_LEVEL = 0 ]; then
116 # enable / disable Debugging
117 if [ $MSGLEVEL -le 0 ]; then
120 if [ $MSGLEVEL -le 1 ]; then
124 if [ $MSGLEVEL -le 2 ]; then
126 MSGTEST_MSGMSG
="$(msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@")"
130 MSGTEST_MSG
="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")"
131 if [ "$MSGTEST_GRP" = 'NEXT' ]; then
132 MSGTEST_GRP
="$MSGTEST_MSG"
135 msgpass
() { printf " ${CPASS}P${CNORMAL}"; }
137 if [ $MSGLEVEL -le 3 ]; then
141 if [ $MSGLEVEL -le 4 ]; then
143 msgndebug
() { true
; }
146 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
147 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
148 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
149 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
150 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
153 printf "${CDONE}DONE${CNORMAL}\n";
157 if [ -f .
/aptconfig.conf
]; then
158 echo "$(readlink -f ./aptconfig.conf)"
159 elif [ -f ..
/aptconfig.conf
]; then
160 echo "$(readlink -f ../aptconfig.conf)"
161 elif [ -f ..
/..
/aptconfig.conf
]; then
162 echo "$(readlink -f ../../aptconfig.conf)"
163 elif [ -f "${TMPWORKINGDIRECTORY}/aptconfig.conf" ]; then
164 echo "$(readlink -f "${TMPWORKINGDIRECTORY}/aptconfig.conf")"
168 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
172 sh
|aptitude
|*/*|command) ;;
173 *) CMD
="${BUILDDIRECTORY}/$CMD";;
175 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
="${LIBRARYPATH}:${LD_LIBRARY_PATH}" "$CMD" "$@"
177 runpython3
() { runapt
command python3
"$@"; }
178 aptconfig
() { runapt apt
-config "$@"; }
179 aptcache
() { runapt apt
-cache "$@"; }
180 aptcdrom
() { runapt apt
-cdrom "$@"; }
181 aptget
() { runapt apt
-get "$@"; }
182 aptftparchive
() { runapt
"${APTFTPARCHIVEBINDIR}/apt-ftparchive" "$@"; }
183 aptkey
() { runapt apt
-key "$@"; }
184 aptmark
() { runapt apt
-mark "$@"; }
185 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; }
186 apt
() { runapt apt
"$@"; }
187 apthelper
() { runapt
"${APTHELPERBINDIR}/apt-helper" "$@"; }
188 aptwebserver
() { runapt
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
189 aptitude
() { runapt aptitude
"$@"; }
190 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; }
191 aptinternalsolver
() { runapt
"${APTINTERNALSOLVER}" "$@"; }
192 aptdumpsolver
() { runapt
"${APTDUMPSOLVER}" "$@"; }
193 aptinternalplanner
() { runapt
"${APTINTERNALPLANNER}" "$@"; }
196 "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@"
198 dpkgcheckbuilddeps
() {
199 command dpkg
-checkbuilddeps --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" "$@"
204 aptget
) CMD
="apt-get";;
205 aptcache
) CMD
="apt-cache";;
206 aptcdrom
) CMD
="apt-cdrom";;
207 aptconfig
) CMD
="apt-config";;
208 aptmark
) CMD
="apt-mark";;
209 apthelper
) CMD
="apt-helper";;
210 aptftparchive
) CMD
="apt-ftparchive";;
211 dpkg
) shift; runapt
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" "$@"; return;;
215 if [ "${CMD##*/}" = "$CMD" ]; then
216 CMD
="${BUILDDIRECTORY}/${CMD}"
218 runapt
command gdb
--quiet -ex "directory '$SOURCEDIRECTORY'" -ex run
"$CMD" --args "$CMD" "$@"
221 date -u -d "@$(stat -c '%Y' "${TMPWORKINGDIRECTORY}/$1")" -R
224 grep "^${2:-Date}:" "$1" | cut
-d' ' -f 2-
228 # error if we about to overflow, but ...
229 # "255 failures ought to be enough for everybody"
230 if [ $EXIT_CODE -gt 255 ]; then
231 msgdie
"Total failure count $EXIT_CODE too big"
233 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
236 shellsetedetector
() {
238 if [ "$exit_status" != '0' ]; then
239 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
240 if [ "$EXIT_CODE" = '0' ]; then
241 EXIT_CODE
="$exit_status"
247 if [ "$1" = 'prefix' ]; then
248 CURRENTTRAP
="$2 $CURRENTTRAP"
250 CURRENTTRAP
="$CURRENTTRAP $1"
252 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
256 echo "$@" | sed -e "s#'#'\"'\"'#g"
259 find_project_binary_dir
() {
260 local TESTDIRECTORY
="$(readlink -f "$(dirname $0)")"
261 if [ -z "$PROJECT_BINARY_DIR" ]; then
263 for dir in ${TESTDIRECTORY}/../../ ${TESTDIRECTORY}/../../*; do
264 test -e "$dir/CMakeCache.txt
" || continue
265 if [ -z "$PROJECT_BINARY_DIR" ] ||
266 [ "$dir/CMakeCache.txt
" -nt "$PROJECT_BINARY_DIR/CMakeCache.txt
" ]; then
267 PROJECT_BINARY_DIR="$dir"
270 if [ -z "$PROJECT_BINARY_DIR" ]; then
271 echo "Cannot
find build directory
, you might want to
set PROJECT_BINARY_DIR
" >&2
274 export PROJECT_BINARY_DIR
278 # Next check needs a gnu stat, let's figure that out early.
280 if command -v gnustat >/dev/null 2>&1; then
283 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
284 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$($stat --format '%a' "$TMPDIR")" != '1777' ]; then
287 TMPWORKINGDIRECTORY="$(mktemp -d)"
288 addtrap "cd /; rm -rf '$(escape_shell "$TMPWORKINGDIRECTORY")';"
289 if [ -n "$TMPDIR_ADD" ]; then
290 TMPWORKINGDIRECTORY="${TMPWORKINGDIRECTORY}/${TMPDIR_ADD}"
291 mkdir -p "$TMPWORKINGDIRECTORY"
293 export TMPDIR="$TMPWORKINGDIRECTORY"
295 msgninfo "Preparing environment
for ${0##*/} in ${TMPWORKINGDIRECTORY}…
"
297 # Setup coreutils on BSD systems
298 mkdir "${TMPWORKINGDIRECTORY}/bin
"
299 for prefix in gnu g; do
300 for command in stat touch sed cp tr sha1sum sha256sum md5sum sha512sum grep date wc chmod head readlink tar expr base64; do
301 if command -v $prefix$command 2>/dev/null >/dev/null; then
302 [ -e "${TMPWORKINGDIRECTORY}/bin
/$command" ] || ln -sf $(command -v $prefix$command) "${TMPWORKINGDIRECTORY}/bin
/$command"
306 export PATH="${TMPWORKINGDIRECTORY}/bin
/:$PATH"
309 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded
"
310 if [ "$(id -u)" = '0' ]; then
311 # relax permissions so that running as root with user switching works
313 chmod 711 "$TMPWORKINGDIRECTORY"
314 chown _apt:root "${TMPWORKINGDIRECTORY}/downloaded
"
317 TESTDIRECTORY="$(readlink -f "$(dirname $0)")"
318 # Find the newest build directory (sets PROJECT_BINARY_DIR)
319 find_project_binary_dir
320 # allow overriding the default BUILDDIR location
321 SOURCEDIRECTORY
="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}"
322 BUILDDIRECTORY
="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${PROJECT_BINARY_DIR}/cmdline"}"
323 LIBRARYPATH
="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}/../apt-pkg"}"
324 METHODSDIR
="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/../methods"}"
325 APTHELPERBINDIR
="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}"
326 APTWEBSERVERBINDIR
="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}/../test/interactive-helper"}"
327 APTFTPARCHIVEBINDIR
="${APT_INTEGRATION_TESTS_FTPARCHIVE_BIN_DIR:-"${BUILDDIRECTORY}/../ftparchive"}"
328 APTINTERNALSOLVER
="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/solvers/apt"}"
329 APTDUMPSOLVER
="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/solvers/dump"}"
330 APTINTERNALPLANNER
="${APT_INTEGRATION_TESTS_INTERNAL_PLANNER:-"${BUILDDIRECTORY}/planners/apt"}"
331 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
334 cd "$TMPWORKINGDIRECTORY"
335 mkdir rootdir aptarchive keys
337 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
338 mkdir -p usr
/bin var
/cache var
/lib var
/log var
/crash tmp
339 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
340 mkdir -p usr
/lib
/apt
/solvers usr
/lib
/apt
/planners
341 touch var
/lib
/dpkg
/available
342 ln -s "${METHODSDIR}" usr
/lib
/apt
/methods
343 ln -s "${APTDUMPSOLVER}" usr
/lib
/apt
/solvers
/dump
344 ln -s "${APTDUMPSOLVER}" usr
/lib
/apt
/planners
/dump
345 ln -s "${APTINTERNALSOLVER}" usr
/lib
/apt
/solvers
/apt
346 ln -s "${APTINTERNALPLANNER}" usr
/lib
/apt
/planners
/apt
347 echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" >> ..
/aptconfig.conf
348 echo "Dir::Bin::Planners \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/planners\";" >> ..
/aptconfig.conf
349 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
351 if [ -z "${APT_INTEGRATION_TESTS_SOURCE_DIR}" ]; then
352 ln -s "${SOURCEDIRECTORY}/debian/apt.conf.autoremove" etc
/apt
/apt.conf.d
/01autoremove
354 ln -s /etc
/apt
/apt.conf.d
/01autoremove etc
/apt
/apt.conf.d
/01autoremove
357 local BASENAME
="${0##*/}"
358 local PACKAGESFILE
="Packages-${BASENAME#*-}"
359 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
360 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive
/Packages
362 local SOURCESSFILE
="Sources-${BASENAME#*-}"
363 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
364 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
366 find "$TESTDIRECTORY" \
( -name '*.pub' -o -name '*.sec' \
) -exec cp '{}' keys
/ \
;
368 ln -s "${TMPWORKINGDIRECTORY}/keys/joesixpack.pub" rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
370 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
371 echo "Dir::Etc \"etc\";" >> aptconfig.conf
372 echo "Dir::State \"var/lib/apt\";" >> aptconfig.conf
373 echo "Dir::Cache \"var/cache/apt\";" >> aptconfig.conf
374 echo "Dir::Etc \"etc/apt\";" >> aptconfig.conf
375 echo "Dir::Log \"var/log/apt\";" >> aptconfig.conf
376 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
377 echo "Dir::Bin::Methods \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/methods\";" >> aptconfig.conf
378 # either store apt-key were we can access it, even if we run it as a different user
379 #cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
380 #chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
381 #echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
382 # destroys coverage reporting though, so we disable changing user for the calling gpgv
383 echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
384 if [ "$(id -u)" = '0' ]; then
385 echo 'Binary::gpgv::APT::Sandbox::User "root";' >> aptconfig.conf
386 # same for the solver executables
387 echo 'APT::Solver::RunAsUser "root";' >> aptconfig.conf
388 echo 'APT::Planner::RunAsUser "root";' >> aptconfig.conf
391 cat > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" <<EOF
394 if [ -r '${TMPWORKINGDIRECTORY}/noopchroot.so' ]; then
395 if [ -n "\$LD_LIBRARY_PATH" ]; then
396 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}:'"\${LD_LIBRARY_PATH}"
398 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}'
400 if [ -n "\$LD_PRELOAD" ]; then
401 export LD_PRELOAD="noopchroot.so \${LD_PRELOAD}"
403 export LD_PRELOAD="noopchroot.so"
407 cp "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg"
408 cat >> "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" <<EOF
409 exec fakeroot '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
410 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
411 --force-not-root --force-bad-path "\$@"
413 cat >> "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" <<EOF
414 exec fakeroot gdb --quiet -ex run '${DPKG:-dpkg}' --args '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
415 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
416 --force-not-root --force-bad-path "\$@"
418 chmod +x
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg"
419 echo "Dir::Bin::dpkg \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg\";" > rootdir
/etc
/apt
/apt.conf.d
/99dpkg
422 if ! command dpkg
--assert-multi-arch >/dev
/null
2>&1; then
423 echo "DPKG::options:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
426 echo 'quiet::NoUpdate "true";'
427 echo 'quiet::NoStatistic "true";'
428 # too distracting for users, but helpful to detect changes
429 echo 'Acquire::Progress::Ignore::ShowErrorText "true";'
430 echo 'Acquire::Progress::Diffpercent "true";'
431 # in testcases, it can appear as if localhost has a rotation setup,
432 # hide this as we can't really deal with it properly
433 echo 'Acquire::Failure::ShowIP "false";'
434 # fakeroot can't fake everything, so disabled in production but good for tests
435 echo 'APT::Sandbox::Verify "true";'
438 cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
439 if [ "$(id -u)" = '0' ]; then
440 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
442 echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
443 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary
444 export APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE
=no
445 echo 'Acquire::Connect::AddrConfig "false";' > rootdir
/etc
/apt
/apt.conf.d
/connect
-addrconfig
447 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
448 confighashes
'SHA256' # these are tests, not security best-practices
450 # create some files in /tmp and look at user/group to get what this means
451 TEST_DEFAULT_USER
="$(id -un)"
452 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
453 TEST_DEFAULT_GROUP
='root'
455 TEST_DEFAULT_GROUP
="$(id -gn)"
458 # cleanup the environment a bit
459 # prefer our apt binaries over the system apt binaries
460 export PATH
="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
462 unset LANGUAGE APT_CONFIG
463 unset GREP_OPTIONS DEB_BUILD_PROFILES
464 unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy
466 # If gpgv supports --weak-digest, pass it to make sure we can disable SHA1
467 if aptkey verify
--weak-digest SHA1
--help 2>/dev
/null
>/dev
/null
; then
468 echo 'Acquire::gpgv::Options { "--weak-digest"; "sha1"; };' > rootdir
/etc
/apt
/apt.conf.d
/no
-sha1
471 # most tests just need one signed Release file, not both
472 export APT_DONT_SIGN
='Release.gpg'
474 if [ -r "${TESTDIRECTORY}/extra-environment" ]; then
475 .
"${TESTDIRECTORY}/extra-environment"
482 if [ "$1" = "native" -o -z "$1" ]; then
483 eval `aptconfig shell ARCH APT::Architecture`
484 if [ -n "$ARCH" ]; then
487 dpkg
--print-architecture
495 aptconfig dump
--no-empty --format '%v%n' APT
::Architecture APT
::Architectures
| sort -u | tr '\n' ' '
498 getarchitecturesfromcommalist
() {
499 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
502 configarchitecture
() {
504 echo "APT::Architecture \"$(getarchitecture $1)\";"
505 while [ -n "$1" ]; do
506 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
509 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
514 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
515 local BASENAME
="${0##*/}"
516 local STATUSFILE
="status-${BASENAME#*-}"
517 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
518 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir
/var
/lib
/dpkg
/status
520 echo -n > rootdir
/var
/lib
/dpkg
/status
523 rm -f rootdir
/etc
/apt
/apt.conf.d
/00foreigndpkg
524 if command dpkg
--assert-multi-arch >/dev
/null
2>&1 ; then
525 local ARCHS
="$(getarchitectures)"
526 local DPKGARCH
="$(dpkg --print-architecture)"
527 # this ensures that even if multi-arch isn't active in the view
528 # of apt, given that dpkg can't be told which arch is native
529 # the arch apt treats as native might be foreign for dpkg
530 for ARCH
in ${ARCHS}; do
531 if [ "${ARCH}" != "${DPKGARCH}" ]; then
532 if ! dpkg
--add-architecture ${ARCH} >/dev
/null
2>&1; then
533 # old-style used e.g. in Ubuntu-P – and as it seems travis
534 echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir
/etc
/apt
/apt.conf.d
/00foreigndpkg
535 echo "DPKG::options:: \"${ARCH}\";" >> rootdir
/etc
/apt
/apt.conf.d
/00foreigndpkg
539 # if multi-arch make sure dpkg can detect itself as capable of it
540 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
541 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
542 # dpkg doesn't really check the version as long as it is fully installed,
543 # but just to be sure we choose one above the required version
544 insertinstalledpackage
'dpkg' "all" '1.16.2+fake'
550 configdpkgnoopchroot
() {
551 # create a library to noop chroot() and rewrite maintainer script executions
552 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
553 # chroot directory dpkg could chroot into to execute the maintainer scripts
554 msgtest
'Building library to preload to make maintainerscript work in' 'dpkg'
555 cat > noopchroot.c
<< EOF
562 static char * chrootdir = NULL;
564 int chroot(const char *path) {
565 printf("WARNING: CHROOTing to %s was ignored!\n", path);
567 chrootdir = strdup(path);
570 int execvp(const char *file, char *const argv[]) {
571 static int (*func_execvp) (const char *, char * const []) = NULL;
572 if (func_execvp == NULL)
573 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp");
574 if (chrootdir == NULL || strncmp(file, "/var/lib/dpkg/", strlen("/var/lib/dpkg/")) != 0)
575 return func_execvp(file, argv);
576 printf("REWRITE execvp call %s into %s\n", file, chrootdir);
578 if (asprintf(&newfile, "%s%s", chrootdir, file) == -1) {
582 char const * const baseadmindir = "/var/lib/dpkg";
584 if (asprintf(&admindir, "%s%s", chrootdir, baseadmindir) == -1) {
588 setenv("DPKG_ADMINDIR", admindir, 1);
589 return func_execvp(newfile, argv);
592 if cc
-ldl 2>&1 | grep -q dl
; then
593 testempty
--nomsg cc
-Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c
595 testempty
--nomsg cc
-Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c
-ldl
598 configcompression
() {
599 if [ "$1" = 'ALL' ]; then
600 configcompression
'.' $(aptconfig dump APT::Compressor --format '%t %v%n' | sed -n 's#^Extension \.\(.*\)$#\
1#p')
603 local CMD
='apthelper cat-file -C'
604 while [ -n "$1" ]; do
606 '.') printf ".\t.\tcat\n";;
607 'gz') printf "gzip\tgz\t$CMD $1\n";;
608 'bz2') printf "bzip2\tbz2\t$CMD $1\n";;
609 *) printf "$1\t$1\t$CMD $1\n";;
612 done > "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf"
616 echo 'APT::FTPArchive {'
618 while [ -n "$1" ]; do
619 printf "$1" | tr 'a-z' 'A-Z'
620 printf "\t\"true\";\n"
623 for h
in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
624 printf "$h\t\"false\";\n"
628 } >> "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/ftparchive-hashes.conf"
633 COMPRESSOR_CMD
="apthelper cat-file -C $1"
635 gzip) COMPRESS
='gz';;
636 bzip2) COMPRESS
='bz2';;
638 local CONFFILE
="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
639 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
640 Dir::Bin::uncompressed \"/does/not/exist\";" > "$CONFFILE"
641 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
642 if [ -z "$COMP" -o "$COMP" = '.' -o "$COMP" = "$COMPRESSOR" ]; then continue; fi
643 echo "Dir::Bin::${COMP} \"/does/not/exist\";" >> "$CONFFILE"
644 echo "APT::Compressor::${COMP}::Name \"${COMP}-disabled\";" >> "$CONFFILE"
648 _setupsimplenativepackage
() {
652 local RELEASE
="${4:-unstable}"
653 local DEPENDENCIES
="$5"
654 local DESCRIPTION
="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
655 If you find such a package installed on your system,
656 something went horribly wrong! They are autogenerated
657 und used only by testcases and serve no other purpose…"}"
659 local SECTION="${7:-others}"
660 local PRIORITY="${8:-optional}"
662 local COMPRESS_TYPE="${10:-gzip}"
664 if [ "$SECTION" = "${SECTION#*/}" ]; then
667 DISTSECTION="${SECTION%/*}"
669 local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming
/${NAME}-${VERSION}"
671 mkdir -p "$BUILDDIR/debian
/source"
672 echo "* most suckless software product ever
" > "${BUILDDIR}/FEATURES
"
674 echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}"
676 echo "Copyleft by Joe Sixpack
$(date -u +%Y)" > "${BUILDDIR}/debian
/copyright
"
677 echo "$NAME ($VERSION) $RELEASE; urgency
=low
681 -- Joe Sixpack
<joe@example.org
> $(date -u -R)" > "${BUILDDIR}/debian
/changelog
"
685 Maintainer
: Joe Sixpack
<joe@example.org
>
686 Standards
-Version: 3.9.3"
687 if [ "$SECTION" != '<none>' ]; then
688 echo "Section
: $SECTION"
690 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
691 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
695 if [ "$ARCH" = 'all' ]; then
696 echo "Architecture
: all
"
698 echo "Architecture
: any
"
700 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
701 test -z "$DEPS" || echo "$DEPS"
702 echo "Description
: $DESCRIPTION"
703 } > "${BUILDDIR}/debian
/control
"
705 echo '3.0 (native)' > "${BUILDDIR}/debian
/source
/format
"
710 if command -v gmake >/dev/null 2>&1; then
711 [ -e ${TMPWORKINGDIRECTORY}/bin/make ] || ln -s $(command -v gmake) ${TMPWORKINGDIRECTORY}/bin/make
712 echo "#!${TMPWORKINGDIRECTORY}/bin/make -f" > "$OUT"
714 echo '#!/usr/bin/make -f' > "$OUT"
717 echo ' dh $@' >> "$OUT"
720 setupsimplenativepackage
() {
721 _setupsimplenativepackage
"$@"
724 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
725 test -e "${BUILDDIR}/debian/compat" || echo '7' > "${BUILDDIR}/debian/compat"
726 test -e "${BUILDDIR}/debian/rules" || make_tiny_rules
"${BUILDDIR}/debian/rules"
729 buildsimplenativepackage
() {
733 local RELEASE
="${4:-unstable}"
734 local DEPENDENCIES
="$5"
735 local DESCRIPTION
="$6"
736 local SECTION
="${7:-others}"
737 local PRIORITY
="${8:-optional}"
739 local COMPRESS_TYPE
="${10:-gzip}"
741 if [ "$SECTION" = "${SECTION#*/}" ]; then
744 DISTSECTION
="${SECTION%/*}"
746 local BUILDDIR
="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
747 msgtest
"Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
748 _setupsimplenativepackage
"$@"
750 testsuccess
--nomsg dpkg
-source -b ${NAME}-${VERSION}
752 sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" \
754 echo "pool/${SRC}" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist"
755 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
756 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
757 # adv --yes --default-key 'Joe Sixpack' \
758 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
759 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
763 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
764 msgtest
"Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
765 rm -rf "${BUILDDIR}/debian/tmp"
766 mkdir -p "${BUILDDIR}/debian/tmp/DEBIAN" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin"
767 cp "${BUILDDIR}/debian/copyright" "${BUILDDIR}/debian/changelog" "${BUILDDIR}/FEATURES" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}"
768 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}"
769 if [ -n "$FILE_TREE" ]; then
770 cp -ar "$FILE_TREE" "${BUILDDIR}/debian/tmp"
773 (cd "${BUILDDIR}"; dpkg
-gencontrol -DArchitecture=$arch)
774 (cd "${BUILDDIR}/debian/tmp"; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
775 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
776 # ensure the right permissions as dpkg-deb insists
777 chmod 755 "${BUILDDIR}/debian/tmp/DEBIAN"
778 testsuccess
--nomsg dpkg
-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian/tmp" "${BUILDDIR}/.."
779 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist"
783 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then
784 NM
="$(echo "$NAME" | cut -c 1-4)"
786 NM
="$(echo "$NAME" | cut -c 1)"
788 local CHANGEPATH
="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}"
789 mkdir -p "$CHANGEPATH"
790 cp "${BUILDDIR}/debian/changelog" "$CHANGEPATH"
799 local ARCH
=$(getarchitecture $4)
800 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
801 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
802 msgtest
"Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
804 if [ "$ARCH" = "all" ]; then
805 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
807 testsuccess
--nomsg dpkg
-buildpackage -uc -us -a$ARCH
808 cp "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$BUILDLOG"
809 local PKGS
="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
810 local SRCS
="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
813 echo "pool/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist"
816 echo "pool/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist"
821 if [ -d incoming
]; then
822 buildaptarchivefromincoming
"$@"
824 buildaptarchivefromfiles
"$@"
828 createaptftparchiveconfig
() {
829 local COMPRESSORS
="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
830 local COMPRESSORS
="${COMPRESSORS%* }"
831 local ARCHS
="$(getarchitectures)"
832 cat > ftparchive.conf
<<EOF
834 ArchiveDir "$(readlink -f .)";
835 CacheDir "$(readlink -f ..)";
836 FileListDir "$(readlink -f pool/)";
839 Packages::Compress "$COMPRESSORS";
840 Sources::Compress "$COMPRESSORS";
841 Contents::Compress "$COMPRESSORS";
842 Translation::Compress "$COMPRESSORS";
843 LongDescription "false";
847 SrcDirectory "pool/";
850 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
853 Architectures "$ARCHS all source";
854 FileList "${DIST}.\$(SECTION).pkglist";
855 SourceFileList "${DIST}.\$(SECTION).srclist";
856 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
859 done >> ftparchive.conf
862 buildaptftparchivedirectorystructure
() {
863 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
864 for DIST
in $DISTS; do
865 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
866 for SECTION
in $SECTIONS; do
867 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
868 for ARCH
in $ARCHS; do
869 mkdir -p "dists/${DIST}/${SECTION}/binary-${ARCH}"
871 mkdir -p "dists/${DIST}/${SECTION}/source"
872 mkdir -p "dists/${DIST}/${SECTION}/i18n"
882 local DEPENDENCIES
="$5"
883 local PRIORITY
="${6:-optional}"
884 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
885 If you find such a package installed on your system,
886 something went horribly wrong! They are autogenerated
887 und used only by testcases and serve no other purpose…"}"
889 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
890 if [ "$RELEASE" = 'installed' ]; then
891 insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
894 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
895 if [ "$arch" = 'none' ]; then
896 ARCHS="$(getarchitectures)"
900 for BUILDARCH in $ARCHS; do
901 local PPATH="aptarchive
/dists
/${RELEASE}/main
/binary
-${BUILDARCH}"
908 Maintainer
: Joe Sixpack
<joe@example.org
>"
909 test "$arch" = 'none' || echo "Architecture
: $arch"
910 echo "Version
: $VERSION
911 Filename
: pool
/main
/${NAME}/${NAME}_
${VERSION}_
${arch}.deb
"
912 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES"
913 echo "Description
: $(printf '%s' "$DESCRIPTION" | head -n 1)"
914 echo "Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
916 } >> "${PPATH}/Packages
"
919 mkdir -p "aptarchive
/dists
/${RELEASE}/main
/source" "aptarchive
/dists
/${RELEASE}/main
/i18n
"
920 touch "aptarchive
/dists
/${RELEASE}/main
/source
/Sources
"
922 Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
923 Description
-en: $DESCRIPTION
924 " >> "aptarchive
/dists
/${RELEASE}/main
/i
18n
/Translation
-en"
933 local DEPENDENCIES="$5"
934 local BINARY="${6:-$NAME}"
936 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
937 local SPATH="aptarchive
/dists
/${RELEASE}/main
/source"
939 local FILE="${SPATH}/Sources
"
940 local DSCFILE="${NAME}_
${VERSION}.dsc
"
941 local TARFILE="${NAME}_
${VERSION}.
tar.gz
"
945 Maintainer
: Joe Sixpack
<joe@example.org
>
946 Architecture
: $ARCH" >> $FILE
947 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
949 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
950 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
952 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
953 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
958 insertinstalledpackage() {
962 local DEPENDENCIES="$4"
963 local PRIORITY="${5:-optional}"
964 local STATUS="${6:-install ok installed}"
965 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
966 If you
find such a package installed on your system
,
967 something went horribly wrong
! They are autogenerated
968 und used only by testcases and serve no other purpose…
"}"
970 local FILE
='rootdir/var/lib/dpkg/status'
971 local INFO
='rootdir/var/lib/dpkg/info'
972 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
978 Maintainer: Joe Sixpack <joe@example.org>
979 Version: $VERSION" >> "$FILE"
980 test "$arch" = 'none' || echo "Architecture: $arch" >> "$FILE"
981 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
982 echo "Description: $DESCRIPTION" >> "$FILE"
984 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
985 echo -n > "${INFO}/${NAME}:${arch}.list"
987 echo -n > "${INFO}/${NAME}.list"
993 buildaptarchivefromincoming
() {
994 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on incoming packages…"
996 [ -e pool
] || ln -s ..
/incoming pool
997 [ -e ftparchive.conf
] || createaptftparchiveconfig
998 [ -e dists
] || buildaptftparchivedirectorystructure
999 msgninfo
"\tGenerate Packages, Sources and Contents files… "
1000 testsuccess aptftparchive generate ftparchive.conf
1003 generatereleasefiles
"$@"
1006 buildaptarchivefromfiles
() {
1007 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on prebuild files…"
1008 local DIR
='aptarchive'
1009 if [ -d "${DIR}/dists" ]; then DIR
="${DIR}/dists"; fi
1010 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
1011 msgninfo
"\t${line} file… "
1012 compressfile
"$line" "$1"
1015 generatereleasefiles
"$@"
1019 while read compressor extension
command; do
1020 if [ "$compressor" = '.' ]; then
1021 if [ -n "$2" ]; then
1026 cat "$1" | $command > "${1}.${extension}"
1027 if [ -n "$2" ]; then
1028 touch -d "$2" "${1}.${extension}"
1030 done < "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf"
1033 # can be overridden by testcases for their pleasure
1034 getcodenamefromsuite
() {
1036 unstable
) echo 'sid';;
1040 getreleaseversionfromsuite
() { true
; }
1041 getlabelfromsuite
() { true
; }
1042 getoriginfromsuite
() { true
; }
1043 getarchitecturesfromreleasefile
() { echo "all $(getarchitectures)"; }
1045 aptftparchiverelease
() {
1046 aptftparchive
-qq release
"$@" | sed -e '/0 Release$/ d' # remove the self reference
1048 generatereleasefiles
() {
1049 # $1 is the Date header and $2 is the ValidUntil header to be set
1050 # both should be given in notation date/touch can understand
1052 local VALIDUNTIL
="$2"
1053 if [ -e aptarchive
/dists
]; then
1054 msgninfo
"\tGenerate Release files for dists… "
1055 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
1056 local ARCHITECTURES
="$(getarchitecturesfromreleasefile "$dir")"
1057 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
1058 local CODENAME
="$(getcodenamefromsuite $SUITE)"
1059 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
1060 local LABEL
="$(getlabelfromsuite $SUITE)"
1061 local ORIGIN
="$(getoriginfromsuite $SUITE)"
1062 aptftparchiverelease
"$dir" \
1063 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
1064 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
1065 -o APT
::FTPArchive
::Release
::Architectures
="${ARCHITECTURES}" \
1066 -o APT
::FTPArchive
::Release
::Label
="${LABEL}" \
1067 -o APT
::FTPArchive
::Release
::Origin
="${ORIGIN}" \
1068 -o APT
::FTPArchive
::Release
::Version
="${VERSION}" \
1070 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
1071 sed -i '/^Date: / a\
1072 NotAutomatic: yes' "$dir/Release"
1076 msgninfo
"\tGenerate Release files for flat… "
1077 aptftparchiverelease .
/aptarchive
> aptarchive
/Release
1079 if [ -n "$DATE" -a "$DATE" != "now" ]; then
1080 for release
in $(find ./aptarchive -name 'Release'); do
1081 sed -i "s/^Date: .*$/Date: $(date -u -d "$DATE" -R)/" "$release"
1082 touch -d "$DATE" "$release"
1085 if [ -n "$VALIDUNTIL" ]; then
1086 sed -i "/^Date: / a\
1087 Valid-Until: $(date -u -d "$VALIDUNTIL" -R)" $(find ./aptarchive -name 'Release')
1092 setupdistsaptarchive
() {
1093 local APTARCHIVE
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1094 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
1095 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
1096 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1097 SECTIONS
=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1098 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
1099 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list"
1100 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list"
1105 setupflataptarchive
() {
1106 local APTARCHIVE
="$(readlink -f ./aptarchive)"
1107 local APTARCHIVEURI
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1108 if [ -f "${APTARCHIVE}/Packages" ]; then
1109 msgninfo
"\tadd deb sources.list line… "
1110 echo "deb file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1113 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1115 if [ -f "${APTARCHIVE}/Sources" ]; then
1116 msgninfo
"\tadd deb-src sources.list line… "
1117 echo "deb-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1120 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1126 if [ "$1" = '--no-update' ]; then
1130 buildaptarchive
"$@"
1131 if [ -e aptarchive
/dists
]; then
1132 setupdistsaptarchive
1136 signreleasefiles
'Joe Sixpack'
1137 if [ "1" != "$NOUPDATE" ]; then
1138 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
1142 signreleasefiles
() {
1143 local SIGNERS
="${1:-Joe Sixpack}"
1144 local REPODIR
="${2:-aptarchive}"
1145 if [ -n "$1" ]; then shift; fi
1146 if [ -n "$1" ]; then shift; fi
1147 local KEY
="keys/$(echo "$SIGNERS" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1148 msgninfo
"\tSign archive with $SIGNERS key $KEY… "
1149 local REXKEY
='keys/rexexpired'
1150 local SECEXPIREBAK
="${REXKEY}.sec.bak"
1151 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
1153 while [ -n "${SIGNERS%%,*}" ]; do
1154 local SIGNER
="${SIGNERS%%,*}"
1155 if [ "${SIGNERS}" = "${SIGNER}" ]; then
1158 SIGNERS
="${SIGNERS#*,}"
1159 # FIXME: This should be the full name, but we can't encode the space properly currently
1160 SIGUSERS
="${SIGUSERS} -u ${SIGNER#* }"
1161 if [ "${SIGNER}" = 'Rex Expired' ]; then
1162 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1163 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1164 # therefore we 'temporary' make the key not expired and restore a backup after signing
1165 cp "${REXKEY}.sec" "$SECEXPIREBAK"
1166 cp "${REXKEY}.pub" "$PUBEXPIREBAK"
1167 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
1168 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
1169 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1170 cp "$SECUNEXPIRED" "${REXKEY}.sec"
1171 cp "$PUBUNEXPIRED" "${REXKEY}.pub"
1173 if ! printf "expire\n1w\nsave\n" | aptkey
--quiet --keyring "${REXKEY}.pub" --secret-keyring "${REXKEY}.sec" \
1174 --readonly adv
--batch --yes --digest-algo "${APT_TESTS_DIGEST_ALGO:-SHA512}" \
1175 --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
1179 cp "${REXKEY}.sec" "$SECUNEXPIRED"
1180 cp "${REXKEY}.pub" "$PUBUNEXPIRED"
1183 if [ ! -e "${KEY}.pub" ]; then
1184 local K
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1185 cat "${K}.pub" >> "${KEY}.new.pub"
1186 cat "${K}.sec" >> "${KEY}.new.sec"
1189 if [ ! -e "${KEY}.pub" ]; then
1190 mv "${KEY}.new.pub" "${KEY}.pub"
1191 mv "${KEY}.new.sec" "${KEY}.sec"
1193 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes --digest-algo ${APT_TESTS_DIGEST_ALGO:-SHA512}"
1194 for RELEASE
in $(find "${REPODIR}/" -name Release); do
1195 # we might have set a specific date for the Release file, so copy it
1196 local DATE
="$(stat --format "%y" "${RELEASE}")"
1197 if [ "$APT_DONT_SIGN" = 'Release.gpg' ]; then
1198 rm -f "${RELEASE}.gpg"
1200 testsuccess
$GPG "$@" $SIGUSERS --armor --detach-sign --sign --output "${RELEASE}.gpg" "${RELEASE}"
1201 touch -d "$DATE" "${RELEASE}.gpg"
1203 local INRELEASE
="${RELEASE%/*}/InRelease"
1204 if [ "$APT_DONT_SIGN" = 'InRelease' ]; then
1207 testsuccess
$GPG "$@" $SIGUSERS --clearsign --output "$INRELEASE" "$RELEASE"
1208 touch -d "$DATE" "${INRELEASE}"
1211 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1212 mv -f "$SECEXPIREBAK" "${REXKEY}.sec"
1213 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub"
1218 redatereleasefiles
() {
1219 local DATE
="$(date -u -d "$1" -R)"
1220 for release
in $(find aptarchive/ -name 'Release'); do
1221 sed -i "s/^Date: .*$/Date: ${DATE}/" "$release"
1222 touch -d "$DATE" "$release"
1224 signreleasefiles
"${2:-Joe Sixpack}"
1228 local WEBSERVER
="${3:-http://localhost:${APTHTTPPORT}}"
1230 if [ "$1" = '--no-check' ]; then
1234 local DOWNLOG
='rootdir/tmp/download-testfile.log'
1235 local STATUS
='downloaded/webserverconfig.status'
1236 rm -f "$STATUS" "$DOWNLOG"
1237 # very very basic URI encoding
1239 if [ -n "$2" ]; then
1240 msgtest
"Set webserver config option '${1}' to" "$2"
1241 URI
="${WEBSERVER}/_config/set/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1243 msgtest
'Clear webserver config option' "${1}"
1244 URI
="${WEBSERVER}/_config/clear/$(echo "${1}" | sed -e 's/\//%2f/g')"
1246 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
1249 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.output"
1250 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1251 msgfailoutput
'' "$OUTPUT"
1253 $NOCHECK || testwebserverlaststatuscode
'200'
1256 rewritesourceslist
() {
1257 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1258 local APTARCHIVE2
="copy://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1259 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1260 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
1261 -e "s#http://[^@]*@\?localhost:${APTHTTPPORT}/\?#${1}#" \
1262 -e "s#https://[^@]*@\?localhost:${APTHTTPSPORT}/\?#${1}#"
1266 # wait for up to 10s for a pid file to appear to avoid possible race
1267 # when a helper is started and dosn't write the PID quick enough
1270 for i
in $(seq 10); do
1271 if test -s "$PIDFILE"; then
1276 msgdie
"waiting for $PIDFILE failed"
1280 changetowebserver
() {
1282 if [ "$1" != '--no-rewrite' ]; then
1287 if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
1289 local LOG
="webserver.log"
1290 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1294 waitforpidfile aptwebserver.pid
1295 local PID
="$(cat aptwebserver.pid)"
1296 if [ -z "$PID" ]; then
1297 msgdie
'Could not fork aptwebserver successfully'
1299 addtrap
"kill $PID;"
1300 waitforpidfile aptwebserver.port
1301 APTHTTPPORT
="$(cat aptwebserver.port)"
1302 if [ -z "$APTHTTPPORT" ]; then
1303 msgdie
'Could not get port for aptwebserver successfully'
1307 msgdie
'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver'
1309 if [ "$REWRTE" != 'yes' ]; then
1310 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1314 changetohttpswebserver
() {
1316 if command -v stunnel4
>/dev
/null
2>&1; then
1318 elif command -v stunnel
>/dev
/null
2>&1; then
1321 msgdie
'You need to install stunnel4 for https testcases'
1323 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1324 changetowebserver
--no-rewrite "$@"
1326 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1327 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1332 connect = $APTHTTPPORT
1333 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1334 $stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
1335 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1336 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1337 if [ -z "$PID" ]; then
1338 msgdie
'Could not fork $stunnel4 successfully'
1340 addtrap
'prefix' "kill ${PID};"
1341 APTHTTPSPORT
="$(lsof -i -n | awk "/^$stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1342 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1343 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1347 mkdir -p rootdir
/media
/cdrom
/.disk
1348 local CD
="$(readlink -f rootdir/media/cdrom)"
1349 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1350 acquire::cdrom::mount "${CD}";
1351 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1352 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1353 acquire::cdrom::autodetect 0;
1355 echo -n "$1" > "${CD}/.disk/info"
1356 if [ ! -d aptarchive
/dists
]; then
1357 msgdie
'Flat file archive cdroms can not be created currently'
1360 mv aptarchive
/dists
"$CD"
1361 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1362 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1363 # start with an unmounted disk
1364 mv "${CD}" "${CD}-unmounted"
1365 # we don't want the disk to be modifiable
1366 addtrap
'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;"
1367 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1371 local PROTO
="${1%%:*}"
1372 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1373 download
-file "$1" "$2" "$3" 2>&1 ; then
1376 # only if the file exists the download was successful
1377 if [ -r "$2" ]; then
1385 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1386 if [ -n "$DIFFTEXT" ]; then
1388 echo >&2 "$DIFFTEXT"
1396 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1397 local COMPAREFILE
="$1"
1399 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1402 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1403 cat "$COMPAREFILE" >>"${OUTPUT}"
1404 msgfailoutput
'' "$OUTPUT" "$@"
1409 msggroup
'testfileequal'
1410 local MSG
='Test for correctness of file'
1411 if [ "$1" = '--nomsg' ]; then
1417 if [ -n "$MSG" ]; then
1418 msgtest
"$MSG" "$FILE"
1420 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1421 if [ -z "$*" ]; then
1422 testoutputequal
"$FILE" echo -n ''
1424 testoutputequal
"$FILE" echo "$*"
1430 msggroup
'testempty'
1431 if [ "$1" = '--nomsg' ]; then
1434 msgtest
"Test for no output of" "$*"
1436 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1437 if "$@" >"$COMPAREFILE" 2>&1 && test ! -s "$COMPAREFILE"; then
1440 msgfailoutput
'' "$COMPAREFILE" "$@"
1442 aptautotest
'testempty' "$@"
1446 msggroup
'testnotempty'
1447 msgtest
"Test for some output of" "$*"
1448 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
1449 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then
1452 msgfailoutput
'' "$COMPAREFILE" "$@"
1454 aptautotest
'testnotempty' "$@"
1459 msggroup
'testequal'
1460 local MSG
='Test of equality of'
1461 if [ "$1" = '--nomsg' ]; then
1466 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1467 echo "$1" > "$COMPAREFILE"
1470 if [ -n "$MSG" ]; then
1473 testoutputequal
"$COMPAREFILE" "$@"
1474 aptautotest
'testequal' "$@"
1479 msggroup
'testequalor2'
1480 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1481 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1482 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1483 echo "$1" > "$COMPAREFILE1"
1484 echo "$2" > "$COMPAREFILE2"
1486 msgtest
"Test for equality OR of" "$*"
1487 "$@" >"$COMPAREAGAINST" 2>&1 || true
1488 if checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null
2>&1 || \
1489 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null
2>&1
1493 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1494 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1495 checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1496 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1497 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1498 msgfailoutput
'' "$OUTPUT"
1500 aptautotest
'testequalor2' "$@"
1505 msggroup
'testshowvirtual'
1506 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1509 while [ -n "$1" ]; do
1511 N: Can't select versions from package '$1' as it is purely virtual"
1512 PACKAGE
="${PACKAGE} $1"
1515 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1517 N: No packages found"
1518 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1519 local ARCH
="$(getarchitecture 'native')"
1520 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1521 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1522 testoutputequal
"$COMPAREFILE" aptcache show
"$PACKAGE"
1527 msggroup
'testnopackage'
1528 msgtest
"Test for non-existent packages" "apt-cache show $*"
1529 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1530 if [ -n "$SHOWPKG" ]; then
1531 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1532 echo "$SHOWPKG" >"$OUTPUT"
1533 msgfailoutput
'' "$OUTPUT"
1539 testnosrcpackage
() {
1540 msggroup
'testnosrcpackage'
1541 msgtest
"Test for non-existent source packages" "apt-cache showsrc $*"
1542 local SHOWPKG
="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')"
1543 if [ -n "$SHOWPKG" ]; then
1544 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output"
1545 echo "$SHOWPKG" >"$OUTPUT"
1546 msgfailoutput
'' "$OUTPUT"
1554 msggroup
'testdpkgstatus'
1558 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1559 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1560 if [ "$PKGS" != $NR ]; then
1561 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1562 echo "$PKGS" >"$OUTPUT"
1563 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1564 msgfailoutput
'' "$OUTPUT"
1571 testdpkginstalled
() {
1572 msggroup
'testdpkginstalled'
1573 testdpkgstatus
'ii' "$#" "$@"
1577 testdpkgnotinstalled
() {
1578 msggroup
'testdpkgnotinstalled'
1579 testdpkgstatus
'ii' '0' "$@"
1584 msggroup
'testmarkedauto'
1585 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1586 if [ -n "$1" ]; then
1587 msgtest
'Test for correctly marked as auto-installed' "$*"
1588 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1590 msgtest
'Test for correctly marked as auto-installed' 'no package'
1591 echo -n > "$COMPAREFILE"
1593 testoutputequal
"$COMPAREFILE" aptmark showauto
1596 testmarkedmanual
() {
1597 msggroup
'testmarkedmanual'
1598 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1599 if [ -n "$1" ]; then
1600 msgtest
'Test for correctly marked as manually installed' "$*"
1601 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1603 msgtest
'Test for correctly marked as manually installed' 'no package'
1604 echo -n > "$COMPAREFILE"
1606 testoutputequal
"$COMPAREFILE" aptmark showmanual
1611 if [ "${1##*.}" = 'deb' ]; then
1612 stat
>&2 "$1" || true
1613 file >&2 "$1" || true
1615 cat >&2 "$1" || true
1619 msgreportheader
'msgfailoutput'
1624 if [ "$1" = 'grep' -o "$1" = 'tail' -o "$1" = 'head' ]; then
1626 while [ -n "$2" ]; do shift; done
1627 echo "#### Complete file: $1 ####"
1629 echo "#### $CMD output ####"
1630 elif [ "$1" = 'test' ]; then
1632 # doesn't support ! or non-file flags
1633 msgfailoutputstatfile
() {
1634 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1635 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1636 echo "#### stat(2) of file: $2 ####"
1638 if test -d "$2"; then
1639 echo "#### The directory contains: $2 ####"
1641 elif test -e "$2"; then
1642 echo "#### Complete file: $2 ####"
1647 msgfailoutputstatfile
"$2" "$3"
1648 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1650 msgfailoutputstatfile
"$2" "$3"
1652 echo '#### test output ####'
1653 elif [ "$1" = 'cmp' ]; then
1655 while [ -n "$2" ]; do
1656 echo "#### Complete file: $2 ####"
1660 echo '#### cmp output ####'
1666 testsuccesswithglobalerror
() {
1671 if [ "$1" = '--nomsg' ]; then
1674 msgtest
'Test for successful execution of' "$*"
1676 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output"
1677 if "$@" >"${OUTPUT}" 2>&1; then
1678 if expr match
"$1" '^apt.*' >/dev
/null
; then
1679 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1680 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1681 elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1682 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1683 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1684 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1687 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1690 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1692 elif [ "$TYPE" = 'testsuccesswithnotice' ]; then
1693 if grep -q -E "^N: " "$OUTPUT"; then
1696 msgfailoutput
'successful run, but output had no notices' "$OUTPUT" "$@"
1706 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1708 aptautotest
"$TYPE" "$@"
1711 testsuccesswithnotice
() {
1712 testsuccesswithglobalerror
'testsuccesswithnotice' 'WE' "$@"
1715 testsuccesswithglobalerror
'testsuccess' 'NWE' "$@"
1718 msggroup
'testwarning'
1719 if [ "$1" = '--nomsg' ]; then
1722 msgtest
'Test for successful execution with warnings of' "$*"
1724 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1725 if "$@" >"${OUTPUT}" 2>&1; then
1726 if expr match
"$1" '^apt.*' >/dev
/null
; then
1727 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1728 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1729 elif grep -q -E '^E: ' "$OUTPUT"; then
1730 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1731 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1732 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1741 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1743 aptautotest
'testwarning' "$@"
1747 msggroup
'testfailure'
1748 if [ "$1" = '--nomsg' ]; then
1751 msgtest
'Test for failure in execution of' "$*"
1753 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1754 if "$@" >"${OUTPUT}" 2>&1; then
1756 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1759 if expr match
"$1" '^apt.*' >/dev
/null
; then
1760 if [ "$1" = 'aptkey' ]; then
1761 if grep -q " Can't check signature:
1763 signature could not be verified" "$OUTPUT"; then
1766 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1769 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1770 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1771 elif grep -q -E '==ERROR' "$OUTPUT"; then
1772 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1773 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1774 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1783 aptautotest
'testfailure' "$@"
1787 testreturnstateequal
() {
1789 if [ "$STATE" = 'testsuccesswithglobalerror' ]; then
1793 msggroup
"${STATE}equal"
1794 if [ "$1" != '--nomsg' ]; then
1797 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1798 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1802 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1803 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1806 msggroup
"${STATE}equal"
1807 if [ "$2" != '--nomsg' ]; then
1811 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1815 "$STATE" --nomsg "$@"
1816 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1821 testsuccessequal
() {
1822 # we compare output, so we know perfectly well about N:
1823 testreturnstateequal
'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@"
1825 testwarningequal
() {
1826 testreturnstateequal
'testwarning' "$@"
1828 testfailureequal
() {
1829 testreturnstateequal
'testfailure' "$@"
1833 msggroup
'testfailuremsg'
1837 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1838 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1839 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1840 testoutputequal
"$COMPAREFILE" echo "$CMP"
1844 msggroup
'testwarningmsg'
1848 msgtest
'Check that the output of the previous warned command has expected' 'warnings'
1849 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
1850 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
1851 testoutputequal
"$COMPAREFILE" echo "$CMP"
1856 msggroup
'testfilestats'
1857 msgtest
"Test that file $1 has $2 $3" "$4"
1858 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1861 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1864 echo -n "stat(1) reports for $2: "
1865 stat
--format "$2" "$1" || true
1867 msgfailoutput
'' "$OUTPUT"
1871 testaccessrights
() {
1872 msggroup
'testaccessrights'
1873 testfilestats
"$1" '%a' '=' "$2"
1877 testwebserverlaststatuscode
() {
1878 msggroup
'testwebserverlaststatuscode'
1879 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1880 local STATUS
='downloaded/webserverstatus-statusfile.log'
1881 rm -f "$DOWNLOG" "$STATUS"
1882 msgtest
'Test last status code from the webserver was' "$1"
1883 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1886 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1888 if [ -n "$2" ]; then
1890 echo >&2 '#### Additionally provided output files contain:'
1893 echo >&2 '#### Download log of the status code:'
1896 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1901 mapkeynametokeyid
() {
1902 while [ -n "$1" ]; do
1904 *Joe
*|*Sixpack
*|newarchive
) echo '5A90D141DBAC8DAE';;
1905 *Rex
*|*Expired
*) echo '4BC0A39C27CE74F9';;
1906 *Marvin
*|*Paranoid
*) echo 'E8525D47528144E2';;
1907 oldarchive
) echo 'FDD2DB85F68C85A3';;
1908 *) echo 'UNKNOWN KEY';;
1914 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output"
1915 if ! aptkey list
--with-colon | grep '^pub' | cut
-d':' -f 5 > "$OUTPUT"; then
1918 testfileequal
"$OUTPUT" "$(mapkeynametokeyid "$@")"
1922 echo "STOPPED execution. Press enter to continue"
1927 logcurrentarchivedirectory
() {
1928 find "${TMPWORKINGDIRECTORY}/aptarchive/dists" -type f
| while read line
; do
1929 stat
--format '%U:%G:%a:%n' "$line"
1930 done | sort > "${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst"
1932 listcurrentlistsdirectory
() {
1934 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1935 stat
--format '%U:%G:%a:%n' "$line"
1937 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1938 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1942 forallsupportedcompressors
() {
1943 rm -f "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
1944 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
1945 if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi
1950 ### convenience hacks ###
1952 # creating some directories by hand is a tedious task, so make it look simple
1954 if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then
1955 # only the last directory created by mkdir is effected by the -m !
1956 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1957 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1958 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1959 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1960 if [ "$(id -u)" = '0' ]; then
1961 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1968 ### The following tests are run by most test methods automatically to check
1969 ### general things about commands executed without writing the test every time.
1972 if [ $# -lt 3 ]; then return; fi
1978 if ! expr match
"$i" '^-' >/dev
/null
2>&1; then
1984 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')"
1985 if command -v $AUTOTEST >/dev
/null
; then
1986 # save and restore the *.output files from other tests
1987 # as we might otherwise override them in these automatic tests
1988 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1989 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1990 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1991 $AUTOTEST "$TESTCALL" "$@"
1992 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1993 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1994 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1998 aptautotest_aptget_update
() {
2000 while [ -n "$2" ]; do
2001 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
2004 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
2005 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
2006 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
2007 # all copied files are properly chmodded
2008 local backupIFS
="$IFS"
2009 IFS
="$(printf "\n\b")"
2010 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
2011 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
2014 if [ "$TESTCALL" = 'testsuccess' ]; then
2015 # failure cases can retain partial files and such
2016 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
2018 if [ -s "${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" ]; then
2019 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/var/log/aptgetupdate.before.lst" \
2020 "$(find "${TMPWORKINGDIRECTORY}/aptarchive/dists" -type f | while read line; do stat --format '%U:%G:%a:%n' "$line"; done | sort)"
2023 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
2024 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
2026 testaptautotestnodpkgwarning
() {
2028 while [ -n "$2" ]; do
2029 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
2030 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
2033 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
2036 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
2037 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
2038 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
2039 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
2040 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
2041 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }
2043 testaptmarknodefaultsections
() {
2044 testfailure
grep '^Auto-Installed: 0$' "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/extended_states"
2046 aptautotest_aptmark_auto
() { testaptmarknodefaultsections
"$@"; }
2047 aptautotest_aptmark_manual
() { testaptmarknodefaultsections
"$@"; }
2048 aptautotest_aptget_markauto
() { testaptmarknodefaultsections
"$@"; }
2049 aptautotest_aptget_markmanual
() { testaptmarknodefaultsections
"$@"; }