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
35 if [ "$MSGCOLOR" != 'NO' ]; then
36 CERROR
="\033[1;31m" # red
37 CWARNING
="\033[1;33m" # yellow
38 CMSG
="\033[1;32m" # green
39 CINFO
="\033[1;96m" # light blue
40 CDEBUG
="\033[1;94m" # blue
41 CNORMAL
="\033[0;39m" # default system console color
42 CDONE
="\033[1;32m" # green
43 CPASS
="\033[1;32m" # green
44 CFAIL
="\033[1;31m" # red
45 CCMD
="\033[1;35m" # pink
57 printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghks]\)#apt-\1#')"
63 msgdie
() { msgprintf
"${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; }
64 msgwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; }
65 msgmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; }
66 msginfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; }
67 msgdebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; }
68 msgdone
() { msgprintf
"${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; }
69 msgnwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; }
70 msgnmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}" "$@"; }
71 msgninfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
72 msgndebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
73 msgtest
() { msgprintf
"${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
74 msgpass
() { printf "${CPASS}PASS${CNORMAL}\n"; }
76 if [ -n "$MSGTEST_MSG" ]; then
77 test "$1" != 'msgfailoutput' || echo
78 if [ -n "$MSGTEST_MSGMSG" ]; then
79 echo "$MSGTEST_MSGMSG"
81 if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then
82 echo "${CFAIL}Part of the test group: $MSGTEST_GRP"
84 echo -n "$MSGTEST_MSG"
89 msgreportheader
'msgskip'
90 if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
91 else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
94 msgreportheader
'msgfail'
95 if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
96 else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
97 if [ -n "$APT_DEBUG_TESTS" ]; then
100 EXIT_CODE
=$((EXIT_CODE+1));
105 if [ $MSGGROUP_LEVEL = 0 ]; then
108 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL+1));
110 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL-1));
111 if [ $MSGGROUP_LEVEL = 0 ]; then
117 # enable / disable Debugging
118 if [ $MSGLEVEL -le 0 ]; then
121 if [ $MSGLEVEL -le 1 ]; then
125 if [ $MSGLEVEL -le 2 ]; then
127 MSGTEST_MSGMSG
="$(msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@")"
131 MSGTEST_MSG
="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")"
132 if [ "$MSGTEST_GRP" = 'NEXT' ]; then
133 MSGTEST_GRP
="$MSGTEST_MSG"
136 msgpass
() { printf " ${CPASS}P${CNORMAL}"; }
138 if [ $MSGLEVEL -le 3 ]; then
142 if [ $MSGLEVEL -le 4 ]; then
144 msgndebug
() { true
; }
147 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
148 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
149 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
150 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
151 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
154 printf "${CDONE}DONE${CNORMAL}\n";
158 if [ -f .
/aptconfig.conf
]; then
159 echo "$(readlink -f ./aptconfig.conf)"
160 elif [ -f ..
/aptconfig.conf
]; then
161 echo "$(readlink -f ../aptconfig.conf)"
162 elif [ -f ..
/..
/aptconfig.conf
]; then
163 echo "$(readlink -f ../../aptconfig.conf)"
164 elif [ -f "${TMPWORKINGDIRECTORY}/aptconfig.conf" ]; then
165 echo "$(readlink -f "${TMPWORKINGDIRECTORY}/aptconfig.conf")"
169 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
173 sh
|aptitude
|*/*|command) ;;
174 *) CMD
="${BUILDDIRECTORY}/$CMD";;
176 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
="${LIBRARYPATH}:${LD_LIBRARY_PATH}" "$CMD" "$@"
178 runpython3
() { runapt
command python3
"$@"; }
179 aptconfig
() { runapt apt
-config "$@"; }
180 aptcache
() { runapt apt
-cache "$@"; }
181 aptcdrom
() { runapt apt
-cdrom "$@"; }
182 aptget
() { runapt apt
-get "$@"; }
183 aptftparchive
() { runapt apt
-ftparchive "$@"; }
184 aptkey
() { runapt apt
-key "$@"; }
185 aptmark
() { runapt apt
-mark "$@"; }
186 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; }
187 apt
() { runapt apt
"$@"; }
188 apthelper
() { runapt
"${APTHELPERBINDIR}/apt-helper" "$@"; }
189 aptwebserver
() { runapt
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
190 aptitude
() { runapt aptitude
"$@"; }
191 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; }
192 aptinternalsolver
() { runapt
"${APTINTERNALSOLVER}" "$@"; }
193 aptdumpsolver
() { runapt
"${APTDUMPSOLVER}" "$@"; }
194 aptinternalplaner
() { runapt
"${APTINTERNALPLANER}" "$@"; }
197 "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@"
199 dpkgcheckbuilddeps
() {
200 command dpkg
-checkbuilddeps --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" "$@"
205 aptget
) CMD
="apt-get";;
206 aptcache
) CMD
="apt-cache";;
207 aptcdrom
) CMD
="apt-cdrom";;
208 aptconfig
) CMD
="apt-config";;
209 aptmark
) CMD
="apt-mark";;
210 apthelper
) CMD
="apt-helper";;
211 aptftparchive
) CMD
="apt-ftparchive";;
212 dpkg
) shift; runapt
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" "$@"; return;;
216 if [ "${CMD##*/}" = "$CMD" ]; then
217 CMD
="${BUILDDIRECTORY}/${CMD}"
219 runapt
command gdb
--quiet -ex run
"$CMD" --args "$CMD" "$@"
222 date -u -d "@$(stat -c '%Y' "${TMPWORKINGDIRECTORY}/$1")" '+%a, %d %b %Y %H:%M:%S GMT'
225 grep "^${2:-Date}:" "$1" | cut
-d' ' -f 2- | sed -e 's#UTC#GMT#'
229 # error if we about to overflow, but ...
230 # "255 failures ought to be enough for everybody"
231 if [ $EXIT_CODE -gt 255 ]; then
232 msgdie
"Total failure count $EXIT_CODE too big"
234 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
237 shellsetedetector
() {
239 if [ "$exit_status" != '0' ]; then
240 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
241 if [ "$EXIT_CODE" = '0' ]; then
242 EXIT_CODE
="$exit_status"
248 if [ "$1" = 'prefix' ]; then
249 CURRENTTRAP
="$2 $CURRENTTRAP"
251 CURRENTTRAP
="$CURRENTTRAP $1"
253 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
257 echo "$@" | sed -e "s#'#'\"'\"'#g"
261 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
262 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
265 TMPWORKINGDIRECTORY
="$(mktemp -d)"
266 addtrap
"cd /; rm -rf '$(escape_shell "$TMPWORKINGDIRECTORY")';"
267 if [ -n "$TMPDIR_ADD" ]; then
268 TMPWORKINGDIRECTORY
="${TMPWORKINGDIRECTORY}/${TMPDIR_ADD}"
269 mkdir -p "$TMPWORKINGDIRECTORY"
271 export TMPDIR
="$TMPWORKINGDIRECTORY"
273 msgninfo
"Preparing environment for ${0##*/} in ${TMPWORKINGDIRECTORY}…"
275 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
276 if [ "$(id -u)" = '0' ]; then
277 # relax permissions so that running as root with user switching works
279 chmod 711 "$TMPWORKINGDIRECTORY"
280 chown _apt
:root
"${TMPWORKINGDIRECTORY}/downloaded"
283 TESTDIRECTORY
="$(readlink -f "$(dirname $0)")"
284 # allow overriding the default BUILDDIR location
285 SOURCEDIRECTORY="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}"
286 BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}"
287 LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}"
288 METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}"
289 APTHELPERBINDIR="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}"
290 APTWEBSERVERBINDIR="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}"
291 APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}"
292 APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}"
293 APTINTERNALPLANER="${APT_INTEGRATION_TESTS_INTERNAL_PLANER:-"${BUILDDIRECTORY}/apt-internal-planer"}"
294 test -x "${BUILDDIRECTORY}/apt
-get" || msgdie "You need to build tree first
"
297 cd "$TMPWORKINGDIRECTORY"
298 mkdir rootdir aptarchive keys
300 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
301 mkdir -p usr/bin var/cache var/lib var/log tmp
302 mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
303 touch var/lib/dpkg/available
305 ln -s "${METHODSDIR}" usr/lib/apt/methods
306 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
307 mkdir -p usr/lib/apt/solvers usr/lib/apt/planers
308 ln -s "${BUILDDIRECTORY}/apt
-dump-solver" usr/lib/apt/solvers/dump
309 ln -s "${BUILDDIRECTORY}/apt
-dump-solver" usr/lib/apt/planers/dump
310 ln -s "${BUILDDIRECTORY}/apt
-internal-solver" usr/lib/apt/solvers/apt
311 ln -s "${BUILDDIRECTORY}/apt
-internal-planer" usr/lib/apt/planers/apt
312 echo "Dir
::Bin
::Solvers
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/solvers
\";" >> ../aptconfig.conf
313 echo "Dir
::Bin
::Planers
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/planers
\";" >> ../aptconfig.conf
315 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
317 if [ -e "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" ]; then
318 ln -s "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" etc/apt/apt.conf.d/01autoremove
320 ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
323 local BASENAME="${0##*/}"
324 local PACKAGESFILE="Packages
-${BASENAME#*-}"
325 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
326 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
328 local SOURCESSFILE="Sources
-${BASENAME#*-}"
329 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
330 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
332 find "$TESTDIRECTORY" \( -name '*.pub' -o -name '*.sec' \) -exec cp '{}' keys/ \;
334 ln -s "${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub
" rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
336 echo "Dir
\"${TMPWORKINGDIRECTORY}/rootdir
\";" >> aptconfig.conf
337 echo "Dir
::state
::status
\"${TMPWORKINGDIRECTORY}/rootdir
/var
/lib
/dpkg
/status
\";" >> aptconfig.conf
338 echo "APT
::Get
::Show
-User-Simulation-Note \"false
\";" >> aptconfig.conf
339 echo "Dir
::Bin
::Methods
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/methods
\";" >> aptconfig.conf
340 # either store apt-key were we can access it, even if we run it as a different user
341 #cp "${BUILDDIRECTORY}/apt
-key" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/"
342 #chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key"
343 #echo "Dir
::Bin
::apt
-key \"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key\";" >> aptconfig.conf
344 # destroys coverage reporting though, so we disable changing user for the calling gpgv
345 echo "Dir
::Bin
::apt
-key \"${BUILDDIRECTORY}/apt
-key\";" >> aptconfig.conf
346 if [ "$(id -u)" = '0' ]; then
347 echo 'Binary::gpgv::APT::Sandbox::User "root
";' >> aptconfig.conf
348 # same for the solver executables
349 echo 'APT::Solver::RunAsUser "root
";' >> aptconfig.conf
352 cat > "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
355 if [ -r '${TMPWORKINGDIRECTORY}/noopchroot.so' ]; then
356 if [ -n "\
$LD_LIBRARY_PATH" ]; then
357 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}:'"\
${LD_LIBRARY_PATH}"
359 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}'
361 if [ -n "\
$LD_PRELOAD" ]; then
362 export LD_PRELOAD="noopchroot.so \
${LD_PRELOAD}"
364 export LD_PRELOAD="noopchroot.so
"
368 cp "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
369 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
370 exec fakeroot '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
371 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
372 --force-not-root --force-bad-path "\$@
"
374 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg" <<EOF
375 exec fakeroot gdb --quiet -ex run '${DPKG:-dpkg}' --args '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
376 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
377 --force-not-root --force-bad-path "\$@
"
379 chmod +x "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
380 echo "Dir
::Bin
::dpkg
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
\";" > rootdir/etc/apt/apt.conf.d/99dpkg
383 if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
384 echo "DPKG
::options
:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
387 echo 'quiet::NoUpdate "true
";'
388 echo 'quiet::NoStatistic "true
";'
389 # too distracting for users, but helpful to detect changes
390 echo 'Acquire::Progress::Ignore::ShowErrorText "true
";'
391 echo 'Acquire::Progress::Diffpercent "true
";'
392 # in testcases, it can appear as if localhost has a rotation setup,
393 # hide this as we can't really deal with it properly
394 echo 'Acquire::Failure::ShowIP "false
";'
395 # fakeroot can't fake everything, so disabled in production but good for tests
396 echo 'APT::Sandbox::Verify "true
";'
399 cp "${TESTDIRECTORY}/apt.pem
" "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
400 if [ "$(id -u)" = '0' ]; then
401 chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
403 echo "Acquire
::https
::CaInfo
\"${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
\";" > rootdir/etc/apt/apt.conf.d/99https
404 echo "Apt
::Cmd
::Disable
-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
405 echo 'Acquire::Connect::AddrConfig "false
";' > rootdir/etc/apt/apt.conf.d/connect-addrconfig
407 configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
408 confighashes 'SHA256' # these are tests, not security best-practices
410 # create some files in /tmp and look at user/group to get what this means
411 TEST_DEFAULT_USER="$(id -un)"
412 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
413 TEST_DEFAULT_GROUP='root'
415 TEST_DEFAULT_GROUP="$(id -gn)"
418 # cleanup the environment a bit
419 # prefer our apt binaries over the system apt binaries
420 export PATH="${BUILDDIRECTORY}:${PATH}:/usr
/local
/sbin
:/usr
/sbin
:/sbin
"
421 export LC_ALL=C.UTF-8
422 unset LANGUAGE APT_CONFIG
423 unset GREP_OPTIONS DEB_BUILD_PROFILES
424 unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy
426 # If gpgv supports --weak-digest, pass it to make sure we can disable SHA1
427 if aptkey verify --weak-digest SHA1 --help 2>/dev/null >/dev/null; then
428 echo 'Acquire::gpgv::Options { "--weak-digest"; "sha1
"; };' > rootdir/etc/apt/apt.conf.d/no-sha1
431 # most tests just need one signed Release file, not both
432 export APT_DONT_SIGN='Release.gpg'
438 if [ "$1" = "native
" -o -z "$1" ]; then
439 eval `aptconfig shell ARCH APT::Architecture`
440 if [ -n "$ARCH" ]; then
443 dpkg --print-architecture
451 aptconfig dump --no-empty --format '%v%n' APT::Architecture APT::Architectures | sort -u | tr '\n' ' '
454 getarchitecturesfromcommalist() {
455 echo "$1" | sed -e 's#,#\n#g' | sed -e "s
/^native\$
/$(getarchitecture 'native')/"
458 configarchitecture() {
460 echo "APT
::Architecture
\"$(getarchitecture $1)\";"
461 while [ -n "$1" ]; do
462 echo "APT
::Architectures
:: \"$(getarchitecture $1)\";"
465 } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
470 if [ ! -e rootdir/var/lib/dpkg/status ]; then
471 local BASENAME="${0##*/}"
472 local STATUSFILE="status
-${BASENAME#*-}"
473 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
474 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
476 echo -n > rootdir/var/lib/dpkg/status
479 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
480 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
481 local ARCHS="$(getarchitectures)"
482 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
483 DPKGARCH="$(dpkg --print-architecture)"
484 for ARCH in ${ARCHS}; do
485 if [ "${ARCH}" != "${DPKGARCH}" ]; then
486 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
487 # old-style used e.g. in Ubuntu-P – and as it seems travis
488 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
489 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
493 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
494 # dpkg doesn't really check the version as long as it is fully installed,
495 # but just to be sure we choose one above the required version
496 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
502 configdpkgnoopchroot() {
503 # create a library to noop chroot() and rewrite maintainer script executions
504 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
505 # chroot directory dpkg could chroot into to execute the maintainer scripts
506 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
507 cat > noopchroot.c << EOF
514 static char * chrootdir = NULL;
516 int chroot(const char *path) {
517 printf("WARNING
: CHROOTing to
%s was ignored
!\n", path);
519 chrootdir = strdup(path);
522 int execvp(const char *file, char *const argv[]) {
523 static int (*func_execvp) (const char *, char * const []) = NULL;
524 if (func_execvp == NULL)
525 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
");
526 if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0)
527 return func_execvp(file, argv);
528 printf("REWRITE execvp call
%s into
%s
\n", file, chrootdir);
530 if (asprintf(&newfile, "%s
%s
", chrootdir, file) == -1) {
534 char const * const baseadmindir = "/var
/lib
/dpkg
";
536 if (asprintf(&admindir, "%s
%s
", chrootdir, baseadmindir) == -1) {
540 setenv("DPKG_ADMINDIR
", admindir, 1);
541 return func_execvp(newfile, argv);
544 testempty --nomsg gcc -Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c -ldl
546 configcompression() {
547 if [ "$1" = 'ALL' ]; then
548 configcompression '.' $(aptconfig dump APT::Compressor --format '%t %v%n' | sed -n 's#^Extension \.\(.*\)$#\1#p')
551 local CMD='apthelper cat-file -C'
552 while [ -n "$1" ]; do
554 '.') printf ".
\t.
\tcat
\n";;
555 'gz') printf "gzip\tgz
\t$CMD $1\n";;
556 'bz2') printf "bzip2\tbz
2\t$CMD $1\n";;
557 *) printf "$1\t$1\t$CMD $1\n";;
560 done > "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
"
564 echo 'APT::FTPArchive {'
566 while [ -n "$1" ]; do
567 printf "$1" | tr 'a-z' 'A-Z'
568 printf "\t\"true
\";\n"
571 for h in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
572 printf "$h\t\"false
\";\n"
576 } >> "${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/ftparchive
-hashes.conf
"
581 COMPRESSOR_CMD="apthelper
cat-file -C $1"
583 gzip) COMPRESS='gz';;
584 bzip2) COMPRESS='bz2';;
586 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/00force
-compressor"
587 echo "Acquire
::CompressionTypes
::Order
{ \"${COMPRESS}\"; };
588 Dir
::Bin
::uncompressed
\"/does
/not
/exist
\";" > "$CONFFILE"
589 for COMP in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
590 if [ -z "$COMP" -o "$COMP" = '.' -o "$COMP" = "$COMPRESSOR" ]; then continue; fi
591 echo "Dir
::Bin
::${COMP} \"/does
/not
/exist
\";" >> "$CONFFILE"
592 echo "APT
::Compressor
::${COMP}::Name
\"${COMP}-disabled\";" >> "$CONFFILE"
596 setupsimplenativepackage() {
600 local RELEASE="${4:-unstable}"
601 local DEPENDENCIES="$5"
602 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
603 If you
find such a package installed on your system
,
604 something went horribly wrong
! They are autogenerated
605 und used only by testcases and serve no other purpose…
"}"
607 local SECTION
="${7:-others}"
609 if [ "$SECTION" = "${SECTION#*/}" ]; then
612 DISTSECTION
="${SECTION%/*}"
614 local BUILDDIR
=incoming
/${NAME}-${VERSION}
615 mkdir -p ${BUILDDIR}/debian
/source
617 echo "* most suckless software product ever" > FEATURES
618 test -e debian
/copyright
|| echo "Copyleft by Joe Sixpack $(date -u +%Y)" > debian
/copyright
619 test -e debian
/changelog
|| echo "$NAME ($VERSION) $RELEASE; urgency=low
623 -- Joe Sixpack <joe@example.org> $(date -u -R)" > debian
/changelog
624 test -e debian
/control
|| echo "Source: $NAME
627 Maintainer: Joe Sixpack <joe@example.org>
628 Build-Depends: debhelper (>= 7)
629 Standards-Version: 3.9.1
631 Package: $NAME" > debian
/control
632 if [ "$ARCH" = 'all' ]; then
633 echo "Architecture: all" >> debian
/control
635 echo "Architecture: any" >> debian
/control
637 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian
/control
638 echo "Description: $DESCRIPTION" >> debian
/control
640 test -e debian
/compat
|| echo "7" > debian
/compat
641 test -e debian
/source
/format
|| echo "3.0 (native)" > debian
/source
/format
642 test -e debian
/rules
|| cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny debian
/rules
646 buildsimplenativepackage
() {
649 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then
650 NM
="$(echo "$NAME" | cut -c 1-4)"
652 NM
="$(echo "$NAME" | cut -c 1)"
656 local RELEASE
="${4:-unstable}"
657 local DEPENDENCIES
="$5"
658 local DESCRIPTION
="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
659 If you find such a package installed on your system,
660 something went horribly wrong! They are autogenerated
661 und used only by testcases and serve no other purpose…"}"
663 local SECTION="${7:-others}"
664 local PRIORITY="${8:-optional}"
666 local COMPRESS_TYPE="${10:-gzip}"
668 if [ "$SECTION" = "${SECTION#*/}" ]; then
671 DISTSECTION="${SECTION%/*}"
673 local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming
/${NAME}-${VERSION}"
675 msgtest "Build
source package
in version
${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
676 mkdir -p "$BUILDDIR/debian
/source"
677 echo "* most suckless software product ever
" > "${BUILDDIR}/FEATURES
"
679 echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}"
681 echo "Copyleft by Joe Sixpack
$(date -u +%Y)" > "${BUILDDIR}/debian
/copyright
"
682 echo "$NAME ($VERSION) $RELEASE; urgency
=low
686 -- Joe Sixpack
<joe@example.org
> $(date -u -R)" > "${BUILDDIR}/debian
/changelog
"
690 Maintainer
: Joe Sixpack
<joe@example.org
>
691 Standards
-Version: 3.9.3"
692 if [ "$SECTION" != '<none>' ]; then
693 echo "Section
: $SECTION"
695 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
696 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
700 if [ "$ARCH" = 'all' ]; then
701 echo "Architecture
: all
"
703 echo "Architecture
: any
"
705 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
706 test -z "$DEPS" || echo "$DEPS"
707 echo "Description
: $DESCRIPTION"
708 } > "${BUILDDIR}/debian
/control
"
710 echo '3.0 (native)' > "${BUILDDIR}/debian
/source
/format
"
712 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
714 sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
" \
716 echo "pool
/${SRC}" >> "${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
"
717 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
718 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
719 # adv --yes --default-key 'Joe Sixpack' \
720 # --clearsign -o "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
721 # mv "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
725 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
726 msgtest "Build binary package
for ${RELEASE} in ${SECTION}" "$NAME"
727 rm -rf "${BUILDDIR}/debian
/tmp
"
728 mkdir -p "${BUILDDIR}/debian
/tmp
/DEBIAN
" "${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}" "${BUILDDIR}/debian
/tmp
/usr
/bin
"
729 cp "${BUILDDIR}/debian
/copyright
" "${BUILDDIR}/debian
/changelog
" "${BUILDDIR}/FEATURES
" "${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}"
730 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}"
731 if [ -n "$FILE_TREE" ]; then
732 cp -ar "$FILE_TREE" "${BUILDDIR}/debian
/tmp
"
735 (cd "${BUILDDIR}"; dpkg-gencontrol -DArchitecture=$arch)
736 (cd "${BUILDDIR}/debian
/tmp
"; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
737 local LOG="${BUILDDIR}/..
/${NAME}_
${VERSION}_
${arch}.dpkg
-deb.log
"
738 # ensure the right permissions as dpkg-deb insists
739 chmod 755 "${BUILDDIR}/debian
/tmp
/DEBIAN
"
740 testsuccess --nomsg dpkg-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian
/tmp
" "${BUILDDIR}/..
"
741 echo "pool
/${NAME}_
${VERSION}_
${arch}.deb
" >> "${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
"
744 local CHANGEPATH="${BUILDDIR}/..
/${DISTSECTION}/${NM}/${NAME}/${NAME}_
${VERSION}"
745 mkdir -p "$CHANGEPATH"
746 cp "${BUILDDIR}/debian
/changelog
" "$CHANGEPATH"
755 local ARCH=$(getarchitecture $4)
756 local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
757 local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
758 msgtest "Build package
for ${RELEASE} in ${SECTION}" "$PKGNAME"
760 if [ "$ARCH" = "all
" ]; then
761 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
763 testsuccess --nomsg dpkg-buildpackage -uc -us -a$ARCH
764 cp "${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
" "$BUILDLOG"
765 local PKGS="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
766 local SRCS="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
769 echo "pool
/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
"
772 echo "pool
/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
"
777 if [ -d incoming ]; then
778 buildaptarchivefromincoming "$@
"
780 buildaptarchivefromfiles "$@
"
784 createaptftparchiveconfig() {
785 local COMPRESSORS="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
786 local COMPRESSORS="${COMPRESSORS%* }"
787 local ARCHS="$(getarchitectures)"
788 cat > ftparchive.conf <<EOF
790 ArchiveDir "$(readlink -f .)";
791 CacheDir "$(readlink -f ..)";
792 FileListDir "$(readlink -f pool/)";
795 Packages::Compress "$COMPRESSORS";
796 Sources::Compress "$COMPRESSORS";
797 Contents::Compress "$COMPRESSORS";
798 Translation::Compress "$COMPRESSORS";
799 LongDescription "false
";
803 SrcDirectory "pool
/";
806 for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
809 Architectures "$ARCHS all
source";
810 FileList "${DIST}.\
$(SECTION).pkglist
";
811 SourceFileList "${DIST}.\
$(SECTION).srclist
";
812 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
815 done >> ftparchive.conf
818 buildaptftparchivedirectorystructure() {
819 local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
820 for DIST in $DISTS; do
821 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
822 for SECTION in $SECTIONS; do
823 local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
824 for ARCH in $ARCHS; do
825 mkdir -p "dists
/${DIST}/${SECTION}/binary
-${ARCH}"
827 mkdir -p "dists
/${DIST}/${SECTION}/source"
828 mkdir -p "dists
/${DIST}/${SECTION}/i18n
"
838 local DEPENDENCIES="$5"
839 local PRIORITY="${6:-optional}"
840 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
841 If you
find such a package installed on your system
,
842 something went horribly wrong
! They are autogenerated
843 und used only by testcases and serve no other purpose…
"}"
845 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
846 if [ "$RELEASE" = 'installed' ]; then
847 insertinstalledpackage
"$2" "$3" "$4" "$5" "$6" "$7"
850 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
851 if [ "$arch" = 'none' ]; then
852 ARCHS
="$(getarchitectures)"
856 for BUILDARCH
in $ARCHS; do
857 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
864 Maintainer: Joe Sixpack <joe@example.org>"
865 test "$arch" = 'none' || echo "Architecture: $arch"
866 echo "Version: $VERSION
867 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb"
868 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES"
869 echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)"
870 echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
872 } >> "${PPATH}/Packages"
875 mkdir -p "aptarchive/dists/${RELEASE}/main/source" "aptarchive/dists/${RELEASE}/main/i18n"
876 touch "aptarchive/dists/${RELEASE}/main/source/Sources"
878 Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
879 Description-en: $DESCRIPTION
880 " >> "aptarchive/dists/${RELEASE}/main/i18n/Translation-en"
889 local DEPENDENCIES
="$5"
890 local BINARY
="${6:-$NAME}"
892 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
893 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
895 local FILE
="${SPATH}/Sources"
896 local DSCFILE
="${NAME}_${VERSION}.dsc"
897 local TARFILE
="${NAME}_${VERSION}.tar.gz"
901 Maintainer: Joe Sixpack <joe@example.org>
902 Architecture: $ARCH" >> $FILE
903 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
905 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
906 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
908 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
909 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
914 insertinstalledpackage
() {
918 local DEPENDENCIES
="$4"
919 local PRIORITY
="${5:-optional}"
920 local STATUS
="${6:-install ok installed}"
921 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
922 If you find such a package installed on your system,
923 something went horribly wrong! They are autogenerated
924 und used only by testcases and serve no other purpose…"}"
926 local FILE='rootdir/var/lib/dpkg/status'
927 local INFO='rootdir/var/lib/dpkg/info'
928 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
934 Maintainer
: Joe Sixpack
<joe@example.org
>
935 Version
: $VERSION" >> "$FILE"
936 test "$arch" = 'none' || echo "Architecture
: $arch" >> "$FILE"
937 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
938 echo "Description
: $DESCRIPTION" >> "$FILE"
940 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
941 echo -n > "${INFO}/${NAME}:${arch}.list
"
943 echo -n > "${INFO}/${NAME}.list
"
949 buildaptarchivefromincoming() {
950 msginfo "Build APT archive
for ${CCMD}${0##*/}${CINFO} based on incoming packages…
"
952 [ -e pool ] || ln -s ../incoming pool
953 [ -e ftparchive.conf ] || createaptftparchiveconfig
954 [ -e dists ] || buildaptftparchivedirectorystructure
955 msgninfo "\tGenerate Packages
, Sources and Contents files…
"
956 testsuccess aptftparchive generate ftparchive.conf
959 generatereleasefiles "$@
"
962 buildaptarchivefromfiles() {
963 msginfo "Build APT archive
for ${CCMD}${0##*/}${CINFO} based on prebuild files…
"
964 local DIR='aptarchive'
965 if [ -d "${DIR}/dists
" ]; then DIR="${DIR}/dists
"; fi
966 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do
967 msgninfo "\t${line} file…
"
968 compressfile "$line" "$1"
971 generatereleasefiles "$@
"
975 while read compressor extension command; do
976 if [ "$compressor" = '.' ]; then
982 cat "$1" | $command > "${1}.
${extension}"
984 touch -d "$2" "${1}.
${extension}"
986 done < "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
"
989 # can be overridden by testcases for their pleasure
990 getcodenamefromsuite() {
992 unstable) echo 'sid';;
996 getreleaseversionfromsuite() { true; }
997 getlabelfromsuite() { true; }
998 getoriginfromsuite() { true; }
999 getarchitecturesfromreleasefile() { echo "all
$(getarchitectures)"; }
1001 aptftparchiverelease() {
1002 aptftparchive -qq release "$@
" | sed -e '/0 Release$/ d' # remove the self reference
1004 generatereleasefiles() {
1005 # $1 is the Date header and $2 is the ValidUntil header to be set
1006 # both should be given in notation date/touch can understand
1008 local VALIDUNTIL="$2"
1009 if [ -e aptarchive/dists ]; then
1010 msgninfo "\tGenerate Release files
for dists…
"
1011 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
1012 local ARCHITECTURES="$(getarchitecturesfromreleasefile "$dir")"
1013 local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
1014 local CODENAME="$(getcodenamefromsuite $SUITE)"
1015 local VERSION="$(getreleaseversionfromsuite $SUITE)"
1016 local LABEL="$(getlabelfromsuite $SUITE)"
1017 local ORIGIN="$(getoriginfromsuite $SUITE)"
1018 aptftparchiverelease "$dir" \
1019 -o APT::FTPArchive::Release::Suite="${SUITE}" \
1020 -o APT::FTPArchive::Release::Codename="${CODENAME}" \
1021 -o APT::FTPArchive::Release::Architectures="${ARCHITECTURES}" \
1022 -o APT::FTPArchive::Release::Label="${LABEL}" \
1023 -o APT::FTPArchive::Release::Origin="${ORIGIN}" \
1024 -o APT::FTPArchive::Release::Version="${VERSION}" \
1026 if [ "$SUITE" = "experimental
" -o "$SUITE" = "experimental2
" ]; then
1027 sed -i '/^Date: / a\
1028 NotAutomatic: yes' "$dir/Release
"
1032 msgninfo "\tGenerate Release files
for flat…
"
1033 aptftparchiverelease ./aptarchive > aptarchive/Release
1035 if [ -n "$DATE" -a "$DATE" != "now
" ]; then
1036 for release in $(find ./aptarchive -name 'Release'); do
1037 sed -i "s
/^Date
: .
*$
/Date
: $(date -u -d "$DATE" '+%a, %d %b %Y %H:%M:%S %Z')/" "$release"
1038 touch -d "$DATE" "$release"
1041 if [ -n "$VALIDUNTIL" ]; then
1042 sed -i "/^Date
: / a\
1043 Valid
-Until: $(date -u -d "$VALIDUNTIL" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release')
1048 setupdistsaptarchive() {
1049 local APTARCHIVE="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1050 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
1051 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
1052 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1053 SECTIONS=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1054 msgninfo "\tadd deb and deb
-src sources.list lines
for ${CCMD}${DISTS} ${SECTIONS}${CINFO}…
"
1055 echo "deb
file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
"
1056 echo "deb
-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
"
1061 setupflataptarchive() {
1062 local APTARCHIVE="$(readlink -f ./aptarchive)"
1063 local APTARCHIVEURI="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1064 if [ -f "${APTARCHIVE}/Packages
" ]; then
1065 msgninfo "\tadd deb sources.list line…
"
1066 echo "deb
file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1069 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1071 if [ -f "${APTARCHIVE}/Sources
" ]; then
1072 msgninfo "\tadd deb
-src sources.list line…
"
1073 echo "deb
-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1076 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1082 if [ "$1" = '--no-update' ]; then
1086 buildaptarchive "$@
"
1087 if [ -e aptarchive/dists ]; then
1088 setupdistsaptarchive
1092 signreleasefiles 'Joe Sixpack'
1093 if [ "1" != "$NOUPDATE" ]; then
1094 testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true
1098 signreleasefiles() {
1099 local SIGNERS="${1:-Joe Sixpack}"
1100 local REPODIR="${2:-aptarchive}"
1101 if [ -n "$1" ]; then shift; fi
1102 if [ -n "$1" ]; then shift; fi
1103 local KEY="keys
/$(echo "$SIGNERS" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1104 msgninfo "\tSign archive with
$SIGNERS key
$KEY…
"
1105 local REXKEY='keys/rexexpired'
1106 local SECEXPIREBAK="${REXKEY}.sec.bak
"
1107 local PUBEXPIREBAK="${REXKEY}.pub.bak
"
1109 while [ -n "${SIGNERS%%,*}" ]; do
1110 local SIGNER="${SIGNERS%%,*}"
1111 if [ "${SIGNERS}" = "${SIGNER}" ]; then
1114 SIGNERS="${SIGNERS#*,}"
1115 # FIXME: This should be the full name, but we can't encode the space properly currently
1116 SIGUSERS="${SIGUSERS} -u ${SIGNER#* }"
1117 if [ "${SIGNER}" = 'Rex Expired' ]; then
1118 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1119 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1120 # therefore we 'temporary' make the key not expired and restore a backup after signing
1121 cp "${REXKEY}.sec
" "$SECEXPIREBAK"
1122 cp "${REXKEY}.pub
" "$PUBEXPIREBAK"
1123 local SECUNEXPIRED="${REXKEY}.sec.unexpired
"
1124 local PUBUNEXPIRED="${REXKEY}.pub.unexpired
"
1125 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1126 cp "$SECUNEXPIRED" "${REXKEY}.sec
"
1127 cp "$PUBUNEXPIRED" "${REXKEY}.pub
"
1129 if ! printf "expire
\n1w
\nsave
\n" | aptkey --quiet --keyring "${REXKEY}.pub
" --secret-keyring "${REXKEY}.sec
" \
1130 --readonly adv --batch --yes --digest-algo "${APT_TESTS_DIGEST_ALGO:-SHA512}" \
1131 --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then
1135 cp "${REXKEY}.sec
" "$SECUNEXPIRED"
1136 cp "${REXKEY}.pub
" "$PUBUNEXPIRED"
1139 if [ ! -e "${KEY}.pub
" ]; then
1140 local K="keys
/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1141 cat "${K}.pub
" >> "${KEY}.new.pub
"
1142 cat "${K}.sec
" >> "${KEY}.new.sec
"
1145 if [ ! -e "${KEY}.pub
" ]; then
1146 mv "${KEY}.new.pub
" "${KEY}.pub
"
1147 mv "${KEY}.new.sec
" "${KEY}.sec
"
1149 local GPG="aptkey
--quiet --keyring ${KEY}.pub
--secret-keyring ${KEY}.sec
--readonly adv
--batch --yes --digest-algo ${APT_TESTS_DIGEST_ALGO:-SHA512}"
1150 for RELEASE in $(find "${REPODIR}/" -name Release); do
1151 # we might have set a specific date for the Release file, so copy it
1152 local DATE="$(stat --format "%y" "${RELEASE}")"
1153 if [ "$APT_DONT_SIGN" = 'Release.gpg' ]; then
1154 rm -f "${RELEASE}.gpg
"
1156 testsuccess $GPG "$@
" $SIGUSERS --armor --detach-sign --sign --output "${RELEASE}.gpg
" "${RELEASE}"
1157 touch -d "$DATE" "${RELEASE}.gpg
"
1159 local INRELEASE="${RELEASE%/*}/InRelease
"
1160 if [ "$APT_DONT_SIGN" = 'InRelease' ]; then
1163 testsuccess $GPG "$@
" $SIGUSERS --clearsign --output "$INRELEASE" "$RELEASE"
1164 touch -d "$DATE" "${INRELEASE}"
1167 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1168 mv -f "$SECEXPIREBAK" "${REXKEY}.sec
"
1169 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub
"
1174 redatereleasefiles() {
1175 local DATE="$(date -u -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
1176 for release in $(find aptarchive/ -name 'Release'); do
1177 sed -i "s
/^Date
: .
*$
/Date
: ${DATE}/" "$release"
1178 touch -d "$DATE" "$release"
1180 signreleasefiles "${2:-Joe Sixpack}"
1184 local WEBSERVER="${3:-http://localhost:${APTHTTPPORT}}"
1186 if [ "$1" = '--no-check' ]; then
1190 local DOWNLOG='rootdir/tmp/download-testfile.log'
1191 local STATUS='downloaded/webserverconfig.status'
1192 rm -f "$STATUS" "$DOWNLOG"
1193 # very very basic URI encoding
1195 if [ -n "$2" ]; then
1196 msgtest "Set webserver config option
'${1}' to
" "$2"
1197 URI="${WEBSERVER}/_config
/set
/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1199 msgtest 'Clear webserver config option' "${1}"
1200 URI="${WEBSERVER}/_config
/clear
/$(echo "${1}" | sed -e 's/\//%2f/g')"
1202 if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then
1205 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir
/tmp
/webserverconfig.output
"
1206 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1207 msgfailoutput '' "$OUTPUT"
1209 $NOCHECK || testwebserverlaststatuscode '200'
1212 rewritesourceslist() {
1213 local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1214 local APTARCHIVE2="copy
://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1215 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1216 sed -i $LIST -e "s
#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
1217 -e "s#http://[^@]*@\?localhost:${APTHTTPPORT}/\?#${1}#" \
1218 -e "s#https://[^@]*@\?localhost:${APTHTTPSPORT}/\?#${1}#"
1222 # wait for up to 10s for a pid file to appear to avoid possible race
1223 # when a helper is started and dosn't write the PID quick enough
1226 for i
in $(seq 10); do
1227 if test -s "$PIDFILE"; then
1232 msgdie
"waiting for $PIDFILE failed"
1236 changetowebserver
() {
1238 if [ "$1" != '--no-rewrite' ]; then
1243 if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
1245 local LOG
="webserver.log"
1246 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1250 waitforpidfile aptwebserver.pid
1251 local PID
="$(cat aptwebserver.pid)"
1252 if [ -z "$PID" ]; then
1253 msgdie
'Could not fork aptwebserver successfully'
1255 addtrap
"kill $PID;"
1256 waitforpidfile aptwebserver.port
1257 APTHTTPPORT
="$(cat aptwebserver.port)"
1258 if [ -z "$APTHTTPPORT" ]; then
1259 msgdie
'Could not get port for aptwebserver successfully'
1263 msgdie
'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver'
1265 if [ "$REWRTE" != 'yes' ]; then
1266 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1270 changetohttpswebserver
() {
1271 if ! command -v stunnel4
>/dev
/null
2>&1; then
1272 msgdie
'You need to install stunnel4 for https testcases'
1274 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1275 changetowebserver
--no-rewrite "$@"
1277 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1278 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1283 connect = $APTHTTPPORT
1284 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1285 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1286 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1287 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1288 if [ -z "$PID" ]; then
1289 msgdie
'Could not fork stunnel4 successfully'
1291 addtrap
'prefix' "kill ${PID};"
1292 APTHTTPSPORT
="$(lsof -i -n | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1293 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1294 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1298 mkdir -p rootdir
/media
/cdrom
/.disk
1299 local CD
="$(readlink -f rootdir/media/cdrom)"
1300 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1301 acquire::cdrom::mount "${CD}";
1302 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1303 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1304 acquire::cdrom::autodetect 0;
1306 echo -n "$1" > "${CD}/.disk/info"
1307 if [ ! -d aptarchive
/dists
]; then
1308 msgdie
'Flat file archive cdroms can not be created currently'
1311 mv aptarchive
/dists
"$CD"
1312 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1313 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1314 # start with an unmounted disk
1315 mv "${CD}" "${CD}-unmounted"
1316 # we don't want the disk to be modifiable
1317 addtrap
'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;"
1318 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1322 local PROTO
="${1%%:*}"
1323 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1324 download
-file "$1" "$2" "$3" 2>&1 ; then
1327 # only if the file exists the download was successful
1328 if [ -r "$2" ]; then
1336 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1337 if [ -n "$DIFFTEXT" ]; then
1339 echo >&2 "$DIFFTEXT"
1347 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1348 local COMPAREFILE
="$1"
1350 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1353 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1354 cat "$COMPAREFILE" >>"${OUTPUT}"
1355 msgfailoutput
'' "$OUTPUT" "$@"
1360 msggroup
'testfileequal'
1361 local MSG
='Test for correctness of file'
1362 if [ "$1" = '--nomsg' ]; then
1368 if [ -n "$MSG" ]; then
1369 msgtest
"$MSG" "$FILE"
1371 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1372 if [ -z "$*" ]; then
1373 testoutputequal
"$FILE" echo -n ''
1375 testoutputequal
"$FILE" echo "$*"
1381 msggroup
'testempty'
1382 if [ "$1" = '--nomsg' ]; then
1385 msgtest
"Test for no output of" "$*"
1387 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1388 if "$@" >"$COMPAREFILE" 2>&1 && test ! -s "$COMPAREFILE"; then
1391 msgfailoutput
'' "$COMPAREFILE" "$@"
1393 aptautotest
'testempty' "$@"
1397 msggroup
'testnotempty'
1398 msgtest
"Test for some output of" "$*"
1399 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
1400 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then
1403 msgfailoutput
'' "$COMPAREFILE" "$@"
1405 aptautotest
'testnotempty' "$@"
1410 msggroup
'testequal'
1411 local MSG
='Test of equality of'
1412 if [ "$1" = '--nomsg' ]; then
1417 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1418 echo "$1" > "$COMPAREFILE"
1421 if [ -n "$MSG" ]; then
1424 testoutputequal
"$COMPAREFILE" "$@"
1425 aptautotest
'testequal' "$@"
1430 msggroup
'testequalor2'
1431 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1432 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1433 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1434 echo "$1" > "$COMPAREFILE1"
1435 echo "$2" > "$COMPAREFILE2"
1437 msgtest
"Test for equality OR of" "$*"
1438 "$@" >"$COMPAREAGAINST" 2>&1 || true
1439 if checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null
2>&1 || \
1440 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null
2>&1
1444 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1445 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1446 checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1447 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1448 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1449 msgfailoutput
'' "$OUTPUT"
1451 aptautotest
'testequalor2' "$@"
1456 msggroup
'testshowvirtual'
1457 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1460 while [ -n "$1" ]; do
1462 N: Can't select versions from package '$1' as it is purely virtual"
1463 PACKAGE
="${PACKAGE} $1"
1466 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1468 N: No packages found"
1469 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1470 local ARCH
="$(getarchitecture 'native')"
1471 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1472 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1473 testoutputequal
"$COMPAREFILE" aptcache show
"$PACKAGE"
1478 msggroup
'testnopackage'
1479 msgtest
"Test for non-existent packages" "apt-cache show $*"
1480 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1481 if [ -n "$SHOWPKG" ]; then
1482 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1483 echo "$SHOWPKG" >"$OUTPUT"
1484 msgfailoutput
'' "$OUTPUT"
1490 testnosrcpackage
() {
1491 msggroup
'testnosrcpackage'
1492 msgtest
"Test for non-existent source packages" "apt-cache showsrc $*"
1493 local SHOWPKG
="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')"
1494 if [ -n "$SHOWPKG" ]; then
1495 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output"
1496 echo "$SHOWPKG" >"$OUTPUT"
1497 msgfailoutput
'' "$OUTPUT"
1505 msggroup
'testdpkgstatus'
1509 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1510 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1511 if [ "$PKGS" != $NR ]; then
1512 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1513 echo "$PKGS" >"$OUTPUT"
1514 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1515 msgfailoutput
'' "$OUTPUT"
1522 testdpkginstalled
() {
1523 msggroup
'testdpkginstalled'
1524 testdpkgstatus
'ii' "$#" "$@"
1528 testdpkgnotinstalled
() {
1529 msggroup
'testdpkgnotinstalled'
1530 testdpkgstatus
'ii' '0' "$@"
1535 msggroup
'testmarkedauto'
1536 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1537 if [ -n "$1" ]; then
1538 msgtest
'Test for correctly marked as auto-installed' "$*"
1539 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1541 msgtest
'Test for correctly marked as auto-installed' 'no package'
1542 echo -n > "$COMPAREFILE"
1544 testoutputequal
"$COMPAREFILE" aptmark showauto
1547 testmarkedmanual
() {
1548 msggroup
'testmarkedmanual'
1549 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1550 if [ -n "$1" ]; then
1551 msgtest
'Test for correctly marked as manually installed' "$*"
1552 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1554 msgtest
'Test for correctly marked as manually installed' 'no package'
1555 echo -n > "$COMPAREFILE"
1557 testoutputequal
"$COMPAREFILE" aptmark showmanual
1562 if [ "${1##*.}" = 'deb' ]; then
1563 stat
>&2 "$1" || true
1564 file >&2 "$1" || true
1566 cat >&2 "$1" || true
1570 msgreportheader
'msgfailoutput'
1575 if [ "$1" = 'grep' -o "$1" = 'tail' -o "$1" = 'head' ]; then
1577 while [ -n "$2" ]; do shift; done
1578 echo "#### Complete file: $1 ####"
1580 echo "#### $CMD output ####"
1581 elif [ "$1" = 'test' ]; then
1583 # doesn't support ! or non-file flags
1584 msgfailoutputstatfile
() {
1585 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1586 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1587 echo "#### stat(2) of file: $2 ####"
1589 if test -d "$2"; then
1590 echo "#### The directory contains: $2 ####"
1592 elif test -e "$2"; then
1593 echo "#### Complete file: $2 ####"
1598 msgfailoutputstatfile
"$2" "$3"
1599 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1601 msgfailoutputstatfile
"$2" "$3"
1603 echo '#### test output ####'
1604 elif [ "$1" = 'cmp' ]; then
1606 while [ -n "$2" ]; do
1607 echo "#### Complete file: $2 ####"
1611 echo '#### cmp output ####'
1617 testsuccesswithglobalerror
() {
1622 if [ "$1" = '--nomsg' ]; then
1625 msgtest
'Test for successful execution of' "$*"
1627 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output"
1628 if "$@" >"${OUTPUT}" 2>&1; then
1629 if expr match
"$1" '^apt.*' >/dev
/null
; then
1630 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1631 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1632 elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1633 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1634 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1635 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1638 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1641 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1643 elif [ "$TYPE" = 'testsuccesswithnotice' ]; then
1644 if grep -q -E "^N: " "$OUTPUT"; then
1647 msgfailoutput
'successful run, but output had no notices' "$OUTPUT" "$@"
1657 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1659 aptautotest
"$TYPE" "$@"
1662 testsuccesswithnotice
() {
1663 testsuccesswithglobalerror
'testsuccesswithnotice' 'WE' "$@"
1666 testsuccesswithglobalerror
'testsuccess' 'NWE' "$@"
1669 msggroup
'testwarning'
1670 if [ "$1" = '--nomsg' ]; then
1673 msgtest
'Test for successful execution with warnings of' "$*"
1675 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1676 if "$@" >"${OUTPUT}" 2>&1; then
1677 if expr match
"$1" '^apt.*' >/dev
/null
; then
1678 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1679 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1680 elif grep -q -E '^E: ' "$OUTPUT"; then
1681 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1682 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1683 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1692 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1694 aptautotest
'testwarning' "$@"
1698 msggroup
'testfailure'
1699 if [ "$1" = '--nomsg' ]; then
1702 msgtest
'Test for failure in execution of' "$*"
1704 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1705 if "$@" >"${OUTPUT}" 2>&1; then
1707 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1710 if expr match
"$1" '^apt.*' >/dev
/null
; then
1711 if [ "$1" = 'aptkey' ]; then
1712 if grep -q " Can't check signature:
1714 signature could not be verified" "$OUTPUT"; then
1717 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1720 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1721 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1722 elif grep -q -E '==ERROR' "$OUTPUT"; then
1723 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1724 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1725 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1734 aptautotest
'testfailure' "$@"
1738 testreturnstateequal
() {
1740 if [ "$STATE" = 'testsuccesswithglobalerror' ]; then
1744 msggroup
"${STATE}equal"
1745 if [ "$1" != '--nomsg' ]; then
1748 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1749 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1753 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1754 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1757 msggroup
"${STATE}equal"
1758 if [ "$2" != '--nomsg' ]; then
1762 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1766 "$STATE" --nomsg "$@"
1767 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1772 testsuccessequal
() {
1773 # we compare output, so we know perfectly well about N:
1774 testreturnstateequal
'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@"
1776 testwarningequal
() {
1777 testreturnstateequal
'testwarning' "$@"
1779 testfailureequal
() {
1780 testreturnstateequal
'testfailure' "$@"
1784 msggroup
'testfailuremsg'
1788 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1789 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1790 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1791 testoutputequal
"$COMPAREFILE" echo "$CMP"
1795 msggroup
'testwarningmsg'
1799 msgtest
'Check that the output of the previous warned command has expected' 'warnings'
1800 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
1801 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
1802 testoutputequal
"$COMPAREFILE" echo "$CMP"
1807 msggroup
'testfilestats'
1808 msgtest
"Test that file $1 has $2 $3" "$4"
1809 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1812 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1815 echo -n "stat(1) reports for $2: "
1816 stat
--format "$2" "$1" || true
1818 msgfailoutput
'' "$OUTPUT"
1822 testaccessrights
() {
1823 msggroup
'testaccessrights'
1824 testfilestats
"$1" '%a' '=' "$2"
1828 testwebserverlaststatuscode
() {
1829 msggroup
'testwebserverlaststatuscode'
1830 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1831 local STATUS
='downloaded/webserverstatus-statusfile.log'
1832 rm -f "$DOWNLOG" "$STATUS"
1833 msgtest
'Test last status code from the webserver was' "$1"
1834 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1837 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1839 if [ -n "$2" ]; then
1841 echo >&2 '#### Additionally provided output files contain:'
1844 echo >&2 '#### Download log of the status code:'
1847 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1852 createlistofkeys
() {
1855 while [ -n "$1" ]; do
1856 # gpg 2.1.something starts printing [SC] at some point
1857 if grep -q ' rsa2048/' "$OUTPUT" && grep -qF '[SC]' "$OUTPUT"; then
1859 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';;
1860 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [SC] [expired: 2013-07-13]';;
1861 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16 [SC]';;
1862 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19 [SC]';;
1863 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';;
1864 *) echo 'UNKNOWN KEY';;
1866 # gpg 2.1 has a slightly different output format
1867 elif grep -q ' rsa2048/' "$OUTPUT"; then
1869 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1870 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1871 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16';;
1872 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19';;
1873 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1874 *) echo 'UNKNOWN KEY';;
1878 *Joe
*|*Sixpack
*) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1879 *Rex
*|*Expired
*) echo 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1880 *Marvin
*|*Paranoid
*) echo 'pub 2048R/528144E2 2011-01-16';;
1881 oldarchive
) echo 'pub 1024R/F68C85A3 2013-12-19';;
1882 newarchive
) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1883 *) echo 'UNKNOWN KEY';;
1890 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output"
1891 if ! aptkey list
| grep '^pub' > "$OUTPUT"; then
1894 testfileequal
"$OUTPUT" "$(createlistofkeys "$OUTPUT" "$@")"
1898 echo "STOPPED execution. Press enter to continue"
1903 listcurrentlistsdirectory
() {
1905 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1906 stat
--format '%U:%G:%a:%n' "$line"
1908 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1909 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1913 forallsupportedcompressors
() {
1914 rm -f "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
1915 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
1916 if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi
1921 ### convenience hacks ###
1923 # creating some directories by hand is a tedious task, so make it look simple
1925 if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then
1926 # only the last directory created by mkdir is effected by the -m !
1927 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1928 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1929 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1930 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1931 if [ "$(id -u)" = '0' ]; then
1932 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1939 ### The following tests are run by most test methods automatically to check
1940 ### general things about commands executed without writing the test every time.
1946 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')"
1947 if command -v $AUTOTEST >/dev
/null
; then
1949 # save and restore the *.output files from other tests
1950 # as we might otherwise override them in these automatic tests
1951 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1952 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1953 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1954 $AUTOTEST "$TESTCALL" "$@"
1955 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1956 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1957 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1961 aptautotest_aptget_update
() {
1963 while [ -n "$2" ]; do
1964 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1967 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1968 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1969 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1970 # all copied files are properly chmodded
1971 local backupIFS
="$IFS"
1972 IFS
="$(printf "\n\b")"
1973 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1974 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1977 if [ "$TESTCALL" = 'testsuccess' ]; then
1978 # failure cases can retain partial files and such
1979 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
1982 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1983 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
1985 testaptautotestnodpkgwarning
() {
1987 while [ -n "$2" ]; do
1988 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
1989 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
1992 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1995 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
1996 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
1997 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
1998 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
1999 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
2000 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }