1 #!/bin/sh -- # no runable script, just for vi
6 if [ "$1" = "-q" ]; then
8 elif [ "$1" = "-v" ]; then
10 elif [ "$1" = '--color=no' ]; then
12 elif [ "$1" = '--color=yes' ]; then
14 elif [ "$1" = '--color' ]; then
15 export MSGCOLOR
="$(echo "$2" | tr 'a-z' 'A-Z')"
17 elif [ "$1" = '--level' ]; then
21 echo >&2 "WARNING: Unknown parameter »$1« will be ignored"
25 export MSGLEVEL
="${MSGLEVEL:-3}"
27 # we all like colorful messages
28 if [ "${MSGCOLOR:-YES}" = 'YES' ]; then
29 if [ ! -t 1 ]; then # but check that we output to a terminal
35 if [ "$MSGCOLOR" != 'NO' ]; then
36 CERROR
="\033[1;31m" # red
37 CWARNING
="\033[1;33m" # yellow
38 CMSG
="\033[1;32m" # green
39 CINFO
="\033[1;96m" # light blue
40 CDEBUG
="\033[1;94m" # blue
41 CNORMAL
="\033[0;39m" # default system console color
42 CDONE
="\033[1;32m" # green
43 CPASS
="\033[1;32m" # green
44 CFAIL
="\033[1;31m" # red
45 CCMD
="\033[1;35m" # pink
57 printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghks]\)#apt-\1#')"
63 msgdie
() { msgprintf
"${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; }
64 msgwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; }
65 msgmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; }
66 msginfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; }
67 msgdebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; }
68 msgdone
() { msgprintf
"${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; }
69 msgnwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; }
70 msgnmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}" "$@"; }
71 msgninfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
72 msgndebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
73 msgtest
() { msgprintf
"${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
74 msgpass
() { printf "${CPASS}PASS${CNORMAL}\n"; }
76 if [ -n "$MSGTEST_MSG" ]; then
77 test "$1" != 'msgfailoutput' || echo
78 if [ -n "$MSGTEST_MSGMSG" ]; then
79 echo "$MSGTEST_MSGMSG"
81 if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then
82 echo "${CFAIL}Part of the test group: $MSGTEST_GRP"
84 echo -n "$MSGTEST_MSG"
89 msgreportheader
'msgskip'
90 if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
91 else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
94 msgreportheader
'msgfail'
95 if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
96 else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
97 if [ -n "$APT_DEBUG_TESTS" ]; then
100 EXIT_CODE
=$((EXIT_CODE+1));
105 if [ $MSGGROUP_LEVEL = 0 ]; then
108 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL+1));
110 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL-1));
111 if [ $MSGGROUP_LEVEL = 0 ]; then
117 # enable / disable Debugging
118 if [ $MSGLEVEL -le 0 ]; then
121 if [ $MSGLEVEL -le 1 ]; then
125 if [ $MSGLEVEL -le 2 ]; then
127 MSGTEST_MSGMSG
="$(msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@")"
131 MSGTEST_MSG
="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")"
132 if [ "$MSGTEST_GRP" = 'NEXT' ]; then
133 MSGTEST_GRP
="$MSGTEST_MSG"
136 msgpass
() { printf " ${CPASS}P${CNORMAL}"; }
138 if [ $MSGLEVEL -le 3 ]; then
142 if [ $MSGLEVEL -le 4 ]; then
144 msgndebug
() { true
; }
147 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
148 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
149 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
150 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
151 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
154 printf "${CDONE}DONE${CNORMAL}\n";
158 if [ -f .
/aptconfig.conf
]; then
159 echo "$(readlink -f ./aptconfig.conf)"
160 elif [ -f ..
/aptconfig.conf
]; then
161 echo "$(readlink -f ../aptconfig.conf)"
162 elif [ -f ..
/..
/aptconfig.conf
]; then
163 echo "$(readlink -f ../../aptconfig.conf)"
164 elif [ -f "${TMPWORKINGDIRECTORY}/aptconfig.conf" ]; then
165 echo "$(readlink -f "${TMPWORKINGDIRECTORY}/aptconfig.conf")"
169 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
173 sh
|aptitude
|*/*|command) ;;
174 *) CMD
="${BUILDDIRECTORY}/$CMD";;
176 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
="${LIBRARYPATH}:${LD_LIBRARY_PATH}" "$CMD" "$@"
178 runpython3
() { runapt
command python3
"$@"; }
179 aptconfig
() { runapt apt
-config "$@"; }
180 aptcache
() { runapt apt
-cache "$@"; }
181 aptcdrom
() { runapt apt
-cdrom "$@"; }
182 aptget
() { runapt apt
-get "$@"; }
183 aptftparchive
() { runapt apt
-ftparchive "$@"; }
184 aptkey
() { runapt apt
-key "$@"; }
185 aptmark
() { runapt apt
-mark "$@"; }
186 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; }
187 apt
() { runapt apt
"$@"; }
188 apthelper
() { runapt
"${APTHELPERBINDIR}/apt-helper" "$@"; }
189 aptwebserver
() { runapt
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
190 aptitude
() { runapt aptitude
"$@"; }
191 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; }
192 aptinternalsolver
() { runapt
"${APTINTERNALSOLVER}" "$@"; }
193 aptdumpsolver
() { runapt
"${APTDUMPSOLVER}" "$@"; }
196 "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@"
198 dpkgcheckbuilddeps
() {
199 command dpkg
-checkbuilddeps --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" "$@"
204 aptget
) CMD
="apt-get";;
205 aptcache
) CMD
="apt-cache";;
206 aptcdrom
) CMD
="apt-cdrom";;
207 aptconfig
) CMD
="apt-config";;
208 aptmark
) CMD
="apt-mark";;
209 apthelper
) CMD
="apt-helper";;
210 aptftparchive
) CMD
="apt-ftparchive";;
211 dpkg
) shift; runapt
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" "$@"; return;;
215 if [ "${CMD##*/}" = "$CMD" ]; then
216 CMD
="${BUILDDIRECTORY}/${CMD}"
218 runapt
command gdb
--quiet -ex run
"$CMD" --args "$CMD" "$@"
221 date -u -d "@$(stat -c '%Y' "${TMPWORKINGDIRECTORY}/$1")" '+%a, %d %b %Y %H:%M:%S GMT'
224 grep "^${2:-Date}:" "$1" | cut
-d' ' -f 2- | sed -e 's#UTC#GMT#'
228 # error if we about to overflow, but ...
229 # "255 failures ought to be enough for everybody"
230 if [ $EXIT_CODE -gt 255 ]; then
231 msgdie
"Total failure count $EXIT_CODE too big"
233 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
236 shellsetedetector
() {
238 if [ "$exit_status" != '0' ]; then
239 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
240 if [ "$EXIT_CODE" = '0' ]; then
241 EXIT_CODE
="$exit_status"
247 if [ "$1" = 'prefix' ]; then
248 CURRENTTRAP
="$2 $CURRENTTRAP"
250 CURRENTTRAP
="$CURRENTTRAP $1"
252 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
256 echo "$@" | sed -e "s#'#'\"'\"'#g"
260 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
261 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
264 TMPWORKINGDIRECTORY
="$(mktemp -d)"
265 addtrap
"cd /; rm -rf '$(escape_shell "$TMPWORKINGDIRECTORY")';"
266 if [ -n "$TMPDIR_ADD" ]; then
267 TMPWORKINGDIRECTORY
="${TMPWORKINGDIRECTORY}/${TMPDIR_ADD}"
268 mkdir -p "$TMPWORKINGDIRECTORY"
270 export TMPDIR
="$TMPWORKINGDIRECTORY"
272 msgninfo
"Preparing environment for ${0##*/} in ${TMPWORKINGDIRECTORY}…"
274 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
275 if [ "$(id -u)" = '0' ]; then
276 # relax permissions so that running as root with user switching works
278 chmod 711 "$TMPWORKINGDIRECTORY"
279 chown _apt
:root
"${TMPWORKINGDIRECTORY}/downloaded"
282 TESTDIRECTORY
="$(readlink -f "$(dirname $0)")"
283 # allow overriding the default BUILDDIR location
284 SOURCEDIRECTORY="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}"
285 BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}"
286 LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}"
287 METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}"
288 APTHELPERBINDIR="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}"
289 APTWEBSERVERBINDIR="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}"
290 APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}"
291 APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}"
292 test -x "${BUILDDIRECTORY}/apt
-get" || msgdie "You need to build tree first
"
295 cd "$TMPWORKINGDIRECTORY"
296 mkdir rootdir aptarchive keys
298 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
299 mkdir -p usr/bin var/cache var/lib var/log tmp
300 mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
301 touch var/lib/dpkg/available
303 ln -s "${METHODSDIR}" usr/lib/apt/methods
304 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
305 mkdir -p usr/lib/apt/solvers
306 ln -s "${BUILDDIRECTORY}/apt
-dump-solver" usr/lib/apt/solvers/dump
307 ln -s "${BUILDDIRECTORY}/apt
-internal-solver" usr/lib/apt/solvers/apt
308 echo "Dir
::Bin
::Solvers
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/solvers
\";" > etc/apt/apt.conf.d/externalsolver.conf
310 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
312 if [ -e "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" ]; then
313 ln -s "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" etc/apt/apt.conf.d/01autoremove
315 ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
318 local BASENAME="${0##*/}"
319 local PACKAGESFILE="Packages
-${BASENAME#*-}"
320 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
321 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
323 local SOURCESSFILE="Sources
-${BASENAME#*-}"
324 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
325 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
327 find "$TESTDIRECTORY" \( -name '*.pub' -o -name '*.sec' \) -exec cp '{}' keys/ \;
329 ln -s "${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub
" rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
331 echo "Dir
\"${TMPWORKINGDIRECTORY}/rootdir
\";" > aptconfig.conf
332 echo "Dir
::state
::status
\"${TMPWORKINGDIRECTORY}/rootdir
/var
/lib
/dpkg
/status
\";" >> aptconfig.conf
333 echo "APT
::Get
::Show
-User-Simulation-Note \"false
\";" >> aptconfig.conf
334 echo "Dir
::Bin
::Methods
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/methods
\";" >> aptconfig.conf
335 # either store apt-key were we can access it, even if we run it as a different user
336 #cp "${BUILDDIRECTORY}/apt
-key" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/"
337 #chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key"
338 #echo "Dir
::Bin
::apt
-key \"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key\";" >> aptconfig.conf
339 # destroys coverage reporting though, so we disable changing user for the calling gpgv
340 echo "Dir
::Bin
::apt
-key \"${BUILDDIRECTORY}/apt
-key\";" >> aptconfig.conf
341 if [ "$(id -u)" = '0' ]; then
342 echo 'Binary::gpgv::APT::Sandbox::User "root
";' >> aptconfig.conf
343 # same for the solver executables
344 echo 'APT::Solver::RunAsUser "root
";' >> aptconfig.conf
347 cat > "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
350 if [ -r '${TMPWORKINGDIRECTORY}/noopchroot.so' ]; then
351 if [ -n "\
$LD_LIBRARY_PATH" ]; then
352 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}:'"\
${LD_LIBRARY_PATH}"
354 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}'
356 if [ -n "\
$LD_PRELOAD" ]; then
357 export LD_PRELOAD="noopchroot.so \
${LD_PRELOAD}"
359 export LD_PRELOAD="noopchroot.so
"
363 cp "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
364 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
365 exec fakeroot '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
366 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
367 --force-not-root --force-bad-path "\$@
"
369 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg" <<EOF
370 exec fakeroot gdb --quiet -ex run '${DPKG:-dpkg}' --args '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
371 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
372 --force-not-root --force-bad-path "\$@
"
374 chmod +x "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
375 echo "Dir
::Bin
::dpkg
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
\";" > rootdir/etc/apt/apt.conf.d/99dpkg
378 if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
379 echo "DPKG
::options
:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
382 echo 'quiet::NoUpdate "true
";'
383 echo 'quiet::NoStatistic "true
";'
384 # too distracting for users, but helpful to detect changes
385 echo 'Acquire::Progress::Ignore::ShowErrorText "true
";'
386 echo 'Acquire::Progress::Diffpercent "true
";'
387 # in testcases, it can appear as if localhost has a rotation setup,
388 # hide this as we can't really deal with it properly
389 echo 'Acquire::Failure::ShowIP "false
";'
390 # fakeroot can't fake everything, so disabled in production but good for tests
391 echo 'APT::Sandbox::Verify "true
";'
394 cp "${TESTDIRECTORY}/apt.pem
" "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
395 if [ "$(id -u)" = '0' ]; then
396 chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
398 echo "Acquire
::https
::CaInfo
\"${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
\";" > rootdir/etc/apt/apt.conf.d/99https
399 echo "Apt
::Cmd
::Disable
-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
400 echo 'Acquire::Connect::AddrConfig "false
";' > rootdir/etc/apt/apt.conf.d/connect-addrconfig
402 configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
403 confighashes 'SHA256' # these are tests, not security best-practices
405 # create some files in /tmp and look at user/group to get what this means
406 TEST_DEFAULT_USER="$(id -un)"
407 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
408 TEST_DEFAULT_GROUP='root'
410 TEST_DEFAULT_GROUP="$(id -gn)"
413 # cleanup the environment a bit
414 # prefer our apt binaries over the system apt binaries
415 export PATH="${BUILDDIRECTORY}:${PATH}:/usr
/local
/sbin
:/usr
/sbin
:/sbin
"
416 export LC_ALL=C.UTF-8
417 unset LANGUAGE APT_CONFIG
418 unset GREP_OPTIONS DEB_BUILD_PROFILES
419 unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy
421 # If gpgv supports --weak-digest, pass it to make sure we can disable SHA1
422 if aptkey verify --weak-digest SHA1 --help 2>/dev/null >/dev/null; then
423 echo 'Acquire::gpgv::Options { "--weak-digest"; "sha1
"; };' > rootdir/etc/apt/apt.conf.d/no-sha1
426 # most tests just need one signed Release file, not both
427 export APT_DONT_SIGN='Release.gpg'
433 if [ "$1" = "native
" -o -z "$1" ]; then
434 eval `aptconfig shell ARCH APT::Architecture`
435 if [ -n "$ARCH" ]; then
438 dpkg --print-architecture
446 aptconfig dump --no-empty --format '%v%n' APT::Architecture APT::Architectures | sort -u | tr '\n' ' '
449 getarchitecturesfromcommalist() {
450 echo "$1" | sed -e 's#,#\n#g' | sed -e "s
/^native\$
/$(getarchitecture 'native')/"
453 configarchitecture() {
455 echo "APT
::Architecture
\"$(getarchitecture $1)\";"
456 while [ -n "$1" ]; do
457 echo "APT
::Architectures
:: \"$(getarchitecture $1)\";"
460 } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
465 if [ ! -e rootdir/var/lib/dpkg/status ]; then
466 local BASENAME="${0##*/}"
467 local STATUSFILE="status
-${BASENAME#*-}"
468 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
469 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
471 echo -n > rootdir/var/lib/dpkg/status
474 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
475 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
476 local ARCHS="$(getarchitectures)"
477 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
478 DPKGARCH="$(dpkg --print-architecture)"
479 for ARCH in ${ARCHS}; do
480 if [ "${ARCH}" != "${DPKGARCH}" ]; then
481 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
482 # old-style used e.g. in Ubuntu-P – and as it seems travis
483 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
484 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
488 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
489 # dpkg doesn't really check the version as long as it is fully installed,
490 # but just to be sure we choose one above the required version
491 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
497 configdpkgnoopchroot() {
498 # create a library to noop chroot() and rewrite maintainer script executions
499 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
500 # chroot directory dpkg could chroot into to execute the maintainer scripts
501 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
502 cat > noopchroot.c << EOF
509 static char * chrootdir = NULL;
511 int chroot(const char *path) {
512 printf("WARNING
: CHROOTing to
%s was ignored
!\n", path);
514 chrootdir = strdup(path);
517 int execvp(const char *file, char *const argv[]) {
518 static int (*func_execvp) (const char *, char * const []) = NULL;
519 if (func_execvp == NULL)
520 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
");
521 if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0)
522 return func_execvp(file, argv);
523 printf("REWRITE execvp call
%s into
%s
\n", file, chrootdir);
525 if (asprintf(&newfile, "%s
%s
", chrootdir, file) == -1) {
529 char const * const baseadmindir = "/var
/lib
/dpkg
";
531 if (asprintf(&admindir, "%s
%s
", chrootdir, baseadmindir) == -1) {
535 setenv("DPKG_ADMINDIR
", admindir, 1);
536 return func_execvp(newfile, argv);
539 testempty --nomsg gcc -Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c -ldl
541 configcompression() {
542 if [ "$1" = 'ALL' ]; then
543 configcompression '.' $(aptconfig dump APT::Compressor --format '%t %v%n' | sed -n 's#^Extension \.\(.*\)$#\1#p')
546 local CMD='apthelper cat-file -C'
547 while [ -n "$1" ]; do
549 '.') printf ".
\t.
\tcat
\n";;
550 'gz') printf "gzip\tgz
\t$CMD $1\n";;
551 'bz2') printf "bzip2\tbz
2\t$CMD $1\n";;
552 *) printf "$1\t$1\t$CMD $1\n";;
555 done > "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
"
559 echo 'APT::FTPArchive {'
561 while [ -n "$1" ]; do
562 printf "$1" | tr 'a-z' 'A-Z'
563 printf "\t\"true
\";\n"
566 for h in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
567 printf "$h\t\"false
\";\n"
571 } >> "${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/ftparchive
-hashes.conf
"
576 COMPRESSOR_CMD="apthelper
cat-file -C $1"
578 gzip) COMPRESS='gz';;
579 bzip2) COMPRESS='bz2';;
581 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/00force
-compressor"
582 echo "Acquire
::CompressionTypes
::Order
{ \"${COMPRESS}\"; };
583 Dir
::Bin
::uncompressed
\"/does
/not
/exist
\";" > "$CONFFILE"
584 for COMP in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
585 if [ -z "$COMP" -o "$COMP" = '.' -o "$COMP" = "$COMPRESSOR" ]; then continue; fi
586 echo "Dir
::Bin
::${COMP} \"/does
/not
/exist
\";" >> "$CONFFILE"
587 echo "APT
::Compressor
::${COMP}::Name
\"${COMP}-disabled\";" >> "$CONFFILE"
591 setupsimplenativepackage() {
595 local RELEASE="${4:-unstable}"
596 local DEPENDENCIES="$5"
597 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
598 If you
find such a package installed on your system
,
599 something went horribly wrong
! They are autogenerated
600 und used only by testcases and serve no other purpose…
"}"
602 local SECTION
="${7:-others}"
604 if [ "$SECTION" = "${SECTION#*/}" ]; then
607 DISTSECTION
="${SECTION%/*}"
609 local BUILDDIR
=incoming
/${NAME}-${VERSION}
610 mkdir -p ${BUILDDIR}/debian
/source
612 echo "* most suckless software product ever" > FEATURES
613 test -e debian
/copyright
|| echo "Copyleft by Joe Sixpack $(date -u +%Y)" > debian
/copyright
614 test -e debian
/changelog
|| echo "$NAME ($VERSION) $RELEASE; urgency=low
618 -- Joe Sixpack <joe@example.org> $(date -u -R)" > debian
/changelog
619 test -e debian
/control
|| echo "Source: $NAME
622 Maintainer: Joe Sixpack <joe@example.org>
623 Build-Depends: debhelper (>= 7)
624 Standards-Version: 3.9.1
626 Package: $NAME" > debian
/control
627 if [ "$ARCH" = 'all' ]; then
628 echo "Architecture: all" >> debian
/control
630 echo "Architecture: any" >> debian
/control
632 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian
/control
633 echo "Description: $DESCRIPTION" >> debian
/control
635 test -e debian
/compat
|| echo "7" > debian
/compat
636 test -e debian
/source
/format
|| echo "3.0 (native)" > debian
/source
/format
637 test -e debian
/rules
|| cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny debian
/rules
641 buildsimplenativepackage
() {
644 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then
645 NM
="$(echo "$NAME" | cut -c 1-4)"
647 NM
="$(echo "$NAME" | cut -c 1)"
651 local RELEASE
="${4:-unstable}"
652 local DEPENDENCIES
="$5"
653 local DESCRIPTION
="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
654 If you find such a package installed on your system,
655 something went horribly wrong! They are autogenerated
656 und used only by testcases and serve no other purpose…"}"
658 local SECTION="${7:-others}"
659 local PRIORITY="${8:-optional}"
661 local COMPRESS_TYPE="${10:-gzip}"
663 if [ "$SECTION" = "${SECTION#*/}" ]; then
666 DISTSECTION="${SECTION%/*}"
668 local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming
/${NAME}-${VERSION}"
670 msgtest "Build
source package
in version
${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
671 mkdir -p "$BUILDDIR/debian
/source"
672 echo "* most suckless software product ever
" > "${BUILDDIR}/FEATURES
"
674 echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}"
676 echo "Copyleft by Joe Sixpack
$(date -u +%Y)" > "${BUILDDIR}/debian
/copyright
"
677 echo "$NAME ($VERSION) $RELEASE; urgency
=low
681 -- Joe Sixpack
<joe@example.org
> $(date -u -R)" > "${BUILDDIR}/debian
/changelog
"
685 Maintainer
: Joe Sixpack
<joe@example.org
>
686 Standards
-Version: 3.9.3"
687 if [ "$SECTION" != '<none>' ]; then
688 echo "Section
: $SECTION"
690 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
691 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
695 if [ "$ARCH" = 'all' ]; then
696 echo "Architecture
: all
"
698 echo "Architecture
: any
"
700 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
701 test -z "$DEPS" || echo "$DEPS"
702 echo "Description
: $DESCRIPTION"
703 } > "${BUILDDIR}/debian
/control
"
705 echo '3.0 (native)' > "${BUILDDIR}/debian
/source
/format
"
707 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
709 sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
" \
711 echo "pool
/${SRC}" >> "${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
"
712 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
713 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
714 # adv --yes --default-key 'Joe Sixpack' \
715 # --clearsign -o "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
716 # mv "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
720 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
721 msgtest "Build binary package
for ${RELEASE} in ${SECTION}" "$NAME"
722 rm -rf "${BUILDDIR}/debian
/tmp
"
723 mkdir -p "${BUILDDIR}/debian
/tmp
/DEBIAN
" "${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}" "${BUILDDIR}/debian
/tmp
/usr
/bin
"
724 cp "${BUILDDIR}/debian
/copyright
" "${BUILDDIR}/debian
/changelog
" "${BUILDDIR}/FEATURES
" "${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}"
725 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}"
726 if [ -n "$FILE_TREE" ]; then
727 cp -ar "$FILE_TREE" "${BUILDDIR}/debian
/tmp
"
730 (cd "${BUILDDIR}"; dpkg-gencontrol -DArchitecture=$arch)
731 (cd "${BUILDDIR}/debian
/tmp
"; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
732 local LOG="${BUILDDIR}/..
/${NAME}_
${VERSION}_
${arch}.dpkg
-deb.log
"
733 # ensure the right permissions as dpkg-deb insists
734 chmod 755 "${BUILDDIR}/debian
/tmp
/DEBIAN
"
735 testsuccess --nomsg dpkg-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian
/tmp
" "${BUILDDIR}/..
"
736 echo "pool
/${NAME}_
${VERSION}_
${arch}.deb
" >> "${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
"
739 local CHANGEPATH="${BUILDDIR}/..
/${DISTSECTION}/${NM}/${NAME}/${NAME}_
${VERSION}"
740 mkdir -p "$CHANGEPATH"
741 cp "${BUILDDIR}/debian
/changelog
" "$CHANGEPATH"
750 local ARCH=$(getarchitecture $4)
751 local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
752 local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
753 msgtest "Build package
for ${RELEASE} in ${SECTION}" "$PKGNAME"
755 if [ "$ARCH" = "all
" ]; then
756 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
758 testsuccess --nomsg dpkg-buildpackage -uc -us -a$ARCH
759 cp "${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
" "$BUILDLOG"
760 local PKGS="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
761 local SRCS="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
764 echo "pool
/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
"
767 echo "pool
/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
"
772 if [ -d incoming ]; then
773 buildaptarchivefromincoming "$@
"
775 buildaptarchivefromfiles "$@
"
779 createaptftparchiveconfig() {
780 local COMPRESSORS="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
781 local COMPRESSORS="${COMPRESSORS%* }"
782 local ARCHS="$(getarchitectures)"
783 cat > ftparchive.conf <<EOF
785 ArchiveDir "$(readlink -f .)";
786 CacheDir "$(readlink -f ..)";
787 FileListDir "$(readlink -f pool/)";
790 Packages::Compress "$COMPRESSORS";
791 Sources::Compress "$COMPRESSORS";
792 Contents::Compress "$COMPRESSORS";
793 Translation::Compress "$COMPRESSORS";
794 LongDescription "false
";
798 SrcDirectory "pool
/";
801 for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
804 Architectures "$ARCHS all
source";
805 FileList "${DIST}.\
$(SECTION).pkglist
";
806 SourceFileList "${DIST}.\
$(SECTION).srclist
";
807 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
810 done >> ftparchive.conf
813 buildaptftparchivedirectorystructure() {
814 local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
815 for DIST in $DISTS; do
816 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
817 for SECTION in $SECTIONS; do
818 local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
819 for ARCH in $ARCHS; do
820 mkdir -p "dists
/${DIST}/${SECTION}/binary
-${ARCH}"
822 mkdir -p "dists
/${DIST}/${SECTION}/source"
823 mkdir -p "dists
/${DIST}/${SECTION}/i18n
"
833 local DEPENDENCIES="$5"
834 local PRIORITY="${6:-optional}"
835 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
836 If you
find such a package installed on your system
,
837 something went horribly wrong
! They are autogenerated
838 und used only by testcases and serve no other purpose…
"}"
840 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
841 if [ "$RELEASE" = 'installed' ]; then
842 insertinstalledpackage
"$2" "$3" "$4" "$5" "$6" "$7"
845 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
846 if [ "$arch" = 'none' ]; then
847 ARCHS
="$(getarchitectures)"
851 for BUILDARCH
in $ARCHS; do
852 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
859 Maintainer: Joe Sixpack <joe@example.org>"
860 test "$arch" = 'none' || echo "Architecture: $arch"
861 echo "Version: $VERSION
862 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb"
863 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES"
864 echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)"
865 echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
867 } >> "${PPATH}/Packages"
870 mkdir -p "aptarchive/dists/${RELEASE}/main/source" "aptarchive/dists/${RELEASE}/main/i18n"
871 touch "aptarchive/dists/${RELEASE}/main/source/Sources"
873 Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
874 Description-en: $DESCRIPTION
875 " >> "aptarchive/dists/${RELEASE}/main/i18n/Translation-en"
884 local DEPENDENCIES
="$5"
885 local BINARY
="${6:-$NAME}"
887 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
888 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
890 local FILE
="${SPATH}/Sources"
891 local DSCFILE
="${NAME}_${VERSION}.dsc"
892 local TARFILE
="${NAME}_${VERSION}.tar.gz"
896 Maintainer: Joe Sixpack <joe@example.org>
897 Architecture: $ARCH" >> $FILE
898 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
900 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
901 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
903 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
904 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
909 insertinstalledpackage
() {
913 local DEPENDENCIES
="$4"
914 local PRIORITY
="${5:-optional}"
915 local STATUS
="${6:-install ok installed}"
916 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
917 If you find such a package installed on your system,
918 something went horribly wrong! They are autogenerated
919 und used only by testcases and serve no other purpose…"}"
921 local FILE='rootdir/var/lib/dpkg/status'
922 local INFO='rootdir/var/lib/dpkg/info'
923 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
929 Maintainer
: Joe Sixpack
<joe@example.org
>
930 Version
: $VERSION" >> "$FILE"
931 test "$arch" = 'none' || echo "Architecture
: $arch" >> "$FILE"
932 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
933 echo "Description
: $DESCRIPTION" >> "$FILE"
935 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
936 echo -n > "${INFO}/${NAME}:${arch}.list
"
938 echo -n > "${INFO}/${NAME}.list
"
944 buildaptarchivefromincoming() {
945 msginfo "Build APT archive
for ${CCMD}${0##*/}${CINFO} based on incoming packages…
"
947 [ -e pool ] || ln -s ../incoming pool
948 [ -e ftparchive.conf ] || createaptftparchiveconfig
949 [ -e dists ] || buildaptftparchivedirectorystructure
950 msgninfo "\tGenerate Packages
, Sources and Contents files…
"
951 testsuccess aptftparchive generate ftparchive.conf
954 generatereleasefiles "$@
"
957 buildaptarchivefromfiles() {
958 msginfo "Build APT archive
for ${CCMD}${0##*/}${CINFO} based on prebuild files…
"
959 local DIR='aptarchive'
960 if [ -d "${DIR}/dists
" ]; then DIR="${DIR}/dists
"; fi
961 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do
962 msgninfo "\t${line} file…
"
963 compressfile "$line" "$1"
966 generatereleasefiles "$@
"
970 while read compressor extension command; do
971 if [ "$compressor" = '.' ]; then
977 cat "$1" | $command > "${1}.
${extension}"
979 touch -d "$2" "${1}.
${extension}"
981 done < "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
"
984 # can be overridden by testcases for their pleasure
985 getcodenamefromsuite() {
987 unstable) echo 'sid';;
991 getreleaseversionfromsuite() { true; }
992 getlabelfromsuite() { true; }
993 getoriginfromsuite() { true; }
994 getarchitecturesfromreleasefile() { echo "all
$(getarchitectures)"; }
996 aptftparchiverelease() {
997 aptftparchive -qq release "$@
" | sed -e '/0 Release$/ d' # remove the self reference
999 generatereleasefiles() {
1000 # $1 is the Date header and $2 is the ValidUntil header to be set
1001 # both should be given in notation date/touch can understand
1003 local VALIDUNTIL="$2"
1004 if [ -e aptarchive/dists ]; then
1005 msgninfo "\tGenerate Release files
for dists…
"
1006 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
1007 local ARCHITECTURES="$(getarchitecturesfromreleasefile "$dir")"
1008 local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
1009 local CODENAME="$(getcodenamefromsuite $SUITE)"
1010 local VERSION="$(getreleaseversionfromsuite $SUITE)"
1011 local LABEL="$(getlabelfromsuite $SUITE)"
1012 local ORIGIN="$(getoriginfromsuite $SUITE)"
1013 aptftparchiverelease "$dir" \
1014 -o APT::FTPArchive::Release::Suite="${SUITE}" \
1015 -o APT::FTPArchive::Release::Codename="${CODENAME}" \
1016 -o APT::FTPArchive::Release::Architectures="${ARCHITECTURES}" \
1017 -o APT::FTPArchive::Release::Label="${LABEL}" \
1018 -o APT::FTPArchive::Release::Origin="${ORIGIN}" \
1019 -o APT::FTPArchive::Release::Version="${VERSION}" \
1021 if [ "$SUITE" = "experimental
" -o "$SUITE" = "experimental2
" ]; then
1022 sed -i '/^Date: / a\
1023 NotAutomatic: yes' "$dir/Release
"
1027 msgninfo "\tGenerate Release files
for flat…
"
1028 aptftparchiverelease ./aptarchive > aptarchive/Release
1030 if [ -n "$DATE" -a "$DATE" != "now
" ]; then
1031 for release in $(find ./aptarchive -name 'Release'); do
1032 sed -i "s
/^Date
: .
*$
/Date
: $(date -u -d "$DATE" '+%a, %d %b %Y %H:%M:%S %Z')/" "$release"
1033 touch -d "$DATE" "$release"
1036 if [ -n "$VALIDUNTIL" ]; then
1037 sed -i "/^Date
: / a\
1038 Valid
-Until: $(date -u -d "$VALIDUNTIL" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release')
1043 setupdistsaptarchive() {
1044 local APTARCHIVE="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1045 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
1046 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
1047 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1048 SECTIONS=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1049 msgninfo "\tadd deb and deb
-src sources.list lines
for ${CCMD}${DISTS} ${SECTIONS}${CINFO}…
"
1050 echo "deb
file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
"
1051 echo "deb
-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
"
1056 setupflataptarchive() {
1057 local APTARCHIVE="$(readlink -f ./aptarchive)"
1058 local APTARCHIVEURI="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1059 if [ -f "${APTARCHIVE}/Packages
" ]; then
1060 msgninfo "\tadd deb sources.list line…
"
1061 echo "deb
file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1064 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1066 if [ -f "${APTARCHIVE}/Sources
" ]; then
1067 msgninfo "\tadd deb
-src sources.list line…
"
1068 echo "deb
-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1071 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1077 if [ "$1" = '--no-update' ]; then
1081 buildaptarchive "$@
"
1082 if [ -e aptarchive/dists ]; then
1083 setupdistsaptarchive
1087 signreleasefiles 'Joe Sixpack'
1088 if [ "1" != "$NOUPDATE" ]; then
1089 testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true
1093 signreleasefiles() {
1094 local SIGNERS="${1:-Joe Sixpack}"
1095 local REPODIR="${2:-aptarchive}"
1096 if [ -n "$1" ]; then shift; fi
1097 if [ -n "$1" ]; then shift; fi
1098 local KEY="keys
/$(echo "$SIGNERS" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1099 msgninfo "\tSign archive with
$SIGNERS key
$KEY…
"
1100 local REXKEY='keys/rexexpired'
1101 local SECEXPIREBAK="${REXKEY}.sec.bak
"
1102 local PUBEXPIREBAK="${REXKEY}.pub.bak
"
1104 while [ -n "${SIGNERS%%,*}" ]; do
1105 local SIGNER="${SIGNERS%%,*}"
1106 if [ "${SIGNERS}" = "${SIGNER}" ]; then
1109 SIGNERS="${SIGNERS#*,}"
1110 # FIXME: This should be the full name, but we can't encode the space properly currently
1111 SIGUSERS="${SIGUSERS} -u ${SIGNER#* }"
1112 if [ "${SIGNER}" = 'Rex Expired' ]; then
1113 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1114 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1115 # therefore we 'temporary' make the key not expired and restore a backup after signing
1116 cp "${REXKEY}.sec
" "$SECEXPIREBAK"
1117 cp "${REXKEY}.pub
" "$PUBEXPIREBAK"
1118 local SECUNEXPIRED="${REXKEY}.sec.unexpired
"
1119 local PUBUNEXPIRED="${REXKEY}.pub.unexpired
"
1120 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1121 cp "$SECUNEXPIRED" "${REXKEY}.sec
"
1122 cp "$PUBUNEXPIRED" "${REXKEY}.pub
"
1124 if ! printf "expire
\n1w
\nsave
\n" | aptkey --quiet --keyring "${REXKEY}.pub
" --secret-keyring "${REXKEY}.sec
" \
1125 --readonly adv --batch --yes --digest-algo "${APT_TESTS_DIGEST_ALGO:-SHA512}" \
1126 --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then
1130 cp "${REXKEY}.sec
" "$SECUNEXPIRED"
1131 cp "${REXKEY}.pub
" "$PUBUNEXPIRED"
1134 if [ ! -e "${KEY}.pub
" ]; then
1135 local K="keys
/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1136 cat "${K}.pub
" >> "${KEY}.new.pub
"
1137 cat "${K}.sec
" >> "${KEY}.new.sec
"
1140 if [ ! -e "${KEY}.pub
" ]; then
1141 mv "${KEY}.new.pub
" "${KEY}.pub
"
1142 mv "${KEY}.new.sec
" "${KEY}.sec
"
1144 local GPG="aptkey
--quiet --keyring ${KEY}.pub
--secret-keyring ${KEY}.sec
--readonly adv
--batch --yes --digest-algo ${APT_TESTS_DIGEST_ALGO:-SHA512}"
1145 for RELEASE in $(find "${REPODIR}/" -name Release); do
1146 # we might have set a specific date for the Release file, so copy it
1147 local DATE="$(stat --format "%y" "${RELEASE}")"
1148 if [ "$APT_DONT_SIGN" = 'Release.gpg' ]; then
1149 rm -f "${RELEASE}.gpg
"
1151 testsuccess $GPG "$@
" $SIGUSERS --armor --detach-sign --sign --output "${RELEASE}.gpg
" "${RELEASE}"
1152 touch -d "$DATE" "${RELEASE}.gpg
"
1154 local INRELEASE="${RELEASE%/*}/InRelease
"
1155 if [ "$APT_DONT_SIGN" = 'InRelease' ]; then
1158 testsuccess $GPG "$@
" $SIGUSERS --clearsign --output "$INRELEASE" "$RELEASE"
1159 touch -d "$DATE" "${INRELEASE}"
1162 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1163 mv -f "$SECEXPIREBAK" "${REXKEY}.sec
"
1164 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub
"
1169 redatereleasefiles() {
1170 local DATE="$(date -u -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
1171 for release in $(find aptarchive/ -name 'Release'); do
1172 sed -i "s
/^Date
: .
*$
/Date
: ${DATE}/" "$release"
1173 touch -d "$DATE" "$release"
1175 signreleasefiles "${2:-Joe Sixpack}"
1179 local WEBSERVER="${3:-http://localhost:${APTHTTPPORT}}"
1181 if [ "$1" = '--no-check' ]; then
1185 local DOWNLOG='rootdir/tmp/download-testfile.log'
1186 local STATUS='downloaded/webserverconfig.status'
1187 rm -f "$STATUS" "$DOWNLOG"
1188 # very very basic URI encoding
1190 if [ -n "$2" ]; then
1191 msgtest "Set webserver config option
'${1}' to
" "$2"
1192 URI="${WEBSERVER}/_config
/set
/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1194 msgtest 'Clear webserver config option' "${1}"
1195 URI="${WEBSERVER}/_config
/clear
/$(echo "${1}" | sed -e 's/\//%2f/g')"
1197 if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then
1200 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir
/tmp
/webserverconfig.output
"
1201 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1202 msgfailoutput '' "$OUTPUT"
1204 $NOCHECK || testwebserverlaststatuscode '200'
1207 rewritesourceslist() {
1208 local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1209 local APTARCHIVE2="copy
://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1210 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1211 sed -i $LIST -e "s
#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
1212 -e "s#http://[^@]*@\?localhost:${APTHTTPPORT}/\?#${1}#" \
1213 -e "s#https://[^@]*@\?localhost:${APTHTTPSPORT}/\?#${1}#"
1217 # wait for up to 10s for a pid file to appear to avoid possible race
1218 # when a helper is started and dosn't write the PID quick enough
1221 for i
in $(seq 10); do
1222 if test -s "$PIDFILE"; then
1227 msgdie
"waiting for $PIDFILE failed"
1231 changetowebserver
() {
1233 if [ "$1" != '--no-rewrite' ]; then
1238 if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
1240 local LOG
="webserver.log"
1241 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1245 waitforpidfile aptwebserver.pid
1246 local PID
="$(cat aptwebserver.pid)"
1247 if [ -z "$PID" ]; then
1248 msgdie
'Could not fork aptwebserver successfully'
1250 addtrap
"kill $PID;"
1251 waitforpidfile aptwebserver.port
1252 APTHTTPPORT
="$(cat aptwebserver.port)"
1253 if [ -z "$APTHTTPPORT" ]; then
1254 msgdie
'Could not get port for aptwebserver successfully'
1258 msgdie
'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver'
1260 if [ "$REWRTE" != 'yes' ]; then
1261 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1265 changetohttpswebserver
() {
1266 if ! command -v stunnel4
>/dev
/null
2>&1; then
1267 msgdie
'You need to install stunnel4 for https testcases'
1269 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1270 changetowebserver
--no-rewrite "$@"
1272 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1273 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1278 connect = $APTHTTPPORT
1279 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1280 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1281 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1282 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1283 if [ -z "$PID" ]; then
1284 msgdie
'Could not fork stunnel4 successfully'
1286 addtrap
'prefix' "kill ${PID};"
1287 APTHTTPSPORT
="$(lsof -i -n | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1288 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1289 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1293 mkdir -p rootdir
/media
/cdrom
/.disk
1294 local CD
="$(readlink -f rootdir/media/cdrom)"
1295 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1296 acquire::cdrom::mount "${CD}";
1297 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1298 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1299 acquire::cdrom::autodetect 0;
1301 echo -n "$1" > "${CD}/.disk/info"
1302 if [ ! -d aptarchive
/dists
]; then
1303 msgdie
'Flat file archive cdroms can not be created currently'
1306 mv aptarchive
/dists
"$CD"
1307 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1308 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1309 # start with an unmounted disk
1310 mv "${CD}" "${CD}-unmounted"
1311 # we don't want the disk to be modifiable
1312 addtrap
'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;"
1313 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1317 local PROTO
="${1%%:*}"
1318 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1319 download
-file "$1" "$2" "$3" 2>&1 ; then
1322 # only if the file exists the download was successful
1323 if [ -r "$2" ]; then
1331 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1332 if [ -n "$DIFFTEXT" ]; then
1334 echo >&2 "$DIFFTEXT"
1342 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1343 local COMPAREFILE
="$1"
1345 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1348 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1349 cat "$COMPAREFILE" >>"${OUTPUT}"
1350 msgfailoutput
'' "$OUTPUT" "$@"
1355 msggroup
'testfileequal'
1356 local MSG
='Test for correctness of file'
1357 if [ "$1" = '--nomsg' ]; then
1363 if [ -n "$MSG" ]; then
1364 msgtest
"$MSG" "$FILE"
1366 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1367 if [ -z "$*" ]; then
1368 testoutputequal
"$FILE" echo -n ''
1370 testoutputequal
"$FILE" echo "$*"
1376 msggroup
'testempty'
1377 if [ "$1" = '--nomsg' ]; then
1380 msgtest
"Test for no output of" "$*"
1382 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1383 if "$@" >"$COMPAREFILE" 2>&1 && test ! -s "$COMPAREFILE"; then
1386 msgfailoutput
'' "$COMPAREFILE" "$@"
1388 aptautotest
'testempty' "$@"
1392 msggroup
'testnotempty'
1393 msgtest
"Test for some output of" "$*"
1394 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
1395 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then
1398 msgfailoutput
'' "$COMPAREFILE" "$@"
1400 aptautotest
'testnotempty' "$@"
1405 msggroup
'testequal'
1406 local MSG
='Test of equality of'
1407 if [ "$1" = '--nomsg' ]; then
1412 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1413 echo "$1" > "$COMPAREFILE"
1416 if [ -n "$MSG" ]; then
1419 testoutputequal
"$COMPAREFILE" "$@"
1420 aptautotest
'testequal' "$@"
1425 msggroup
'testequalor2'
1426 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1427 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1428 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1429 echo "$1" > "$COMPAREFILE1"
1430 echo "$2" > "$COMPAREFILE2"
1432 msgtest
"Test for equality OR of" "$*"
1433 "$@" >"$COMPAREAGAINST" 2>&1 || true
1434 if checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null
2>&1 || \
1435 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null
2>&1
1439 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1440 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1441 checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1442 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1443 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1444 msgfailoutput
'' "$OUTPUT"
1446 aptautotest
'testequalor2' "$@"
1451 msggroup
'testshowvirtual'
1452 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1455 while [ -n "$1" ]; do
1457 N: Can't select versions from package '$1' as it is purely virtual"
1458 PACKAGE
="${PACKAGE} $1"
1461 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1463 N: No packages found"
1464 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1465 local ARCH
="$(getarchitecture 'native')"
1466 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1467 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1468 testoutputequal
"$COMPAREFILE" aptcache show
"$PACKAGE"
1473 msggroup
'testnopackage'
1474 msgtest
"Test for non-existent packages" "apt-cache show $*"
1475 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1476 if [ -n "$SHOWPKG" ]; then
1477 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1478 echo "$SHOWPKG" >"$OUTPUT"
1479 msgfailoutput
'' "$OUTPUT"
1485 testnosrcpackage
() {
1486 msggroup
'testnosrcpackage'
1487 msgtest
"Test for non-existent source packages" "apt-cache showsrc $*"
1488 local SHOWPKG
="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')"
1489 if [ -n "$SHOWPKG" ]; then
1490 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output"
1491 echo "$SHOWPKG" >"$OUTPUT"
1492 msgfailoutput
'' "$OUTPUT"
1500 msggroup
'testdpkgstatus'
1504 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1505 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1506 if [ "$PKGS" != $NR ]; then
1507 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1508 echo "$PKGS" >"$OUTPUT"
1509 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1510 msgfailoutput
'' "$OUTPUT"
1517 testdpkginstalled
() {
1518 msggroup
'testdpkginstalled'
1519 testdpkgstatus
'ii' "$#" "$@"
1523 testdpkgnotinstalled
() {
1524 msggroup
'testdpkgnotinstalled'
1525 testdpkgstatus
'ii' '0' "$@"
1530 msggroup
'testmarkedauto'
1531 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1532 if [ -n "$1" ]; then
1533 msgtest
'Test for correctly marked as auto-installed' "$*"
1534 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1536 msgtest
'Test for correctly marked as auto-installed' 'no package'
1537 echo -n > "$COMPAREFILE"
1539 testoutputequal
"$COMPAREFILE" aptmark showauto
1542 testmarkedmanual
() {
1543 msggroup
'testmarkedmanual'
1544 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1545 if [ -n "$1" ]; then
1546 msgtest
'Test for correctly marked as manually installed' "$*"
1547 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1549 msgtest
'Test for correctly marked as manually installed' 'no package'
1550 echo -n > "$COMPAREFILE"
1552 testoutputequal
"$COMPAREFILE" aptmark showmanual
1557 if [ "${1##*.}" = 'deb' ]; then
1558 stat
>&2 "$1" || true
1559 file >&2 "$1" || true
1561 cat >&2 "$1" || true
1565 msgreportheader
'msgfailoutput'
1569 if [ "$1" = 'grep' ]; then
1571 while [ -n "$2" ]; do shift; done
1572 echo "#### Complete file: $1 ####"
1574 echo '#### grep output ####'
1575 elif [ "$1" = 'test' ]; then
1577 # doesn't support ! or non-file flags
1578 msgfailoutputstatfile
() {
1579 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1580 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1581 echo "#### stat(2) of file: $2 ####"
1583 if test -d "$2"; then
1584 echo "#### The directory contains: $2 ####"
1586 elif test -e "$2"; then
1587 echo "#### Complete file: $2 ####"
1592 msgfailoutputstatfile
"$2" "$3"
1593 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1595 msgfailoutputstatfile
"$2" "$3"
1597 echo '#### test output ####'
1598 elif [ "$1" = 'cmp' ]; then
1600 while [ -n "$2" ]; do
1601 echo "#### Complete file: $2 ####"
1605 echo '#### cmp output ####'
1611 testsuccesswithglobalerror
() {
1616 if [ "$1" = '--nomsg' ]; then
1619 msgtest
'Test for successful execution of' "$*"
1621 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output"
1622 if "$@" >"${OUTPUT}" 2>&1; then
1623 if expr match
"$1" '^apt.*' >/dev
/null
; then
1624 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1625 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1626 elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1627 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1628 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1629 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1632 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1635 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1637 elif [ "$TYPE" = 'testsuccesswithnotice' ]; then
1638 if grep -q -E "^N: " "$OUTPUT"; then
1641 msgfailoutput
'successful run, but output had no notices' "$OUTPUT" "$@"
1651 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1653 aptautotest
"$TYPE" "$@"
1656 testsuccesswithnotice
() {
1657 testsuccesswithglobalerror
'testsuccesswithnotice' 'WE' "$@"
1660 testsuccesswithglobalerror
'testsuccess' 'NWE' "$@"
1663 msggroup
'testwarning'
1664 if [ "$1" = '--nomsg' ]; then
1667 msgtest
'Test for successful execution with warnings of' "$*"
1669 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1670 if "$@" >"${OUTPUT}" 2>&1; then
1671 if expr match
"$1" '^apt.*' >/dev
/null
; then
1672 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1673 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1674 elif grep -q -E '^E: ' "$OUTPUT"; then
1675 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1676 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1677 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1686 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1688 aptautotest
'testwarning' "$@"
1692 msggroup
'testfailure'
1693 if [ "$1" = '--nomsg' ]; then
1696 msgtest
'Test for failure in execution of' "$*"
1698 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1699 if "$@" >"${OUTPUT}" 2>&1; then
1701 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1704 if expr match
"$1" '^apt.*' >/dev
/null
; then
1705 if [ "$1" = 'aptkey' ]; then
1706 if grep -q " Can't check signature:
1708 signature could not be verified" "$OUTPUT"; then
1711 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1714 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1715 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1716 elif grep -q -E '==ERROR' "$OUTPUT"; then
1717 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1718 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1719 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1728 aptautotest
'testfailure' "$@"
1732 testreturnstateequal
() {
1734 if [ "$STATE" = 'testsuccesswithglobalerror' ]; then
1738 msggroup
"${STATE}equal"
1739 if [ "$1" != '--nomsg' ]; then
1742 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1743 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1747 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1748 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1751 msggroup
"${STATE}equal"
1752 if [ "$2" != '--nomsg' ]; then
1756 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1760 "$STATE" --nomsg "$@"
1761 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1766 testsuccessequal
() {
1767 # we compare output, so we know perfectly well about N:
1768 testreturnstateequal
'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@"
1770 testwarningequal
() {
1771 testreturnstateequal
'testwarning' "$@"
1773 testfailureequal
() {
1774 testreturnstateequal
'testfailure' "$@"
1778 msggroup
'testfailuremsg'
1782 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1783 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1784 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1785 testoutputequal
"$COMPAREFILE" echo "$CMP"
1789 msggroup
'testwarningmsg'
1793 msgtest
'Check that the output of the previous warned command has expected' 'warnings'
1794 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
1795 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
1796 testoutputequal
"$COMPAREFILE" echo "$CMP"
1801 msggroup
'testfilestats'
1802 msgtest
"Test that file $1 has $2 $3" "$4"
1803 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1806 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1809 echo -n "stat(1) reports for $2: "
1810 stat
--format "$2" "$1" || true
1812 msgfailoutput
'' "$OUTPUT"
1816 testaccessrights
() {
1817 msggroup
'testaccessrights'
1818 testfilestats
"$1" '%a' '=' "$2"
1822 testwebserverlaststatuscode
() {
1823 msggroup
'testwebserverlaststatuscode'
1824 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1825 local STATUS
='downloaded/webserverstatus-statusfile.log'
1826 rm -f "$DOWNLOG" "$STATUS"
1827 msgtest
'Test last status code from the webserver was' "$1"
1828 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1831 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1833 if [ -n "$2" ]; then
1835 echo >&2 '#### Additionally provided output files contain:'
1838 echo >&2 '#### Download log of the status code:'
1841 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1846 createlistofkeys
() {
1849 while [ -n "$1" ]; do
1850 # gpg 2.1.something starts printing [SC] at some point
1851 if grep -q ' rsa2048/' "$OUTPUT" && grep -qF '[SC]' "$OUTPUT"; then
1853 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';;
1854 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [SC] [expired: 2013-07-13]';;
1855 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16 [SC]';;
1856 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19 [SC]';;
1857 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';;
1858 *) echo 'UNKNOWN KEY';;
1860 # gpg 2.1 has a slightly different output format
1861 elif grep -q ' rsa2048/' "$OUTPUT"; then
1863 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1864 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1865 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16';;
1866 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19';;
1867 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1868 *) echo 'UNKNOWN KEY';;
1872 *Joe
*|*Sixpack
*) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1873 *Rex
*|*Expired
*) echo 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1874 *Marvin
*|*Paranoid
*) echo 'pub 2048R/528144E2 2011-01-16';;
1875 oldarchive
) echo 'pub 1024R/F68C85A3 2013-12-19';;
1876 newarchive
) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1877 *) echo 'UNKNOWN KEY';;
1884 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output"
1885 if ! aptkey list
| grep '^pub' > "$OUTPUT"; then
1888 testfileequal
"$OUTPUT" "$(createlistofkeys "$OUTPUT" "$@")"
1892 echo "STOPPED execution. Press enter to continue"
1897 listcurrentlistsdirectory
() {
1899 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1900 stat
--format '%U:%G:%a:%n' "$line"
1902 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1903 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1907 forallsupportedcompressors
() {
1908 rm -f "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
1909 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
1910 if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi
1915 ### convenience hacks ###
1917 # creating some directories by hand is a tedious task, so make it look simple
1919 if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then
1920 # only the last directory created by mkdir is effected by the -m !
1921 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1922 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1923 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1924 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1925 if [ "$(id -u)" = '0' ]; then
1926 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1933 ### The following tests are run by most test methods automatically to check
1934 ### general things about commands executed without writing the test every time.
1940 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')"
1941 if command -v $AUTOTEST >/dev
/null
; then
1943 # save and restore the *.output files from other tests
1944 # as we might otherwise override them in these automatic tests
1945 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1946 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1947 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1948 $AUTOTEST "$TESTCALL" "$@"
1949 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1950 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1951 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1955 aptautotest_aptget_update
() {
1957 while [ -n "$2" ]; do
1958 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1961 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1962 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1963 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1964 # all copied files are properly chmodded
1965 local backupIFS
="$IFS"
1966 IFS
="$(printf "\n\b")"
1967 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1968 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1971 if [ "$TESTCALL" = 'testsuccess' ]; then
1972 # failure cases can retain partial files and such
1973 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
1976 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1977 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
1979 testaptautotestnodpkgwarning
() {
1981 while [ -n "$2" ]; do
1982 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
1983 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
1986 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1989 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
1990 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
1991 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
1992 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
1993 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
1994 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }