1 #!/bin/sh -- # no runable script, just for vi
6 if [ "$1" = "-q" ]; then
8 elif [ "$1" = "-v" ]; then
10 elif [ "$1" = '--color=no' ]; then
12 elif [ "$1" = '--color=yes' ]; then
14 elif [ "$1" = '--color' ]; then
15 export MSGCOLOR
="$(echo "$2" | tr 'a-z' 'A-Z')"
17 elif [ "$1" = '--level' ]; then
21 echo >&2 "WARNING: Unknown parameter »$1« will be ignored"
25 export MSGLEVEL
="${MSGLEVEL:-3}"
27 # we all like colorful messages
28 if [ "${MSGCOLOR:-YES}" = 'YES' ]; then
29 if [ ! -t 1 ]; then # but check that we output to a terminal
35 if [ "$MSGCOLOR" != 'NO' ]; then
36 CERROR
="\033[1;31m" # red
37 CWARNING
="\033[1;33m" # yellow
38 CMSG
="\033[1;32m" # green
39 CINFO
="\033[1;96m" # light blue
40 CDEBUG
="\033[1;94m" # blue
41 CNORMAL
="\033[0;39m" # default system console color
42 CDONE
="\033[1;32m" # green
43 CPASS
="\033[1;32m" # green
44 CFAIL
="\033[1;31m" # red
45 CCMD
="\033[1;35m" # pink
57 printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghks]\)#apt-\1#')"
63 msgdie
() { msgprintf
"${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; }
64 msgwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; }
65 msgmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; }
66 msginfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; }
67 msgdebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; }
68 msgdone
() { msgprintf
"${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; }
69 msgnwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; }
70 msgnmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}" "$@"; }
71 msgninfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
72 msgndebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
73 msgtest
() { msgprintf
"${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
74 msgpass
() { printf "${CPASS}PASS${CNORMAL}\n"; }
76 if [ -n "$MSGTEST_MSG" ]; then
77 test "$1" != 'msgfailoutput' || echo
78 if [ -n "$MSGTEST_MSGMSG" ]; then
79 echo "$MSGTEST_MSGMSG"
81 if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then
82 echo "${CFAIL}Part of the test group: $MSGTEST_GRP"
84 echo -n "$MSGTEST_MSG"
89 msgreportheader
'msgskip'
90 if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
91 else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
94 msgreportheader
'msgfail'
95 if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
96 else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
97 if [ -n "$APT_DEBUG_TESTS" ]; then
100 EXIT_CODE
=$((EXIT_CODE+1));
105 if [ $MSGGROUP_LEVEL = 0 ]; then
108 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL+1));
110 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL-1));
111 if [ $MSGGROUP_LEVEL = 0 ]; then
117 # enable / disable Debugging
118 if [ $MSGLEVEL -le 0 ]; then
121 if [ $MSGLEVEL -le 1 ]; then
125 if [ $MSGLEVEL -le 2 ]; then
127 MSGTEST_MSGMSG
="$(msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@")"
131 MSGTEST_MSG
="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")"
132 if [ "$MSGTEST_GRP" = 'NEXT' ]; then
133 MSGTEST_GRP
="$MSGTEST_MSG"
136 msgpass
() { printf " ${CPASS}P${CNORMAL}"; }
138 if [ $MSGLEVEL -le 3 ]; then
142 if [ $MSGLEVEL -le 4 ]; then
144 msgndebug
() { true
; }
147 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
148 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
149 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
150 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
151 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
154 printf "${CDONE}DONE${CNORMAL}\n";
158 if [ -f .
/aptconfig.conf
]; then
159 echo "$(readlink -f ./aptconfig.conf)"
160 elif [ -f ..
/aptconfig.conf
]; then
161 echo "$(readlink -f ../aptconfig.conf)"
162 elif [ -f ..
/..
/aptconfig.conf
]; then
163 echo "$(readlink -f ../../aptconfig.conf)"
164 elif [ -f "${TMPWORKINGDIRECTORY}/aptconfig.conf" ]; then
165 echo "$(readlink -f "${TMPWORKINGDIRECTORY}/aptconfig.conf")"
169 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
173 sh
|aptitude
|*/*|command) ;;
174 *) CMD
="${BUILDDIRECTORY}/$CMD";;
176 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
="${LIBRARYPATH}:${LD_LIBRARY_PATH}" "$CMD" "$@"
178 runpython3
() { runapt
command python3
"$@"; }
179 aptconfig
() { runapt apt
-config "$@"; }
180 aptcache
() { runapt apt
-cache "$@"; }
181 aptcdrom
() { runapt apt
-cdrom "$@"; }
182 aptget
() { runapt apt
-get "$@"; }
183 aptftparchive
() { runapt apt
-ftparchive "$@"; }
184 aptkey
() { runapt apt
-key "$@"; }
185 aptmark
() { runapt apt
-mark "$@"; }
186 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; }
187 apt
() { runapt apt
"$@"; }
188 apthelper
() { runapt
"${APTHELPERBINDIR}/apt-helper" "$@"; }
189 aptwebserver
() { runapt
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
190 aptitude
() { runapt aptitude
"$@"; }
191 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; }
192 aptinternalsolver
() { runapt
"${APTINTERNALSOLVER}" "$@"; }
193 aptdumpsolver
() { runapt
"${APTDUMPSOLVER}" "$@"; }
194 aptinternalplanner
() { runapt
"${APTINTERNALPLANNER}" "$@"; }
197 "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@"
199 dpkgcheckbuilddeps
() {
200 command dpkg
-checkbuilddeps --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" "$@"
205 aptget
) CMD
="apt-get";;
206 aptcache
) CMD
="apt-cache";;
207 aptcdrom
) CMD
="apt-cdrom";;
208 aptconfig
) CMD
="apt-config";;
209 aptmark
) CMD
="apt-mark";;
210 apthelper
) CMD
="apt-helper";;
211 aptftparchive
) CMD
="apt-ftparchive";;
212 dpkg
) shift; runapt
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" "$@"; return;;
216 if [ "${CMD##*/}" = "$CMD" ]; then
217 CMD
="${BUILDDIRECTORY}/${CMD}"
219 runapt
command gdb
--quiet -ex run
"$CMD" --args "$CMD" "$@"
222 date -u -d "@$(stat -c '%Y' "${TMPWORKINGDIRECTORY}/$1")" '+%a, %d %b %Y %H:%M:%S GMT'
225 grep "^${2:-Date}:" "$1" | cut
-d' ' -f 2- | sed -e 's#UTC#GMT#'
229 # error if we about to overflow, but ...
230 # "255 failures ought to be enough for everybody"
231 if [ $EXIT_CODE -gt 255 ]; then
232 msgdie
"Total failure count $EXIT_CODE too big"
234 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
237 shellsetedetector
() {
239 if [ "$exit_status" != '0' ]; then
240 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
241 if [ "$EXIT_CODE" = '0' ]; then
242 EXIT_CODE
="$exit_status"
248 if [ "$1" = 'prefix' ]; then
249 CURRENTTRAP
="$2 $CURRENTTRAP"
251 CURRENTTRAP
="$CURRENTTRAP $1"
253 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
257 echo "$@" | sed -e "s#'#'\"'\"'#g"
261 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
262 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
265 TMPWORKINGDIRECTORY
="$(mktemp -d)"
266 addtrap
"cd /; rm -rf '$(escape_shell "$TMPWORKINGDIRECTORY")';"
267 if [ -n "$TMPDIR_ADD" ]; then
268 TMPWORKINGDIRECTORY
="${TMPWORKINGDIRECTORY}/${TMPDIR_ADD}"
269 mkdir -p "$TMPWORKINGDIRECTORY"
271 export TMPDIR
="$TMPWORKINGDIRECTORY"
273 msgninfo
"Preparing environment for ${0##*/} in ${TMPWORKINGDIRECTORY}…"
275 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
276 if [ "$(id -u)" = '0' ]; then
277 # relax permissions so that running as root with user switching works
279 chmod 711 "$TMPWORKINGDIRECTORY"
280 chown _apt
:root
"${TMPWORKINGDIRECTORY}/downloaded"
283 TESTDIRECTORY
="$(readlink -f "$(dirname $0)")"
284 # allow overriding the default BUILDDIR location
285 SOURCEDIRECTORY="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}"
286 BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}"
287 LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}"
288 METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}"
289 APTHELPERBINDIR="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}"
290 APTWEBSERVERBINDIR="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}"
291 APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}"
292 APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}"
293 APTINTERNALPLANNER="${APT_INTEGRATION_TESTS_INTERNAL_PLANNER:-"${BUILDDIRECTORY}/apt-internal-planner"}"
294 test -x "${BUILDDIRECTORY}/apt
-get" || msgdie "You need to build tree first
"
297 cd "$TMPWORKINGDIRECTORY"
298 mkdir rootdir aptarchive keys
300 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
301 mkdir -p usr/bin var/cache var/lib var/log tmp
302 mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
303 touch var/lib/dpkg/available
305 ln -s "${METHODSDIR}" usr/lib/apt/methods
306 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
307 mkdir -p usr/lib/apt/solvers usr/lib/apt/planners
308 ln -s "${BUILDDIRECTORY}/apt
-dump-solver" usr/lib/apt/solvers/dump
309 ln -s "${BUILDDIRECTORY}/apt
-dump-solver" usr/lib/apt/planners/dump
310 ln -s "${BUILDDIRECTORY}/apt
-internal-solver" usr/lib/apt/solvers/apt
311 ln -s "${BUILDDIRECTORY}/apt
-internal-planner" usr/lib/apt/planners/apt
312 echo "Dir
::Bin
::Solvers
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/solvers
\";" >> ../aptconfig.conf
313 echo "Dir
::Bin
::Planners
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/planners
\";" >> ../aptconfig.conf
315 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
317 if [ -e "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" ]; then
318 ln -s "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" etc/apt/apt.conf.d/01autoremove
320 ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
323 local BASENAME="${0##*/}"
324 local PACKAGESFILE="Packages
-${BASENAME#*-}"
325 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
326 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
328 local SOURCESSFILE="Sources
-${BASENAME#*-}"
329 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
330 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
332 find "$TESTDIRECTORY" \( -name '*.pub' -o -name '*.sec' \) -exec cp '{}' keys/ \;
334 ln -s "${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub
" rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
336 echo "Dir
\"${TMPWORKINGDIRECTORY}/rootdir
\";" >> aptconfig.conf
337 echo "Dir
::state
::status
\"${TMPWORKINGDIRECTORY}/rootdir
/var
/lib
/dpkg
/status
\";" >> aptconfig.conf
338 echo "APT
::Get
::Show
-User-Simulation-Note \"false
\";" >> aptconfig.conf
339 echo "Dir
::Bin
::Methods
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/methods
\";" >> aptconfig.conf
340 # either store apt-key were we can access it, even if we run it as a different user
341 #cp "${BUILDDIRECTORY}/apt
-key" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/"
342 #chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key"
343 #echo "Dir
::Bin
::apt
-key \"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key\";" >> aptconfig.conf
344 # destroys coverage reporting though, so we disable changing user for the calling gpgv
345 echo "Dir
::Bin
::apt
-key \"${BUILDDIRECTORY}/apt
-key\";" >> aptconfig.conf
346 if [ "$(id -u)" = '0' ]; then
347 echo 'Binary::gpgv::APT::Sandbox::User "root
";' >> aptconfig.conf
348 # same for the solver executables
349 echo 'APT::Solver::RunAsUser "root
";' >> aptconfig.conf
350 echo 'APT::Planner::RunAsUser "root
";' >> aptconfig.conf
353 cat > "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
356 if [ -r '${TMPWORKINGDIRECTORY}/noopchroot.so' ]; then
357 if [ -n "\
$LD_LIBRARY_PATH" ]; then
358 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}:'"\
${LD_LIBRARY_PATH}"
360 export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}'
362 if [ -n "\
$LD_PRELOAD" ]; then
363 export LD_PRELOAD="noopchroot.so \
${LD_PRELOAD}"
365 export LD_PRELOAD="noopchroot.so
"
369 cp "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
370 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
371 exec fakeroot '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
372 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
373 --force-not-root --force-bad-path "\$@
"
375 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg" <<EOF
376 exec fakeroot gdb --quiet -ex run '${DPKG:-dpkg}' --args '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
377 --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
378 --force-not-root --force-bad-path "\$@
"
380 chmod +x "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
381 echo "Dir
::Bin
::dpkg
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
\";" > rootdir/etc/apt/apt.conf.d/99dpkg
384 if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
385 echo "DPKG
::options
:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
388 echo 'quiet::NoUpdate "true
";'
389 echo 'quiet::NoStatistic "true
";'
390 # too distracting for users, but helpful to detect changes
391 echo 'Acquire::Progress::Ignore::ShowErrorText "true
";'
392 echo 'Acquire::Progress::Diffpercent "true
";'
393 # in testcases, it can appear as if localhost has a rotation setup,
394 # hide this as we can't really deal with it properly
395 echo 'Acquire::Failure::ShowIP "false
";'
396 # fakeroot can't fake everything, so disabled in production but good for tests
397 echo 'APT::Sandbox::Verify "true
";'
400 cp "${TESTDIRECTORY}/apt.pem
" "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
401 if [ "$(id -u)" = '0' ]; then
402 chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
404 echo "Acquire
::https
::CaInfo
\"${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
\";" > rootdir/etc/apt/apt.conf.d/99https
405 echo "Apt
::Cmd
::Disable
-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
406 echo 'Acquire::Connect::AddrConfig "false
";' > rootdir/etc/apt/apt.conf.d/connect-addrconfig
408 configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
409 confighashes 'SHA256' # these are tests, not security best-practices
411 # create some files in /tmp and look at user/group to get what this means
412 TEST_DEFAULT_USER="$(id -un)"
413 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
414 TEST_DEFAULT_GROUP='root'
416 TEST_DEFAULT_GROUP="$(id -gn)"
419 # cleanup the environment a bit
420 # prefer our apt binaries over the system apt binaries
421 export PATH="${BUILDDIRECTORY}:${PATH}:/usr
/local
/sbin
:/usr
/sbin
:/sbin
"
422 export LC_ALL=C.UTF-8
423 unset LANGUAGE APT_CONFIG
424 unset GREP_OPTIONS DEB_BUILD_PROFILES
425 unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy
427 # If gpgv supports --weak-digest, pass it to make sure we can disable SHA1
428 if aptkey verify --weak-digest SHA1 --help 2>/dev/null >/dev/null; then
429 echo 'Acquire::gpgv::Options { "--weak-digest"; "sha1
"; };' > rootdir/etc/apt/apt.conf.d/no-sha1
432 # most tests just need one signed Release file, not both
433 export APT_DONT_SIGN='Release.gpg'
439 if [ "$1" = "native
" -o -z "$1" ]; then
440 eval `aptconfig shell ARCH APT::Architecture`
441 if [ -n "$ARCH" ]; then
444 dpkg --print-architecture
452 aptconfig dump --no-empty --format '%v%n' APT::Architecture APT::Architectures | sort -u | tr '\n' ' '
455 getarchitecturesfromcommalist() {
456 echo "$1" | sed -e 's#,#\n#g' | sed -e "s
/^native\$
/$(getarchitecture 'native')/"
459 configarchitecture() {
461 echo "APT
::Architecture
\"$(getarchitecture $1)\";"
462 while [ -n "$1" ]; do
463 echo "APT
::Architectures
:: \"$(getarchitecture $1)\";"
466 } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
471 if [ ! -e rootdir/var/lib/dpkg/status ]; then
472 local BASENAME="${0##*/}"
473 local STATUSFILE="status
-${BASENAME#*-}"
474 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
475 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
477 echo -n > rootdir/var/lib/dpkg/status
480 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
481 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
482 local ARCHS="$(getarchitectures)"
483 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
484 DPKGARCH="$(dpkg --print-architecture)"
485 for ARCH in ${ARCHS}; do
486 if [ "${ARCH}" != "${DPKGARCH}" ]; then
487 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
488 # old-style used e.g. in Ubuntu-P – and as it seems travis
489 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
490 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
494 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
495 # dpkg doesn't really check the version as long as it is fully installed,
496 # but just to be sure we choose one above the required version
497 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
503 configdpkgnoopchroot() {
504 # create a library to noop chroot() and rewrite maintainer script executions
505 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
506 # chroot directory dpkg could chroot into to execute the maintainer scripts
507 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
508 cat > noopchroot.c << EOF
515 static char * chrootdir = NULL;
517 int chroot(const char *path) {
518 printf("WARNING
: CHROOTing to
%s was ignored
!\n", path);
520 chrootdir = strdup(path);
523 int execvp(const char *file, char *const argv[]) {
524 static int (*func_execvp) (const char *, char * const []) = NULL;
525 if (func_execvp == NULL)
526 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
");
527 if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0)
528 return func_execvp(file, argv);
529 printf("REWRITE execvp call
%s into
%s
\n", file, chrootdir);
531 if (asprintf(&newfile, "%s
%s
", chrootdir, file) == -1) {
535 char const * const baseadmindir = "/var
/lib
/dpkg
";
537 if (asprintf(&admindir, "%s
%s
", chrootdir, baseadmindir) == -1) {
541 setenv("DPKG_ADMINDIR
", admindir, 1);
542 return func_execvp(newfile, argv);
545 testempty --nomsg gcc -Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c -ldl
547 configcompression() {
548 if [ "$1" = 'ALL' ]; then
549 configcompression '.' $(aptconfig dump APT::Compressor --format '%t %v%n' | sed -n 's#^Extension \.\(.*\)$#\1#p')
552 local CMD='apthelper cat-file -C'
553 while [ -n "$1" ]; do
555 '.') printf ".
\t.
\tcat
\n";;
556 'gz') printf "gzip\tgz
\t$CMD $1\n";;
557 'bz2') printf "bzip2\tbz
2\t$CMD $1\n";;
558 *) printf "$1\t$1\t$CMD $1\n";;
561 done > "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
"
565 echo 'APT::FTPArchive {'
567 while [ -n "$1" ]; do
568 printf "$1" | tr 'a-z' 'A-Z'
569 printf "\t\"true
\";\n"
572 for h in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
573 printf "$h\t\"false
\";\n"
577 } >> "${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/ftparchive
-hashes.conf
"
582 COMPRESSOR_CMD="apthelper
cat-file -C $1"
584 gzip) COMPRESS='gz';;
585 bzip2) COMPRESS='bz2';;
587 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/00force
-compressor"
588 echo "Acquire
::CompressionTypes
::Order
{ \"${COMPRESS}\"; };
589 Dir
::Bin
::uncompressed
\"/does
/not
/exist
\";" > "$CONFFILE"
590 for COMP in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
591 if [ -z "$COMP" -o "$COMP" = '.' -o "$COMP" = "$COMPRESSOR" ]; then continue; fi
592 echo "Dir
::Bin
::${COMP} \"/does
/not
/exist
\";" >> "$CONFFILE"
593 echo "APT
::Compressor
::${COMP}::Name
\"${COMP}-disabled\";" >> "$CONFFILE"
597 setupsimplenativepackage() {
601 local RELEASE="${4:-unstable}"
602 local DEPENDENCIES="$5"
603 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
604 If you
find such a package installed on your system
,
605 something went horribly wrong
! They are autogenerated
606 und used only by testcases and serve no other purpose…
"}"
608 local SECTION
="${7:-others}"
610 if [ "$SECTION" = "${SECTION#*/}" ]; then
613 DISTSECTION
="${SECTION%/*}"
615 local BUILDDIR
=incoming
/${NAME}-${VERSION}
616 mkdir -p ${BUILDDIR}/debian
/source
618 echo "* most suckless software product ever" > FEATURES
619 test -e debian
/copyright
|| echo "Copyleft by Joe Sixpack $(date -u +%Y)" > debian
/copyright
620 test -e debian
/changelog
|| echo "$NAME ($VERSION) $RELEASE; urgency=low
624 -- Joe Sixpack <joe@example.org> $(date -u -R)" > debian
/changelog
625 test -e debian
/control
|| echo "Source: $NAME
628 Maintainer: Joe Sixpack <joe@example.org>
629 Build-Depends: debhelper (>= 7)
630 Standards-Version: 3.9.1
632 Package: $NAME" > debian
/control
633 if [ "$ARCH" = 'all' ]; then
634 echo "Architecture: all" >> debian
/control
636 echo "Architecture: any" >> debian
/control
638 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian
/control
639 echo "Description: $DESCRIPTION" >> debian
/control
641 test -e debian
/compat
|| echo "7" > debian
/compat
642 test -e debian
/source
/format
|| echo "3.0 (native)" > debian
/source
/format
643 test -e debian
/rules
|| cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny debian
/rules
647 buildsimplenativepackage
() {
650 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then
651 NM
="$(echo "$NAME" | cut -c 1-4)"
653 NM
="$(echo "$NAME" | cut -c 1)"
657 local RELEASE
="${4:-unstable}"
658 local DEPENDENCIES
="$5"
659 local DESCRIPTION
="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
660 If you find such a package installed on your system,
661 something went horribly wrong! They are autogenerated
662 und used only by testcases and serve no other purpose…"}"
664 local SECTION="${7:-others}"
665 local PRIORITY="${8:-optional}"
667 local COMPRESS_TYPE="${10:-gzip}"
669 if [ "$SECTION" = "${SECTION#*/}" ]; then
672 DISTSECTION="${SECTION%/*}"
674 local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming
/${NAME}-${VERSION}"
676 msgtest "Build
source package
in version
${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
677 mkdir -p "$BUILDDIR/debian
/source"
678 echo "* most suckless software product ever
" > "${BUILDDIR}/FEATURES
"
680 echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}"
682 echo "Copyleft by Joe Sixpack
$(date -u +%Y)" > "${BUILDDIR}/debian
/copyright
"
683 echo "$NAME ($VERSION) $RELEASE; urgency
=low
687 -- Joe Sixpack
<joe@example.org
> $(date -u -R)" > "${BUILDDIR}/debian
/changelog
"
691 Maintainer
: Joe Sixpack
<joe@example.org
>
692 Standards
-Version: 3.9.3"
693 if [ "$SECTION" != '<none>' ]; then
694 echo "Section
: $SECTION"
696 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
697 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
701 if [ "$ARCH" = 'all' ]; then
702 echo "Architecture
: all
"
704 echo "Architecture
: any
"
706 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
707 test -z "$DEPS" || echo "$DEPS"
708 echo "Description
: $DESCRIPTION"
709 } > "${BUILDDIR}/debian
/control
"
711 echo '3.0 (native)' > "${BUILDDIR}/debian
/source
/format
"
713 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
715 sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
" \
717 echo "pool
/${SRC}" >> "${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.srclist
"
718 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
719 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
720 # adv --yes --default-key 'Joe Sixpack' \
721 # --clearsign -o "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
722 # mv "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
726 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
727 msgtest "Build binary package
for ${RELEASE} in ${SECTION}" "$NAME"
728 rm -rf "${BUILDDIR}/debian
/tmp
"
729 mkdir -p "${BUILDDIR}/debian
/tmp
/DEBIAN
" "${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}" "${BUILDDIR}/debian
/tmp
/usr
/bin
"
730 cp "${BUILDDIR}/debian
/copyright
" "${BUILDDIR}/debian
/changelog
" "${BUILDDIR}/FEATURES
" "${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}"
731 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}"
732 if [ -n "$FILE_TREE" ]; then
733 cp -ar "$FILE_TREE" "${BUILDDIR}/debian
/tmp
"
736 (cd "${BUILDDIR}"; dpkg-gencontrol -DArchitecture=$arch)
737 (cd "${BUILDDIR}/debian
/tmp
"; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
738 local LOG="${BUILDDIR}/..
/${NAME}_
${VERSION}_
${arch}.dpkg
-deb.log
"
739 # ensure the right permissions as dpkg-deb insists
740 chmod 755 "${BUILDDIR}/debian
/tmp
/DEBIAN
"
741 testsuccess --nomsg dpkg-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian
/tmp
" "${BUILDDIR}/..
"
742 echo "pool
/${NAME}_
${VERSION}_
${arch}.deb
" >> "${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
"
745 local CHANGEPATH="${BUILDDIR}/..
/${DISTSECTION}/${NM}/${NAME}/${NAME}_
${VERSION}"
746 mkdir -p "$CHANGEPATH"
747 cp "${BUILDDIR}/debian
/changelog
" "$CHANGEPATH"
756 local ARCH=$(getarchitecture $4)
757 local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
758 local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
759 msgtest "Build package
for ${RELEASE} in ${SECTION}" "$PKGNAME"
761 if [ "$ARCH" = "all
" ]; then
762 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
764 testsuccess --nomsg dpkg-buildpackage -uc -us -a$ARCH
765 cp "${TMPWORKINGDIRECTORY}/rootdir
/tmp
/testsuccess.output
" "$BUILDLOG"
766 local PKGS="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
767 local SRCS="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
770 echo "pool
/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
"
773 echo "pool
/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
"
778 if [ -d incoming ]; then
779 buildaptarchivefromincoming "$@
"
781 buildaptarchivefromfiles "$@
"
785 createaptftparchiveconfig() {
786 local COMPRESSORS="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
787 local COMPRESSORS="${COMPRESSORS%* }"
788 local ARCHS="$(getarchitectures)"
789 cat > ftparchive.conf <<EOF
791 ArchiveDir "$(readlink -f .)";
792 CacheDir "$(readlink -f ..)";
793 FileListDir "$(readlink -f pool/)";
796 Packages::Compress "$COMPRESSORS";
797 Sources::Compress "$COMPRESSORS";
798 Contents::Compress "$COMPRESSORS";
799 Translation::Compress "$COMPRESSORS";
800 LongDescription "false
";
804 SrcDirectory "pool
/";
807 for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
810 Architectures "$ARCHS all
source";
811 FileList "${DIST}.\
$(SECTION).pkglist
";
812 SourceFileList "${DIST}.\
$(SECTION).srclist
";
813 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
816 done >> ftparchive.conf
819 buildaptftparchivedirectorystructure() {
820 local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
821 for DIST in $DISTS; do
822 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
823 for SECTION in $SECTIONS; do
824 local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
825 for ARCH in $ARCHS; do
826 mkdir -p "dists
/${DIST}/${SECTION}/binary
-${ARCH}"
828 mkdir -p "dists
/${DIST}/${SECTION}/source"
829 mkdir -p "dists
/${DIST}/${SECTION}/i18n
"
839 local DEPENDENCIES="$5"
840 local PRIORITY="${6:-optional}"
841 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
842 If you
find such a package installed on your system
,
843 something went horribly wrong
! They are autogenerated
844 und used only by testcases and serve no other purpose…
"}"
846 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
847 if [ "$RELEASE" = 'installed' ]; then
848 insertinstalledpackage
"$2" "$3" "$4" "$5" "$6" "$7"
851 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
852 if [ "$arch" = 'none' ]; then
853 ARCHS
="$(getarchitectures)"
857 for BUILDARCH
in $ARCHS; do
858 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
865 Maintainer: Joe Sixpack <joe@example.org>"
866 test "$arch" = 'none' || echo "Architecture: $arch"
867 echo "Version: $VERSION
868 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb"
869 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES"
870 echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)"
871 echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
873 } >> "${PPATH}/Packages"
876 mkdir -p "aptarchive/dists/${RELEASE}/main/source" "aptarchive/dists/${RELEASE}/main/i18n"
877 touch "aptarchive/dists/${RELEASE}/main/source/Sources"
879 Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
880 Description-en: $DESCRIPTION
881 " >> "aptarchive/dists/${RELEASE}/main/i18n/Translation-en"
890 local DEPENDENCIES
="$5"
891 local BINARY
="${6:-$NAME}"
893 for RELEASE
in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
894 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
896 local FILE
="${SPATH}/Sources"
897 local DSCFILE
="${NAME}_${VERSION}.dsc"
898 local TARFILE
="${NAME}_${VERSION}.tar.gz"
902 Maintainer: Joe Sixpack <joe@example.org>
903 Architecture: $ARCH" >> $FILE
904 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
906 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
907 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
909 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
910 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
915 insertinstalledpackage
() {
919 local DEPENDENCIES
="$4"
920 local PRIORITY
="${5:-optional}"
921 local STATUS
="${6:-install ok installed}"
922 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
923 If you find such a package installed on your system,
924 something went horribly wrong! They are autogenerated
925 und used only by testcases and serve no other purpose…"}"
927 local FILE='rootdir/var/lib/dpkg/status'
928 local INFO='rootdir/var/lib/dpkg/info'
929 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
935 Maintainer
: Joe Sixpack
<joe@example.org
>
936 Version
: $VERSION" >> "$FILE"
937 test "$arch" = 'none' || echo "Architecture
: $arch" >> "$FILE"
938 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
939 echo "Description
: $DESCRIPTION" >> "$FILE"
941 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
942 echo -n > "${INFO}/${NAME}:${arch}.list
"
944 echo -n > "${INFO}/${NAME}.list
"
950 buildaptarchivefromincoming() {
951 msginfo "Build APT archive
for ${CCMD}${0##*/}${CINFO} based on incoming packages…
"
953 [ -e pool ] || ln -s ../incoming pool
954 [ -e ftparchive.conf ] || createaptftparchiveconfig
955 [ -e dists ] || buildaptftparchivedirectorystructure
956 msgninfo "\tGenerate Packages
, Sources and Contents files…
"
957 testsuccess aptftparchive generate ftparchive.conf
960 generatereleasefiles "$@
"
963 buildaptarchivefromfiles() {
964 msginfo "Build APT archive
for ${CCMD}${0##*/}${CINFO} based on prebuild files…
"
965 local DIR='aptarchive'
966 if [ -d "${DIR}/dists
" ]; then DIR="${DIR}/dists
"; fi
967 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do
968 msgninfo "\t${line} file…
"
969 compressfile "$line" "$1"
972 generatereleasefiles "$@
"
976 while read compressor extension command; do
977 if [ "$compressor" = '.' ]; then
983 cat "$1" | $command > "${1}.
${extension}"
985 touch -d "$2" "${1}.
${extension}"
987 done < "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
"
990 # can be overridden by testcases for their pleasure
991 getcodenamefromsuite() {
993 unstable) echo 'sid';;
997 getreleaseversionfromsuite() { true; }
998 getlabelfromsuite() { true; }
999 getoriginfromsuite() { true; }
1000 getarchitecturesfromreleasefile() { echo "all
$(getarchitectures)"; }
1002 aptftparchiverelease() {
1003 aptftparchive -qq release "$@
" | sed -e '/0 Release$/ d' # remove the self reference
1005 generatereleasefiles() {
1006 # $1 is the Date header and $2 is the ValidUntil header to be set
1007 # both should be given in notation date/touch can understand
1009 local VALIDUNTIL="$2"
1010 if [ -e aptarchive/dists ]; then
1011 msgninfo "\tGenerate Release files
for dists…
"
1012 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
1013 local ARCHITECTURES="$(getarchitecturesfromreleasefile "$dir")"
1014 local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
1015 local CODENAME="$(getcodenamefromsuite $SUITE)"
1016 local VERSION="$(getreleaseversionfromsuite $SUITE)"
1017 local LABEL="$(getlabelfromsuite $SUITE)"
1018 local ORIGIN="$(getoriginfromsuite $SUITE)"
1019 aptftparchiverelease "$dir" \
1020 -o APT::FTPArchive::Release::Suite="${SUITE}" \
1021 -o APT::FTPArchive::Release::Codename="${CODENAME}" \
1022 -o APT::FTPArchive::Release::Architectures="${ARCHITECTURES}" \
1023 -o APT::FTPArchive::Release::Label="${LABEL}" \
1024 -o APT::FTPArchive::Release::Origin="${ORIGIN}" \
1025 -o APT::FTPArchive::Release::Version="${VERSION}" \
1027 if [ "$SUITE" = "experimental
" -o "$SUITE" = "experimental2
" ]; then
1028 sed -i '/^Date: / a\
1029 NotAutomatic: yes' "$dir/Release
"
1033 msgninfo "\tGenerate Release files
for flat…
"
1034 aptftparchiverelease ./aptarchive > aptarchive/Release
1036 if [ -n "$DATE" -a "$DATE" != "now
" ]; then
1037 for release in $(find ./aptarchive -name 'Release'); do
1038 sed -i "s
/^Date
: .
*$
/Date
: $(date -u -d "$DATE" '+%a, %d %b %Y %H:%M:%S %Z')/" "$release"
1039 touch -d "$DATE" "$release"
1042 if [ -n "$VALIDUNTIL" ]; then
1043 sed -i "/^Date
: / a\
1044 Valid
-Until: $(date -u -d "$VALIDUNTIL" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release')
1049 setupdistsaptarchive() {
1050 local APTARCHIVE="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1051 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
1052 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
1053 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1054 SECTIONS=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1055 msgninfo "\tadd deb and deb
-src sources.list lines
for ${CCMD}${DISTS} ${SECTIONS}${CINFO}…
"
1056 echo "deb
file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
"
1057 echo "deb
-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
"
1062 setupflataptarchive() {
1063 local APTARCHIVE="$(readlink -f ./aptarchive)"
1064 local APTARCHIVEURI="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1065 if [ -f "${APTARCHIVE}/Packages
" ]; then
1066 msgninfo "\tadd deb sources.list line…
"
1067 echo "deb
file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1070 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1072 if [ -f "${APTARCHIVE}/Sources
" ]; then
1073 msgninfo "\tadd deb
-src sources.list line…
"
1074 echo "deb
-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1077 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1083 if [ "$1" = '--no-update' ]; then
1087 buildaptarchive "$@
"
1088 if [ -e aptarchive/dists ]; then
1089 setupdistsaptarchive
1093 signreleasefiles 'Joe Sixpack'
1094 if [ "1" != "$NOUPDATE" ]; then
1095 testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true
1099 signreleasefiles() {
1100 local SIGNERS="${1:-Joe Sixpack}"
1101 local REPODIR="${2:-aptarchive}"
1102 if [ -n "$1" ]; then shift; fi
1103 if [ -n "$1" ]; then shift; fi
1104 local KEY="keys
/$(echo "$SIGNERS" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1105 msgninfo "\tSign archive with
$SIGNERS key
$KEY…
"
1106 local REXKEY='keys/rexexpired'
1107 local SECEXPIREBAK="${REXKEY}.sec.bak
"
1108 local PUBEXPIREBAK="${REXKEY}.pub.bak
"
1110 while [ -n "${SIGNERS%%,*}" ]; do
1111 local SIGNER="${SIGNERS%%,*}"
1112 if [ "${SIGNERS}" = "${SIGNER}" ]; then
1115 SIGNERS="${SIGNERS#*,}"
1116 # FIXME: This should be the full name, but we can't encode the space properly currently
1117 SIGUSERS="${SIGUSERS} -u ${SIGNER#* }"
1118 if [ "${SIGNER}" = 'Rex Expired' ]; then
1119 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1120 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1121 # therefore we 'temporary' make the key not expired and restore a backup after signing
1122 cp "${REXKEY}.sec
" "$SECEXPIREBAK"
1123 cp "${REXKEY}.pub
" "$PUBEXPIREBAK"
1124 local SECUNEXPIRED="${REXKEY}.sec.unexpired
"
1125 local PUBUNEXPIRED="${REXKEY}.pub.unexpired
"
1126 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1127 cp "$SECUNEXPIRED" "${REXKEY}.sec
"
1128 cp "$PUBUNEXPIRED" "${REXKEY}.pub
"
1130 if ! printf "expire
\n1w
\nsave
\n" | aptkey --quiet --keyring "${REXKEY}.pub
" --secret-keyring "${REXKEY}.sec
" \
1131 --readonly adv --batch --yes --digest-algo "${APT_TESTS_DIGEST_ALGO:-SHA512}" \
1132 --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then
1136 cp "${REXKEY}.sec
" "$SECUNEXPIRED"
1137 cp "${REXKEY}.pub
" "$PUBUNEXPIRED"
1140 if [ ! -e "${KEY}.pub
" ]; then
1141 local K="keys
/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | tr -d ' ,')"
1142 cat "${K}.pub
" >> "${KEY}.new.pub
"
1143 cat "${K}.sec
" >> "${KEY}.new.sec
"
1146 if [ ! -e "${KEY}.pub
" ]; then
1147 mv "${KEY}.new.pub
" "${KEY}.pub
"
1148 mv "${KEY}.new.sec
" "${KEY}.sec
"
1150 local GPG="aptkey
--quiet --keyring ${KEY}.pub
--secret-keyring ${KEY}.sec
--readonly adv
--batch --yes --digest-algo ${APT_TESTS_DIGEST_ALGO:-SHA512}"
1151 for RELEASE in $(find "${REPODIR}/" -name Release); do
1152 # we might have set a specific date for the Release file, so copy it
1153 local DATE="$(stat --format "%y" "${RELEASE}")"
1154 if [ "$APT_DONT_SIGN" = 'Release.gpg' ]; then
1155 rm -f "${RELEASE}.gpg
"
1157 testsuccess $GPG "$@
" $SIGUSERS --armor --detach-sign --sign --output "${RELEASE}.gpg
" "${RELEASE}"
1158 touch -d "$DATE" "${RELEASE}.gpg
"
1160 local INRELEASE="${RELEASE%/*}/InRelease
"
1161 if [ "$APT_DONT_SIGN" = 'InRelease' ]; then
1164 testsuccess $GPG "$@
" $SIGUSERS --clearsign --output "$INRELEASE" "$RELEASE"
1165 touch -d "$DATE" "${INRELEASE}"
1168 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1169 mv -f "$SECEXPIREBAK" "${REXKEY}.sec
"
1170 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub
"
1175 redatereleasefiles() {
1176 local DATE="$(date -u -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
1177 for release in $(find aptarchive/ -name 'Release'); do
1178 sed -i "s
/^Date
: .
*$
/Date
: ${DATE}/" "$release"
1179 touch -d "$DATE" "$release"
1181 signreleasefiles "${2:-Joe Sixpack}"
1185 local WEBSERVER="${3:-http://localhost:${APTHTTPPORT}}"
1187 if [ "$1" = '--no-check' ]; then
1191 local DOWNLOG='rootdir/tmp/download-testfile.log'
1192 local STATUS='downloaded/webserverconfig.status'
1193 rm -f "$STATUS" "$DOWNLOG"
1194 # very very basic URI encoding
1196 if [ -n "$2" ]; then
1197 msgtest "Set webserver config option
'${1}' to
" "$2"
1198 URI="${WEBSERVER}/_config
/set
/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1200 msgtest 'Clear webserver config option' "${1}"
1201 URI="${WEBSERVER}/_config
/clear
/$(echo "${1}" | sed -e 's/\//%2f/g')"
1203 if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then
1206 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir
/tmp
/webserverconfig.output
"
1207 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1208 msgfailoutput '' "$OUTPUT"
1210 $NOCHECK || testwebserverlaststatuscode '200'
1213 rewritesourceslist() {
1214 local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1215 local APTARCHIVE2="copy
://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1216 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1217 sed -i $LIST -e "s
#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
1218 -e "s#http://[^@]*@\?localhost:${APTHTTPPORT}/\?#${1}#" \
1219 -e "s#https://[^@]*@\?localhost:${APTHTTPSPORT}/\?#${1}#"
1223 # wait for up to 10s for a pid file to appear to avoid possible race
1224 # when a helper is started and dosn't write the PID quick enough
1227 for i
in $(seq 10); do
1228 if test -s "$PIDFILE"; then
1233 msgdie
"waiting for $PIDFILE failed"
1237 changetowebserver
() {
1239 if [ "$1" != '--no-rewrite' ]; then
1244 if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
1246 local LOG
="webserver.log"
1247 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1251 waitforpidfile aptwebserver.pid
1252 local PID
="$(cat aptwebserver.pid)"
1253 if [ -z "$PID" ]; then
1254 msgdie
'Could not fork aptwebserver successfully'
1256 addtrap
"kill $PID;"
1257 waitforpidfile aptwebserver.port
1258 APTHTTPPORT
="$(cat aptwebserver.port)"
1259 if [ -z "$APTHTTPPORT" ]; then
1260 msgdie
'Could not get port for aptwebserver successfully'
1264 msgdie
'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver'
1266 if [ "$REWRTE" != 'yes' ]; then
1267 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1271 changetohttpswebserver
() {
1272 if ! command -v stunnel4
>/dev
/null
2>&1; then
1273 msgdie
'You need to install stunnel4 for https testcases'
1275 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1276 changetowebserver
--no-rewrite "$@"
1278 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1279 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1284 connect = $APTHTTPPORT
1285 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1286 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1287 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1288 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1289 if [ -z "$PID" ]; then
1290 msgdie
'Could not fork stunnel4 successfully'
1292 addtrap
'prefix' "kill ${PID};"
1293 APTHTTPSPORT
="$(lsof -i -n | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1294 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1295 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1299 mkdir -p rootdir
/media
/cdrom
/.disk
1300 local CD
="$(readlink -f rootdir/media/cdrom)"
1301 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1302 acquire::cdrom::mount "${CD}";
1303 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1304 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1305 acquire::cdrom::autodetect 0;
1307 echo -n "$1" > "${CD}/.disk/info"
1308 if [ ! -d aptarchive
/dists
]; then
1309 msgdie
'Flat file archive cdroms can not be created currently'
1312 mv aptarchive
/dists
"$CD"
1313 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1314 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1315 # start with an unmounted disk
1316 mv "${CD}" "${CD}-unmounted"
1317 # we don't want the disk to be modifiable
1318 addtrap
'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;"
1319 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1323 local PROTO
="${1%%:*}"
1324 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1325 download
-file "$1" "$2" "$3" 2>&1 ; then
1328 # only if the file exists the download was successful
1329 if [ -r "$2" ]; then
1337 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1338 if [ -n "$DIFFTEXT" ]; then
1340 echo >&2 "$DIFFTEXT"
1348 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1349 local COMPAREFILE
="$1"
1351 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1354 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1355 cat "$COMPAREFILE" >>"${OUTPUT}"
1356 msgfailoutput
'' "$OUTPUT" "$@"
1361 msggroup
'testfileequal'
1362 local MSG
='Test for correctness of file'
1363 if [ "$1" = '--nomsg' ]; then
1369 if [ -n "$MSG" ]; then
1370 msgtest
"$MSG" "$FILE"
1372 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1373 if [ -z "$*" ]; then
1374 testoutputequal
"$FILE" echo -n ''
1376 testoutputequal
"$FILE" echo "$*"
1382 msggroup
'testempty'
1383 if [ "$1" = '--nomsg' ]; then
1386 msgtest
"Test for no output of" "$*"
1388 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1389 if "$@" >"$COMPAREFILE" 2>&1 && test ! -s "$COMPAREFILE"; then
1392 msgfailoutput
'' "$COMPAREFILE" "$@"
1394 aptautotest
'testempty' "$@"
1398 msggroup
'testnotempty'
1399 msgtest
"Test for some output of" "$*"
1400 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
1401 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then
1404 msgfailoutput
'' "$COMPAREFILE" "$@"
1406 aptautotest
'testnotempty' "$@"
1411 msggroup
'testequal'
1412 local MSG
='Test of equality of'
1413 if [ "$1" = '--nomsg' ]; then
1418 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1419 echo "$1" > "$COMPAREFILE"
1422 if [ -n "$MSG" ]; then
1425 testoutputequal
"$COMPAREFILE" "$@"
1426 aptautotest
'testequal' "$@"
1431 msggroup
'testequalor2'
1432 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1433 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1434 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1435 echo "$1" > "$COMPAREFILE1"
1436 echo "$2" > "$COMPAREFILE2"
1438 msgtest
"Test for equality OR of" "$*"
1439 "$@" >"$COMPAREAGAINST" 2>&1 || true
1440 if checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null
2>&1 || \
1441 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null
2>&1
1445 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1446 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1447 checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1448 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1449 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1450 msgfailoutput
'' "$OUTPUT"
1452 aptautotest
'testequalor2' "$@"
1457 msggroup
'testshowvirtual'
1458 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1461 while [ -n "$1" ]; do
1463 N: Can't select versions from package '$1' as it is purely virtual"
1464 PACKAGE
="${PACKAGE} $1"
1467 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1469 N: No packages found"
1470 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1471 local ARCH
="$(getarchitecture 'native')"
1472 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1473 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1474 testoutputequal
"$COMPAREFILE" aptcache show
"$PACKAGE"
1479 msggroup
'testnopackage'
1480 msgtest
"Test for non-existent packages" "apt-cache show $*"
1481 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1482 if [ -n "$SHOWPKG" ]; then
1483 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1484 echo "$SHOWPKG" >"$OUTPUT"
1485 msgfailoutput
'' "$OUTPUT"
1491 testnosrcpackage
() {
1492 msggroup
'testnosrcpackage'
1493 msgtest
"Test for non-existent source packages" "apt-cache showsrc $*"
1494 local SHOWPKG
="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')"
1495 if [ -n "$SHOWPKG" ]; then
1496 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output"
1497 echo "$SHOWPKG" >"$OUTPUT"
1498 msgfailoutput
'' "$OUTPUT"
1506 msggroup
'testdpkgstatus'
1510 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1511 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1512 if [ "$PKGS" != $NR ]; then
1513 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1514 echo "$PKGS" >"$OUTPUT"
1515 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1516 msgfailoutput
'' "$OUTPUT"
1523 testdpkginstalled
() {
1524 msggroup
'testdpkginstalled'
1525 testdpkgstatus
'ii' "$#" "$@"
1529 testdpkgnotinstalled
() {
1530 msggroup
'testdpkgnotinstalled'
1531 testdpkgstatus
'ii' '0' "$@"
1536 msggroup
'testmarkedauto'
1537 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1538 if [ -n "$1" ]; then
1539 msgtest
'Test for correctly marked as auto-installed' "$*"
1540 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1542 msgtest
'Test for correctly marked as auto-installed' 'no package'
1543 echo -n > "$COMPAREFILE"
1545 testoutputequal
"$COMPAREFILE" aptmark showauto
1548 testmarkedmanual
() {
1549 msggroup
'testmarkedmanual'
1550 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1551 if [ -n "$1" ]; then
1552 msgtest
'Test for correctly marked as manually installed' "$*"
1553 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1555 msgtest
'Test for correctly marked as manually installed' 'no package'
1556 echo -n > "$COMPAREFILE"
1558 testoutputequal
"$COMPAREFILE" aptmark showmanual
1563 if [ "${1##*.}" = 'deb' ]; then
1564 stat
>&2 "$1" || true
1565 file >&2 "$1" || true
1567 cat >&2 "$1" || true
1571 msgreportheader
'msgfailoutput'
1576 if [ "$1" = 'grep' -o "$1" = 'tail' -o "$1" = 'head' ]; then
1578 while [ -n "$2" ]; do shift; done
1579 echo "#### Complete file: $1 ####"
1581 echo "#### $CMD output ####"
1582 elif [ "$1" = 'test' ]; then
1584 # doesn't support ! or non-file flags
1585 msgfailoutputstatfile
() {
1586 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1587 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1588 echo "#### stat(2) of file: $2 ####"
1590 if test -d "$2"; then
1591 echo "#### The directory contains: $2 ####"
1593 elif test -e "$2"; then
1594 echo "#### Complete file: $2 ####"
1599 msgfailoutputstatfile
"$2" "$3"
1600 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1602 msgfailoutputstatfile
"$2" "$3"
1604 echo '#### test output ####'
1605 elif [ "$1" = 'cmp' ]; then
1607 while [ -n "$2" ]; do
1608 echo "#### Complete file: $2 ####"
1612 echo '#### cmp output ####'
1618 testsuccesswithglobalerror
() {
1623 if [ "$1" = '--nomsg' ]; then
1626 msgtest
'Test for successful execution of' "$*"
1628 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output"
1629 if "$@" >"${OUTPUT}" 2>&1; then
1630 if expr match
"$1" '^apt.*' >/dev
/null
; then
1631 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1632 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1633 elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1634 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1635 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1636 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1639 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1642 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1644 elif [ "$TYPE" = 'testsuccesswithnotice' ]; then
1645 if grep -q -E "^N: " "$OUTPUT"; then
1648 msgfailoutput
'successful run, but output had no notices' "$OUTPUT" "$@"
1658 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1660 aptautotest
"$TYPE" "$@"
1663 testsuccesswithnotice
() {
1664 testsuccesswithglobalerror
'testsuccesswithnotice' 'WE' "$@"
1667 testsuccesswithglobalerror
'testsuccess' 'NWE' "$@"
1670 msggroup
'testwarning'
1671 if [ "$1" = '--nomsg' ]; then
1674 msgtest
'Test for successful execution with warnings of' "$*"
1676 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1677 if "$@" >"${OUTPUT}" 2>&1; then
1678 if expr match
"$1" '^apt.*' >/dev
/null
; then
1679 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1680 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1681 elif grep -q -E '^E: ' "$OUTPUT"; then
1682 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1683 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1684 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1693 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1695 aptautotest
'testwarning' "$@"
1699 msggroup
'testfailure'
1700 if [ "$1" = '--nomsg' ]; then
1703 msgtest
'Test for failure in execution of' "$*"
1705 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1706 if "$@" >"${OUTPUT}" 2>&1; then
1708 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1711 if expr match
"$1" '^apt.*' >/dev
/null
; then
1712 if [ "$1" = 'aptkey' ]; then
1713 if grep -q " Can't check signature:
1715 signature could not be verified" "$OUTPUT"; then
1718 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1721 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1722 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1723 elif grep -q -E '==ERROR' "$OUTPUT"; then
1724 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1725 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1726 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1735 aptautotest
'testfailure' "$@"
1739 testreturnstateequal
() {
1741 if [ "$STATE" = 'testsuccesswithglobalerror' ]; then
1745 msggroup
"${STATE}equal"
1746 if [ "$1" != '--nomsg' ]; then
1749 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1750 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1754 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1755 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1758 msggroup
"${STATE}equal"
1759 if [ "$2" != '--nomsg' ]; then
1763 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1767 "$STATE" --nomsg "$@"
1768 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1773 testsuccessequal
() {
1774 # we compare output, so we know perfectly well about N:
1775 testreturnstateequal
'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@"
1777 testwarningequal
() {
1778 testreturnstateequal
'testwarning' "$@"
1780 testfailureequal
() {
1781 testreturnstateequal
'testfailure' "$@"
1785 msggroup
'testfailuremsg'
1789 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1790 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1791 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1792 testoutputequal
"$COMPAREFILE" echo "$CMP"
1796 msggroup
'testwarningmsg'
1800 msgtest
'Check that the output of the previous warned command has expected' 'warnings'
1801 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
1802 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
1803 testoutputequal
"$COMPAREFILE" echo "$CMP"
1808 msggroup
'testfilestats'
1809 msgtest
"Test that file $1 has $2 $3" "$4"
1810 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1813 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1816 echo -n "stat(1) reports for $2: "
1817 stat
--format "$2" "$1" || true
1819 msgfailoutput
'' "$OUTPUT"
1823 testaccessrights
() {
1824 msggroup
'testaccessrights'
1825 testfilestats
"$1" '%a' '=' "$2"
1829 testwebserverlaststatuscode
() {
1830 msggroup
'testwebserverlaststatuscode'
1831 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1832 local STATUS
='downloaded/webserverstatus-statusfile.log'
1833 rm -f "$DOWNLOG" "$STATUS"
1834 msgtest
'Test last status code from the webserver was' "$1"
1835 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1838 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1840 if [ -n "$2" ]; then
1842 echo >&2 '#### Additionally provided output files contain:'
1845 echo >&2 '#### Download log of the status code:'
1848 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1853 createlistofkeys
() {
1856 while [ -n "$1" ]; do
1857 # gpg 2.1.something starts printing [SC] at some point
1858 if grep -q ' rsa2048/' "$OUTPUT" && grep -qF '[SC]' "$OUTPUT"; then
1860 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';;
1861 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [SC] [expired: 2013-07-13]';;
1862 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16 [SC]';;
1863 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19 [SC]';;
1864 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';;
1865 *) echo 'UNKNOWN KEY';;
1867 # gpg 2.1 has a slightly different output format
1868 elif grep -q ' rsa2048/' "$OUTPUT"; then
1870 *Joe
*|*Sixpack
*) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1871 *Rex
*|*Expired
*) echo 'pub rsa2048/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1872 *Marvin
*|*Paranoid
*) echo 'pub rsa2048/528144E2 2011-01-16';;
1873 oldarchive
) echo 'pub rsa1024/F68C85A3 2013-12-19';;
1874 newarchive
) echo 'pub rsa2048/DBAC8DAE 2010-08-18';;
1875 *) echo 'UNKNOWN KEY';;
1879 *Joe
*|*Sixpack
*) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1880 *Rex
*|*Expired
*) echo 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
1881 *Marvin
*|*Paranoid
*) echo 'pub 2048R/528144E2 2011-01-16';;
1882 oldarchive
) echo 'pub 1024R/F68C85A3 2013-12-19';;
1883 newarchive
) echo 'pub 2048R/DBAC8DAE 2010-08-18';;
1884 *) echo 'UNKNOWN KEY';;
1891 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output"
1892 if ! aptkey list
| grep '^pub' > "$OUTPUT"; then
1895 testfileequal
"$OUTPUT" "$(createlistofkeys "$OUTPUT" "$@")"
1899 echo "STOPPED execution. Press enter to continue"
1904 listcurrentlistsdirectory
() {
1906 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1907 stat
--format '%U:%G:%a:%n' "$line"
1909 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1910 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1914 forallsupportedcompressors
() {
1915 rm -f "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
1916 for COMP
in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
1917 if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi
1922 ### convenience hacks ###
1924 # creating some directories by hand is a tedious task, so make it look simple
1926 if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then
1927 # only the last directory created by mkdir is effected by the -m !
1928 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1929 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1930 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1931 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1932 if [ "$(id -u)" = '0' ]; then
1933 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1940 ### The following tests are run by most test methods automatically to check
1941 ### general things about commands executed without writing the test every time.
1947 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')"
1948 if command -v $AUTOTEST >/dev
/null
; then
1950 # save and restore the *.output files from other tests
1951 # as we might otherwise override them in these automatic tests
1952 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1953 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1954 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1955 $AUTOTEST "$TESTCALL" "$@"
1956 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1957 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1958 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1962 aptautotest_aptget_update
() {
1964 while [ -n "$2" ]; do
1965 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1968 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1969 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1970 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1971 # all copied files are properly chmodded
1972 local backupIFS
="$IFS"
1973 IFS
="$(printf "\n\b")"
1974 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1975 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1978 if [ "$TESTCALL" = 'testsuccess' ]; then
1979 # failure cases can retain partial files and such
1980 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
1983 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1984 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
1986 testaptautotestnodpkgwarning
() {
1988 while [ -n "$2" ]; do
1989 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
1990 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
1993 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1996 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
1997 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
1998 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
1999 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
2000 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
2001 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }