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 aptconfig
() { runapt apt
-config "$@"; }
179 aptcache
() { runapt apt
-cache "$@"; }
180 aptcdrom
() { runapt apt
-cdrom "$@"; }
181 aptget
() { runapt apt
-get "$@"; }
182 aptftparchive
() { runapt apt
-ftparchive "$@"; }
183 aptkey
() { runapt apt
-key "$@"; }
184 aptmark
() { runapt apt
-mark "$@"; }
185 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; }
186 apt
() { runapt apt
"$@"; }
187 apthelper
() { runapt
"${APTHELPERBINDIR}/apt-helper" "$@"; }
188 aptwebserver
() { runapt
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
189 aptitude
() { runapt aptitude
"$@"; }
190 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; }
191 aptinternalsolver
() { runapt
"${APTINTERNALSOLVER}" "$@"; }
192 aptdumpsolver
() { runapt
"${APTDUMPSOLVER}" "$@"; }
195 "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@"
197 dpkgcheckbuilddeps
() {
198 command dpkg
-checkbuilddeps --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" "$@"
203 aptget
) CMD
="apt-get";;
204 aptcache
) CMD
="apt-cache";;
205 aptcdrom
) CMD
="apt-cdrom";;
206 aptconfig
) CMD
="apt-config";;
207 aptmark
) CMD
="apt-mark";;
208 apthelper
) CMD
="apt-helper";;
209 aptftparchive
) CMD
="apt-ftparchive";;
210 dpkg
) shift; runapt
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" "$@"; return;;
214 if [ "${CMD##*/}" = "$CMD" ]; then
215 CMD
="${BUILDDIRECTORY}/${CMD}"
217 runapt
command gdb
--quiet -ex run
"$CMD" --args "$CMD" "$@"
221 # error if we about to overflow, but ...
222 # "255 failures ought to be enough for everybody"
223 if [ $EXIT_CODE -gt 255 ]; then
224 msgdie
"Total failure count $EXIT_CODE too big"
226 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
229 shellsetedetector
() {
231 if [ "$exit_status" != '0' ]; then
232 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
233 if [ "$EXIT_CODE" = '0' ]; then
234 EXIT_CODE
="$exit_status"
240 if [ "$1" = 'prefix' ]; then
241 CURRENTTRAP
="$2 $CURRENTTRAP"
243 CURRENTTRAP
="$CURRENTTRAP $1"
245 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
249 echo "$@" | sed -e "s#'#'\"'\"'#g"
253 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
254 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
257 TMPWORKINGDIRECTORY
="$(mktemp -d)"
258 addtrap
"cd /; rm -rf '$(escape_shell "$TMPWORKINGDIRECTORY")';"
259 if [ -n "$TMPDIR_ADD" ]; then
260 TMPWORKINGDIRECTORY
="${TMPWORKINGDIRECTORY}/${TMPDIR_ADD}"
261 mkdir -p "$TMPWORKINGDIRECTORY"
263 export TMPDIR
="$TMPWORKINGDIRECTORY"
265 msgninfo
"Preparing environment for ${0##*/} in ${TMPWORKINGDIRECTORY}…"
267 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
268 if [ "$(id -u)" = '0' ]; then
269 # relax permissions so that running as root with user switching works
271 chmod 711 "$TMPWORKINGDIRECTORY"
272 chown _apt
:root
"${TMPWORKINGDIRECTORY}/downloaded"
275 TESTDIRECTORY
="$(readlink -f "$(dirname $0)")"
276 # allow overriding the default BUILDDIR location
277 SOURCEDIRECTORY="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}"
278 BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}"
279 LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}"
280 METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}"
281 APTHELPERBINDIR="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}"
282 APTWEBSERVERBINDIR="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}"
283 APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}"
284 APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}"
285 test -x "${BUILDDIRECTORY}/apt
-get" || msgdie "You need to build tree first
"
288 cd "$TMPWORKINGDIRECTORY"
289 mkdir rootdir aptarchive keys
291 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
292 mkdir -p usr/bin var/cache var/lib var/log tmp
293 mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
294 touch var/lib/dpkg/available
296 ln -s "${METHODSDIR}" usr/lib/apt/methods
297 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
298 mkdir -p usr/lib/apt/solvers
299 ln -s "${BUILDDIRECTORY}/apt
-dump-solver" usr/lib/apt/solvers/dump
300 ln -s "${BUILDDIRECTORY}/apt
-internal-solver" usr/lib/apt/solvers/apt
301 echo "Dir
::Bin
::Solvers
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/solvers
\";" > etc/apt/apt.conf.d/externalsolver.conf
303 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
305 if [ -e "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" ]; then
306 ln -s "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" etc/apt/apt.conf.d/01autoremove
308 ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
311 local BASENAME="${0##*/}"
312 local PACKAGESFILE="Packages
-${BASENAME#*-}"
313 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
314 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
316 local SOURCESSFILE="Sources
-${BASENAME#*-}"
317 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
318 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
320 find "$TESTDIRECTORY" \( -name '*.pub' -o -name '*.sec' \) -exec cp '{}' keys/ \;
322 ln -s "${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub
" rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
324 echo "Dir
\"${TMPWORKINGDIRECTORY}/rootdir
\";" > aptconfig.conf
325 echo "Dir
::state
::status
\"${TMPWORKINGDIRECTORY}/rootdir
/var
/lib
/dpkg
/status
\";" >> aptconfig.conf
326 echo "APT
::Get
::Show
-User-Simulation-Note \"false
\";" >> aptconfig.conf
327 echo "Dir
::Bin
::Methods
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/methods
\";" >> aptconfig.conf
328 # either store apt-key were we can access it, even if we run it as a different user
329 #cp "${BUILDDIRECTORY}/apt
-key" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/"
330 #chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key"
331 #echo "Dir
::Bin
::apt
-key \"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key\";" >> aptconfig.conf
332 # destroys coverage reporting though, so we disable changing user for the calling gpgv
333 echo "Dir
::Bin
::apt
-key \"${BUILDDIRECTORY}/apt
-key\";" >> aptconfig.conf
334 if [ "$(id -u)" = '0' ]; then
335 echo 'Binary::gpgv::Debug::NoDropPrivs "true
";' >>aptconfig.conf
338 cat > "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
341 if [ -r '${TMPWORKINGDIRECTORY}/noopchroot.so' ]; then
342 if [ -n "\
$LD_LIBRARY_PATH" ]; then
343 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}:'"\
${LD_LIBRARY_PATH}"
345 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}'
347 if [ -n "\
$LD_PRELOAD" ]; then
348 export LD_PRELOAD="noopchroot.so \
${LD_PRELOAD}"
350 export LD_PRELOAD="noopchroot.so
"
354 cp "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
355 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
356 exec fakeroot '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
357 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
358 --force-not-root --force-bad-path "\$@
"
360 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg" <<EOF
361 exec fakeroot gdb --quiet -ex run '${DPKG:-dpkg}' --args '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
362 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
363 --force-not-root --force-bad-path "\$@
"
365 chmod +x "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
366 echo "Dir
::Bin
::dpkg
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
\";" > rootdir/etc/apt/apt.conf.d/99dpkg
369 if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
370 echo "DPKG
::options
:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
373 echo 'quiet::NoUpdate "true
";'
374 echo 'quiet::NoStatistic "true
";'
375 # too distracting for users, but helpful to detect changes
376 echo 'Acquire::Progress::Ignore::ShowErrorText "true
";'
377 echo 'Acquire::Progress::Diffpercent "true
";'
378 # in testcases, it can appear as if localhost has a rotation setup,
379 # hide this as we can't really deal with it properly
380 echo 'Acquire::Failure::ShowIP "false
";'
381 # fakeroot can't fake everything, so disabled in production but good for tests
382 echo 'APT::Sandbox::Verify "true
";'
385 cp "${TESTDIRECTORY}/apt.pem
" "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
386 if [ "$(id -u)" = '0' ]; then
387 chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
389 echo "Acquire
::https
::CaInfo
\"${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
\";" > rootdir/etc/apt/apt.conf.d/99https
390 echo "Apt
::Cmd
::Disable
-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
391 echo 'Acquire::Connect::AddrConfig "false
";' > rootdir/etc/apt/apt.conf.d/connect-addrconfig
392 configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
393 confighashes 'SHA1' # these are tests, not security best-practices
395 # create some files in /tmp and look at user/group to get what this means
396 TEST_DEFAULT_USER="$(id -un)"
397 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
398 TEST_DEFAULT_GROUP='root'
400 TEST_DEFAULT_GROUP="$(id -gn)"
403 # cleanup the environment a bit
404 # prefer our apt binaries over the system apt binaries
405 export PATH="${BUILDDIRECTORY}:${PATH}:/usr
/local
/sbin
:/usr
/sbin
:/sbin
"
406 export LC_ALL=C.UTF-8
407 unset LANGUAGE APT_CONFIG
408 unset GREP_OPTIONS DEB_BUILD_PROFILES
409 unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy
414 if [ "$1" = "native
" -o -z "$1" ]; then
415 eval `aptconfig shell ARCH APT::Architecture`
416 if [ -n "$ARCH" ]; then
419 dpkg --print-architecture
427 aptconfig dump --no-empty --format '%v%n' APT::Architecture APT::Architectures | sort -u | tr '\n' ' '
430 getarchitecturesfromcommalist() {
431 echo "$1" | sed -e 's#,#\n#g' | sed -e "s
/^native\$
/$(getarchitecture 'native')/"
434 configarchitecture() {
436 echo "APT
::Architecture
\"$(getarchitecture $1)\";"
437 while [ -n "$1" ]; do
438 echo "APT
::Architectures
:: \"$(getarchitecture $1)\";"
441 } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
446 if [ ! -e rootdir/var/lib/dpkg/status ]; then
447 local BASENAME="${0##*/}"
448 local STATUSFILE="status
-${BASENAME#*-}"
449 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
450 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
452 echo -n > rootdir/var/lib/dpkg/status
455 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
456 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
457 local ARCHS="$(getarchitectures)"
458 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
459 DPKGARCH="$(dpkg --print-architecture)"
460 for ARCH in ${ARCHS}; do
461 if [ "${ARCH}" != "${DPKGARCH}" ]; then
462 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
463 # old-style used e.g. in Ubuntu-P – and as it seems travis
464 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
465 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
469 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
470 # dpkg doesn't really check the version as long as it is fully installed,
471 # but just to be sure we choose one above the required version
472 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
478 configdpkgnoopchroot() {
479 # create a library to noop chroot() and rewrite maintainer script executions
480 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
481 # chroot directory dpkg could chroot into to execute the maintainer scripts
482 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
483 cat > noopchroot.c << EOF
490 static char * chrootdir = NULL;
492 int chroot(const char *path) {
493 printf("WARNING
: CHROOTing to
%s was ignored
!\n", path);
495 chrootdir = strdup(path);
498 int execvp(const char *file, char *const argv[]) {
499 static int (*func_execvp) (const char *, char * const []) = NULL;
500 if (func_execvp == NULL)
501 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
");
502 if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0)
503 return func_execvp(file, argv);
504 printf("REWRITE execvp call
%s into
%s
\n", file, chrootdir);
506 if (asprintf(&newfile, "%s
%s
", chrootdir, file) == -1) {
510 char const * const baseadmindir = "/var
/lib
/dpkg
";
512 if (asprintf(&admindir, "%s
%s
", chrootdir, baseadmindir) == -1) {
516 setenv("DPKG_ADMINDIR
", admindir, 1);
517 return func_execvp(newfile, argv);
520 testsuccess --nomsg gcc -Wall -fPIC -shared -o noopchroot.so noopchroot.c -ldl
522 configcompression() {
523 local CMD='apthelper cat-file -C'
524 while [ -n "$1" ]; do
526 '.') printf ".
\t.
\tcat
\n";;
527 'gz') printf "gzip\tgz
\t$CMD $1\n";;
528 'bz2') printf "bzip2\tbz
2\t$CMD $1\n";;
529 *) printf "$1\t$1\t$CMD $1\n";;
532 done > "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
"
536 echo 'APT::FTPArchive {'
538 while [ -n "$1" ]; do
539 printf "$1" | tr 'a-z' 'A-Z'
540 printf "\t\"true
\";\n"
543 for h in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
544 printf "$h\t\"false
\";\n"
548 } >> "${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/ftparchive
-hashes.conf
"
553 COMPRESSOR_CMD="apthelper
cat-file -C $1"
555 gzip) COMPRESS='gz';;
556 bzip2) COMPRESS='bz2';;
558 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/00force
-compressor"
559 echo "Acquire
::CompressionTypes
::Order
{ \"${COMPRESS}\"; };
560 Dir
::Bin
::uncompressed
\"/does
/not
/exist
\";" > "$CONFFILE"
563 setupsimplenativepackage() {
567 local RELEASE="${4:-unstable}"
568 local DEPENDENCIES="$5"
569 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
570 If you
find such a package installed on your system
,
571 something went horribly wrong
! They are autogenerated
572 und used only by testcases and serve no other purpose…
"}"
574 local SECTION
="${7:-others}"
576 if [ "$SECTION" = "${SECTION#*/}" ]; then
579 DISTSECTION
="${SECTION%/*}"
581 local BUILDDIR
=incoming
/${NAME}-${VERSION}
582 mkdir -p ${BUILDDIR}/debian
/source
584 echo "* most suckless software product ever" > FEATURES
585 test -e debian
/copyright
|| echo "Copyleft by Joe Sixpack $(date +%Y)" > debian
/copyright
586 test -e debian
/changelog
|| echo "$NAME ($VERSION) $RELEASE; urgency=low
590 -- Joe Sixpack <joe@example.org> $(date -R)" > debian
/changelog
591 test -e debian
/control
|| echo "Source: $NAME
594 Maintainer: Joe Sixpack <joe@example.org>
595 Build-Depends: debhelper (>= 7)
596 Standards-Version: 3.9.1
598 Package: $NAME" > debian
/control
599 if [ "$ARCH" = 'all' ]; then
600 echo "Architecture: all" >> debian
/control
602 echo "Architecture: any" >> debian
/control
604 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian
/control
605 echo "Description: $DESCRIPTION" >> debian
/control
607 test -e debian
/compat
|| echo "7" > debian
/compat
608 test -e debian
/source
/format
|| echo "3.0 (native)" > debian
/source
/format
609 test -e debian
/rules
|| cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny debian
/rules
613 buildsimplenativepackage
() {
616 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then
617 NM
="$(echo "$NAME" | cut -c 1-4)"
619 NM
="$(echo "$NAME" | cut -c 1)"
623 local RELEASE
="${4:-unstable}"
624 local DEPENDENCIES
="$5"
625 local DESCRIPTION
="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
626 If you find such a package installed on your system,
627 something went horribly wrong! They are autogenerated
628 und used only by testcases and serve no other purpose…"}"
630 local SECTION="${7:-others}"
631 local PRIORITY="${8:-optional}"
633 local COMPRESS_TYPE="${10:-gzip}"
635 if [ "$SECTION" = "${SECTION#*/}" ]; then
638 DISTSECTION="${SECTION%/*}"
640 local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming
/${NAME}-${VERSION}"
642 msgtest "Build
source package
in version
${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
643 mkdir -p "$BUILDDIR/debian
/source"
644 echo "* most suckless software product ever
" > "${BUILDDIR}/FEATURES
"
646 echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}"
648 echo "Copyleft by Joe Sixpack
$(date +%Y)" > "${BUILDDIR}/debian
/copyright
"
649 echo "$NAME ($VERSION) $RELEASE; urgency
=low
653 -- Joe Sixpack
<joe@example.org
> $(date -R)" > "${BUILDDIR}/debian
/changelog
"
657 Maintainer
: Joe Sixpack
<joe@example.org
>
658 Standards
-Version: 3.9.3"
659 if [ "$SECTION" != '<none>' ]; then
660 echo "Section
: $SECTION"
662 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
663 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
667 if [ "$ARCH" = 'all' ]; then
668 echo "Architecture
: all
"
670 echo "Architecture
: any
"
672 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
673 test -z "$DEPS" || echo "$DEPS"
674 echo "Description
: $DESCRIPTION"
675 } > "${BUILDDIR}/debian
/control
"
677 echo '3.0 (native)' > "${BUILDDIR}/debian
/source
/format
"
679 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
681 sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
" \
683 echo "pool
/${SRC}" >> "${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
"
684 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
685 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
686 # adv --yes --default-key 'Joe Sixpack' \
687 # --clearsign -o "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
688 # mv "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
692 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
693 msgtest "Build binary package
for ${RELEASE} in ${SECTION}" "$NAME"
694 rm -rf "${BUILDDIR}/debian
/tmp
"
695 mkdir -p "${BUILDDIR}/debian
/tmp
/DEBIAN
" "${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}" "${BUILDDIR}/debian
/tmp
/usr
/bin
"
696 cp "${BUILDDIR}/debian
/copyright
" "${BUILDDIR}/debian
/changelog
" "${BUILDDIR}/FEATURES
" "${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}"
697 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}"
698 if [ -n "$FILE_TREE" ]; then
699 cp -ar "$FILE_TREE" "${BUILDDIR}/debian
/tmp
"
702 (cd "${BUILDDIR}"; dpkg-gencontrol -DArchitecture=$arch)
703 (cd "${BUILDDIR}/debian
/tmp
"; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
704 local LOG="${BUILDDIR}/..
/${NAME}_
${VERSION}_
${arch}.dpkg
-deb.log
"
705 # ensure the right permissions as dpkg-deb insists
706 chmod 755 "${BUILDDIR}/debian
/tmp
/DEBIAN
"
707 testsuccess --nomsg dpkg-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian
/tmp
" "${BUILDDIR}/..
"
708 echo "pool
/${NAME}_
${VERSION}_
${arch}.deb
" >> "${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
"
711 local CHANGEPATH="${BUILDDIR}/..
/${DISTSECTION}/${NM}/${NAME}/${NAME}_
${VERSION}"
712 mkdir -p "$CHANGEPATH"
713 cp "${BUILDDIR}/debian
/changelog
" "$CHANGEPATH"
722 local ARCH=$(getarchitecture $4)
723 local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
724 local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
725 msgtest "Build package
for ${RELEASE} in ${SECTION}" "$PKGNAME"
727 if [ "$ARCH" = "all
" ]; then
728 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
730 testsuccess --nomsg dpkg-buildpackage -uc -us -a$ARCH
731 cp "${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
" "$BUILDLOG"
732 local PKGS="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
733 local SRCS="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
736 echo "pool
/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
"
739 echo "pool
/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
"
744 if [ -d incoming ]; then
745 buildaptarchivefromincoming "$@
"
747 buildaptarchivefromfiles "$@
"
751 createaptftparchiveconfig() {
752 local COMPRESSORS="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
753 local COMPRESSORS="${COMPRESSORS%* }"
754 local ARCHS="$(getarchitectures)"
755 cat > ftparchive.conf <<EOF
757 ArchiveDir "$(readlink -f .)";
758 CacheDir "$(readlink -f ..)";
759 FileListDir "$(readlink -f pool/)";
762 Packages::Compress "$COMPRESSORS";
763 Sources::Compress "$COMPRESSORS";
764 Contents::Compress "$COMPRESSORS";
765 Translation::Compress "$COMPRESSORS";
766 LongDescription "false
";
770 SrcDirectory "pool
/";
773 for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
776 Architectures "$ARCHS all
source";
777 FileList "${DIST}.\
$(SECTION).pkglist
";
778 SourceFileList "${DIST}.\
$(SECTION).srclist
";
779 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
782 done >> ftparchive.conf
785 buildaptftparchivedirectorystructure() {
786 local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
787 for DIST in $DISTS; do
788 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
789 for SECTION in $SECTIONS; do
790 local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
791 for ARCH in $ARCHS; do
792 mkdir -p "dists
/${DIST}/${SECTION}/binary
-${ARCH}"
794 mkdir -p "dists
/${DIST}/${SECTION}/source"
795 mkdir -p "dists
/${DIST}/${SECTION}/i18n
"
805 local DEPENDENCIES="$5"
806 local PRIORITY="${6:-optional}"
807 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
808 If you
find such a package installed on your system
,
809 something went horribly wrong
! They are autogenerated
810 und used only by testcases and serve no other purpose…
"}"
812 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
813 if [ "$RELEASE" = 'installed' ]; then
814 insertinstalledpackage
"$2" "$3" "$4" "$5" "$6" "$7"
817 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
818 if [ "$arch" = 'none' ]; then
819 ARCHS
="$(getarchitectures)"
823 for BUILDARCH
in $ARCHS; do
824 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
831 Maintainer: Joe Sixpack <joe@example.org>"
832 test "$arch" = 'none' || echo "Architecture: $arch"
833 echo "Version: $VERSION
834 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb"
835 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES"
836 echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)"
837 echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
839 } >> "${PPATH}/Packages"
842 mkdir -p "aptarchive/dists/${RELEASE}/main/source" "aptarchive/dists/${RELEASE}/main/i18n"
843 touch "aptarchive/dists/${RELEASE}/main/source/Sources"
845 Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
846 Description-en: $DESCRIPTION
847 " >> "aptarchive/dists/${RELEASE}/main/i18n/Translation-en"
856 local DEPENDENCIES
="$5"
857 local BINARY
="${6:-$NAME}"
859 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
861 local FILE
="${SPATH}/Sources"
862 local DSCFILE
="${NAME}_${VERSION}.dsc"
863 local TARFILE
="${NAME}_${VERSION}.tar.gz"
867 Maintainer: Joe Sixpack <joe@example.org>
868 Architecture: $ARCH" >> $FILE
869 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
871 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
872 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
874 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
875 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
879 insertinstalledpackage
() {
883 local DEPENDENCIES
="$4"
884 local PRIORITY
="${5:-optional}"
885 local STATUS
="${6:-install ok installed}"
886 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
887 If you find such a package installed on your system,
888 something went horribly wrong! They are autogenerated
889 und used only by testcases and serve no other purpose…"}"
891 local FILE='rootdir/var/lib/dpkg/status'
892 local INFO='rootdir/var/lib/dpkg/info'
893 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
899 Maintainer
: Joe Sixpack
<joe@example.org
>
900 Version
: $VERSION" >> "$FILE"
901 test "$arch" = 'none' || echo "Architecture
: $arch" >> "$FILE"
902 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
903 echo "Description
: $DESCRIPTION" >> "$FILE"
905 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
906 echo -n > "${INFO}/${NAME}:${arch}.list
"
908 echo -n > "${INFO}/${NAME}.list
"
914 buildaptarchivefromincoming() {
915 msginfo "Build APT archive
for ${CCMD}${0##*/}${CINFO} based on incoming packages…
"
917 [ -e pool ] || ln -s ../incoming pool
918 [ -e ftparchive.conf ] || createaptftparchiveconfig
919 [ -e dists ] || buildaptftparchivedirectorystructure
920 msgninfo "\tGenerate Packages
, Sources and Contents files…
"
921 testsuccess aptftparchive generate ftparchive.conf
924 generatereleasefiles "$@
"
927 buildaptarchivefromfiles() {
928 msginfo "Build APT archive
for ${CCMD}${0##*/}${CINFO} based on prebuild files…
"
929 local DIR='aptarchive'
930 if [ -d "${DIR}/dists
" ]; then DIR="${DIR}/dists
"; fi
931 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do
932 msgninfo "\t${line} file…
"
933 compressfile "$line" "$1"
936 generatereleasefiles "$@
"
940 cat "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
" | while read compressor extension command; do
941 if [ "$compressor" = '.' ]; then
947 cat "$1" | $command > "${1}.
${extension}"
949 touch -d "$2" "${1}.
${extension}"
954 # can be overridden by testcases for their pleasure
955 getcodenamefromsuite() {
957 unstable) echo 'sid';;
961 getreleaseversionfromsuite() { true; }
962 getlabelfromsuite() { true; }
963 getoriginfromsuite() { true; }
964 getarchitecturesfromreleasefile() { echo "all
$(getarchitectures)"; }
966 aptftparchiverelease() {
967 aptftparchive -qq release "$@
" | sed -e '/0 Release$/ d' # remove the self reference
969 generatereleasefiles() {
970 # $1 is the Date header and $2 is the ValidUntil header to be set
971 # both should be given in notation date/touch can understand
973 local VALIDUNTIL="$2"
974 if [ -e aptarchive/dists ]; then
975 msgninfo "\tGenerate Release files
for dists…
"
976 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
977 local ARCHITECTURES="$(getarchitecturesfromreleasefile "$dir")"
978 local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
979 local CODENAME="$(getcodenamefromsuite $SUITE)"
980 local VERSION="$(getreleaseversionfromsuite $SUITE)"
981 local LABEL="$(getlabelfromsuite $SUITE)"
982 local ORIGIN="$(getoriginfromsuite $SUITE)"
983 aptftparchiverelease "$dir" \
984 -o APT::FTPArchive::Release::Suite="${SUITE}" \
985 -o APT::FTPArchive::Release::Codename="${CODENAME}" \
986 -o APT::FTPArchive::Release::Architectures="${ARCHITECTURES}" \
987 -o APT::FTPArchive::Release::Label="${LABEL}" \
988 -o APT::FTPArchive::Release::Origin="${ORIGIN}" \
989 -o APT::FTPArchive::Release::Version="${VERSION}" \
991 if [ "$SUITE" = "experimental
" -o "$SUITE" = "experimental2
" ]; then
993 NotAutomatic: yes' "$dir/Release
"
997 msgninfo "\tGenerate Release files
for flat…
"
998 aptftparchiverelease ./aptarchive > aptarchive/Release
1000 if [ -n "$DATE" -a "$DATE" != "now
" ]; then
1001 for release in $(find ./aptarchive -name 'Release'); do
1002 sed -i "s
/^Date
: .
*$
/Date
: $(date -d "$DATE" '+%a, %d %b %Y %H:%M:%S %Z')/" "$release"
1003 touch -d "$DATE" "$release"
1006 if [ -n "$VALIDUNTIL" ]; then
1007 sed -i "/^Date
: / a\
1008 Valid
-Until: $(date -d "$VALIDUNTIL" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release')
1013 setupdistsaptarchive() {
1014 local APTARCHIVE="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1015 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
1016 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
1017 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1018 SECTIONS=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1019 msgninfo "\tadd deb and deb
-src sources.list lines
for ${CCMD}${DISTS} ${SECTIONS}${CINFO}…
"
1020 echo "deb
file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
"
1021 echo "deb
-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
"
1026 setupflataptarchive() {
1027 local APTARCHIVE="$(readlink -f ./aptarchive)"
1028 local APTARCHIVEURI="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1029 if [ -f "${APTARCHIVE}/Packages
" ]; then
1030 msgninfo "\tadd deb sources.list line…
"
1031 echo "deb
file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1034 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1036 if [ -f "${APTARCHIVE}/Sources
" ]; then
1037 msgninfo "\tadd deb
-src sources.list line…
"
1038 echo "deb
-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1041 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1047 if [ "$1" = '--no-update' ]; then
1051 buildaptarchive "$@
"
1052 if [ -e aptarchive/dists ]; then
1053 setupdistsaptarchive
1057 signreleasefiles 'Joe Sixpack'
1058 if [ "1" != "$NOUPDATE" ]; then
1059 testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true
1063 signreleasefiles() {
1064 local SIGNER="${1:-Joe Sixpack}"
1065 local REPODIR="${2:-aptarchive}"
1066 local KEY="keys
/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
1067 local GPG="aptkey
--quiet --keyring ${KEY}.pub
--secret-keyring ${KEY}.sec
--readonly adv
--batch --yes"
1068 msgninfo "\tSign archive with
$SIGNER key
$KEY…
"
1069 local REXKEY='keys/rexexpired'
1070 local SECEXPIREBAK="${REXKEY}.sec.bak
"
1071 local PUBEXPIREBAK="${REXKEY}.pub.bak
"
1072 if [ "${SIGNER}" = 'Rex Expired' ]; then
1073 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1074 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1075 # therefore we 'temporary' make the key not expired and restore a backup after signing
1076 cp "${REXKEY}.sec
" "$SECEXPIREBAK"
1077 cp "${REXKEY}.pub
" "$PUBEXPIREBAK"
1078 local SECUNEXPIRED="${REXKEY}.sec.unexpired
"
1079 local PUBUNEXPIRED="${REXKEY}.pub.unexpired
"
1080 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1081 cp "$SECUNEXPIRED" "${REXKEY}.sec
"
1082 cp "$PUBUNEXPIRED" "${REXKEY}.pub
"
1084 if ! printf "expire
\n1w
\nsave
\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then
1088 cp "${REXKEY}.sec
" "$SECUNEXPIRED"
1089 cp "${REXKEY}.pub
" "$PUBUNEXPIRED"
1092 for RELEASE in $(find "${REPODIR}/" -name Release); do
1093 testsuccess $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output "${RELEASE}.gpg
" "${RELEASE}"
1094 local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
1095 testsuccess $GPG --default-key "$SIGNER" --clearsign --output "$INRELEASE" "$RELEASE"
1096 # we might have set a specific date for the Release file, so copy it
1097 touch -d "$(stat --format "%y" ${RELEASE})" "${RELEASE}.gpg
" "${INRELEASE}"
1099 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1100 mv -f "$SECEXPIREBAK" "${REXKEY}.sec
"
1101 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub
"
1106 redatereleasefiles() {
1107 local DATE="$(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
1108 for release in $(find aptarchive/ -name 'Release'); do
1109 sed -i "s
/^Date
: .
*$
/Date
: ${DATE}/" "$release"
1110 touch -d "$DATE" "$release"
1112 signreleasefiles "${2:-Joe Sixpack}"
1116 local WEBSERVER="${3:-http://localhost:${APTHTTPPORT}}"
1118 if [ "$1" = '--no-check' ]; then
1122 local DOWNLOG='rootdir/tmp/download-testfile.log'
1123 local STATUS='downloaded/webserverconfig.status'
1124 rm -f "$STATUS" "$DOWNLOG"
1125 # very very basic URI encoding
1127 if [ -n "$2" ]; then
1128 msgtest "Set webserver config option
'${1}' to
" "$2"
1129 URI="${WEBSERVER}/_config
/set
/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1131 msgtest 'Clear webserver config option' "${1}"
1132 URI="${WEBSERVER}/_config
/clear
/$(echo "${1}" | sed -e 's/\//%2f/g')"
1134 if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then
1137 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir
/tmp
/webserverconfig.output
"
1138 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1139 msgfailoutput '' "$OUTPUT"
1141 $NOCHECK || testwebserverlaststatuscode '200'
1144 rewritesourceslist() {
1145 local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1146 local APTARCHIVE2="copy
://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1147 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1148 sed -i $LIST -e "s
#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
1149 -e "s#http://localhost:${APTHTTPPORT}/#${1}#" \
1150 -e "s#https://localhost:${APTHTTPSPORT}/#${1}#"
1154 # wait for up to 10s for a pid file to appear to avoid possible race
1155 # when a helper is started and dosn't write the PID quick enough
1158 for i
in $(seq 10); do
1159 if test -s "$PIDFILE"; then
1164 msgdie
"waiting for $PIDFILE failed"
1168 changetowebserver
() {
1170 if [ "$1" != '--no-rewrite' ]; then
1175 if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
1177 local LOG
="webserver.log"
1178 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1182 waitforpidfile aptwebserver.pid
1183 local PID
="$(cat aptwebserver.pid)"
1184 if [ -z "$PID" ]; then
1185 msgdie
'Could not fork aptwebserver successfully'
1187 addtrap
"kill $PID;"
1188 waitforpidfile aptwebserver.port
1189 APTHTTPPORT
="$(cat aptwebserver.port)"
1190 if [ -z "$APTHTTPPORT" ]; then
1191 msgdie
'Could not get port for aptwebserver successfully'
1195 msgdie
'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver'
1197 if [ "$REWRTE" != 'yes' ]; then
1198 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1202 changetohttpswebserver
() {
1203 if ! command -v stunnel4
>/dev
/null
2>&1; then
1204 msgdie
'You need to install stunnel4 for https testcases'
1206 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1207 changetowebserver
--no-rewrite "$@"
1209 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1210 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1215 connect = $APTHTTPPORT
1216 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1217 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1218 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1219 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1220 if [ -z "$PID" ]; then
1221 msgdie
'Could not fork stunnel4 successfully'
1223 addtrap
'prefix' "kill ${PID};"
1224 APTHTTPSPORT
="$(lsof -i | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1225 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1226 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1230 mkdir -p rootdir
/media
/cdrom
/.disk
1231 local CD
="$(readlink -f rootdir/media/cdrom)"
1232 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1233 acquire::cdrom::mount "${CD}";
1234 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1235 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1236 acquire::cdrom::autodetect 0;
1238 echo -n "$1" > "${CD}/.disk/info"
1239 if [ ! -d aptarchive
/dists
]; then
1240 msgdie
'Flat file archive cdroms can not be created currently'
1243 mv aptarchive
/dists
"$CD"
1244 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1245 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1246 # start with an unmounted disk
1247 mv "${CD}" "${CD}-unmounted"
1248 # we don't want the disk to be modifiable
1249 addtrap
'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;"
1250 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1254 local PROTO
="${1%%:*}"
1255 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1256 download
-file "$1" "$2" "$3" 2>&1 ; then
1259 # only if the file exists the download was successful
1260 if [ -r "$2" ]; then
1268 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1269 if [ -n "$DIFFTEXT" ]; then
1271 echo >&2 "$DIFFTEXT"
1279 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1280 local COMPAREFILE
="$1"
1282 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1285 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1286 cat "$COMPAREFILE" >>"${OUTPUT}"
1287 msgfailoutput
'' "$OUTPUT" "$@"
1292 msggroup
'testfileequal'
1293 local MSG
='Test for correctness of file'
1294 if [ "$1" = '--nomsg' ]; then
1300 if [ -n "$MSG" ]; then
1301 msgtest
"$MSG" "$FILE"
1303 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1304 if [ -z "$*" ]; then
1305 testoutputequal
"$FILE" echo -n ''
1307 testoutputequal
"$FILE" echo "$*"
1313 msggroup
'testempty'
1314 msgtest
"Test for no output of" "$*"
1315 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1316 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test ! -s "$COMPAREFILE"; then
1319 msgfailoutput
'' "$COMPAREFILE" "$@"
1321 aptautotest
'testempty' "$@"
1325 msggroup
'testnotempty'
1326 msgtest
"Test for some output of" "$*"
1327 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
1328 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then
1331 msgfailoutput
'' "$COMPAREFILE" "$@"
1333 aptautotest
'testnotempty' "$@"
1338 msggroup
'testequal'
1339 local MSG
='Test of equality of'
1340 if [ "$1" = '--nomsg' ]; then
1345 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1346 echo "$1" > "$COMPAREFILE"
1349 if [ -n "$MSG" ]; then
1352 testoutputequal
"$COMPAREFILE" "$@"
1353 aptautotest
'testequal' "$@"
1358 msggroup
'testequalor2'
1359 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1360 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1361 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1362 echo "$1" > "$COMPAREFILE1"
1363 echo "$2" > "$COMPAREFILE2"
1365 msgtest
"Test for equality OR of" "$*"
1366 "$@" >"$COMPAREAGAINST" 2>&1 || true
1367 if checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null
2>&1 || \
1368 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null
2>&1
1372 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1373 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1374 checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1375 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1376 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1377 msgfailoutput
'' "$OUTPUT"
1379 aptautotest
'testequalor2' "$@"
1384 msggroup
'testshowvirtual'
1385 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1388 while [ -n "$1" ]; do
1390 N: Can't select versions from package '$1' as it is purely virtual"
1391 PACKAGE
="${PACKAGE} $1"
1394 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1396 N: No packages found"
1397 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1398 local ARCH
="$(getarchitecture 'native')"
1399 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1400 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1401 testoutputequal
"$COMPAREFILE" aptcache show
"$PACKAGE"
1406 msggroup
'testnopackage'
1407 msgtest
"Test for non-existent packages" "apt-cache show $*"
1408 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1409 if [ -n "$SHOWPKG" ]; then
1410 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1411 echo "$SHOWPKG" >"$OUTPUT"
1412 msgfailoutput
'' "$OUTPUT"
1418 testnosrcpackage
() {
1419 msggroup
'testnosrcpackage'
1420 msgtest
"Test for non-existent source packages" "apt-cache showsrc $*"
1421 local SHOWPKG
="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')"
1422 if [ -n "$SHOWPKG" ]; then
1423 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output"
1424 echo "$SHOWPKG" >"$OUTPUT"
1425 msgfailoutput
'' "$OUTPUT"
1433 msggroup
'testdpkgstatus'
1437 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1438 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1439 if [ "$PKGS" != $NR ]; then
1440 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1441 echo "$PKGS" >"$OUTPUT"
1442 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1443 msgfailoutput
'' "$OUTPUT"
1450 testdpkginstalled
() {
1451 msggroup
'testdpkginstalled'
1452 testdpkgstatus
'ii' "$#" "$@"
1456 testdpkgnotinstalled
() {
1457 msggroup
'testdpkgnotinstalled'
1458 testdpkgstatus
'ii' '0' "$@"
1463 msggroup
'testmarkedauto'
1464 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1465 if [ -n "$1" ]; then
1466 msgtest
'Test for correctly marked as auto-installed' "$*"
1467 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1469 msgtest
'Test for correctly marked as auto-installed' 'no package'
1470 echo -n > "$COMPAREFILE"
1472 testoutputequal
"$COMPAREFILE" aptmark showauto
1475 testmarkedmanual
() {
1476 msggroup
'testmarkedmanual'
1477 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1478 if [ -n "$1" ]; then
1479 msgtest
'Test for correctly marked as manually installed' "$*"
1480 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1482 msgtest
'Test for correctly marked as manually installed' 'no package'
1483 echo -n > "$COMPAREFILE"
1485 testoutputequal
"$COMPAREFILE" aptmark showmanual
1490 msgreportheader
'msgfailoutput'
1494 if [ "$1" = 'grep' ]; then
1496 while [ -n "$2" ]; do shift; done
1497 echo "#### Complete file: $1 ####"
1498 cat >&2 "$1" || true
1499 echo '#### grep output ####'
1500 elif [ "$1" = 'test' ]; then
1502 # doesn't support ! or non-file flags
1503 msgfailoutputstatfile
() {
1504 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1505 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1506 echo "#### stat(2) of file: $2 ####"
1508 if test -d "$2"; then
1509 echo "#### The directory contains: $2 ####"
1511 elif test -e "$2"; then
1512 echo "#### Complete file: $2 ####"
1513 cat >&2 "$2" || true
1517 msgfailoutputstatfile
"$2" "$3"
1518 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1520 msgfailoutputstatfile
"$2" "$3"
1522 echo '#### test output ####'
1528 testsuccesswithglobalerror
() {
1533 if [ "$1" = '--nomsg' ]; then
1536 msgtest
'Test for successful execution of' "$*"
1538 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output"
1539 if "$@" >"${OUTPUT}" 2>&1; then
1540 if expr match
"$1" '^apt.*' >/dev
/null
; then
1541 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1542 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1543 elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1544 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1545 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1546 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1549 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1552 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1554 elif [ "$TYPE" = 'testsuccesswithnotice' ]; then
1555 if grep -q -E "^N: " "$OUTPUT"; then
1558 msgfailoutput
'successful run, but output had no notices' "$OUTPUT" "$@"
1568 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1570 aptautotest
"$TYPE" "$@"
1573 testsuccesswithnotice
() {
1574 testsuccesswithglobalerror
'testsuccesswithnotice' 'WE' "$@"
1577 testsuccesswithglobalerror
'testsuccess' 'NWE' "$@"
1580 msggroup
'testwarning'
1581 if [ "$1" = '--nomsg' ]; then
1584 msgtest
'Test for successful execution with warnings of' "$*"
1586 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1587 if "$@" >"${OUTPUT}" 2>&1; then
1588 if expr match
"$1" '^apt.*' >/dev
/null
; then
1589 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1590 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1591 elif grep -q -E '^E: ' "$OUTPUT"; then
1592 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1593 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1594 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1603 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1605 aptautotest
'testwarning' "$@"
1609 msggroup
'testfailure'
1610 if [ "$1" = '--nomsg' ]; then
1613 msgtest
'Test for failure in execution of' "$*"
1615 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1616 if "$@" >"${OUTPUT}" 2>&1; then
1618 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1621 if expr match
"$1" '^apt.*' >/dev
/null
; then
1622 if [ "$1" = 'aptkey' ]; then
1623 if grep -q -E " Can't check signature: " "$OUTPUT" || \
1624 grep -q -E " BAD signature from " "$OUTPUT"; then
1627 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1630 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1631 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1632 elif grep -q -E '==ERROR' "$OUTPUT"; then
1633 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1634 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1635 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1644 aptautotest
'testfailure' "$@"
1648 testreturnstateequal
() {
1650 if [ "$STATE" = 'testsuccesswithglobalerror' ]; then
1654 msggroup
"${STATE}equal"
1655 if [ "$1" != '--nomsg' ]; then
1658 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1659 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1663 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1664 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1667 msggroup
"${STATE}equal"
1668 if [ "$2" != '--nomsg' ]; then
1672 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1676 "$STATE" --nomsg "$@"
1677 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1682 testsuccessequal
() {
1683 # we compare output, so we know perfectly well about N:
1684 testreturnstateequal
'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@"
1686 testwarningequal
() {
1687 testreturnstateequal
'testwarning' "$@"
1689 testfailureequal
() {
1690 testreturnstateequal
'testfailure' "$@"
1694 msggroup
'testfailuremsg'
1698 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1699 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1700 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1701 testoutputequal
"$COMPAREFILE" echo "$CMP"
1705 msggroup
'testwarningmsg'
1709 msgtest
'Check that the output of the previous warned command has expected' 'warnings'
1710 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
1711 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
1712 testoutputequal
"$COMPAREFILE" echo "$CMP"
1717 msggroup
'testfilestats'
1718 msgtest
"Test that file $1 has $2 $3" "$4"
1719 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1722 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1725 echo -n "stat(1) reports for $2: "
1726 stat
--format "$2" "$1" || true
1728 msgfailoutput
'' "$OUTPUT"
1732 testaccessrights
() {
1733 msggroup
'testaccessrights'
1734 testfilestats
"$1" '%a' '=' "$2"
1738 testwebserverlaststatuscode
() {
1739 msggroup
'testwebserverlaststatuscode'
1740 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1741 local STATUS
='downloaded/webserverstatus-statusfile.log'
1742 rm -f "$DOWNLOG" "$STATUS"
1743 msgtest
'Test last status code from the webserver was' "$1"
1744 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1747 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1749 if [ -n "$2" ]; then
1751 echo >&2 '#### Additionally provided output files contain:'
1754 echo >&2 '#### Download log of the status code:'
1757 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1762 createlistofkeys
() {
1765 while [ -n "$1" ]; do
1766 # gpg 2.1 has a slightly different output format
1767 if grep -q ' rsa2048/' "$OUTPUT"; then
1769 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1770 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1771 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16';;
1772 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19';;
1773 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1774 *) echo 'UNKNOWN KEY';;
1778 *Joe
*|*Sixpack
*) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1779 *Rex
*|*Expired
*) echo 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1780 *Marvin
*|*Paranoid
*) echo 'pub 2048R/528144E2 2011-01-16';;
1781 oldarchive
) echo 'pub 1024R/F68C85A3 2013-12-19';;
1782 newarchive
) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1783 *) echo 'UNKNOWN KEY';;
1790 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output"
1791 if ! aptkey list
| grep '^pub' > "$OUTPUT"; then
1794 testfileequal
"$OUTPUT" "$(createlistofkeys "$OUTPUT" "$@")"
1798 echo "STOPPED execution. Press enter to continue"
1803 listcurrentlistsdirectory
() {
1805 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1806 stat
--format '%U:%G:%a:%n' "$line"
1808 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1809 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1813 forallsupportedcompressors
() {
1814 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
1815 if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi
1820 ### convenience hacks ###
1822 # creating some directories by hand is a tedious task, so make it look simple
1824 if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then
1825 # only the last directory created by mkdir is effected by the -m !
1826 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1827 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1828 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1829 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1830 if [ "$(id -u)" = '0' ]; then
1831 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1838 ### The following tests are run by most test methods automatically to check
1839 ### general things about commands executed without writing the test every time.
1845 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')"
1846 if command -v $AUTOTEST >/dev
/null
; then
1848 # save and restore the *.output files from other tests
1849 # as we might otherwise override them in these automatic tests
1850 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1851 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1852 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1853 $AUTOTEST "$TESTCALL" "$@"
1854 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1855 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1856 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1860 aptautotest_aptget_update
() {
1862 while [ -n "$2" ]; do
1863 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1866 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1867 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1868 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1869 # all copied files are properly chmodded
1870 local backupIFS
="$IFS"
1871 IFS
="$(printf "\n\b")"
1872 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1873 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1876 if [ "$TESTCALL" = 'testsuccess' ]; then
1877 # failure cases can retain partial files and such
1878 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
1881 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1882 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
1884 testaptautotestnodpkgwarning
() {
1886 while [ -n "$2" ]; do
1887 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
1888 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
1891 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1894 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
1895 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
1896 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
1897 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
1898 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
1899 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }