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}" "$@"; }
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 run
"$CMD" --args "$CMD" "$@"
221 date -u -d "@$(stat -c '%Y' "${TMPWORKINGDIRECTORY}/$1")" '+%a, %d %b %Y %H:%M:%S GMT'
224 grep "^${2:-Date}:" "$1" | cut
-d' ' -f 2- | sed -e 's#UTC#GMT#'
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"
260 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
261 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
264 TMPWORKINGDIRECTORY
="$(mktemp -d)"
265 addtrap
"cd /; rm -rf '$(escape_shell "$TMPWORKINGDIRECTORY")';"
266 if [ -n "$TMPDIR_ADD" ]; then
267 TMPWORKINGDIRECTORY
="${TMPWORKINGDIRECTORY}/${TMPDIR_ADD}"
268 mkdir -p "$TMPWORKINGDIRECTORY"
270 export TMPDIR
="$TMPWORKINGDIRECTORY"
272 msgninfo
"Preparing environment for ${0##*/} in ${TMPWORKINGDIRECTORY}…"
274 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
275 if [ "$(id -u)" = '0' ]; then
276 # relax permissions so that running as root with user switching works
278 chmod 711 "$TMPWORKINGDIRECTORY"
279 chown _apt
:root
"${TMPWORKINGDIRECTORY}/downloaded"
282 TESTDIRECTORY
="$(readlink -f "$(dirname $0)")"
283 # allow overriding the default BUILDDIR location
284 SOURCEDIRECTORY="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}"
285 BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}"
286 LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}"
287 METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}"
288 APTHELPERBINDIR="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}"
289 APTWEBSERVERBINDIR="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}"
290 APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}"
291 APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}"
292 test -x "${BUILDDIRECTORY}/apt
-get" || msgdie "You need to build tree first
"
295 cd "$TMPWORKINGDIRECTORY"
296 mkdir rootdir aptarchive keys
298 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
299 mkdir -p usr/bin var/cache var/lib var/log tmp
300 mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
301 touch var/lib/dpkg/available
303 ln -s "${METHODSDIR}" usr/lib/apt/methods
304 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
305 mkdir -p usr/lib/apt/solvers
306 ln -s "${BUILDDIRECTORY}/apt
-dump-solver" usr/lib/apt/solvers/dump
307 ln -s "${BUILDDIRECTORY}/apt
-internal-solver" usr/lib/apt/solvers/apt
308 echo "Dir
::Bin
::Solvers
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/solvers
\";" > etc/apt/apt.conf.d/externalsolver.conf
310 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
312 if [ -e "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" ]; then
313 ln -s "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" etc/apt/apt.conf.d/01autoremove
315 ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
318 local BASENAME="${0##*/}"
319 local PACKAGESFILE="Packages
-${BASENAME#*-}"
320 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
321 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
323 local SOURCESSFILE="Sources
-${BASENAME#*-}"
324 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
325 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
327 find "$TESTDIRECTORY" \( -name '*.pub' -o -name '*.sec' \) -exec cp '{}' keys/ \;
329 ln -s "${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub
" rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
331 echo "Dir
\"${TMPWORKINGDIRECTORY}/rootdir
\";" > aptconfig.conf
332 echo "Dir
::state
::status
\"${TMPWORKINGDIRECTORY}/rootdir
/var
/lib
/dpkg
/status
\";" >> aptconfig.conf
333 echo "APT
::Get
::Show
-User-Simulation-Note \"false
\";" >> aptconfig.conf
334 echo "Dir
::Bin
::Methods
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/methods
\";" >> aptconfig.conf
335 # either store apt-key were we can access it, even if we run it as a different user
336 #cp "${BUILDDIRECTORY}/apt
-key" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/"
337 #chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key"
338 #echo "Dir
::Bin
::apt
-key \"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key\";" >> aptconfig.conf
339 # destroys coverage reporting though, so we disable changing user for the calling gpgv
340 echo "Dir
::Bin
::apt
-key \"${BUILDDIRECTORY}/apt
-key\";" >> aptconfig.conf
341 if [ "$(id -u)" = '0' ]; then
342 echo 'Binary::gpgv::Debug::NoDropPrivs "true
";' >>aptconfig.conf
345 cat > "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
348 if [ -r '${TMPWORKINGDIRECTORY}/noopchroot.so' ]; then
349 if [ -n "\
$LD_LIBRARY_PATH" ]; then
350 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}:'"\
${LD_LIBRARY_PATH}"
352 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}'
354 if [ -n "\
$LD_PRELOAD" ]; then
355 export LD_PRELOAD="noopchroot.so \
${LD_PRELOAD}"
357 export LD_PRELOAD="noopchroot.so
"
361 cp "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
362 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
363 exec fakeroot '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
364 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
365 --force-not-root --force-bad-path "\$@
"
367 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg" <<EOF
368 exec fakeroot gdb --quiet -ex run '${DPKG:-dpkg}' --args '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
369 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
370 --force-not-root --force-bad-path "\$@
"
372 chmod +x "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
373 echo "Dir
::Bin
::dpkg
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
\";" > rootdir/etc/apt/apt.conf.d/99dpkg
376 if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
377 echo "DPKG
::options
:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
380 echo 'quiet::NoUpdate "true
";'
381 echo 'quiet::NoStatistic "true
";'
382 # too distracting for users, but helpful to detect changes
383 echo 'Acquire::Progress::Ignore::ShowErrorText "true
";'
384 echo 'Acquire::Progress::Diffpercent "true
";'
385 # in testcases, it can appear as if localhost has a rotation setup,
386 # hide this as we can't really deal with it properly
387 echo 'Acquire::Failure::ShowIP "false
";'
388 # fakeroot can't fake everything, so disabled in production but good for tests
389 echo 'APT::Sandbox::Verify "true
";'
392 cp "${TESTDIRECTORY}/apt.pem
" "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
393 if [ "$(id -u)" = '0' ]; then
394 chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
396 echo "Acquire
::https
::CaInfo
\"${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
\";" > rootdir/etc/apt/apt.conf.d/99https
397 echo "Apt
::Cmd
::Disable
-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
398 echo 'Acquire::Connect::AddrConfig "false
";' > rootdir/etc/apt/apt.conf.d/connect-addrconfig
400 configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
401 confighashes 'SHA256' # these are tests, not security best-practices
403 # create some files in /tmp and look at user/group to get what this means
404 TEST_DEFAULT_USER="$(id -un)"
405 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
406 TEST_DEFAULT_GROUP='root'
408 TEST_DEFAULT_GROUP="$(id -gn)"
411 # cleanup the environment a bit
412 # prefer our apt binaries over the system apt binaries
413 export PATH="${BUILDDIRECTORY}:${PATH}:/usr
/local
/sbin
:/usr
/sbin
:/sbin
"
414 export LC_ALL=C.UTF-8
415 unset LANGUAGE APT_CONFIG
416 unset GREP_OPTIONS DEB_BUILD_PROFILES
417 unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy
419 # If gpgv supports --weak-digest, pass it to make sure we can disable SHA1
420 if aptkey verify --weak-digest SHA1 --help 2>/dev/null >/dev/null; then
421 echo 'Acquire::gpgv::Options { "--weak-digest"; "sha1
"; };' > rootdir/etc/apt/apt.conf.d/no-sha1
428 if [ "$1" = "native
" -o -z "$1" ]; then
429 eval `aptconfig shell ARCH APT::Architecture`
430 if [ -n "$ARCH" ]; then
433 dpkg --print-architecture
441 aptconfig dump --no-empty --format '%v%n' APT::Architecture APT::Architectures | sort -u | tr '\n' ' '
444 getarchitecturesfromcommalist() {
445 echo "$1" | sed -e 's#,#\n#g' | sed -e "s
/^native\$
/$(getarchitecture 'native')/"
448 configarchitecture() {
450 echo "APT
::Architecture
\"$(getarchitecture $1)\";"
451 while [ -n "$1" ]; do
452 echo "APT
::Architectures
:: \"$(getarchitecture $1)\";"
455 } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
460 if [ ! -e rootdir/var/lib/dpkg/status ]; then
461 local BASENAME="${0##*/}"
462 local STATUSFILE="status
-${BASENAME#*-}"
463 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
464 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
466 echo -n > rootdir/var/lib/dpkg/status
469 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
470 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
471 local ARCHS="$(getarchitectures)"
472 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
473 DPKGARCH="$(dpkg --print-architecture)"
474 for ARCH in ${ARCHS}; do
475 if [ "${ARCH}" != "${DPKGARCH}" ]; then
476 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
477 # old-style used e.g. in Ubuntu-P – and as it seems travis
478 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
479 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
483 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
484 # dpkg doesn't really check the version as long as it is fully installed,
485 # but just to be sure we choose one above the required version
486 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
492 configdpkgnoopchroot() {
493 # create a library to noop chroot() and rewrite maintainer script executions
494 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
495 # chroot directory dpkg could chroot into to execute the maintainer scripts
496 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
497 cat > noopchroot.c << EOF
504 static char * chrootdir = NULL;
506 int chroot(const char *path) {
507 printf("WARNING
: CHROOTing to
%s was ignored
!\n", path);
509 chrootdir = strdup(path);
512 int execvp(const char *file, char *const argv[]) {
513 static int (*func_execvp) (const char *, char * const []) = NULL;
514 if (func_execvp == NULL)
515 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
");
516 if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0)
517 return func_execvp(file, argv);
518 printf("REWRITE execvp call
%s into
%s
\n", file, chrootdir);
520 if (asprintf(&newfile, "%s
%s
", chrootdir, file) == -1) {
524 char const * const baseadmindir = "/var
/lib
/dpkg
";
526 if (asprintf(&admindir, "%s
%s
", chrootdir, baseadmindir) == -1) {
530 setenv("DPKG_ADMINDIR
", admindir, 1);
531 return func_execvp(newfile, argv);
534 testempty --nomsg gcc -Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c -ldl
536 configcompression() {
537 local CMD='apthelper cat-file -C'
538 while [ -n "$1" ]; do
540 '.') printf ".
\t.
\tcat
\n";;
541 'gz') printf "gzip\tgz
\t$CMD $1\n";;
542 'bz2') printf "bzip2\tbz
2\t$CMD $1\n";;
543 *) printf "$1\t$1\t$CMD $1\n";;
546 done > "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
"
550 echo 'APT::FTPArchive {'
552 while [ -n "$1" ]; do
553 printf "$1" | tr 'a-z' 'A-Z'
554 printf "\t\"true
\";\n"
557 for h in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
558 printf "$h\t\"false
\";\n"
562 } >> "${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/ftparchive
-hashes.conf
"
567 COMPRESSOR_CMD="apthelper
cat-file -C $1"
569 gzip) COMPRESS='gz';;
570 bzip2) COMPRESS='bz2';;
572 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/00force
-compressor"
573 echo "Acquire
::CompressionTypes
::Order
{ \"${COMPRESS}\"; };
574 Dir
::Bin
::uncompressed
\"/does
/not
/exist
\";" > "$CONFFILE"
575 for COMP in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
576 if [ -z "$COMP" -o "$COMP" = '.' -o "$COMP" = "$COMPRESSOR" ]; then continue; fi
577 echo "Dir
::Bin
::${COMP} \"/does
/not
/exist
\";" >> "$CONFFILE"
578 echo "APT
::Compressor
::${COMP}::Name
\"${COMP}-disabled\";" >> "$CONFFILE"
582 setupsimplenativepackage() {
586 local RELEASE="${4:-unstable}"
587 local DEPENDENCIES="$5"
588 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
589 If you
find such a package installed on your system
,
590 something went horribly wrong
! They are autogenerated
591 und used only by testcases and serve no other purpose…
"}"
593 local SECTION
="${7:-others}"
595 if [ "$SECTION" = "${SECTION#*/}" ]; then
598 DISTSECTION
="${SECTION%/*}"
600 local BUILDDIR
=incoming
/${NAME}-${VERSION}
601 mkdir -p ${BUILDDIR}/debian
/source
603 echo "* most suckless software product ever" > FEATURES
604 test -e debian
/copyright
|| echo "Copyleft by Joe Sixpack $(date -u +%Y)" > debian
/copyright
605 test -e debian
/changelog
|| echo "$NAME ($VERSION) $RELEASE; urgency=low
609 -- Joe Sixpack <joe@example.org> $(date -u -R)" > debian
/changelog
610 test -e debian
/control
|| echo "Source: $NAME
613 Maintainer: Joe Sixpack <joe@example.org>
614 Build-Depends: debhelper (>= 7)
615 Standards-Version: 3.9.1
617 Package: $NAME" > debian
/control
618 if [ "$ARCH" = 'all' ]; then
619 echo "Architecture: all" >> debian
/control
621 echo "Architecture: any" >> debian
/control
623 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian
/control
624 echo "Description: $DESCRIPTION" >> debian
/control
626 test -e debian
/compat
|| echo "7" > debian
/compat
627 test -e debian
/source
/format
|| echo "3.0 (native)" > debian
/source
/format
628 test -e debian
/rules
|| cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny debian
/rules
632 buildsimplenativepackage
() {
635 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then
636 NM
="$(echo "$NAME" | cut -c 1-4)"
638 NM
="$(echo "$NAME" | cut -c 1)"
642 local RELEASE
="${4:-unstable}"
643 local DEPENDENCIES
="$5"
644 local DESCRIPTION
="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
645 If you find such a package installed on your system,
646 something went horribly wrong! They are autogenerated
647 und used only by testcases and serve no other purpose…"}"
649 local SECTION="${7:-others}"
650 local PRIORITY="${8:-optional}"
652 local COMPRESS_TYPE="${10:-gzip}"
654 if [ "$SECTION" = "${SECTION#*/}" ]; then
657 DISTSECTION="${SECTION%/*}"
659 local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming
/${NAME}-${VERSION}"
661 msgtest "Build
source package
in version
${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
662 mkdir -p "$BUILDDIR/debian
/source"
663 echo "* most suckless software product ever
" > "${BUILDDIR}/FEATURES
"
665 echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}"
667 echo "Copyleft by Joe Sixpack
$(date -u +%Y)" > "${BUILDDIR}/debian
/copyright
"
668 echo "$NAME ($VERSION) $RELEASE; urgency
=low
672 -- Joe Sixpack
<joe@example.org
> $(date -u -R)" > "${BUILDDIR}/debian
/changelog
"
676 Maintainer
: Joe Sixpack
<joe@example.org
>
677 Standards
-Version: 3.9.3"
678 if [ "$SECTION" != '<none>' ]; then
679 echo "Section
: $SECTION"
681 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
682 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
686 if [ "$ARCH" = 'all' ]; then
687 echo "Architecture
: all
"
689 echo "Architecture
: any
"
691 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
692 test -z "$DEPS" || echo "$DEPS"
693 echo "Description
: $DESCRIPTION"
694 } > "${BUILDDIR}/debian
/control
"
696 echo '3.0 (native)' > "${BUILDDIR}/debian
/source
/format
"
698 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
700 sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
" \
702 echo "pool
/${SRC}" >> "${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
"
703 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
704 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
705 # adv --yes --default-key 'Joe Sixpack' \
706 # --clearsign -o "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
707 # mv "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
711 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
712 msgtest "Build binary package
for ${RELEASE} in ${SECTION}" "$NAME"
713 rm -rf "${BUILDDIR}/debian
/tmp
"
714 mkdir -p "${BUILDDIR}/debian
/tmp
/DEBIAN
" "${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}" "${BUILDDIR}/debian
/tmp
/usr
/bin
"
715 cp "${BUILDDIR}/debian
/copyright
" "${BUILDDIR}/debian
/changelog
" "${BUILDDIR}/FEATURES
" "${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}"
716 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}"
717 if [ -n "$FILE_TREE" ]; then
718 cp -ar "$FILE_TREE" "${BUILDDIR}/debian
/tmp
"
721 (cd "${BUILDDIR}"; dpkg-gencontrol -DArchitecture=$arch)
722 (cd "${BUILDDIR}/debian
/tmp
"; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
723 local LOG="${BUILDDIR}/..
/${NAME}_
${VERSION}_
${arch}.dpkg
-deb.log
"
724 # ensure the right permissions as dpkg-deb insists
725 chmod 755 "${BUILDDIR}/debian
/tmp
/DEBIAN
"
726 testsuccess --nomsg dpkg-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian
/tmp
" "${BUILDDIR}/..
"
727 echo "pool
/${NAME}_
${VERSION}_
${arch}.deb
" >> "${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
"
730 local CHANGEPATH="${BUILDDIR}/..
/${DISTSECTION}/${NM}/${NAME}/${NAME}_
${VERSION}"
731 mkdir -p "$CHANGEPATH"
732 cp "${BUILDDIR}/debian
/changelog
" "$CHANGEPATH"
741 local ARCH=$(getarchitecture $4)
742 local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
743 local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
744 msgtest "Build package
for ${RELEASE} in ${SECTION}" "$PKGNAME"
746 if [ "$ARCH" = "all
" ]; then
747 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
749 testsuccess --nomsg dpkg-buildpackage -uc -us -a$ARCH
750 cp "${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
" "$BUILDLOG"
751 local PKGS="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
752 local SRCS="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
755 echo "pool
/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
"
758 echo "pool
/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
"
763 if [ -d incoming ]; then
764 buildaptarchivefromincoming "$@
"
766 buildaptarchivefromfiles "$@
"
770 createaptftparchiveconfig() {
771 local COMPRESSORS="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
772 local COMPRESSORS="${COMPRESSORS%* }"
773 local ARCHS="$(getarchitectures)"
774 cat > ftparchive.conf <<EOF
776 ArchiveDir "$(readlink -f .)";
777 CacheDir "$(readlink -f ..)";
778 FileListDir "$(readlink -f pool/)";
781 Packages::Compress "$COMPRESSORS";
782 Sources::Compress "$COMPRESSORS";
783 Contents::Compress "$COMPRESSORS";
784 Translation::Compress "$COMPRESSORS";
785 LongDescription "false
";
789 SrcDirectory "pool
/";
792 for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
795 Architectures "$ARCHS all
source";
796 FileList "${DIST}.\
$(SECTION).pkglist
";
797 SourceFileList "${DIST}.\
$(SECTION).srclist
";
798 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
801 done >> ftparchive.conf
804 buildaptftparchivedirectorystructure() {
805 local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
806 for DIST in $DISTS; do
807 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
808 for SECTION in $SECTIONS; do
809 local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
810 for ARCH in $ARCHS; do
811 mkdir -p "dists
/${DIST}/${SECTION}/binary
-${ARCH}"
813 mkdir -p "dists
/${DIST}/${SECTION}/source"
814 mkdir -p "dists
/${DIST}/${SECTION}/i18n
"
824 local DEPENDENCIES="$5"
825 local PRIORITY="${6:-optional}"
826 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
827 If you
find such a package installed on your system
,
828 something went horribly wrong
! They are autogenerated
829 und used only by testcases and serve no other purpose…
"}"
831 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
832 if [ "$RELEASE" = 'installed' ]; then
833 insertinstalledpackage
"$2" "$3" "$4" "$5" "$6" "$7"
836 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
837 if [ "$arch" = 'none' ]; then
838 ARCHS
="$(getarchitectures)"
842 for BUILDARCH
in $ARCHS; do
843 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
850 Maintainer: Joe Sixpack <joe@example.org>"
851 test "$arch" = 'none' || echo "Architecture: $arch"
852 echo "Version: $VERSION
853 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb"
854 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES"
855 echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)"
856 echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
858 } >> "${PPATH}/Packages"
861 mkdir -p "aptarchive/dists/${RELEASE}/main/source" "aptarchive/dists/${RELEASE}/main/i18n"
862 touch "aptarchive/dists/${RELEASE}/main/source/Sources"
864 Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
865 Description-en: $DESCRIPTION
866 " >> "aptarchive/dists/${RELEASE}/main/i18n/Translation-en"
875 local DEPENDENCIES
="$5"
876 local BINARY
="${6:-$NAME}"
878 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
879 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
881 local FILE
="${SPATH}/Sources"
882 local DSCFILE
="${NAME}_${VERSION}.dsc"
883 local TARFILE
="${NAME}_${VERSION}.tar.gz"
887 Maintainer: Joe Sixpack <joe@example.org>
888 Architecture: $ARCH" >> $FILE
889 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
891 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
892 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
894 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
895 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
900 insertinstalledpackage
() {
904 local DEPENDENCIES
="$4"
905 local PRIORITY
="${5:-optional}"
906 local STATUS
="${6:-install ok installed}"
907 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
908 If you find such a package installed on your system,
909 something went horribly wrong! They are autogenerated
910 und used only by testcases and serve no other purpose…"}"
912 local FILE='rootdir/var/lib/dpkg/status'
913 local INFO='rootdir/var/lib/dpkg/info'
914 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
920 Maintainer
: Joe Sixpack
<joe@example.org
>
921 Version
: $VERSION" >> "$FILE"
922 test "$arch" = 'none' || echo "Architecture
: $arch" >> "$FILE"
923 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
924 echo "Description
: $DESCRIPTION" >> "$FILE"
926 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
927 echo -n > "${INFO}/${NAME}:${arch}.list
"
929 echo -n > "${INFO}/${NAME}.list
"
935 buildaptarchivefromincoming() {
936 msginfo "Build APT archive
for ${CCMD}${0##*/}${CINFO} based on incoming packages…
"
938 [ -e pool ] || ln -s ../incoming pool
939 [ -e ftparchive.conf ] || createaptftparchiveconfig
940 [ -e dists ] || buildaptftparchivedirectorystructure
941 msgninfo "\tGenerate Packages
, Sources and Contents files…
"
942 testsuccess aptftparchive generate ftparchive.conf
945 generatereleasefiles "$@
"
948 buildaptarchivefromfiles() {
949 msginfo "Build APT archive
for ${CCMD}${0##*/}${CINFO} based on prebuild files…
"
950 local DIR='aptarchive'
951 if [ -d "${DIR}/dists
" ]; then DIR="${DIR}/dists
"; fi
952 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do
953 msgninfo "\t${line} file…
"
954 compressfile "$line" "$1"
957 generatereleasefiles "$@
"
961 cat "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
" | while read compressor extension command; do
962 if [ "$compressor" = '.' ]; then
968 cat "$1" | $command > "${1}.
${extension}"
970 touch -d "$2" "${1}.
${extension}"
975 # can be overridden by testcases for their pleasure
976 getcodenamefromsuite() {
978 unstable) echo 'sid';;
982 getreleaseversionfromsuite() { true; }
983 getlabelfromsuite() { true; }
984 getoriginfromsuite() { true; }
985 getarchitecturesfromreleasefile() { echo "all
$(getarchitectures)"; }
987 aptftparchiverelease() {
988 aptftparchive -qq release "$@
" | sed -e '/0 Release$/ d' # remove the self reference
990 generatereleasefiles() {
991 # $1 is the Date header and $2 is the ValidUntil header to be set
992 # both should be given in notation date/touch can understand
994 local VALIDUNTIL="$2"
995 if [ -e aptarchive/dists ]; then
996 msgninfo "\tGenerate Release files
for dists…
"
997 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
998 local ARCHITECTURES="$(getarchitecturesfromreleasefile "$dir")"
999 local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
1000 local CODENAME="$(getcodenamefromsuite $SUITE)"
1001 local VERSION="$(getreleaseversionfromsuite $SUITE)"
1002 local LABEL="$(getlabelfromsuite $SUITE)"
1003 local ORIGIN="$(getoriginfromsuite $SUITE)"
1004 aptftparchiverelease "$dir" \
1005 -o APT::FTPArchive::Release::Suite="${SUITE}" \
1006 -o APT::FTPArchive::Release::Codename="${CODENAME}" \
1007 -o APT::FTPArchive::Release::Architectures="${ARCHITECTURES}" \
1008 -o APT::FTPArchive::Release::Label="${LABEL}" \
1009 -o APT::FTPArchive::Release::Origin="${ORIGIN}" \
1010 -o APT::FTPArchive::Release::Version="${VERSION}" \
1012 if [ "$SUITE" = "experimental
" -o "$SUITE" = "experimental2
" ]; then
1013 sed -i '/^Date: / a\
1014 NotAutomatic: yes' "$dir/Release
"
1018 msgninfo "\tGenerate Release files
for flat…
"
1019 aptftparchiverelease ./aptarchive > aptarchive/Release
1021 if [ -n "$DATE" -a "$DATE" != "now
" ]; then
1022 for release in $(find ./aptarchive -name 'Release'); do
1023 sed -i "s
/^Date
: .
*$
/Date
: $(date -u -d "$DATE" '+%a, %d %b %Y %H:%M:%S %Z')/" "$release"
1024 touch -d "$DATE" "$release"
1027 if [ -n "$VALIDUNTIL" ]; then
1028 sed -i "/^Date
: / a\
1029 Valid
-Until: $(date -u -d "$VALIDUNTIL" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release')
1034 setupdistsaptarchive() {
1035 local APTARCHIVE="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1036 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
1037 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
1038 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1039 SECTIONS=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1040 msgninfo "\tadd deb and deb
-src sources.list lines
for ${CCMD}${DISTS} ${SECTIONS}${CINFO}…
"
1041 echo "deb
file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
"
1042 echo "deb
-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
"
1047 setupflataptarchive() {
1048 local APTARCHIVE="$(readlink -f ./aptarchive)"
1049 local APTARCHIVEURI="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1050 if [ -f "${APTARCHIVE}/Packages
" ]; then
1051 msgninfo "\tadd deb sources.list line…
"
1052 echo "deb
file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1055 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1057 if [ -f "${APTARCHIVE}/Sources
" ]; then
1058 msgninfo "\tadd deb
-src sources.list line…
"
1059 echo "deb
-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1062 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1068 if [ "$1" = '--no-update' ]; then
1072 buildaptarchive "$@
"
1073 if [ -e aptarchive/dists ]; then
1074 setupdistsaptarchive
1078 signreleasefiles 'Joe Sixpack'
1079 if [ "1" != "$NOUPDATE" ]; then
1080 testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true
1084 signreleasefiles() {
1085 local SIGNER="${1:-Joe Sixpack}"
1086 local REPODIR="${2:-aptarchive}"
1087 local KEY="keys
/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
1088 local GPG="aptkey
--quiet --keyring ${KEY}.pub
--secret-keyring ${KEY}.sec
--readonly adv
--batch --yes --digest-algo ${APT_TESTS_DIGEST_ALGO:-SHA512}"
1089 msgninfo "\tSign archive with
$SIGNER key
$KEY…
"
1090 local REXKEY='keys/rexexpired'
1091 local SECEXPIREBAK="${REXKEY}.sec.bak
"
1092 local PUBEXPIREBAK="${REXKEY}.pub.bak
"
1093 if [ "${SIGNER}" = 'Rex Expired' ]; then
1094 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1095 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1096 # therefore we 'temporary' make the key not expired and restore a backup after signing
1097 cp "${REXKEY}.sec
" "$SECEXPIREBAK"
1098 cp "${REXKEY}.pub
" "$PUBEXPIREBAK"
1099 local SECUNEXPIRED="${REXKEY}.sec.unexpired
"
1100 local PUBUNEXPIRED="${REXKEY}.pub.unexpired
"
1101 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1102 cp "$SECUNEXPIRED" "${REXKEY}.sec
"
1103 cp "$PUBUNEXPIRED" "${REXKEY}.pub
"
1105 if ! printf "expire
\n1w
\nsave
\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then
1109 cp "${REXKEY}.sec
" "$SECUNEXPIRED"
1110 cp "${REXKEY}.pub
" "$PUBUNEXPIRED"
1113 for RELEASE in $(find "${REPODIR}/" -name Release); do
1114 testsuccess $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output "${RELEASE}.gpg
" "${RELEASE}"
1115 local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
1116 testsuccess $GPG --default-key "$SIGNER" --clearsign --output "$INRELEASE" "$RELEASE"
1117 # we might have set a specific date for the Release file, so copy it
1118 touch -d "$(stat --format "%y" ${RELEASE})" "${RELEASE}.gpg
" "${INRELEASE}"
1120 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1121 mv -f "$SECEXPIREBAK" "${REXKEY}.sec
"
1122 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub
"
1127 redatereleasefiles() {
1128 local DATE="$(date -u -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
1129 for release in $(find aptarchive/ -name 'Release'); do
1130 sed -i "s
/^Date
: .
*$
/Date
: ${DATE}/" "$release"
1131 touch -d "$DATE" "$release"
1133 signreleasefiles "${2:-Joe Sixpack}"
1137 local WEBSERVER="${3:-http://localhost:${APTHTTPPORT}}"
1139 if [ "$1" = '--no-check' ]; then
1143 local DOWNLOG='rootdir/tmp/download-testfile.log'
1144 local STATUS='downloaded/webserverconfig.status'
1145 rm -f "$STATUS" "$DOWNLOG"
1146 # very very basic URI encoding
1148 if [ -n "$2" ]; then
1149 msgtest "Set webserver config option
'${1}' to
" "$2"
1150 URI="${WEBSERVER}/_config
/set
/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1152 msgtest 'Clear webserver config option' "${1}"
1153 URI="${WEBSERVER}/_config
/clear
/$(echo "${1}" | sed -e 's/\//%2f/g')"
1155 if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then
1158 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir
/tmp
/webserverconfig.output
"
1159 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1160 msgfailoutput '' "$OUTPUT"
1162 $NOCHECK || testwebserverlaststatuscode '200'
1165 rewritesourceslist() {
1166 local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1167 local APTARCHIVE2="copy
://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1168 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1169 sed -i $LIST -e "s
#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
1170 -e "s#http://[^@]*@\?localhost:${APTHTTPPORT}/\?#${1}#" \
1171 -e "s#https://[^@]*@\?localhost:${APTHTTPSPORT}/\?#${1}#"
1175 # wait for up to 10s for a pid file to appear to avoid possible race
1176 # when a helper is started and dosn't write the PID quick enough
1179 for i
in $(seq 10); do
1180 if test -s "$PIDFILE"; then
1185 msgdie
"waiting for $PIDFILE failed"
1189 changetowebserver
() {
1191 if [ "$1" != '--no-rewrite' ]; then
1196 if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
1198 local LOG
="webserver.log"
1199 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1203 waitforpidfile aptwebserver.pid
1204 local PID
="$(cat aptwebserver.pid)"
1205 if [ -z "$PID" ]; then
1206 msgdie
'Could not fork aptwebserver successfully'
1208 addtrap
"kill $PID;"
1209 waitforpidfile aptwebserver.port
1210 APTHTTPPORT
="$(cat aptwebserver.port)"
1211 if [ -z "$APTHTTPPORT" ]; then
1212 msgdie
'Could not get port for aptwebserver successfully'
1216 msgdie
'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver'
1218 if [ "$REWRTE" != 'yes' ]; then
1219 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1223 changetohttpswebserver
() {
1224 if ! command -v stunnel4
>/dev
/null
2>&1; then
1225 msgdie
'You need to install stunnel4 for https testcases'
1227 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1228 changetowebserver
--no-rewrite "$@"
1230 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1231 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1236 connect = $APTHTTPPORT
1237 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1238 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1239 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1240 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1241 if [ -z "$PID" ]; then
1242 msgdie
'Could not fork stunnel4 successfully'
1244 addtrap
'prefix' "kill ${PID};"
1245 APTHTTPSPORT
="$(lsof -i -n | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1246 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1247 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1251 mkdir -p rootdir
/media
/cdrom
/.disk
1252 local CD
="$(readlink -f rootdir/media/cdrom)"
1253 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1254 acquire::cdrom::mount "${CD}";
1255 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1256 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1257 acquire::cdrom::autodetect 0;
1259 echo -n "$1" > "${CD}/.disk/info"
1260 if [ ! -d aptarchive
/dists
]; then
1261 msgdie
'Flat file archive cdroms can not be created currently'
1264 mv aptarchive
/dists
"$CD"
1265 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1266 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1267 # start with an unmounted disk
1268 mv "${CD}" "${CD}-unmounted"
1269 # we don't want the disk to be modifiable
1270 addtrap
'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;"
1271 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1275 local PROTO
="${1%%:*}"
1276 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1277 download
-file "$1" "$2" "$3" 2>&1 ; then
1280 # only if the file exists the download was successful
1281 if [ -r "$2" ]; then
1289 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1290 if [ -n "$DIFFTEXT" ]; then
1292 echo >&2 "$DIFFTEXT"
1300 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1301 local COMPAREFILE
="$1"
1303 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1306 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1307 cat "$COMPAREFILE" >>"${OUTPUT}"
1308 msgfailoutput
'' "$OUTPUT" "$@"
1313 msggroup
'testfileequal'
1314 local MSG
='Test for correctness of file'
1315 if [ "$1" = '--nomsg' ]; then
1321 if [ -n "$MSG" ]; then
1322 msgtest
"$MSG" "$FILE"
1324 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1325 if [ -z "$*" ]; then
1326 testoutputequal
"$FILE" echo -n ''
1328 testoutputequal
"$FILE" echo "$*"
1334 msggroup
'testempty'
1335 if [ "$1" = '--nomsg' ]; then
1338 msgtest
"Test for no output of" "$*"
1340 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1341 if "$@" >"$COMPAREFILE" 2>&1 && test ! -s "$COMPAREFILE"; then
1344 msgfailoutput
'' "$COMPAREFILE" "$@"
1346 aptautotest
'testempty' "$@"
1350 msggroup
'testnotempty'
1351 msgtest
"Test for some output of" "$*"
1352 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
1353 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then
1356 msgfailoutput
'' "$COMPAREFILE" "$@"
1358 aptautotest
'testnotempty' "$@"
1363 msggroup
'testequal'
1364 local MSG
='Test of equality of'
1365 if [ "$1" = '--nomsg' ]; then
1370 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1371 echo "$1" > "$COMPAREFILE"
1374 if [ -n "$MSG" ]; then
1377 testoutputequal
"$COMPAREFILE" "$@"
1378 aptautotest
'testequal' "$@"
1383 msggroup
'testequalor2'
1384 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1385 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1386 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1387 echo "$1" > "$COMPAREFILE1"
1388 echo "$2" > "$COMPAREFILE2"
1390 msgtest
"Test for equality OR of" "$*"
1391 "$@" >"$COMPAREAGAINST" 2>&1 || true
1392 if checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null
2>&1 || \
1393 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null
2>&1
1397 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1398 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1399 checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1400 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1401 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1402 msgfailoutput
'' "$OUTPUT"
1404 aptautotest
'testequalor2' "$@"
1409 msggroup
'testshowvirtual'
1410 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1413 while [ -n "$1" ]; do
1415 N: Can't select versions from package '$1' as it is purely virtual"
1416 PACKAGE
="${PACKAGE} $1"
1419 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1421 N: No packages found"
1422 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1423 local ARCH
="$(getarchitecture 'native')"
1424 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1425 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1426 testoutputequal
"$COMPAREFILE" aptcache show
"$PACKAGE"
1431 msggroup
'testnopackage'
1432 msgtest
"Test for non-existent packages" "apt-cache show $*"
1433 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1434 if [ -n "$SHOWPKG" ]; then
1435 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1436 echo "$SHOWPKG" >"$OUTPUT"
1437 msgfailoutput
'' "$OUTPUT"
1443 testnosrcpackage
() {
1444 msggroup
'testnosrcpackage'
1445 msgtest
"Test for non-existent source packages" "apt-cache showsrc $*"
1446 local SHOWPKG
="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')"
1447 if [ -n "$SHOWPKG" ]; then
1448 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output"
1449 echo "$SHOWPKG" >"$OUTPUT"
1450 msgfailoutput
'' "$OUTPUT"
1458 msggroup
'testdpkgstatus'
1462 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1463 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1464 if [ "$PKGS" != $NR ]; then
1465 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1466 echo "$PKGS" >"$OUTPUT"
1467 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1468 msgfailoutput
'' "$OUTPUT"
1475 testdpkginstalled
() {
1476 msggroup
'testdpkginstalled'
1477 testdpkgstatus
'ii' "$#" "$@"
1481 testdpkgnotinstalled
() {
1482 msggroup
'testdpkgnotinstalled'
1483 testdpkgstatus
'ii' '0' "$@"
1488 msggroup
'testmarkedauto'
1489 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1490 if [ -n "$1" ]; then
1491 msgtest
'Test for correctly marked as auto-installed' "$*"
1492 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1494 msgtest
'Test for correctly marked as auto-installed' 'no package'
1495 echo -n > "$COMPAREFILE"
1497 testoutputequal
"$COMPAREFILE" aptmark showauto
1500 testmarkedmanual
() {
1501 msggroup
'testmarkedmanual'
1502 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1503 if [ -n "$1" ]; then
1504 msgtest
'Test for correctly marked as manually installed' "$*"
1505 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1507 msgtest
'Test for correctly marked as manually installed' 'no package'
1508 echo -n > "$COMPAREFILE"
1510 testoutputequal
"$COMPAREFILE" aptmark showmanual
1515 if [ "${1##*.}" = 'deb' ]; then
1516 stat
>&2 "$1" || true
1517 file >&2 "$1" || true
1519 cat >&2 "$1" || true
1523 msgreportheader
'msgfailoutput'
1527 if [ "$1" = 'grep' ]; then
1529 while [ -n "$2" ]; do shift; done
1530 echo "#### Complete file: $1 ####"
1532 echo '#### grep output ####'
1533 elif [ "$1" = 'test' ]; then
1535 # doesn't support ! or non-file flags
1536 msgfailoutputstatfile
() {
1537 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1538 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1539 echo "#### stat(2) of file: $2 ####"
1541 if test -d "$2"; then
1542 echo "#### The directory contains: $2 ####"
1544 elif test -e "$2"; then
1545 echo "#### Complete file: $2 ####"
1550 msgfailoutputstatfile
"$2" "$3"
1551 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1553 msgfailoutputstatfile
"$2" "$3"
1555 echo '#### test output ####'
1556 elif [ "$1" = 'cmp' ]; then
1558 while [ -n "$2" ]; do
1559 echo "#### Complete file: $2 ####"
1563 echo '#### cmp output ####'
1569 testsuccesswithglobalerror
() {
1574 if [ "$1" = '--nomsg' ]; then
1577 msgtest
'Test for successful execution of' "$*"
1579 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output"
1580 if "$@" >"${OUTPUT}" 2>&1; then
1581 if expr match
"$1" '^apt.*' >/dev
/null
; then
1582 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1583 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1584 elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1585 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1586 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1587 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1590 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1593 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1595 elif [ "$TYPE" = 'testsuccesswithnotice' ]; then
1596 if grep -q -E "^N: " "$OUTPUT"; then
1599 msgfailoutput
'successful run, but output had no notices' "$OUTPUT" "$@"
1609 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1611 aptautotest
"$TYPE" "$@"
1614 testsuccesswithnotice
() {
1615 testsuccesswithglobalerror
'testsuccesswithnotice' 'WE' "$@"
1618 testsuccesswithglobalerror
'testsuccess' 'NWE' "$@"
1621 msggroup
'testwarning'
1622 if [ "$1" = '--nomsg' ]; then
1625 msgtest
'Test for successful execution with warnings of' "$*"
1627 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.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 -q -E '^E: ' "$OUTPUT"; then
1633 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1634 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1635 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1644 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1646 aptautotest
'testwarning' "$@"
1650 msggroup
'testfailure'
1651 if [ "$1" = '--nomsg' ]; then
1654 msgtest
'Test for failure in execution of' "$*"
1656 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1657 if "$@" >"${OUTPUT}" 2>&1; then
1659 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1662 if expr match
"$1" '^apt.*' >/dev
/null
; then
1663 if [ "$1" = 'aptkey' ]; then
1664 if grep -q -E " Can't check signature: " "$OUTPUT" || \
1665 grep -q -E " BAD signature from " "$OUTPUT"; then
1668 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1671 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1672 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1673 elif grep -q -E '==ERROR' "$OUTPUT"; then
1674 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1675 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1676 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1685 aptautotest
'testfailure' "$@"
1689 testreturnstateequal
() {
1691 if [ "$STATE" = 'testsuccesswithglobalerror' ]; then
1695 msggroup
"${STATE}equal"
1696 if [ "$1" != '--nomsg' ]; then
1699 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1700 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1704 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1705 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1708 msggroup
"${STATE}equal"
1709 if [ "$2" != '--nomsg' ]; then
1713 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1717 "$STATE" --nomsg "$@"
1718 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1723 testsuccessequal
() {
1724 # we compare output, so we know perfectly well about N:
1725 testreturnstateequal
'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@"
1727 testwarningequal
() {
1728 testreturnstateequal
'testwarning' "$@"
1730 testfailureequal
() {
1731 testreturnstateequal
'testfailure' "$@"
1735 msggroup
'testfailuremsg'
1739 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1740 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1741 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1742 testoutputequal
"$COMPAREFILE" echo "$CMP"
1746 msggroup
'testwarningmsg'
1750 msgtest
'Check that the output of the previous warned command has expected' 'warnings'
1751 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
1752 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
1753 testoutputequal
"$COMPAREFILE" echo "$CMP"
1758 msggroup
'testfilestats'
1759 msgtest
"Test that file $1 has $2 $3" "$4"
1760 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1763 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1766 echo -n "stat(1) reports for $2: "
1767 stat
--format "$2" "$1" || true
1769 msgfailoutput
'' "$OUTPUT"
1773 testaccessrights
() {
1774 msggroup
'testaccessrights'
1775 testfilestats
"$1" '%a' '=' "$2"
1779 testwebserverlaststatuscode
() {
1780 msggroup
'testwebserverlaststatuscode'
1781 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1782 local STATUS
='downloaded/webserverstatus-statusfile.log'
1783 rm -f "$DOWNLOG" "$STATUS"
1784 msgtest
'Test last status code from the webserver was' "$1"
1785 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1788 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1790 if [ -n "$2" ]; then
1792 echo >&2 '#### Additionally provided output files contain:'
1795 echo >&2 '#### Download log of the status code:'
1798 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1803 createlistofkeys
() {
1806 while [ -n "$1" ]; do
1807 # gpg 2.1.something starts printing [SC] at some point
1808 if grep -q ' rsa2048/' "$OUTPUT" && grep -qF '[SC]' "$OUTPUT"; then
1810 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';;
1811 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [SC] [expired: 2013-07-13]';;
1812 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16 [SC]';;
1813 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19 [SC]';;
1814 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';;
1815 *) echo 'UNKNOWN KEY';;
1817 # gpg 2.1 has a slightly different output format
1818 elif grep -q ' rsa2048/' "$OUTPUT"; then
1820 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1821 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1822 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16';;
1823 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19';;
1824 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1825 *) echo 'UNKNOWN KEY';;
1829 *Joe
*|*Sixpack
*) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1830 *Rex
*|*Expired
*) echo 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1831 *Marvin
*|*Paranoid
*) echo 'pub 2048R/528144E2 2011-01-16';;
1832 oldarchive
) echo 'pub 1024R/F68C85A3 2013-12-19';;
1833 newarchive
) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1834 *) echo 'UNKNOWN KEY';;
1841 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output"
1842 if ! aptkey list
| grep '^pub' > "$OUTPUT"; then
1845 testfileequal
"$OUTPUT" "$(createlistofkeys "$OUTPUT" "$@")"
1849 echo "STOPPED execution. Press enter to continue"
1854 listcurrentlistsdirectory
() {
1856 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1857 stat
--format '%U:%G:%a:%n' "$line"
1859 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1860 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1864 forallsupportedcompressors
() {
1865 rm -f "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
1866 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
1867 if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi
1872 ### convenience hacks ###
1874 # creating some directories by hand is a tedious task, so make it look simple
1876 if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then
1877 # only the last directory created by mkdir is effected by the -m !
1878 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1879 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1880 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1881 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1882 if [ "$(id -u)" = '0' ]; then
1883 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1890 ### The following tests are run by most test methods automatically to check
1891 ### general things about commands executed without writing the test every time.
1897 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')"
1898 if command -v $AUTOTEST >/dev
/null
; then
1900 # save and restore the *.output files from other tests
1901 # as we might otherwise override them in these automatic tests
1902 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1903 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1904 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1905 $AUTOTEST "$TESTCALL" "$@"
1906 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1907 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1908 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1912 aptautotest_aptget_update
() {
1914 while [ -n "$2" ]; do
1915 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1918 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1919 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1920 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1921 # all copied files are properly chmodded
1922 local backupIFS
="$IFS"
1923 IFS
="$(printf "\n\b")"
1924 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1925 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1928 if [ "$TESTCALL" = 'testsuccess' ]; then
1929 # failure cases can retain partial files and such
1930 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
1933 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1934 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
1936 testaptautotestnodpkgwarning
() {
1938 while [ -n "$2" ]; do
1939 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
1940 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
1943 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1946 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
1947 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
1948 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
1949 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
1950 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
1951 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }