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
393 configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
394 confighashes 'SHA256' # these are tests, not security best-practices
396 # create some files in /tmp and look at user/group to get what this means
397 TEST_DEFAULT_USER="$(id -un)"
398 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
399 TEST_DEFAULT_GROUP='root'
401 TEST_DEFAULT_GROUP="$(id -gn)"
404 # cleanup the environment a bit
405 # prefer our apt binaries over the system apt binaries
406 export PATH="${BUILDDIRECTORY}:${PATH}:/usr
/local
/sbin
:/usr
/sbin
:/sbin
"
407 export LC_ALL=C.UTF-8
408 unset LANGUAGE APT_CONFIG
409 unset GREP_OPTIONS DEB_BUILD_PROFILES
410 unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy
412 # If gpgv supports --weak-digest, pass it to make sure we can disable SHA1
413 if aptkey verify --weak-digest SHA1 --help 2>/dev/null >/dev/null; then
414 echo 'Acquire::gpgv::Options { "--weak-digest"; "sha1
"; };' > rootdir/etc/apt/apt.conf.d/no-sha1
421 if [ "$1" = "native
" -o -z "$1" ]; then
422 eval `aptconfig shell ARCH APT::Architecture`
423 if [ -n "$ARCH" ]; then
426 dpkg --print-architecture
434 aptconfig dump --no-empty --format '%v%n' APT::Architecture APT::Architectures | sort -u | tr '\n' ' '
437 getarchitecturesfromcommalist() {
438 echo "$1" | sed -e 's#,#\n#g' | sed -e "s
/^native\$
/$(getarchitecture 'native')/"
441 configarchitecture() {
443 echo "APT
::Architecture
\"$(getarchitecture $1)\";"
444 while [ -n "$1" ]; do
445 echo "APT
::Architectures
:: \"$(getarchitecture $1)\";"
448 } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
453 if [ ! -e rootdir/var/lib/dpkg/status ]; then
454 local BASENAME="${0##*/}"
455 local STATUSFILE="status
-${BASENAME#*-}"
456 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
457 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
459 echo -n > rootdir/var/lib/dpkg/status
462 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
463 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
464 local ARCHS="$(getarchitectures)"
465 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
466 DPKGARCH="$(dpkg --print-architecture)"
467 for ARCH in ${ARCHS}; do
468 if [ "${ARCH}" != "${DPKGARCH}" ]; then
469 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
470 # old-style used e.g. in Ubuntu-P – and as it seems travis
471 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
472 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
476 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
477 # dpkg doesn't really check the version as long as it is fully installed,
478 # but just to be sure we choose one above the required version
479 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
485 configdpkgnoopchroot() {
486 # create a library to noop chroot() and rewrite maintainer script executions
487 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
488 # chroot directory dpkg could chroot into to execute the maintainer scripts
489 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
490 cat > noopchroot.c << EOF
497 static char * chrootdir = NULL;
499 int chroot(const char *path) {
500 printf("WARNING
: CHROOTing to
%s was ignored
!\n", path);
502 chrootdir = strdup(path);
505 int execvp(const char *file, char *const argv[]) {
506 static int (*func_execvp) (const char *, char * const []) = NULL;
507 if (func_execvp == NULL)
508 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
");
509 if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0)
510 return func_execvp(file, argv);
511 printf("REWRITE execvp call
%s into
%s
\n", file, chrootdir);
513 if (asprintf(&newfile, "%s
%s
", chrootdir, file) == -1) {
517 char const * const baseadmindir = "/var
/lib
/dpkg
";
519 if (asprintf(&admindir, "%s
%s
", chrootdir, baseadmindir) == -1) {
523 setenv("DPKG_ADMINDIR
", admindir, 1);
524 return func_execvp(newfile, argv);
527 testempty --nomsg gcc -Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c -ldl
529 configcompression() {
530 local CMD='apthelper cat-file -C'
531 while [ -n "$1" ]; do
533 '.') printf ".
\t.
\tcat
\n";;
534 'gz') printf "gzip\tgz
\t$CMD $1\n";;
535 'bz2') printf "bzip2\tbz
2\t$CMD $1\n";;
536 *) printf "$1\t$1\t$CMD $1\n";;
539 done > "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
"
543 echo 'APT::FTPArchive {'
545 while [ -n "$1" ]; do
546 printf "$1" | tr 'a-z' 'A-Z'
547 printf "\t\"true
\";\n"
550 for h in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
551 printf "$h\t\"false
\";\n"
555 } >> "${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/ftparchive
-hashes.conf
"
560 COMPRESSOR_CMD="apthelper
cat-file -C $1"
562 gzip) COMPRESS='gz';;
563 bzip2) COMPRESS='bz2';;
565 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/00force
-compressor"
566 echo "Acquire
::CompressionTypes
::Order
{ \"${COMPRESS}\"; };
567 Dir
::Bin
::uncompressed
\"/does
/not
/exist
\";" > "$CONFFILE"
570 setupsimplenativepackage() {
574 local RELEASE="${4:-unstable}"
575 local DEPENDENCIES="$5"
576 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
577 If you
find such a package installed on your system
,
578 something went horribly wrong
! They are autogenerated
579 und used only by testcases and serve no other purpose…
"}"
581 local SECTION
="${7:-others}"
583 if [ "$SECTION" = "${SECTION#*/}" ]; then
586 DISTSECTION
="${SECTION%/*}"
588 local BUILDDIR
=incoming
/${NAME}-${VERSION}
589 mkdir -p ${BUILDDIR}/debian
/source
591 echo "* most suckless software product ever" > FEATURES
592 test -e debian
/copyright
|| echo "Copyleft by Joe Sixpack $(date +%Y)" > debian
/copyright
593 test -e debian
/changelog
|| echo "$NAME ($VERSION) $RELEASE; urgency=low
597 -- Joe Sixpack <joe@example.org> $(date -R)" > debian
/changelog
598 test -e debian
/control
|| echo "Source: $NAME
601 Maintainer: Joe Sixpack <joe@example.org>
602 Build-Depends: debhelper (>= 7)
603 Standards-Version: 3.9.1
605 Package: $NAME" > debian
/control
606 if [ "$ARCH" = 'all' ]; then
607 echo "Architecture: all" >> debian
/control
609 echo "Architecture: any" >> debian
/control
611 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian
/control
612 echo "Description: $DESCRIPTION" >> debian
/control
614 test -e debian
/compat
|| echo "7" > debian
/compat
615 test -e debian
/source
/format
|| echo "3.0 (native)" > debian
/source
/format
616 test -e debian
/rules
|| cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny debian
/rules
620 buildsimplenativepackage
() {
623 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then
624 NM
="$(echo "$NAME" | cut -c 1-4)"
626 NM
="$(echo "$NAME" | cut -c 1)"
630 local RELEASE
="${4:-unstable}"
631 local DEPENDENCIES
="$5"
632 local DESCRIPTION
="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
633 If you find such a package installed on your system,
634 something went horribly wrong! They are autogenerated
635 und used only by testcases and serve no other purpose…"}"
637 local SECTION="${7:-others}"
638 local PRIORITY="${8:-optional}"
640 local COMPRESS_TYPE="${10:-gzip}"
642 if [ "$SECTION" = "${SECTION#*/}" ]; then
645 DISTSECTION="${SECTION%/*}"
647 local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming
/${NAME}-${VERSION}"
649 msgtest "Build
source package
in version
${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
650 mkdir -p "$BUILDDIR/debian
/source"
651 echo "* most suckless software product ever
" > "${BUILDDIR}/FEATURES
"
653 echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}"
655 echo "Copyleft by Joe Sixpack
$(date +%Y)" > "${BUILDDIR}/debian
/copyright
"
656 echo "$NAME ($VERSION) $RELEASE; urgency
=low
660 -- Joe Sixpack
<joe@example.org
> $(date -R)" > "${BUILDDIR}/debian
/changelog
"
664 Maintainer
: Joe Sixpack
<joe@example.org
>
665 Standards
-Version: 3.9.3"
666 if [ "$SECTION" != '<none>' ]; then
667 echo "Section
: $SECTION"
669 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
670 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
674 if [ "$ARCH" = 'all' ]; then
675 echo "Architecture
: all
"
677 echo "Architecture
: any
"
679 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
680 test -z "$DEPS" || echo "$DEPS"
681 echo "Description
: $DESCRIPTION"
682 } > "${BUILDDIR}/debian
/control
"
684 echo '3.0 (native)' > "${BUILDDIR}/debian
/source
/format
"
686 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
688 sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
" \
690 echo "pool
/${SRC}" >> "${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
"
691 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
692 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
693 # adv --yes --default-key 'Joe Sixpack' \
694 # --clearsign -o "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
695 # mv "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
699 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
700 msgtest "Build binary package
for ${RELEASE} in ${SECTION}" "$NAME"
701 rm -rf "${BUILDDIR}/debian
/tmp
"
702 mkdir -p "${BUILDDIR}/debian
/tmp
/DEBIAN
" "${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}" "${BUILDDIR}/debian
/tmp
/usr
/bin
"
703 cp "${BUILDDIR}/debian
/copyright
" "${BUILDDIR}/debian
/changelog
" "${BUILDDIR}/FEATURES
" "${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}"
704 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}"
705 if [ -n "$FILE_TREE" ]; then
706 cp -ar "$FILE_TREE" "${BUILDDIR}/debian
/tmp
"
709 (cd "${BUILDDIR}"; dpkg-gencontrol -DArchitecture=$arch)
710 (cd "${BUILDDIR}/debian
/tmp
"; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
711 local LOG="${BUILDDIR}/..
/${NAME}_
${VERSION}_
${arch}.dpkg
-deb.log
"
712 # ensure the right permissions as dpkg-deb insists
713 chmod 755 "${BUILDDIR}/debian
/tmp
/DEBIAN
"
714 testsuccess --nomsg dpkg-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian
/tmp
" "${BUILDDIR}/..
"
715 echo "pool
/${NAME}_
${VERSION}_
${arch}.deb
" >> "${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
"
718 local CHANGEPATH="${BUILDDIR}/..
/${DISTSECTION}/${NM}/${NAME}/${NAME}_
${VERSION}"
719 mkdir -p "$CHANGEPATH"
720 cp "${BUILDDIR}/debian
/changelog
" "$CHANGEPATH"
729 local ARCH=$(getarchitecture $4)
730 local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
731 local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
732 msgtest "Build package
for ${RELEASE} in ${SECTION}" "$PKGNAME"
734 if [ "$ARCH" = "all
" ]; then
735 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
737 testsuccess --nomsg dpkg-buildpackage -uc -us -a$ARCH
738 cp "${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
" "$BUILDLOG"
739 local PKGS="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
740 local SRCS="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
743 echo "pool
/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
"
746 echo "pool
/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
"
751 if [ -d incoming ]; then
752 buildaptarchivefromincoming "$@
"
754 buildaptarchivefromfiles "$@
"
758 createaptftparchiveconfig() {
759 local COMPRESSORS="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
760 local COMPRESSORS="${COMPRESSORS%* }"
761 local ARCHS="$(getarchitectures)"
762 cat > ftparchive.conf <<EOF
764 ArchiveDir "$(readlink -f .)";
765 CacheDir "$(readlink -f ..)";
766 FileListDir "$(readlink -f pool/)";
769 Packages::Compress "$COMPRESSORS";
770 Sources::Compress "$COMPRESSORS";
771 Contents::Compress "$COMPRESSORS";
772 Translation::Compress "$COMPRESSORS";
773 LongDescription "false
";
777 SrcDirectory "pool
/";
780 for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
783 Architectures "$ARCHS all
source";
784 FileList "${DIST}.\
$(SECTION).pkglist
";
785 SourceFileList "${DIST}.\
$(SECTION).srclist
";
786 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
789 done >> ftparchive.conf
792 buildaptftparchivedirectorystructure() {
793 local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
794 for DIST in $DISTS; do
795 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
796 for SECTION in $SECTIONS; do
797 local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
798 for ARCH in $ARCHS; do
799 mkdir -p "dists
/${DIST}/${SECTION}/binary
-${ARCH}"
801 mkdir -p "dists
/${DIST}/${SECTION}/source"
802 mkdir -p "dists
/${DIST}/${SECTION}/i18n
"
812 local DEPENDENCIES="$5"
813 local PRIORITY="${6:-optional}"
814 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
815 If you
find such a package installed on your system
,
816 something went horribly wrong
! They are autogenerated
817 und used only by testcases and serve no other purpose…
"}"
819 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
820 if [ "$RELEASE" = 'installed' ]; then
821 insertinstalledpackage
"$2" "$3" "$4" "$5" "$6" "$7"
824 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
825 if [ "$arch" = 'none' ]; then
826 ARCHS
="$(getarchitectures)"
830 for BUILDARCH
in $ARCHS; do
831 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
838 Maintainer: Joe Sixpack <joe@example.org>"
839 test "$arch" = 'none' || echo "Architecture: $arch"
840 echo "Version: $VERSION
841 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb"
842 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES"
843 echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)"
844 echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
846 } >> "${PPATH}/Packages"
849 mkdir -p "aptarchive/dists/${RELEASE}/main/source" "aptarchive/dists/${RELEASE}/main/i18n"
850 touch "aptarchive/dists/${RELEASE}/main/source/Sources"
852 Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
853 Description-en: $DESCRIPTION
854 " >> "aptarchive/dists/${RELEASE}/main/i18n/Translation-en"
863 local DEPENDENCIES
="$5"
864 local BINARY
="${6:-$NAME}"
866 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
867 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
869 local FILE
="${SPATH}/Sources"
870 local DSCFILE
="${NAME}_${VERSION}.dsc"
871 local TARFILE
="${NAME}_${VERSION}.tar.gz"
875 Maintainer: Joe Sixpack <joe@example.org>
876 Architecture: $ARCH" >> $FILE
877 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
879 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
880 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
882 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
883 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
888 insertinstalledpackage
() {
892 local DEPENDENCIES
="$4"
893 local PRIORITY
="${5:-optional}"
894 local STATUS
="${6:-install ok installed}"
895 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
896 If you find such a package installed on your system,
897 something went horribly wrong! They are autogenerated
898 und used only by testcases and serve no other purpose…"}"
900 local FILE='rootdir/var/lib/dpkg/status'
901 local INFO='rootdir/var/lib/dpkg/info'
902 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
908 Maintainer
: Joe Sixpack
<joe@example.org
>
909 Version
: $VERSION" >> "$FILE"
910 test "$arch" = 'none' || echo "Architecture
: $arch" >> "$FILE"
911 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
912 echo "Description
: $DESCRIPTION" >> "$FILE"
914 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
915 echo -n > "${INFO}/${NAME}:${arch}.list
"
917 echo -n > "${INFO}/${NAME}.list
"
923 buildaptarchivefromincoming() {
924 msginfo "Build APT archive
for ${CCMD}${0##*/}${CINFO} based on incoming packages…
"
926 [ -e pool ] || ln -s ../incoming pool
927 [ -e ftparchive.conf ] || createaptftparchiveconfig
928 [ -e dists ] || buildaptftparchivedirectorystructure
929 msgninfo "\tGenerate Packages
, Sources and Contents files…
"
930 testsuccess aptftparchive generate ftparchive.conf
933 generatereleasefiles "$@
"
936 buildaptarchivefromfiles() {
937 msginfo "Build APT archive
for ${CCMD}${0##*/}${CINFO} based on prebuild files…
"
938 local DIR='aptarchive'
939 if [ -d "${DIR}/dists
" ]; then DIR="${DIR}/dists
"; fi
940 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do
941 msgninfo "\t${line} file…
"
942 compressfile "$line" "$1"
945 generatereleasefiles "$@
"
949 cat "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
" | while read compressor extension command; do
950 if [ "$compressor" = '.' ]; then
956 cat "$1" | $command > "${1}.
${extension}"
958 touch -d "$2" "${1}.
${extension}"
963 # can be overridden by testcases for their pleasure
964 getcodenamefromsuite() {
966 unstable) echo 'sid';;
970 getreleaseversionfromsuite() { true; }
971 getlabelfromsuite() { true; }
972 getoriginfromsuite() { true; }
973 getarchitecturesfromreleasefile() { echo "all
$(getarchitectures)"; }
975 aptftparchiverelease() {
976 aptftparchive -qq release "$@
" | sed -e '/0 Release$/ d' # remove the self reference
978 generatereleasefiles() {
979 # $1 is the Date header and $2 is the ValidUntil header to be set
980 # both should be given in notation date/touch can understand
982 local VALIDUNTIL="$2"
983 if [ -e aptarchive/dists ]; then
984 msgninfo "\tGenerate Release files
for dists…
"
985 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
986 local ARCHITECTURES="$(getarchitecturesfromreleasefile "$dir")"
987 local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
988 local CODENAME="$(getcodenamefromsuite $SUITE)"
989 local VERSION="$(getreleaseversionfromsuite $SUITE)"
990 local LABEL="$(getlabelfromsuite $SUITE)"
991 local ORIGIN="$(getoriginfromsuite $SUITE)"
992 aptftparchiverelease "$dir" \
993 -o APT::FTPArchive::Release::Suite="${SUITE}" \
994 -o APT::FTPArchive::Release::Codename="${CODENAME}" \
995 -o APT::FTPArchive::Release::Architectures="${ARCHITECTURES}" \
996 -o APT::FTPArchive::Release::Label="${LABEL}" \
997 -o APT::FTPArchive::Release::Origin="${ORIGIN}" \
998 -o APT::FTPArchive::Release::Version="${VERSION}" \
1000 if [ "$SUITE" = "experimental
" -o "$SUITE" = "experimental2
" ]; then
1001 sed -i '/^Date: / a\
1002 NotAutomatic: yes' "$dir/Release
"
1006 msgninfo "\tGenerate Release files
for flat…
"
1007 aptftparchiverelease ./aptarchive > aptarchive/Release
1009 if [ -n "$DATE" -a "$DATE" != "now
" ]; then
1010 for release in $(find ./aptarchive -name 'Release'); do
1011 sed -i "s
/^Date
: .
*$
/Date
: $(date -d "$DATE" '+%a, %d %b %Y %H:%M:%S %Z')/" "$release"
1012 touch -d "$DATE" "$release"
1015 if [ -n "$VALIDUNTIL" ]; then
1016 sed -i "/^Date
: / a\
1017 Valid
-Until: $(date -d "$VALIDUNTIL" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release')
1022 setupdistsaptarchive() {
1023 local APTARCHIVE="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1024 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
1025 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
1026 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1027 SECTIONS=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1028 msgninfo "\tadd deb and deb
-src sources.list lines
for ${CCMD}${DISTS} ${SECTIONS}${CINFO}…
"
1029 echo "deb
file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
"
1030 echo "deb
-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
"
1035 setupflataptarchive() {
1036 local APTARCHIVE="$(readlink -f ./aptarchive)"
1037 local APTARCHIVEURI="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1038 if [ -f "${APTARCHIVE}/Packages
" ]; then
1039 msgninfo "\tadd deb sources.list line…
"
1040 echo "deb
file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1043 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1045 if [ -f "${APTARCHIVE}/Sources
" ]; then
1046 msgninfo "\tadd deb
-src sources.list line…
"
1047 echo "deb
-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1050 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1056 if [ "$1" = '--no-update' ]; then
1060 buildaptarchive "$@
"
1061 if [ -e aptarchive/dists ]; then
1062 setupdistsaptarchive
1066 signreleasefiles 'Joe Sixpack'
1067 if [ "1" != "$NOUPDATE" ]; then
1068 testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true
1072 signreleasefiles() {
1073 local SIGNER="${1:-Joe Sixpack}"
1074 local REPODIR="${2:-aptarchive}"
1075 local KEY="keys
/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
1076 local GPG="aptkey
--quiet --keyring ${KEY}.pub
--secret-keyring ${KEY}.sec
--readonly adv
--batch --yes --digest-algo SHA512
"
1077 msgninfo "\tSign archive with
$SIGNER key
$KEY…
"
1078 local REXKEY='keys/rexexpired'
1079 local SECEXPIREBAK="${REXKEY}.sec.bak
"
1080 local PUBEXPIREBAK="${REXKEY}.pub.bak
"
1081 if [ "${SIGNER}" = 'Rex Expired' ]; then
1082 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1083 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1084 # therefore we 'temporary' make the key not expired and restore a backup after signing
1085 cp "${REXKEY}.sec
" "$SECEXPIREBAK"
1086 cp "${REXKEY}.pub
" "$PUBEXPIREBAK"
1087 local SECUNEXPIRED="${REXKEY}.sec.unexpired
"
1088 local PUBUNEXPIRED="${REXKEY}.pub.unexpired
"
1089 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1090 cp "$SECUNEXPIRED" "${REXKEY}.sec
"
1091 cp "$PUBUNEXPIRED" "${REXKEY}.pub
"
1093 if ! printf "expire
\n1w
\nsave
\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then
1097 cp "${REXKEY}.sec
" "$SECUNEXPIRED"
1098 cp "${REXKEY}.pub
" "$PUBUNEXPIRED"
1101 for RELEASE in $(find "${REPODIR}/" -name Release); do
1102 testsuccess $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output "${RELEASE}.gpg
" "${RELEASE}"
1103 local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
1104 testsuccess $GPG --default-key "$SIGNER" --clearsign --output "$INRELEASE" "$RELEASE"
1105 # we might have set a specific date for the Release file, so copy it
1106 touch -d "$(stat --format "%y" ${RELEASE})" "${RELEASE}.gpg
" "${INRELEASE}"
1108 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1109 mv -f "$SECEXPIREBAK" "${REXKEY}.sec
"
1110 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub
"
1115 redatereleasefiles() {
1116 local DATE="$(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
1117 for release in $(find aptarchive/ -name 'Release'); do
1118 sed -i "s
/^Date
: .
*$
/Date
: ${DATE}/" "$release"
1119 touch -d "$DATE" "$release"
1121 signreleasefiles "${2:-Joe Sixpack}"
1125 local WEBSERVER="${3:-http://localhost:${APTHTTPPORT}}"
1127 if [ "$1" = '--no-check' ]; then
1131 local DOWNLOG='rootdir/tmp/download-testfile.log'
1132 local STATUS='downloaded/webserverconfig.status'
1133 rm -f "$STATUS" "$DOWNLOG"
1134 # very very basic URI encoding
1136 if [ -n "$2" ]; then
1137 msgtest "Set webserver config option
'${1}' to
" "$2"
1138 URI="${WEBSERVER}/_config
/set
/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1140 msgtest 'Clear webserver config option' "${1}"
1141 URI="${WEBSERVER}/_config
/clear
/$(echo "${1}" | sed -e 's/\//%2f/g')"
1143 if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then
1146 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir
/tmp
/webserverconfig.output
"
1147 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1148 msgfailoutput '' "$OUTPUT"
1150 $NOCHECK || testwebserverlaststatuscode '200'
1153 rewritesourceslist() {
1154 local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1155 local APTARCHIVE2="copy
://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1156 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1157 sed -i $LIST -e "s
#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
1158 -e "s#http://localhost:${APTHTTPPORT}/#${1}#" \
1159 -e "s#https://localhost:${APTHTTPSPORT}/#${1}#"
1163 # wait for up to 10s for a pid file to appear to avoid possible race
1164 # when a helper is started and dosn't write the PID quick enough
1167 for i
in $(seq 10); do
1168 if test -s "$PIDFILE"; then
1173 msgdie
"waiting for $PIDFILE failed"
1177 changetowebserver
() {
1179 if [ "$1" != '--no-rewrite' ]; then
1184 if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
1186 local LOG
="webserver.log"
1187 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1191 waitforpidfile aptwebserver.pid
1192 local PID
="$(cat aptwebserver.pid)"
1193 if [ -z "$PID" ]; then
1194 msgdie
'Could not fork aptwebserver successfully'
1196 addtrap
"kill $PID;"
1197 waitforpidfile aptwebserver.port
1198 APTHTTPPORT
="$(cat aptwebserver.port)"
1199 if [ -z "$APTHTTPPORT" ]; then
1200 msgdie
'Could not get port for aptwebserver successfully'
1204 msgdie
'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver'
1206 if [ "$REWRTE" != 'yes' ]; then
1207 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1211 changetohttpswebserver
() {
1212 if ! command -v stunnel4
>/dev
/null
2>&1; then
1213 msgdie
'You need to install stunnel4 for https testcases'
1215 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1216 changetowebserver
--no-rewrite "$@"
1218 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1219 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1224 connect = $APTHTTPPORT
1225 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1226 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1227 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1228 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1229 if [ -z "$PID" ]; then
1230 msgdie
'Could not fork stunnel4 successfully'
1232 addtrap
'prefix' "kill ${PID};"
1233 APTHTTPSPORT
="$(lsof -i | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1234 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1235 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1239 mkdir -p rootdir
/media
/cdrom
/.disk
1240 local CD
="$(readlink -f rootdir/media/cdrom)"
1241 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1242 acquire::cdrom::mount "${CD}";
1243 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1244 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1245 acquire::cdrom::autodetect 0;
1247 echo -n "$1" > "${CD}/.disk/info"
1248 if [ ! -d aptarchive
/dists
]; then
1249 msgdie
'Flat file archive cdroms can not be created currently'
1252 mv aptarchive
/dists
"$CD"
1253 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1254 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1255 # start with an unmounted disk
1256 mv "${CD}" "${CD}-unmounted"
1257 # we don't want the disk to be modifiable
1258 addtrap
'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;"
1259 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1263 local PROTO
="${1%%:*}"
1264 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1265 download
-file "$1" "$2" "$3" 2>&1 ; then
1268 # only if the file exists the download was successful
1269 if [ -r "$2" ]; then
1277 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1278 if [ -n "$DIFFTEXT" ]; then
1280 echo >&2 "$DIFFTEXT"
1288 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1289 local COMPAREFILE
="$1"
1291 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1294 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1295 cat "$COMPAREFILE" >>"${OUTPUT}"
1296 msgfailoutput
'' "$OUTPUT" "$@"
1301 msggroup
'testfileequal'
1302 local MSG
='Test for correctness of file'
1303 if [ "$1" = '--nomsg' ]; then
1309 if [ -n "$MSG" ]; then
1310 msgtest
"$MSG" "$FILE"
1312 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1313 if [ -z "$*" ]; then
1314 testoutputequal
"$FILE" echo -n ''
1316 testoutputequal
"$FILE" echo "$*"
1322 msggroup
'testempty'
1323 if [ "$1" = '--nomsg' ]; then
1326 msgtest
"Test for no output of" "$*"
1328 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1329 if "$@" >"$COMPAREFILE" 2>&1 && test ! -s "$COMPAREFILE"; then
1332 msgfailoutput
'' "$COMPAREFILE" "$@"
1334 aptautotest
'testempty' "$@"
1338 msggroup
'testnotempty'
1339 msgtest
"Test for some output of" "$*"
1340 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
1341 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then
1344 msgfailoutput
'' "$COMPAREFILE" "$@"
1346 aptautotest
'testnotempty' "$@"
1351 msggroup
'testequal'
1352 local MSG
='Test of equality of'
1353 if [ "$1" = '--nomsg' ]; then
1358 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1359 echo "$1" > "$COMPAREFILE"
1362 if [ -n "$MSG" ]; then
1365 testoutputequal
"$COMPAREFILE" "$@"
1366 aptautotest
'testequal' "$@"
1371 msggroup
'testequalor2'
1372 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1373 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1374 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1375 echo "$1" > "$COMPAREFILE1"
1376 echo "$2" > "$COMPAREFILE2"
1378 msgtest
"Test for equality OR of" "$*"
1379 "$@" >"$COMPAREAGAINST" 2>&1 || true
1380 if checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null
2>&1 || \
1381 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null
2>&1
1385 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1386 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1387 checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1388 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1389 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1390 msgfailoutput
'' "$OUTPUT"
1392 aptautotest
'testequalor2' "$@"
1397 msggroup
'testshowvirtual'
1398 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1401 while [ -n "$1" ]; do
1403 N: Can't select versions from package '$1' as it is purely virtual"
1404 PACKAGE
="${PACKAGE} $1"
1407 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1409 N: No packages found"
1410 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1411 local ARCH
="$(getarchitecture 'native')"
1412 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1413 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1414 testoutputequal
"$COMPAREFILE" aptcache show
"$PACKAGE"
1419 msggroup
'testnopackage'
1420 msgtest
"Test for non-existent packages" "apt-cache show $*"
1421 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1422 if [ -n "$SHOWPKG" ]; then
1423 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1424 echo "$SHOWPKG" >"$OUTPUT"
1425 msgfailoutput
'' "$OUTPUT"
1431 testnosrcpackage
() {
1432 msggroup
'testnosrcpackage'
1433 msgtest
"Test for non-existent source packages" "apt-cache showsrc $*"
1434 local SHOWPKG
="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')"
1435 if [ -n "$SHOWPKG" ]; then
1436 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output"
1437 echo "$SHOWPKG" >"$OUTPUT"
1438 msgfailoutput
'' "$OUTPUT"
1446 msggroup
'testdpkgstatus'
1450 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1451 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1452 if [ "$PKGS" != $NR ]; then
1453 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1454 echo "$PKGS" >"$OUTPUT"
1455 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1456 msgfailoutput
'' "$OUTPUT"
1463 testdpkginstalled
() {
1464 msggroup
'testdpkginstalled'
1465 testdpkgstatus
'ii' "$#" "$@"
1469 testdpkgnotinstalled
() {
1470 msggroup
'testdpkgnotinstalled'
1471 testdpkgstatus
'ii' '0' "$@"
1476 msggroup
'testmarkedauto'
1477 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1478 if [ -n "$1" ]; then
1479 msgtest
'Test for correctly marked as auto-installed' "$*"
1480 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1482 msgtest
'Test for correctly marked as auto-installed' 'no package'
1483 echo -n > "$COMPAREFILE"
1485 testoutputequal
"$COMPAREFILE" aptmark showauto
1488 testmarkedmanual
() {
1489 msggroup
'testmarkedmanual'
1490 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1491 if [ -n "$1" ]; then
1492 msgtest
'Test for correctly marked as manually installed' "$*"
1493 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1495 msgtest
'Test for correctly marked as manually installed' 'no package'
1496 echo -n > "$COMPAREFILE"
1498 testoutputequal
"$COMPAREFILE" aptmark showmanual
1503 msgreportheader
'msgfailoutput'
1507 if [ "$1" = 'grep' ]; then
1509 while [ -n "$2" ]; do shift; done
1510 echo "#### Complete file: $1 ####"
1511 cat >&2 "$1" || true
1512 echo '#### grep output ####'
1513 elif [ "$1" = 'test' ]; then
1515 # doesn't support ! or non-file flags
1516 msgfailoutputstatfile
() {
1517 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1518 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1519 echo "#### stat(2) of file: $2 ####"
1521 if test -d "$2"; then
1522 echo "#### The directory contains: $2 ####"
1524 elif test -e "$2"; then
1525 echo "#### Complete file: $2 ####"
1526 cat >&2 "$2" || true
1530 msgfailoutputstatfile
"$2" "$3"
1531 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1533 msgfailoutputstatfile
"$2" "$3"
1535 echo '#### test output ####'
1536 elif [ "$1" = 'cmp' ]; then
1538 while [ -n "$2" ]; do
1539 echo "#### Complete file: $2 ####"
1540 cat >&2 "$2" || true
1543 echo '#### cmp output ####'
1549 testsuccesswithglobalerror
() {
1554 if [ "$1" = '--nomsg' ]; then
1557 msgtest
'Test for successful execution of' "$*"
1559 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output"
1560 if "$@" >"${OUTPUT}" 2>&1; then
1561 if expr match
"$1" '^apt.*' >/dev
/null
; then
1562 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1563 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1564 elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1565 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1566 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1567 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1570 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1573 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1575 elif [ "$TYPE" = 'testsuccesswithnotice' ]; then
1576 if grep -q -E "^N: " "$OUTPUT"; then
1579 msgfailoutput
'successful run, but output had no notices' "$OUTPUT" "$@"
1589 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1591 aptautotest
"$TYPE" "$@"
1594 testsuccesswithnotice
() {
1595 testsuccesswithglobalerror
'testsuccesswithnotice' 'WE' "$@"
1598 testsuccesswithglobalerror
'testsuccess' 'NWE' "$@"
1601 msggroup
'testwarning'
1602 if [ "$1" = '--nomsg' ]; then
1605 msgtest
'Test for successful execution with warnings of' "$*"
1607 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1608 if "$@" >"${OUTPUT}" 2>&1; then
1609 if expr match
"$1" '^apt.*' >/dev
/null
; then
1610 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1611 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1612 elif grep -q -E '^E: ' "$OUTPUT"; then
1613 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1614 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1615 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1624 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1626 aptautotest
'testwarning' "$@"
1630 msggroup
'testfailure'
1631 if [ "$1" = '--nomsg' ]; then
1634 msgtest
'Test for failure in execution of' "$*"
1636 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1637 if "$@" >"${OUTPUT}" 2>&1; then
1639 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1642 if expr match
"$1" '^apt.*' >/dev
/null
; then
1643 if [ "$1" = 'aptkey' ]; then
1644 if grep -q -E " Can't check signature: " "$OUTPUT" || \
1645 grep -q -E " BAD signature from " "$OUTPUT"; then
1648 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1651 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1652 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1653 elif grep -q -E '==ERROR' "$OUTPUT"; then
1654 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1655 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1656 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1665 aptautotest
'testfailure' "$@"
1669 testreturnstateequal
() {
1671 if [ "$STATE" = 'testsuccesswithglobalerror' ]; then
1675 msggroup
"${STATE}equal"
1676 if [ "$1" != '--nomsg' ]; then
1679 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1680 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1684 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1685 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1688 msggroup
"${STATE}equal"
1689 if [ "$2" != '--nomsg' ]; then
1693 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1697 "$STATE" --nomsg "$@"
1698 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1703 testsuccessequal
() {
1704 # we compare output, so we know perfectly well about N:
1705 testreturnstateequal
'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@"
1707 testwarningequal
() {
1708 testreturnstateequal
'testwarning' "$@"
1710 testfailureequal
() {
1711 testreturnstateequal
'testfailure' "$@"
1715 msggroup
'testfailuremsg'
1719 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1720 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1721 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1722 testoutputequal
"$COMPAREFILE" echo "$CMP"
1726 msggroup
'testwarningmsg'
1730 msgtest
'Check that the output of the previous warned command has expected' 'warnings'
1731 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
1732 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
1733 testoutputequal
"$COMPAREFILE" echo "$CMP"
1738 msggroup
'testfilestats'
1739 msgtest
"Test that file $1 has $2 $3" "$4"
1740 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1743 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1746 echo -n "stat(1) reports for $2: "
1747 stat
--format "$2" "$1" || true
1749 msgfailoutput
'' "$OUTPUT"
1753 testaccessrights
() {
1754 msggroup
'testaccessrights'
1755 testfilestats
"$1" '%a' '=' "$2"
1759 testwebserverlaststatuscode
() {
1760 msggroup
'testwebserverlaststatuscode'
1761 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1762 local STATUS
='downloaded/webserverstatus-statusfile.log'
1763 rm -f "$DOWNLOG" "$STATUS"
1764 msgtest
'Test last status code from the webserver was' "$1"
1765 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1768 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1770 if [ -n "$2" ]; then
1772 echo >&2 '#### Additionally provided output files contain:'
1775 echo >&2 '#### Download log of the status code:'
1778 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1783 createlistofkeys
() {
1786 while [ -n "$1" ]; do
1787 # gpg 2.1.something starts printing [SC] at some point
1788 if grep -q ' rsa2048/' "$OUTPUT" && grep -qF '[SC]' "$OUTPUT"; then
1790 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';;
1791 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [SC] [expired: 2013-07-13]';;
1792 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16 [SC]';;
1793 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19 [SC]';;
1794 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';;
1795 *) echo 'UNKNOWN KEY';;
1797 # gpg 2.1 has a slightly different output format
1798 elif grep -q ' rsa2048/' "$OUTPUT"; then
1800 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1801 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1802 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16';;
1803 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19';;
1804 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1805 *) echo 'UNKNOWN KEY';;
1809 *Joe
*|*Sixpack
*) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1810 *Rex
*|*Expired
*) echo 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1811 *Marvin
*|*Paranoid
*) echo 'pub 2048R/528144E2 2011-01-16';;
1812 oldarchive
) echo 'pub 1024R/F68C85A3 2013-12-19';;
1813 newarchive
) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1814 *) echo 'UNKNOWN KEY';;
1821 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output"
1822 if ! aptkey list
| grep '^pub' > "$OUTPUT"; then
1825 testfileequal
"$OUTPUT" "$(createlistofkeys "$OUTPUT" "$@")"
1829 echo "STOPPED execution. Press enter to continue"
1834 listcurrentlistsdirectory
() {
1836 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1837 stat
--format '%U:%G:%a:%n' "$line"
1839 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1840 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1844 forallsupportedcompressors
() {
1845 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
1846 if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi
1851 ### convenience hacks ###
1853 # creating some directories by hand is a tedious task, so make it look simple
1855 if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then
1856 # only the last directory created by mkdir is effected by the -m !
1857 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1858 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1859 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1860 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1861 if [ "$(id -u)" = '0' ]; then
1862 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1869 ### The following tests are run by most test methods automatically to check
1870 ### general things about commands executed without writing the test every time.
1876 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')"
1877 if command -v $AUTOTEST >/dev
/null
; then
1879 # save and restore the *.output files from other tests
1880 # as we might otherwise override them in these automatic tests
1881 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1882 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1883 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1884 $AUTOTEST "$TESTCALL" "$@"
1885 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1886 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1887 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1891 aptautotest_aptget_update
() {
1893 while [ -n "$2" ]; do
1894 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1897 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1898 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1899 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1900 # all copied files are properly chmodded
1901 local backupIFS
="$IFS"
1902 IFS
="$(printf "\n\b")"
1903 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1904 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1907 if [ "$TESTCALL" = 'testsuccess' ]; then
1908 # failure cases can retain partial files and such
1909 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
1912 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1913 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
1915 testaptautotestnodpkgwarning
() {
1917 while [ -n "$2" ]; do
1918 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
1919 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
1922 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1925 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
1926 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
1927 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
1928 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
1929 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
1930 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }