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\([cfghs]\)#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} $CMD "$@"
178 aptconfig
() { runapt apt
-config "$@"; }
179 aptcache
() { runapt apt
-cache "$@"; }
180 aptcdrom
() { runapt apt
-cdrom "$@"; }
181 aptget
() { runapt apt
-get "$@"; }
182 aptftparchive
() { runapt apt
-ftparchive "$@"; }
183 aptkey
() { runapt apt
-key "$@"; }
184 aptmark
() { runapt apt
-mark "$@"; }
185 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; }
186 apt
() { runapt apt
"$@"; }
187 apthelper
() { runapt
"${APTHELPERBINDIR}/apt-helper" "$@"; }
188 aptwebserver
() { runapt
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
189 aptitude
() { runapt aptitude
"$@"; }
190 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; }
191 aptinternalsolver
() { runapt
"${APTINTERNALSOLVER}" "$@"; }
192 aptdumpsolver
() { runapt
"${APTDUMPSOLVER}" "$@"; }
195 "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@"
197 dpkgcheckbuilddeps
() {
198 command dpkg
-checkbuilddeps --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" "$@"
203 aptget
) CMD
="apt-get";;
204 aptcache
) CMD
="apt-cache";;
205 aptcdrom
) CMD
="apt-cdrom";;
206 aptconfig
) CMD
="apt-config";;
207 aptmark
) CMD
="apt-mark";;
208 apthelper
) CMD
="apt-helper";;
209 aptftparchive
) CMD
="apt-ftparchive";;
210 dpkg
) shift; runapt
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" "$@"; return;;
214 if [ "${CMD##*/}" = "$CMD" ]; then
215 CMD
="${BUILDDIRECTORY}/${CMD}"
217 runapt
command gdb
--quiet -ex run
"$CMD" --args "$CMD" "$@"
221 # error if we about to overflow, but ...
222 # "255 failures ought to be enough for everybody"
223 if [ $EXIT_CODE -gt 255 ]; then
224 msgdie
"Total failure count $EXIT_CODE too big"
226 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
229 shellsetedetector
() {
231 if [ "$exit_status" != '0' ]; then
232 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
233 if [ "$EXIT_CODE" = '0' ]; then
234 EXIT_CODE
="$exit_status"
240 if [ "$1" = 'prefix' ]; then
241 CURRENTTRAP
="$2 $CURRENTTRAP"
243 CURRENTTRAP
="$CURRENTTRAP $1"
245 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
249 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
250 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
253 TMPWORKINGDIRECTORY
="$(mktemp -d)"
254 addtrap
"cd /; rm -rf \"$TMPWORKINGDIRECTORY\";"
255 msgninfo
"Preparing environment for ${0##*/} in ${TMPWORKINGDIRECTORY}…"
257 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
258 if [ "$(id -u)" = '0' ]; then
259 # relax permissions so that running as root with user switching works
261 chmod 711 "$TMPWORKINGDIRECTORY"
262 chown _apt
:root
"${TMPWORKINGDIRECTORY}/downloaded"
265 TESTDIRECTORY
="$(readlink -f "$(dirname $0)")"
266 # allow overriding the default BUILDDIR location
267 SOURCEDIRECTORY="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}"
268 BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}"
269 LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}"
270 METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}"
271 APTHELPERBINDIR="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}"
272 APTWEBSERVERBINDIR="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}"
273 APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}"
274 APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}"
275 test -x "${BUILDDIRECTORY}/apt
-get" || msgdie "You need to build tree first
"
278 cd "$TMPWORKINGDIRECTORY"
279 mkdir rootdir aptarchive keys
281 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
282 mkdir -p usr/bin var/cache var/lib var/log tmp
283 mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
284 touch var/lib/dpkg/available
286 ln -s "${METHODSDIR}" usr/lib/apt/methods
287 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
288 mkdir -p usr/lib/apt/solvers
289 ln -s "${BUILDDIRECTORY}/apt
-dump-solver" usr/lib/apt/solvers/dump
290 ln -s "${BUILDDIRECTORY}/apt
-internal-solver" usr/lib/apt/solvers/apt
291 echo "Dir
::Bin
::Solvers
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/solvers
\";" > etc/apt/apt.conf.d/externalsolver.conf
293 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
295 if [ -e "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" ]; then
296 ln -s "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" etc/apt/apt.conf.d/01autoremove
298 ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
301 local BASENAME="${0##*/}"
302 local PACKAGESFILE="Packages
-${BASENAME#*-}"
303 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
304 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
306 local SOURCESSFILE="Sources
-${BASENAME#*-}"
307 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
308 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
310 for key in $(find "$TESTDIRECTORY" -name '*.pub' -o -name '*.sec'); do
314 ln -s "${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub
" rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
316 echo "Dir
\"${TMPWORKINGDIRECTORY}/rootdir
\";" > aptconfig.conf
317 echo "Dir
::state
::status
\"${TMPWORKINGDIRECTORY}/rootdir
/var
/lib
/dpkg
/status
\";" >> aptconfig.conf
318 echo "APT
::Get
::Show
-User-Simulation-Note \"false
\";" >> aptconfig.conf
319 echo "Dir
::Bin
::Methods
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/methods
\";" >> aptconfig.conf
320 # either store apt-key were we can access it, even if we run it as a different user
321 #cp "${BUILDDIRECTORY}/apt
-key" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/"
322 #chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key"
323 #echo "Dir
::Bin
::apt
-key \"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key\";" >> aptconfig.conf
324 # destroys coverage reporting though, so we disable changing user for the calling gpgv
325 echo "Dir
::Bin
::apt
-key \"${BUILDDIRECTORY}/apt
-key\";" >> aptconfig.conf
326 if [ "$(id -u)" = '0' ]; then
327 echo 'Binary::gpgv::Debug::NoDropPrivs "true
";' >>aptconfig.conf
330 cat > "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
333 if [ -r "${TMPWORKINGDIRECTORY}/noopchroot.so
" ]; then
334 if [ -n "\
$LD_LIBRARY_PATH" ]; then
335 export LD_LIBRARY_PATH="${TMPWORKINGDIRECTORY}:${LD_LIBRARY_PATH}"
337 export LD_LIBRARY_PATH="${TMPWORKINGDIRECTORY}"
339 if [ -n "\
$LD_PRELOAD" ]; then
340 export LD_PRELOAD="noopchroot.so \
${LD_PRELOAD}"
342 export LD_PRELOAD="noopchroot.so
"
346 cp "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
347 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
348 exec fakeroot "${DPKG:-dpkg}" --root="${TMPWORKINGDIRECTORY}/rootdir
" \\
349 --log="${TMPWORKINGDIRECTORY}/rootdir
/var
/log
/dpkg.log
" \\
350 --force-not-root --force-bad-path "\$@
"
352 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg" <<EOF
353 exec fakeroot gdb --quiet -ex run "${DPKG:-dpkg}" --args "${DPKG:-dpkg}" --root="${TMPWORKINGDIRECTORY}/rootdir
" \\
354 --log="${TMPWORKINGDIRECTORY}/rootdir
/var
/log
/dpkg.log
" \\
355 --force-not-root --force-bad-path "\$@
"
357 chmod +x "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
358 echo "Dir
::Bin
::dpkg
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
\";" > rootdir/etc/apt/apt.conf.d/99dpkg
361 if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
362 echo "DPKG
::options
:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
364 echo 'quiet::NoUpdate "true
";'
365 echo 'quiet::NoStatistic "true
";'
366 # too distracting for users, but helpful to detect changes
367 echo 'Acquire::Progress::Ignore::ShowErrorText "true
";'
368 echo 'Acquire::Progress::Diffpercent "true
";'
369 # in testcases, it can appear as if localhost has a rotation setup,
370 # hide this as we can't really deal with it properly
371 echo 'Acquire::Failure::ShowIP "false
";'
374 cp "${TESTDIRECTORY}/apt.pem
" "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
375 if [ "$(id -u)" = '0' ]; then
376 chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
378 echo "Acquire
::https
::CaInfo
\"${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
\";" > rootdir/etc/apt/apt.conf.d/99https
379 echo "Apt
::Cmd
::Disable
-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
380 echo 'Acquire::Connect::AddrConfig "false
";' > rootdir/etc/apt/apt.conf.d/connect-addrconfig
381 configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
382 confighashes 'SHA1' # these are tests, not security best-practices
384 # create some files in /tmp and look at user/group to get what this means
385 TEST_DEFAULT_USER="$USER"
386 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
387 TEST_DEFAULT_GROUP='root'
389 TEST_DEFAULT_GROUP="$USER"
392 # cleanup the environment a bit
393 # prefer our apt binaries over the system apt binaries
394 export PATH="${BUILDDIRECTORY}:${PATH}:/usr
/local
/sbin
:/usr
/sbin
:/sbin
"
395 export LC_ALL=C.UTF-8
396 unset LANGUAGE APT_CONFIG
397 unset GREP_OPTIONS DEB_BUILD_PROFILES
402 if [ "$1" = "native
" -o -z "$1" ]; then
403 eval `aptconfig shell ARCH APT::Architecture`
404 if [ -n "$ARCH" ]; then
407 dpkg --print-architecture
415 aptconfig dump --no-empty --format '%v%n' APT::Architecture APT::Architectures | sort -u | tr '\n' ' '
418 getarchitecturesfromcommalist() {
419 echo "$1" | sed -e 's#,#\n#g' | sed -e "s
/^native\$
/$(getarchitecture 'native')/"
422 configarchitecture() {
424 echo "APT
::Architecture
\"$(getarchitecture $1)\";"
425 while [ -n "$1" ]; do
426 echo "APT
::Architectures
:: \"$(getarchitecture $1)\";"
429 } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
434 if [ ! -e rootdir/var/lib/dpkg/status ]; then
435 local BASENAME="${0##*/}"
436 local STATUSFILE="status
-${BASENAME#*-}"
437 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
438 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
440 echo -n > rootdir/var/lib/dpkg/status
443 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
444 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
445 local ARCHS="$(getarchitectures)"
446 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
447 DPKGARCH="$(dpkg --print-architecture)"
448 for ARCH in ${ARCHS}; do
449 if [ "${ARCH}" != "${DPKGARCH}" ]; then
450 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
451 # old-style used e.g. in Ubuntu-P – and as it seems travis
452 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
453 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
457 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
458 # dpkg doesn't really check the version as long as it is fully installed,
459 # but just to be sure we choose one above the required version
460 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
466 configdpkgnoopchroot() {
467 # create a library to noop chroot() and rewrite maintainer script executions
468 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
469 # chroot directory dpkg could chroot into to execute the maintainer scripts
470 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
471 cat > noopchroot.c << EOF
478 static char * chrootdir = NULL;
480 int chroot(const char *path) {
481 printf("WARNING
: CHROOTing to
%s was ignored
!\n", path);
483 chrootdir = strdup(path);
486 int execvp(const char *file, char *const argv[]) {
487 static int (*func_execvp) (const char *, char * const []) = NULL;
488 if (func_execvp == NULL)
489 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
");
490 if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0)
491 return func_execvp(file, argv);
492 printf("REWRITE execvp call
%s into
%s
\n", file, chrootdir);
493 char newfile[strlen(chrootdir) + strlen(file)];
494 strcpy(newfile, chrootdir);
495 strcat(newfile, file);
496 char const * const baseadmindir = "/var
/lib
/dpkg
";
497 char admindir[strlen(chrootdir) + strlen(baseadmindir)];
498 strcpy(admindir, chrootdir);
499 strcat(admindir, baseadmindir);
500 setenv("DPKG_ADMINDIR
", admindir, 1);
501 return func_execvp(newfile, argv);
504 testsuccess --nomsg gcc -fPIC -shared -o noopchroot.so noopchroot.c -ldl
506 configcompression() {
507 while [ -n "$1" ]; do
509 '.') printf ".
\t.
\tcat
\n";;
510 'gz') printf "gzip\tgz
\tgzip
\n";;
511 'bz2') printf "bzip2\tbz
2\tbzip
2\n";;
512 'lzma') printf "lzma
\tlzma
\txz
--format=lzma
\n";;
513 'xz') printf "xz
\txz
\txz
\n";;
514 *) printf "$1\t$1\t$1\n";;
517 done > "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
"
521 echo 'APT::FTPArchive {'
523 while [ -n "$1" ]; do
524 printf "$1" | tr 'a-z' 'A-Z'
525 printf "\t\"true
\";\n"
528 for h in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
529 printf "$h\t\"false
\";\n"
533 } >> "${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/ftparchive
-hashes.conf
"
539 gzip) COMPRESS='gz';;
540 bzip2) COMPRESS='bz2';;
541 lzma) COMPRESS='lzma';;
543 *) msgdie "Compressor
$COMPRESSOR is unknown to framework
, so can
't be forced by forcecompressor!";;
545 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
546 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
547 Dir::Bin::uncompressed \"/does/not/exist\";
548 Dir::Bin::gzip \"/does/not/exist\";
549 Dir::Bin::bzip2 \"/does/not/exist\";
550 Dir::Bin::lzma \"/does/not/exist\";
551 Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
552 if [ -e "/bin/${COMPRESSOR}" ]; then
553 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
554 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
555 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
556 elif [ "${COMPRESSOR}" = 'lzma
' ]; then
557 echo 'Dir
::Bin
::xz
"/usr/bin/xz";' >> "$CONFFILE"
558 COMPRESSOR_CMD='xz
--format=lzma
'
560 msgtest 'Test
for availability of compressor
' "${COMPRESSOR}"
561 msgfail "${COMPRESSOR} not available"
565 setupsimplenativepackage() {
569 local RELEASE="${4:-unstable}"
570 local DEPENDENCIES="$5"
571 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
572 If you find such a package installed on your system,
573 something went horribly wrong! They are autogenerated
574 und used only by testcases and surf no other propose…"}"
576 local SECTION="${7:-others}"
578 if [ "$SECTION" = "${SECTION#*/}" ]; then
581 DISTSECTION="${SECTION%/*}"
583 local BUILDDIR=incoming/${NAME}-${VERSION}
584 mkdir -p ${BUILDDIR}/debian/source
586 echo "* most suckless software product ever" > FEATURES
587 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
588 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
592 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
593 test -e debian/control || echo "Source: $NAME
596 Maintainer: Joe Sixpack <joe@example.org>
597 Build-Depends: debhelper (>= 7)
598 Standards-Version: 3.9.1
600 Package: $NAME" > debian/control
601 if [ "$ARCH" = 'all
' ]; then
602 echo "Architecture: all" >> debian/control
604 echo "Architecture: any" >> debian/control
606 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
607 echo "Description: $DESCRIPTION" >> debian/control
609 test -e debian/compat || echo "7" > debian/compat
610 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
611 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
615 buildsimplenativepackage() {
618 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib
' ]; then
619 NM="$(echo "$NAME" | cut -c 1-4)"
621 NM="$(echo "$NAME" | cut -c 1)"
625 local RELEASE="${4:-unstable}"
626 local DEPENDENCIES="$5"
627 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
628 If you find such a package installed on your system,
629 something went horribly wrong! They are autogenerated
630 und used only by testcases and surf no other propose…"}"
632 local SECTION="${7:-others}"
633 local PRIORITY="${8:-optional}"
635 local COMPRESS_TYPE="${10:-gzip}"
637 if [ "$SECTION" = "${SECTION#*/}" ]; then
640 DISTSECTION="${SECTION%/*}"
642 local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
644 msgtest "Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
645 mkdir -p "$BUILDDIR/debian/source"
646 echo "* most suckless software product ever" > "${BUILDDIR}/FEATURES"
648 echo '$NAME says
\"Hello
!\"'" > "${BUILDDIR}/${NAME}"
650 echo "Copyleft by Joe Sixpack $(date +%Y)" > "${BUILDDIR}/debian/copyright"
651 echo "$NAME ($VERSION) $RELEASE; urgency=low
655 -- Joe Sixpack <joe@example.org> $(date -R)" > "${BUILDDIR}/debian/changelog"
659 Maintainer: Joe Sixpack <joe@example.org>
660 Standards-Version: 3.9.3"
661 if [ "$SECTION" != '<none
>' ]; then
662 echo "Section: $SECTION"
664 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
665 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
669 if [ "$ARCH" = 'all
' ]; then
670 echo "Architecture: all"
672 echo "Architecture: any"
674 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
675 test -z "$DEPS" || echo "$DEPS"
676 echo "Description: $DESCRIPTION"
677 } > "${BUILDDIR}/debian/control"
679 echo '3.0 (native
)' > "${BUILDDIR}/debian/source/format"
681 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
683 sed -n 's
#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" \
685 echo "pool/${SRC}" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist"
686 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
687 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
688 # adv --yes --default-key 'Joe Sixpack' \
689 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
690 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
694 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
695 msgtest
"Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
696 rm -rf "${BUILDDIR}/debian/tmp"
697 mkdir -p "${BUILDDIR}/debian/tmp/DEBIAN" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin"
698 cp "${BUILDDIR}/debian/copyright" "${BUILDDIR}/debian/changelog" "${BUILDDIR}/FEATURES" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}"
699 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}"
700 if [ -n "$FILE_TREE" ]; then
701 cp -ar "$FILE_TREE" "${BUILDDIR}/debian/tmp"
704 (cd "${BUILDDIR}"; dpkg
-gencontrol -DArchitecture=$arch)
705 (cd "${BUILDDIR}/debian/tmp"; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
706 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
707 # ensure the right permissions as dpkg-deb insists
708 chmod 755 "${BUILDDIR}/debian/tmp/DEBIAN"
709 testsuccess
--nomsg dpkg
-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian/tmp" "${BUILDDIR}/.."
710 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist"
713 local CHANGEPATH
="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}"
714 mkdir -p "$CHANGEPATH"
715 cp "${BUILDDIR}/debian/changelog" "$CHANGEPATH"
724 local ARCH
=$(getarchitecture $4)
725 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
726 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
727 msgtest
"Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
729 if [ "$ARCH" = "all" ]; then
730 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
732 testsuccess
--nomsg dpkg
-buildpackage -uc -us -a$ARCH
733 cp "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$BUILDLOG"
734 local PKGS
="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
735 local SRCS
="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
738 echo "pool/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist"
741 echo "pool/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist"
746 if [ -d incoming
]; then
747 buildaptarchivefromincoming
"$@"
749 buildaptarchivefromfiles
"$@"
753 createaptftparchiveconfig
() {
754 local COMPRESSORS
="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
755 local COMPRESSORS
="${COMPRESSORS%* }"
756 local ARCHS
="$(getarchitectures)"
757 cat > ftparchive.conf
<<EOF
759 ArchiveDir "$(readlink -f .)";
760 CacheDir "$(readlink -f ..)";
761 FileListDir "$(readlink -f pool/)";
764 Packages::Compress "$COMPRESSORS";
765 Sources::Compress "$COMPRESSORS";
766 Contents::Compress "$COMPRESSORS";
767 Translation::Compress "$COMPRESSORS";
768 LongDescription "false";
772 SrcDirectory "pool/";
775 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
778 Architectures "$ARCHS all source";
779 FileList "${DIST}.\$(SECTION).pkglist";
780 SourceFileList "${DIST}.\$(SECTION).srclist";
781 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
784 done >> ftparchive.conf
787 buildaptftparchivedirectorystructure
() {
788 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
789 for DIST
in $DISTS; do
790 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
791 for SECTION
in $SECTIONS; do
792 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
793 for ARCH
in $ARCHS; do
794 mkdir -p "dists/${DIST}/${SECTION}/binary-${ARCH}"
796 mkdir -p "dists/${DIST}/${SECTION}/source"
797 mkdir -p "dists/${DIST}/${SECTION}/i18n"
807 local DEPENDENCIES
="$5"
808 local PRIORITY
="${6:-optional}"
809 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
810 If you find such a package installed on your system,
811 something went horribly wrong! They are autogenerated
812 und used only by testcases and surf no other propose…"}"
814 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
815 if [ "$RELEASE" = 'installed' ]; then
816 insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
819 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
820 if [ "$arch" = 'none' ]; then
821 ARCHS="$(getarchitectures)"
825 for BUILDARCH in $ARCHS; do
826 local PPATH="aptarchive
/dists
/${RELEASE}/main
/binary
-${BUILDARCH}"
833 Maintainer
: Joe Sixpack
<joe@example.org
>"
834 test "$arch" = 'none' || echo "Architecture
: $arch"
835 echo "Version
: $VERSION
836 Filename
: pool
/main
/${NAME}/${NAME}_
${VERSION}_
${arch}.deb
"
837 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES"
838 echo "Description
: $(printf '%s' "$DESCRIPTION" | head -n 1)"
839 echo "Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
841 } >> "${PPATH}/Packages
"
844 mkdir -p "aptarchive
/dists
/${RELEASE}/main
/source" "aptarchive
/dists
/${RELEASE}/main
/i18n
"
845 touch "aptarchive
/dists
/${RELEASE}/main
/source
/Sources
"
847 Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
848 Description
-en: $DESCRIPTION
849 " >> "aptarchive
/dists
/${RELEASE}/main
/i
18n
/Translation
-en"
858 local DEPENDENCIES="$5"
859 local BINARY="${6:-$NAME}"
861 local SPATH="aptarchive
/dists
/${RELEASE}/main
/source"
863 local FILE="${SPATH}/Sources
"
864 local DSCFILE="${NAME}_
${VERSION}.dsc
"
865 local TARFILE="${NAME}_
${VERSION}.
tar.gz
"
869 Maintainer
: Joe Sixpack
<joe@example.org
>
870 Architecture
: $ARCH" >> $FILE
871 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
873 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
874 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
876 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
877 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
881 insertinstalledpackage() {
885 local DEPENDENCIES="$4"
886 local PRIORITY="${5:-optional}"
887 local STATUS="${6:-install ok installed}"
888 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
889 If you
find such a package installed on your system
,
890 something went horribly wrong
! They are autogenerated
891 und used only by testcases and surf no other propose…
"}"
893 local FILE
='rootdir/var/lib/dpkg/status'
894 local INFO
='rootdir/var/lib/dpkg/info'
895 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
901 Maintainer: Joe Sixpack <joe@example.org>
902 Version: $VERSION" >> "$FILE"
903 test "$arch" = 'none' || echo "Architecture: $arch" >> "$FILE"
904 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
905 echo "Description: $DESCRIPTION" >> "$FILE"
907 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
908 echo -n > "${INFO}/${NAME}:${arch}.list"
910 echo -n > "${INFO}/${NAME}.list"
916 buildaptarchivefromincoming
() {
917 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on incoming packages…"
919 [ -e pool
] || ln -s ..
/incoming pool
920 [ -e ftparchive.conf
] || createaptftparchiveconfig
921 [ -e dists
] || buildaptftparchivedirectorystructure
922 msgninfo
"\tGenerate Packages, Sources and Contents files… "
923 testsuccess aptftparchive generate ftparchive.conf
926 generatereleasefiles
"$@"
929 buildaptarchivefromfiles
() {
930 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on prebuild files…"
931 local DIR
='aptarchive'
932 if [ -d "${DIR}/dists" ]; then DIR
="${DIR}/dists"; fi
933 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
934 msgninfo
"\t${line} file… "
935 compressfile
"$line" "$1"
938 generatereleasefiles
"$@"
942 cat "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | while read compressor extension
command; do
943 if [ "$compressor" = '.' ]; then
949 cat "$1" | $command > "${1}.${extension}"
951 touch -d "$2" "${1}.${extension}"
956 # can be overridden by testcases for their pleasure
957 getcodenamefromsuite
() {
959 unstable
) echo 'sid';;
963 getreleaseversionfromsuite
() { true
; }
964 getlabelfromsuite
() { true
; }
965 getoriginfromsuite
() { true
; }
966 getarchitecturesfromreleasefile
() { echo "all $(getarchitectures)"; }
968 aptftparchiverelease
() {
969 aptftparchive
-qq release
"$@" | sed -e '/0 Release$/ d' # remove the self reference
971 generatereleasefiles
() {
972 # $1 is the Date header and $2 is the ValidUntil header to be set
973 # both should be given in notation date/touch can understand
975 local VALIDUNTIL
="$2"
976 msgninfo
"\tGenerate Release files… "
977 if [ -e aptarchive
/dists
]; then
978 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
979 local ARCHITECTURES
="$(getarchitecturesfromreleasefile "$dir")"
980 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
981 local CODENAME
="$(getcodenamefromsuite $SUITE)"
982 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
983 local LABEL
="$(getlabelfromsuite $SUITE)"
984 local ORIGIN
="$(getoriginfromsuite $SUITE)"
985 aptftparchiverelease
"$dir" \
986 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
987 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
988 -o APT
::FTPArchive
::Release
::Architectures
="${ARCHITECTURES}" \
989 -o APT
::FTPArchive
::Release
::Label
="${LABEL}" \
990 -o APT
::FTPArchive
::Release
::Origin
="${ORIGIN}" \
991 -o APT
::FTPArchive
::Release
::Version
="${VERSION}" \
993 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
995 NotAutomatic: yes' "$dir/Release"
999 aptftparchiverelease .
/aptarchive
> aptarchive
/Release
1001 if [ -n "$DATE" -a "$DATE" != "now" ]; then
1002 for release
in $(find ./aptarchive -name 'Release'); do
1003 sed -i "s/^Date: .*$/Date: $(date -d "$DATE" '+%a, %d %b %Y %H:%M:%S %Z')/" "$release"
1004 touch -d "$DATE" "$release"
1007 if [ -n "$VALIDUNTIL" ]; then
1008 sed -i "/^Date: / a\
1009 Valid-Until: $(date -d "$VALIDUNTIL" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release')
1014 setupdistsaptarchive
() {
1015 local APTARCHIVE
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1016 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
1017 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
1018 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1019 SECTIONS
=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1020 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
1021 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list"
1022 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list"
1027 setupflataptarchive
() {
1028 local APTARCHIVE
="$(readlink -f ./aptarchive)"
1029 local APTARCHIVEURI
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1030 if [ -f "${APTARCHIVE}/Packages" ]; then
1031 msgninfo
"\tadd deb sources.list line… "
1032 echo "deb file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1035 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1037 if [ -f "${APTARCHIVE}/Sources" ]; then
1038 msgninfo
"\tadd deb-src sources.list line… "
1039 echo "deb-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1042 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1048 if [ "$1" = '--no-update' ]; then
1052 buildaptarchive
"$@"
1053 if [ -e aptarchive
/dists
]; then
1054 setupdistsaptarchive
1058 signreleasefiles
'Joe Sixpack'
1059 if [ "1" != "$NOUPDATE" ]; then
1060 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
1064 signreleasefiles
() {
1065 local SIGNER
="${1:-Joe Sixpack}"
1066 local REPODIR
="${2:-aptarchive}"
1067 local KEY
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
1068 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
1069 msgninfo
"\tSign archive with $SIGNER key $KEY… "
1070 local REXKEY
='keys/rexexpired'
1071 local SECEXPIREBAK
="${REXKEY}.sec.bak"
1072 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
1073 if [ "${SIGNER}" = 'Rex Expired' ]; then
1074 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1075 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1076 # therefore we 'temporary' make the key not expired and restore a backup after signing
1077 cp "${REXKEY}.sec" "$SECEXPIREBAK"
1078 cp "${REXKEY}.pub" "$PUBEXPIREBAK"
1079 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
1080 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
1081 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1082 cp "$SECUNEXPIRED" "${REXKEY}.sec"
1083 cp "$PUBUNEXPIRED" "${REXKEY}.pub"
1085 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
1089 cp "${REXKEY}.sec" "$SECUNEXPIRED"
1090 cp "${REXKEY}.pub" "$PUBUNEXPIRED"
1093 for RELEASE
in $(find "${REPODIR}/" -name Release); do
1094 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output "${RELEASE}.gpg" "${RELEASE}"
1095 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
1096 $GPG --default-key "$SIGNER" --clearsign --output "$INRELEASE" "$RELEASE"
1097 # we might have set a specific date for the Release file, so copy it
1098 touch -d "$(stat --format "%y" ${RELEASE})" "${RELEASE}.gpg" "${INRELEASE}"
1100 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1101 mv -f "$SECEXPIREBAK" "${REXKEY}.sec"
1102 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub"
1107 redatereleasefiles
() {
1108 local DATE
="$(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
1109 for release
in $(find aptarchive/ -name 'Release'); do
1110 sed -i "s/^Date: .*$/Date: ${DATE}/" "$release"
1111 touch -d "$DATE" "$release"
1113 signreleasefiles
"${2:-Joe Sixpack}"
1117 local WEBSERVER
="${3:-http://localhost:${APTHTTPPORT}}"
1119 if [ "$1" = '--no-check' ]; then
1123 local DOWNLOG
='rootdir/tmp/download-testfile.log'
1124 local STATUS
='downloaded/webserverconfig.status'
1125 rm -f "$STATUS" "$DOWNLOG"
1126 # very very basic URI encoding
1128 if [ -n "$2" ]; then
1129 msgtest
"Set webserver config option '${1}' to" "$2"
1130 URI
="${WEBSERVER}/_config/set/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1132 msgtest
'Clear webserver config option' "${1}"
1133 URI
="${WEBSERVER}/_config/clear/$(echo "${1}" | sed -e 's/\//%2f/g')"
1135 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
1138 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.output"
1139 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1140 msgfailoutput
'' "$OUTPUT"
1142 $NOCHECK || testwebserverlaststatuscode
'200'
1145 rewritesourceslist
() {
1146 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1147 local APTARCHIVE2
="copy://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1148 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1149 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
1150 -e "s#http://localhost:${APTHTTPPORT}/#${1}#" \
1151 -e "s#https://localhost:${APTHTTPSPORT}/#${1}#"
1155 # wait for up to 10s for a pid file to appear to avoid possible race
1156 # when a helper is started and dosn't write the PID quick enough
1159 for i
in $(seq 10); do
1160 if test -s "$PIDFILE"; then
1165 msgdie
"waiting for $PIDFILE failed"
1169 changetowebserver
() {
1171 if [ "$1" != '--no-rewrite' ]; then
1176 if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
1178 local LOG
="webserver.log"
1179 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1183 waitforpidfile aptwebserver.pid
1184 local PID
="$(cat aptwebserver.pid)"
1185 if [ -z "$PID" ]; then
1186 msgdie
'Could not fork aptwebserver successfully'
1188 addtrap
"kill $PID;"
1189 waitforpidfile aptwebserver.port
1190 APTHTTPPORT
="$(cat aptwebserver.port)"
1191 if [ -z "$APTHTTPPORT" ]; then
1192 msgdie
'Could not get port for aptwebserver successfully'
1196 msgdie
'You have to build aptwerbserver or install a webserver'
1198 if [ "$REWRTE" != 'yes' ]; then
1199 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1203 changetohttpswebserver
() {
1204 if ! which stunnel4
>/dev
/null
; then
1205 msgdie
'You need to install stunnel4 for https testcases'
1207 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1208 changetowebserver
--no-rewrite "$@"
1210 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1211 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1216 connect = $APTHTTPPORT
1217 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1218 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1219 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1220 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1221 if [ -z "$PID" ]; then
1222 msgdie
'Could not fork stunnel4 successfully'
1224 addtrap
'prefix' "kill ${PID};"
1225 APTHTTPSPORT
="$(lsof -i | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1226 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1227 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1231 mkdir -p rootdir
/media
/cdrom
/.disk
1232 local CD
="$(readlink -f rootdir/media/cdrom)"
1233 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1234 acquire::cdrom::mount "${CD}";
1235 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1236 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1237 acquire::cdrom::autodetect 0;
1239 echo -n "$1" > "${CD}/.disk/info"
1240 if [ ! -d aptarchive
/dists
]; then
1241 msgdie
'Flat file archive cdroms can not be created currently'
1244 mv aptarchive
/dists
"$CD"
1245 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1246 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1247 # start with an unmounted disk
1248 mv "${CD}" "${CD}-unmounted"
1249 # we don't want the disk to be modifiable
1250 addtrap
'prefix' "chmod -f -R +w \"$PWD/rootdir/media/cdrom/dists/\" \"$PWD/rootdir/media/cdrom-unmounted/dists/\" || true;"
1251 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1255 local PROTO
="${1%%:*}"
1256 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1257 download
-file "$1" "$2" "$3" 2>&1 ; then
1260 # only if the file exists the download was successful
1261 if [ -r "$2" ]; then
1269 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1270 if [ -n "$DIFFTEXT" ]; then
1272 echo >&2 "$DIFFTEXT"
1280 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1281 local COMPAREFILE
="$1"
1283 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1286 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1287 cat "$COMPAREFILE" >>"${OUTPUT}"
1288 msgfailoutput
'' "$OUTPUT" "$@"
1293 msggroup
'testfileequal'
1294 local MSG
='Test for correctness of file'
1295 if [ "$1" = '--nomsg' ]; then
1301 if [ -n "$MSG" ]; then
1302 msgtest
"$MSG" "$FILE"
1304 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1305 if [ -z "$*" ]; then
1306 testoutputequal
"$FILE" echo -n ''
1308 testoutputequal
"$FILE" echo "$*"
1314 msggroup
'testempty'
1315 msgtest
"Test for no output of" "$*"
1316 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1317 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test ! -s "$COMPAREFILE"; then
1320 msgfailoutput
'' "$COMPAREFILE" "$@"
1322 aptautotest
'testempty' "$@"
1326 msggroup
'testnotempty'
1327 msgtest
"Test for some output of" "$*"
1328 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
1329 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then
1332 msgfailoutput
'' "$COMPAREFILE" "$@"
1334 aptautotest
'testnotempty' "$@"
1339 msggroup
'testequal'
1340 local MSG
='Test of equality of'
1341 if [ "$1" = '--nomsg' ]; then
1346 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1347 echo "$1" > "$COMPAREFILE"
1350 if [ -n "$MSG" ]; then
1353 testoutputequal
"$COMPAREFILE" "$@"
1354 aptautotest
'testequal' "$@"
1359 msggroup
'testequalor2'
1360 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1361 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1362 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1363 echo "$1" > "$COMPAREFILE1"
1364 echo "$2" > "$COMPAREFILE2"
1366 msgtest
"Test for equality OR of" "$*"
1367 "$@" >"$COMPAREAGAINST" 2>&1 || true
1368 if checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null
2>&1 || \
1369 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null
2>&1
1373 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1374 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1375 checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1376 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1377 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1378 msgfailoutput
'' "$OUTPUT"
1380 aptautotest
'testequalor2' "$@"
1385 msggroup
'testshowvirtual'
1386 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1389 while [ -n "$1" ]; do
1391 N: Can't select versions from package '$1' as it is purely virtual"
1392 PACKAGE
="${PACKAGE} $1"
1395 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1397 N: No packages found"
1398 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1399 local ARCH
="$(getarchitecture 'native')"
1400 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1401 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1402 testoutputequal
"$COMPAREFILE" aptcache show
-q=0 "$PACKAGE"
1407 msggroup
'testnopackage'
1408 msgtest
"Test for non-existent packages" "apt-cache show $*"
1409 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1410 if [ -n "$SHOWPKG" ]; then
1411 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1412 echo "$SHOWPKG" >"$OUTPUT"
1413 msgfailoutput
'' "$OUTPUT"
1421 msggroup
'testdpkgstatus'
1425 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1426 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1427 if [ "$PKGS" != $NR ]; then
1428 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1429 echo "$PKGS" >"$OUTPUT"
1430 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1431 msgfailoutput
'' "$OUTPUT"
1438 testdpkginstalled
() {
1439 msggroup
'testdpkginstalled'
1440 testdpkgstatus
'ii' "$#" "$@"
1444 testdpkgnotinstalled
() {
1445 msggroup
'testdpkgnotinstalled'
1446 testdpkgstatus
'ii' '0' "$@"
1451 msggroup
'testmarkedauto'
1452 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1453 if [ -n "$1" ]; then
1454 msgtest
'Test for correctly marked as auto-installed' "$*"
1455 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1457 msgtest
'Test for correctly marked as auto-installed' 'no package'
1458 echo -n > "$COMPAREFILE"
1460 testoutputequal
"$COMPAREFILE" aptmark showauto
1463 testmarkedmanual
() {
1464 msggroup
'testmarkedmanual'
1465 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1466 if [ -n "$1" ]; then
1467 msgtest
'Test for correctly marked as manually installed' "$*"
1468 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1470 msgtest
'Test for correctly marked as manually installed' 'no package'
1471 echo -n > "$COMPAREFILE"
1473 testoutputequal
"$COMPAREFILE" aptmark showmanual
1478 msgreportheader
'msgfailoutput'
1482 if [ "$1" = 'grep' ]; then
1484 while [ -n "$2" ]; do shift; done
1485 echo "#### Complete file: $1 ####"
1486 cat >&2 "$1" || true
1487 echo '#### grep output ####'
1488 elif [ "$1" = 'test' ]; then
1490 # doesn't support ! or non-file flags
1491 msgfailoutputstatfile
() {
1492 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1493 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1494 echo "#### stat(2) of file: $2 ####"
1496 if test -e "$2"; then
1497 echo "#### Complete file: $2 ####"
1498 cat >&2 "$2" || true
1502 msgfailoutputstatfile
"$2" "$3"
1503 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1505 msgfailoutputstatfile
"$2" "$3"
1507 echo '#### test output ####'
1513 testsuccesswithglobalerror
() {
1518 if [ "$1" = '--nomsg' ]; then
1521 msgtest
'Test for successful execution of' "$*"
1523 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output"
1524 if "$@" >"${OUTPUT}" 2>&1; then
1525 if expr match
"$1" '^apt.*' >/dev
/null
; then
1526 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1527 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1528 elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1529 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1530 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1531 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1534 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1537 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1539 elif [ "$TYPE" = 'testsuccesswithnotice' ]; then
1540 if grep -q -E "^N: " "$OUTPUT"; then
1543 msgfailoutput
'successful run, but output had no notices' "$OUTPUT" "$@"
1553 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1555 aptautotest
"$TYPE" "$@"
1558 testsuccesswithnotice
() {
1559 testsuccesswithglobalerror
'testsuccesswithnotice' 'WE' "$@"
1562 testsuccesswithglobalerror
'testsuccess' 'NWE' "$@"
1565 msggroup
'testwarning'
1566 if [ "$1" = '--nomsg' ]; then
1569 msgtest
'Test for successful execution with warnings of' "$*"
1571 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1572 if "$@" >"${OUTPUT}" 2>&1; then
1573 if expr match
"$1" '^apt.*' >/dev
/null
; then
1574 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1575 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1576 elif grep -q -E '^E: ' "$OUTPUT"; then
1577 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1578 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1579 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1588 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1590 aptautotest
'testwarning' "$@"
1594 msggroup
'testfailure'
1595 if [ "$1" = '--nomsg' ]; then
1598 msgtest
'Test for failure in execution of' "$*"
1600 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1601 if "$@" >"${OUTPUT}" 2>&1; then
1603 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1606 if expr match
"$1" '^apt.*' >/dev
/null
; then
1607 if [ "$1" = 'aptkey' ]; then
1608 if grep -q -E " Can't check signature: " "$OUTPUT" || \
1609 grep -q -E " BAD signature from " "$OUTPUT"; then
1612 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1615 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1616 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1617 elif grep -q -E '==ERROR' "$OUTPUT"; then
1618 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1619 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1620 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1629 aptautotest
'testfailure' "$@"
1633 testreturnstateequal
() {
1635 if [ "$STATE" = 'testsuccesswithglobalerror' ]; then
1639 msggroup
"${STATE}equal"
1640 if [ "$1" != '--nomsg' ]; then
1643 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1644 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1648 testsuccesswithglobalerror
"$STATE" "$TYPE" "$@"
1649 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1652 msggroup
"${STATE}equal"
1653 if [ "$2" != '--nomsg' ]; then
1657 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1661 "$STATE" --nomsg "$@"
1662 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1667 testsuccessequal
() {
1668 # we compare output, so we know perfectly well about N:
1669 testreturnstateequal
'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@"
1671 testwarningequal
() {
1672 testreturnstateequal
'testwarning' "$@"
1674 testfailureequal
() {
1675 testreturnstateequal
'testfailure' "$@"
1679 msggroup
'testfailuremsg'
1683 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1684 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1685 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1686 testoutputequal
"$COMPAREFILE" echo "$CMP"
1690 msggroup
'testwarningmsg'
1694 msgtest
'Check that the output of the previous warned command has expected' 'warnings'
1695 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
1696 grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
1697 testoutputequal
"$COMPAREFILE" echo "$CMP"
1702 msggroup
'testfilestats'
1703 msgtest
"Test that file $1 has $2 $3" "$4"
1704 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1707 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1710 echo -n "stat(1) reports for $2: "
1711 stat
--format "$2" "$1" || true
1713 msgfailoutput
'' "$OUTPUT"
1717 testaccessrights
() {
1718 msggroup
'testaccessrights'
1719 testfilestats
"$1" '%a' '=' "$2"
1723 testwebserverlaststatuscode
() {
1724 msggroup
'testwebserverlaststatuscode'
1725 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1726 local STATUS
='downloaded/webserverstatus-statusfile.log'
1727 rm -f "$DOWNLOG" "$STATUS"
1728 msgtest
'Test last status code from the webserver was' "$1"
1729 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1732 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1734 if [ -n "$2" ]; then
1736 echo >&2 '#### Additionally provided output files contain:'
1739 echo >&2 '#### Download log of the status code:'
1742 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1748 echo "STOPPED execution. Press enter to continue"
1753 listcurrentlistsdirectory
() {
1755 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1756 stat
--format '%U:%G:%a:%n' "$line"
1758 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1759 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1764 ### convenience hacks ###
1766 # creating some directories by hand is a tedious task, so make it look simple
1767 if [ "$*" = '-p rootdir/var/lib/apt/lists' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" ] ||
1768 [ "$*" = '-p rootdir/var/lib/apt/lists/partial' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" ]; then
1769 # only the last directory created by mkdir is effected by the -m !
1770 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1771 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1772 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1773 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1774 if [ "$(id -u)" = '0' ]; then
1775 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1782 ### The following tests are run by most test methods automatically to check
1783 ### general things about commands executed without writing the test every time.
1789 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d '-')"
1790 if command -v $AUTOTEST >/dev
/null
; then
1792 # save and restore the *.output files from other tests
1793 # as we might otherwise override them in these automatic tests
1794 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1795 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1796 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1797 $AUTOTEST "$TESTCALL" "$@"
1798 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1799 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1800 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1804 aptautotest_aptget_update
() {
1806 while [ -n "$2" ]; do
1807 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1810 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1811 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1812 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1813 # all copied files are properly chmodded
1814 local backupIFS
="$IFS"
1815 IFS
="$(printf "\n\b")"
1816 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1817 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1820 if [ "$TESTCALL" = 'testsuccess' ]; then
1821 # failure cases can retain partial files and such
1822 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
1825 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1826 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
1828 testaptautotestnodpkgwarning
() {
1830 while [ -n "$2" ]; do
1831 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
1832 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
1835 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1838 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
1839 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
1840 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
1841 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
1842 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
1843 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }