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
13 echo >&2 "WARNING: Unknown parameter »$1« will be ignored"
17 export MSGLEVEL
="${MSGLEVEL:-3}"
19 # we all like colorful messages
20 if [ "$MSGCOLOR" != 'NO' ] && [ "$MSGCOLOR" != 'ALWAYS' ]; then
21 if [ ! -t 1 ]; then # but check that we output to a terminal
27 if [ "$MSGCOLOR" != 'NO' ]; then
28 CERROR
="\033[1;31m" # red
29 CWARNING
="\033[1;33m" # yellow
30 CMSG
="\033[1;32m" # green
31 CINFO
="\033[1;96m" # light blue
32 CDEBUG
="\033[1;94m" # blue
33 CNORMAL
="\033[0;39m" # default system console color
34 CDONE
="\033[1;32m" # green
35 CPASS
="\033[1;32m" # green
36 CFAIL
="\033[1;31m" # red
37 CCMD
="\033[1;35m" # pink
49 printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghs]\)#apt-\1#')"
55 msgdie
() { msgprintf
"${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; }
56 msgwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; }
57 msgmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; }
58 msginfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; }
59 msgdebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; }
60 msgdone
() { msgprintf
"${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; }
61 msgnwarn
() { msgprintf
"${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; }
62 msgnmsg
() { msgprintf
"${CMSG}%s" '%s' "${CNORMAL}" "$@"; }
63 msgninfo
() { msgprintf
"${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
64 msgndebug
() { msgprintf
"${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
65 msgtest
() { msgprintf
"${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
66 msgpass
() { printf "${CPASS}PASS${CNORMAL}\n"; }
68 if [ -n "$MSGTEST_MSG" ]; then
69 test "$1" != 'msgfailoutput' || echo
70 if [ -n "$MSGTEST_MSGMSG" ]; then
71 echo "$MSGTEST_MSGMSG"
73 if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then
74 echo "${CFAIL}Part of the test group: $MSGTEST_GRP"
76 echo -n "$MSGTEST_MSG"
81 msgreportheader
'msgskip'
82 if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
83 else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
86 msgreportheader
'msgfail'
87 if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
88 else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
89 if [ -n "$APT_DEBUG_TESTS" ]; then
92 EXIT_CODE
=$((EXIT_CODE+1));
97 if [ $MSGGROUP_LEVEL = 0 ]; then
100 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL+1));
102 MSGGROUP_LEVEL
=$((MSGGROUP_LEVEL-1));
103 if [ $MSGGROUP_LEVEL = 0 ]; then
109 # enable / disable Debugging
110 if [ $MSGLEVEL -le 0 ]; then
113 if [ $MSGLEVEL -le 1 ]; then
117 if [ $MSGLEVEL -le 2 ]; then
119 MSGTEST_MSGMSG
="$(msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@")"
123 MSGTEST_MSG
="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")"
124 if [ "$MSGTEST_GRP" = 'NEXT' ]; then
125 MSGTEST_GRP
="$MSGTEST_MSG"
128 msgpass
() { printf " ${CPASS}P${CNORMAL}"; }
130 if [ $MSGLEVEL -le 3 ]; then
134 if [ $MSGLEVEL -le 4 ]; then
136 msgndebug
() { true
; }
139 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
140 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
141 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
142 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
143 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
146 printf "${CDONE}DONE${CNORMAL}\n";
150 if [ -f .
/aptconfig.conf
]; then
151 echo "$(readlink -f ./aptconfig.conf)"
152 elif [ -f ..
/aptconfig.conf
]; then
153 echo "$(readlink -f ../aptconfig.conf)"
154 elif [ -f ..
/..
/aptconfig.conf
]; then
155 echo "$(readlink -f ../../aptconfig.conf)"
156 elif [ -f "${TMPWORKINGDIRECTORY}/aptconfig.conf" ]; then
157 echo "$(readlink -f "${TMPWORKINGDIRECTORY}/aptconfig.conf")"
161 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
165 sh
|aptitude
|*/*|command) ;;
166 *) CMD
="${BUILDDIRECTORY}/$CMD";;
168 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
=${LIBRARYPATH} $CMD "$@"
170 aptconfig
() { runapt apt
-config "$@"; }
171 aptcache
() { runapt apt
-cache "$@"; }
172 aptcdrom
() { runapt apt
-cdrom "$@"; }
173 aptget
() { runapt apt
-get "$@"; }
174 aptftparchive
() { runapt apt
-ftparchive "$@"; }
175 aptkey
() { runapt apt
-key "$@"; }
176 aptmark
() { runapt apt
-mark "$@"; }
177 aptsortpkgs
() { runapt apt
-sortpkgs "$@"; }
178 apt
() { runapt apt
"$@"; }
179 apthelper
() { runapt
"${APTHELPERBINDIR}/apt-helper" "$@"; }
180 aptwebserver
() { runapt
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
181 aptitude
() { runapt aptitude
"$@"; }
182 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; }
183 aptinternalsolver
() { runapt
"${APTINTERNALSOLVER}" "$@"; }
184 aptdumpsolver
() { runapt
"${APTDUMPSOLVER}" "$@"; }
187 "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@"
189 dpkgcheckbuilddeps
() {
190 command dpkg
-checkbuilddeps --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" "$@"
195 aptget
) CMD
="apt-get";;
196 aptcache
) CMD
="apt-cache";;
197 aptcdrom
) CMD
="apt-cdrom";;
198 aptconfig
) CMD
="apt-config";;
199 aptmark
) CMD
="apt-mark";;
200 apthelper
) CMD
="apt-helper";;
201 aptftparchive
) CMD
="apt-ftparchive";;
202 dpkg
) shift; runapt
"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" "$@"; return;;
206 if [ "${CMD##*/}" = "$CMD" ]; then
207 CMD
="${BUILDDIRECTORY}/${CMD}"
209 runapt
command gdb
--quiet -ex run
"$CMD" --args "$CMD" "$@"
213 # error if we about to overflow, but ...
214 # "255 failures ought to be enough for everybody"
215 if [ $EXIT_CODE -gt 255 ]; then
216 msgdie
"Total failure count $EXIT_CODE too big"
218 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
221 shellsetedetector
() {
223 if [ "$exit_status" != '0' ]; then
224 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
225 if [ "$EXIT_CODE" = '0' ]; then
226 EXIT_CODE
="$exit_status"
232 if [ "$1" = 'prefix' ]; then
233 CURRENTTRAP
="$2 $CURRENTTRAP"
235 CURRENTTRAP
="$CURRENTTRAP $1"
237 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
241 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
242 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
245 TMPWORKINGDIRECTORY
="$(mktemp -d)"
246 addtrap
"cd /; rm -rf \"$TMPWORKINGDIRECTORY\";"
247 msgninfo
"Preparing environment for ${0##*/} in ${TMPWORKINGDIRECTORY}…"
249 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
250 if [ "$(id -u)" = '0' ]; then
251 # relax permissions so that running as root with user switching works
253 chmod 711 "$TMPWORKINGDIRECTORY"
254 chown _apt
:root
"${TMPWORKINGDIRECTORY}/downloaded"
257 TESTDIRECTORY
="$(readlink -f "$(dirname $0)")"
258 # allow overriding the default BUILDDIR location
259 SOURCEDIRECTORY="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}"
260 BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}"
261 LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}"
262 METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}"
263 APTHELPERBINDIR="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}"
264 APTWEBSERVERBINDIR="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}"
265 APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}"
266 APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}"
267 test -x "${BUILDDIRECTORY}/apt
-get" || msgdie "You need to build tree first
"
270 cd "$TMPWORKINGDIRECTORY"
271 mkdir rootdir aptarchive keys
273 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
274 mkdir -p usr/bin var/cache var/lib var/log tmp
275 mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
276 touch var/lib/dpkg/available
278 ln -s "${METHODSDIR}" usr/lib/apt/methods
279 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
280 mkdir -p usr/lib/apt/solvers
281 ln -s "${BUILDDIRECTORY}/apt
-dump-solver" usr/lib/apt/solvers/dump
282 ln -s "${BUILDDIRECTORY}/apt
-internal-solver" usr/lib/apt/solvers/apt
283 echo "Dir
::Bin
::Solvers
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/solvers
\";" > etc/apt/apt.conf.d/externalsolver.conf
285 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
287 if [ -e "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" ]; then
288 ln -s "${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove
" etc/apt/apt.conf.d/01autoremove
290 ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
293 local BASENAME="${0##*/}"
294 local PACKAGESFILE="Packages
-${BASENAME#*-}"
295 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
296 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
298 local SOURCESSFILE="Sources
-${BASENAME#*-}"
299 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
300 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
302 for key in $(find "$TESTDIRECTORY" -name '*.pub' -o -name '*.sec'); do
306 ln -s "${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub
" rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
308 echo "Dir
\"${TMPWORKINGDIRECTORY}/rootdir
\";" > aptconfig.conf
309 echo "Dir
::state
::status
\"${TMPWORKINGDIRECTORY}/rootdir
/var
/lib
/dpkg
/status
\";" >> aptconfig.conf
310 echo "APT
::Get
::Show
-User-Simulation-Note \"false
\";" >> aptconfig.conf
311 echo "Dir
::Bin
::Methods
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/lib
/apt
/methods
\";" >> aptconfig.conf
312 # store apt-key were we can access it, even if we run it as a different user
313 # destroys coverage reporting though, so just do it for root for now
314 if [ "$(id -u)" = '0' ]; then
315 cp "${BUILDDIRECTORY}/apt
-key" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/"
316 chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key"
317 echo "Dir
::Bin
::apt
-key \"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/apt
-key\";" >> aptconfig.conf
319 echo "Dir
::Bin
::apt
-key \"${BUILDDIRECTORY}/apt
-key\";" >> aptconfig.conf
322 cat > "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
325 if [ -r "${TMPWORKINGDIRECTORY}/noopchroot.so
" ]; then
326 if [ -n "\
$LD_LIBRARY_PATH" ]; then
327 export LD_LIBRARY_PATH="${TMPWORKINGDIRECTORY}:${LD_LIBRARY_PATH}"
329 export LD_LIBRARY_PATH="${TMPWORKINGDIRECTORY}"
331 if [ -n "\
$LD_PRELOAD" ]; then
332 export LD_PRELOAD="noopchroot.so \
${LD_PRELOAD}"
334 export LD_PRELOAD="noopchroot.so
"
338 cp "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
339 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" <<EOF
340 exec fakeroot "${DPKG:-dpkg}" --root="${TMPWORKINGDIRECTORY}/rootdir
" \\
341 --log="${TMPWORKINGDIRECTORY}/rootdir
/var
/log
/dpkg.log
" \\
342 --force-not-root --force-bad-path "\$@
"
344 cat >> "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg" <<EOF
345 exec fakeroot gdb --quiet -ex run "${DPKG:-dpkg}" --args "${DPKG:-dpkg}" --root="${TMPWORKINGDIRECTORY}/rootdir
" \\
346 --log="${TMPWORKINGDIRECTORY}/rootdir
/var
/log
/dpkg.log
" \\
347 --force-not-root --force-bad-path "\$@
"
349 chmod +x "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
" "${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/gdb
-dpkg"
350 echo "Dir
::Bin
::dpkg
\"${TMPWORKINGDIRECTORY}/rootdir
/usr
/bin
/dpkg
\";" > rootdir/etc/apt/apt.conf.d/99dpkg
353 if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
354 echo "DPKG
::options
:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
356 echo 'quiet::NoUpdate "true
";'
357 echo 'quiet::NoStatistic "true
";'
358 # too distracting for users, but helpful to detect changes
359 echo 'Acquire::Progress::Ignore::ShowErrorText "true
";'
360 echo 'Acquire::Progress::Diffpercent "true
";'
361 # in testcases, it can appear as if localhost has a rotation setup,
362 # hide this as we can't really deal with it properly
363 echo 'Acquire::Failure::ShowIP "false
";'
366 cp "${TESTDIRECTORY}/apt.pem
" "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
367 if [ "$(id -u)" = '0' ]; then
368 chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
"
370 echo "Acquire
::https
::CaInfo
\"${TMPWORKINGDIRECTORY}/rootdir
/etc
/webserver.pem
\";" > rootdir/etc/apt/apt.conf.d/99https
371 echo "Apt
::Cmd
::Disable
-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
372 configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
373 confighashes 'SHA1' # these are tests, not security best-practices
375 # create some files in /tmp and look at user/group to get what this means
376 TEST_DEFAULT_USER="$USER"
377 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
378 TEST_DEFAULT_GROUP='root'
380 TEST_DEFAULT_GROUP="$USER"
383 # Acquire::AllowInsecureRepositories=false is not yet the default
384 # but we want it to be the default soon
385 configallowinsecurerepositories "false
";
387 # cleanup the environment a bit
388 # prefer our apt binaries over the system apt binaries
389 export PATH="${BUILDDIRECTORY}:${PATH}:/usr
/local
/sbin
:/usr
/sbin
:/sbin
"
390 export LC_ALL=C.UTF-8
391 unset LANGUAGE APT_CONFIG
392 unset GREP_OPTIONS DEB_BUILD_PROFILES
397 if [ "$1" = "native
" -o -z "$1" ]; then
398 eval `aptconfig shell ARCH APT::Architecture`
399 if [ -n "$ARCH" ]; then
402 dpkg --print-architecture
410 aptconfig dump --no-empty --format '%v%n' APT::Architecture APT::Architectures | sort -u | tr '\n' ' '
413 getarchitecturesfromcommalist() {
414 echo "$1" | sed -e 's#,#\n#g' | sed -e "s
/^native\$
/$(getarchitecture 'native')/"
417 configarchitecture() {
419 echo "APT
::Architecture
\"$(getarchitecture $1)\";"
420 while [ -n "$1" ]; do
421 echo "APT
::Architectures
:: \"$(getarchitecture $1)\";"
424 } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
429 if [ ! -e rootdir/var/lib/dpkg/status ]; then
430 local BASENAME="${0##*/}"
431 local STATUSFILE="status
-${BASENAME#*-}"
432 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
433 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
435 echo -n > rootdir/var/lib/dpkg/status
438 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
439 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
440 local ARCHS="$(getarchitectures)"
441 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
442 DPKGARCH="$(dpkg --print-architecture)"
443 for ARCH in ${ARCHS}; do
444 if [ "${ARCH}" != "${DPKGARCH}" ]; then
445 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
446 # old-style used e.g. in Ubuntu-P – and as it seems travis
447 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
448 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
452 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
453 # dpkg doesn't really check the version as long as it is fully installed,
454 # but just to be sure we choose one above the required version
455 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
461 configdpkgnoopchroot() {
462 # create a library to noop chroot() and rewrite maintainer script executions
463 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
464 # chroot directory dpkg could chroot into to execute the maintainer scripts
465 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
466 cat > noopchroot.c << EOF
473 static char * chrootdir = NULL;
475 int chroot(const char *path) {
476 printf("WARNING
: CHROOTing to
%s was ignored
!\n", path);
478 chrootdir = strdup(path);
481 int execvp(const char *file, char *const argv[]) {
482 static int (*func_execvp) (const char *, char * const []) = NULL;
483 if (func_execvp == NULL)
484 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp
");
485 if (chrootdir == NULL || strncmp(file, "/var
/lib
/dpkg
/", strlen("/var
/lib
/dpkg
/")) != 0)
486 return func_execvp(file, argv);
487 printf("REWRITE execvp call
%s into
%s
\n", file, chrootdir);
488 char newfile[strlen(chrootdir) + strlen(file)];
489 strcpy(newfile, chrootdir);
490 strcat(newfile, file);
491 char const * const baseadmindir = "/var
/lib
/dpkg
";
492 char admindir[strlen(chrootdir) + strlen(baseadmindir)];
493 strcpy(admindir, chrootdir);
494 strcat(admindir, baseadmindir);
495 setenv("DPKG_ADMINDIR
", admindir, 1);
496 return func_execvp(newfile, argv);
499 testsuccess --nomsg gcc -fPIC -shared -o noopchroot.so noopchroot.c -ldl
502 configallowinsecurerepositories() {
503 echo "Acquire
::AllowInsecureRepositories
\"$1\";" > rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf
507 configcompression() {
508 while [ -n "$1" ]; do
510 '.') printf ".
\t.
\tcat
\n";;
511 'gz') printf "gzip\tgz
\tgzip
\n";;
512 'bz2') printf "bzip2\tbz
2\tbzip
2\n";;
513 'lzma') printf "lzma
\tlzma
\txz
--format=lzma
\n";;
514 'xz') printf "xz
\txz
\txz
\n";;
515 *) printf "$1\t$1\t$1\n";;
518 done > "${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
"
522 echo 'APT::FTPArchive {'
524 while [ -n "$1" ]; do
525 printf "$1" | tr 'a-z' 'A-Z'
526 printf "\t\"true
\";\n"
529 for h in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do
530 printf "$h\t\"false
\";\n"
534 } >> "${TMPWORKINGDIRECTORY}/rootdir
/etc
/apt
/apt.conf.d
/ftparchive
-hashes.conf
"
540 gzip) COMPRESS='gz';;
541 bzip2) COMPRESS='bz2';;
542 lzma) COMPRESS='lzma';;
544 *) msgdie "Compressor
$COMPRESSOR is unknown to framework
, so can
't be forced by forcecompressor!";;
546 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
547 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
548 Dir::Bin::uncompressed \"/does/not/exist\";
549 Dir::Bin::gzip \"/does/not/exist\";
550 Dir::Bin::bzip2 \"/does/not/exist\";
551 Dir::Bin::lzma \"/does/not/exist\";
552 Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
553 if [ -e "/bin/${COMPRESSOR}" ]; then
554 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
555 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
556 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
557 elif [ "${COMPRESSOR}" = 'lzma
' ]; then
558 echo 'Dir
::Bin
::xz
"/usr/bin/xz";' >> "$CONFFILE"
559 COMPRESSOR_CMD='xz
--format=lzma
'
561 msgtest 'Test
for availability of compressor
' "${COMPRESSOR}"
562 msgfail "${COMPRESSOR} not available"
566 setupsimplenativepackage() {
570 local RELEASE="${4:-unstable}"
571 local DEPENDENCIES="$5"
572 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
573 If you find such a package installed on your system,
574 something went horribly wrong! They are autogenerated
575 und used only by testcases and surf no other propose…"}"
577 local SECTION="${7:-others}"
579 if [ "$SECTION" = "${SECTION#*/}" ]; then
582 DISTSECTION="${SECTION%/*}"
584 local BUILDDIR=incoming/${NAME}-${VERSION}
585 mkdir -p ${BUILDDIR}/debian/source
587 echo "* most suckless software product ever" > FEATURES
588 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
589 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
593 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
594 test -e debian/control || echo "Source: $NAME
597 Maintainer: Joe Sixpack <joe@example.org>
598 Build-Depends: debhelper (>= 7)
599 Standards-Version: 3.9.1
601 Package: $NAME" > debian/control
602 if [ "$ARCH" = 'all
' ]; then
603 echo "Architecture: all" >> debian/control
605 echo "Architecture: any" >> debian/control
607 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
608 echo "Description: $DESCRIPTION" >> debian/control
610 test -e debian/compat || echo "7" > debian/compat
611 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
612 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
616 buildsimplenativepackage() {
619 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib
' ]; then
620 NM="$(echo "$NAME" | cut -c 1-4)"
622 NM="$(echo "$NAME" | cut -c 1)"
626 local RELEASE="${4:-unstable}"
627 local DEPENDENCIES="$5"
628 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
629 If you find such a package installed on your system,
630 something went horribly wrong! They are autogenerated
631 und used only by testcases and surf no other propose…"}"
633 local SECTION="${7:-others}"
634 local PRIORITY="${8:-optional}"
636 local COMPRESS_TYPE="${10:-gzip}"
638 if [ "$SECTION" = "${SECTION#*/}" ]; then
641 DISTSECTION="${SECTION%/*}"
643 local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
645 msgtest "Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
646 mkdir -p "$BUILDDIR/debian/source"
647 echo "* most suckless software product ever" > "${BUILDDIR}/FEATURES"
649 echo '$NAME says
\"Hello
!\"'" > "${BUILDDIR}/${NAME}"
651 echo "Copyleft by Joe Sixpack $(date +%Y)" > "${BUILDDIR}/debian/copyright"
652 echo "$NAME ($VERSION) $RELEASE; urgency=low
656 -- Joe Sixpack <joe@example.org> $(date -R)" > "${BUILDDIR}/debian/changelog"
660 Maintainer: Joe Sixpack <joe@example.org>
661 Standards-Version: 3.9.3"
662 if [ "$SECTION" != '<none
>' ]; then
663 echo "Section: $SECTION"
665 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
666 test -z "$BUILDDEPS" || echo "$BUILDDEPS"
670 if [ "$ARCH" = 'all
' ]; then
671 echo "Architecture: all"
673 echo "Architecture: any"
675 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
676 test -z "$DEPS" || echo "$DEPS"
677 echo "Description: $DESCRIPTION"
678 } > "${BUILDDIR}/debian/control"
680 echo '3.0 (native
)' > "${BUILDDIR}/debian/source/format"
682 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
684 sed -n 's
#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" \
686 echo "pool/${SRC}" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist"
687 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
688 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
689 # adv --yes --default-key 'Joe Sixpack' \
690 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
691 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
695 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
696 msgtest
"Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
697 rm -rf "${BUILDDIR}/debian/tmp"
698 mkdir -p "${BUILDDIR}/debian/tmp/DEBIAN" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin"
699 cp "${BUILDDIR}/debian/copyright" "${BUILDDIR}/debian/changelog" "${BUILDDIR}/FEATURES" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}"
700 cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}"
701 if [ -n "$FILE_TREE" ]; then
702 cp -ar "$FILE_TREE" "${BUILDDIR}/debian/tmp"
705 (cd "${BUILDDIR}"; dpkg
-gencontrol -DArchitecture=$arch)
706 (cd "${BUILDDIR}/debian/tmp"; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
707 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
708 # ensure the right permissions as dpkg-deb insists
709 chmod 755 "${BUILDDIR}/debian/tmp/DEBIAN"
710 testsuccess
--nomsg dpkg
-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian/tmp" "${BUILDDIR}/.."
711 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist"
714 local CHANGEPATH
="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}"
715 mkdir -p "$CHANGEPATH"
716 cp "${BUILDDIR}/debian/changelog" "$CHANGEPATH"
725 local ARCH
=$(getarchitecture $4)
726 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
727 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
728 msgtest
"Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
730 if [ "$ARCH" = "all" ]; then
731 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
733 testsuccess
--nomsg dpkg
-buildpackage -uc -us -a$ARCH
734 cp "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$BUILDLOG"
735 local PKGS
="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")"
736 local SRCS
="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')"
739 echo "pool/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist"
742 echo "pool/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist"
747 if [ -d incoming
]; then
748 buildaptarchivefromincoming
"$@"
750 buildaptarchivefromfiles
"$@"
754 createaptftparchiveconfig
() {
755 local COMPRESSORS
="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')"
756 local COMPRESSORS
="${COMPRESSORS%* }"
757 local ARCHS
="$(getarchitectures)"
758 cat > ftparchive.conf
<<EOF
760 ArchiveDir "$(readlink -f .)";
761 CacheDir "$(readlink -f ..)";
762 FileListDir "$(readlink -f pool/)";
765 Packages::Compress "$COMPRESSORS";
766 Sources::Compress "$COMPRESSORS";
767 Contents::Compress "$COMPRESSORS";
768 Translation::Compress "$COMPRESSORS";
769 LongDescription "false";
773 SrcDirectory "pool/";
776 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
779 Architectures "$ARCHS source";
780 FileList "${DIST}.\$(SECTION).pkglist";
781 SourceFileList "${DIST}.\$(SECTION).srclist";
782 Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
785 done >> ftparchive.conf
788 buildaptftparchivedirectorystructure
() {
789 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
790 for DIST
in $DISTS; do
791 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
792 for SECTION
in $SECTIONS; do
793 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
794 for ARCH
in $ARCHS; do
795 mkdir -p "dists/${DIST}/${SECTION}/binary-${ARCH}"
797 mkdir -p "dists/${DIST}/${SECTION}/source"
798 mkdir -p "dists/${DIST}/${SECTION}/i18n"
808 local DEPENDENCIES
="$5"
809 local PRIORITY
="${6:-optional}"
810 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
811 If you find such a package installed on your system,
812 something went horribly wrong! They are autogenerated
813 und used only by testcases and surf no other propose…"}"
815 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
816 if [ "$RELEASE" = 'installed' ]; then
817 insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
820 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
821 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
822 ARCHS="$(getarchitectures)"
826 for BUILDARCH in $ARCHS; do
827 local PPATH="aptarchive
/dists
/${RELEASE}/main
/binary
-${BUILDARCH}"
834 Maintainer
: Joe Sixpack
<joe@example.org
>"
835 test "$arch" = 'none' || echo "Architecture
: $arch"
836 echo "Version
: $VERSION
837 Filename
: pool
/main
/${NAME}/${NAME}_
${VERSION}_
${arch}.deb
"
838 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES"
839 echo "Description
: $(printf '%s' "$DESCRIPTION" | head -n 1)"
840 echo "Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)"
842 } >> "${PPATH}/Packages
"
845 mkdir -p "aptarchive
/dists
/${RELEASE}/main
/source" "aptarchive
/dists
/${RELEASE}/main
/i18n
"
846 touch "aptarchive
/dists
/${RELEASE}/main
/source
/Sources
"
848 Description
-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
849 Description
-en: $DESCRIPTION
850 " >> "aptarchive
/dists
/${RELEASE}/main
/i
18n
/Translation
-en"
859 local DEPENDENCIES="$5"
860 local BINARY="${6:-$NAME}"
862 local SPATH="aptarchive
/dists
/${RELEASE}/main
/source"
864 local FILE="${SPATH}/Sources
"
865 local DSCFILE="${NAME}_
${VERSION}.dsc
"
866 local TARFILE="${NAME}_
${VERSION}.
tar.gz
"
870 Maintainer
: Joe Sixpack
<joe@example.org
>
871 Architecture
: $ARCH" >> $FILE
872 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
874 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
875 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
877 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
878 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
882 insertinstalledpackage() {
886 local DEPENDENCIES="$4"
887 local PRIORITY="${5:-optional}"
888 local STATUS="${6:-install ok installed}"
889 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
890 If you
find such a package installed on your system
,
891 something went horribly wrong
! They are autogenerated
892 und used only by testcases and surf no other propose…
"}"
894 local FILE
='rootdir/var/lib/dpkg/status'
895 local INFO
='rootdir/var/lib/dpkg/info'
896 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
902 Maintainer: Joe Sixpack <joe@example.org>
903 Version: $VERSION" >> "$FILE"
904 test "$arch" = 'none' || echo "Architecture: $arch" >> "$FILE"
905 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
906 echo "Description: $DESCRIPTION" >> "$FILE"
908 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
909 echo -n > "${INFO}/${NAME}:${arch}.list"
911 echo -n > "${INFO}/${NAME}.list"
917 buildaptarchivefromincoming
() {
918 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on incoming packages…"
920 [ -e pool
] || ln -s ..
/incoming pool
921 [ -e ftparchive.conf
] || createaptftparchiveconfig
922 [ -e dists
] || buildaptftparchivedirectorystructure
923 msgninfo
"\tGenerate Packages, Sources and Contents files… "
924 testsuccess aptftparchive generate ftparchive.conf
927 generatereleasefiles
"$@"
930 buildaptarchivefromfiles
() {
931 msginfo
"Build APT archive for ${CCMD}${0##*/}${CINFO} based on prebuild files…"
932 local DIR
='aptarchive'
933 if [ -d "${DIR}/dists" ]; then DIR
="${DIR}/dists"; fi
934 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line
; do
935 msgninfo
"\t${line} file… "
936 compressfile
"$line" "$1"
939 generatereleasefiles
"$@"
943 cat "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | while read compressor extension
command; do
944 if [ "$compressor" = '.' ]; then
950 cat "$1" | $command > "${1}.${extension}"
952 touch -d "$2" "${1}.${extension}"
957 # can be overridden by testcases for their pleasure
958 getcodenamefromsuite
() {
960 unstable
) echo 'sid';;
964 getreleaseversionfromsuite
() { true
; }
965 getlabelfromsuite
() { true
; }
966 getoriginfromsuite
() { true
; }
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
974 msgninfo
"\tGenerate Release files… "
975 if [ -e aptarchive
/dists
]; then
976 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
977 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
978 local CODENAME
="$(getcodenamefromsuite $SUITE)"
979 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
980 local LABEL
="$(getlabelfromsuite $SUITE)"
981 local ORIGIN
="$(getoriginfromsuite $SUITE)"
982 if [ -n "$VERSION" ]; then
983 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
985 if [ -n "$LABEL" ]; then
986 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
988 if [ -n "$ORIGIN" ]; then
989 ORIGIN
="-o APT::FTPArchive::Release::Origin=${ORIGIN}"
991 aptftparchiverelease
"$dir" \
992 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
993 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
998 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
1000 NotAutomatic: yes' "$dir/Release"
1004 aptftparchiverelease .
/aptarchive
> aptarchive
/Release
1006 if [ -n "$1" -a "$1" != "now" ]; then
1007 for release
in $(find ./aptarchive -name 'Release'); do
1008 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" "$release"
1009 touch -d "$1" "$release"
1012 if [ -n "$2" ]; then
1013 sed -i "/^Date: / a\
1014 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release')
1019 setupdistsaptarchive
() {
1020 local APTARCHIVE
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1021 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
1022 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
1023 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1024 SECTIONS
=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1025 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
1026 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list"
1027 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list"
1032 setupflataptarchive
() {
1033 local APTARCHIVE
="$(readlink -f ./aptarchive)"
1034 local APTARCHIVEURI
="$(readlink -f ./aptarchive | sed 's# #%20#g')"
1035 if [ -f "${APTARCHIVE}/Packages" ]; then
1036 msgninfo
"\tadd deb sources.list line… "
1037 echo "deb file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1040 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list'
1042 if [ -f "${APTARCHIVE}/Sources" ]; then
1043 msgninfo
"\tadd deb-src sources.list line… "
1044 echo "deb-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1047 rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list'
1053 if [ "$1" = '--no-update' ]; then
1057 buildaptarchive
"$@"
1058 if [ -e aptarchive
/dists
]; then
1059 setupdistsaptarchive
1063 signreleasefiles
'Joe Sixpack'
1064 if [ "1" != "$NOUPDATE" ]; then
1065 testsuccess aptget update
-o Debug
::pkgAcquire
::Worker
=true
-o Debug
::Acquire
::gpgv
=true
1069 signreleasefiles
() {
1070 local SIGNER
="${1:-Joe Sixpack}"
1071 local REPODIR
="${2:-aptarchive}"
1072 local KEY
="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
1073 local GPG
="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
1074 msgninfo
"\tSign archive with $SIGNER key $KEY… "
1075 local REXKEY
='keys/rexexpired'
1076 local SECEXPIREBAK
="${REXKEY}.sec.bak"
1077 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
1078 if [ "${SIGNER}" = 'Rex Expired' ]; then
1079 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1080 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1081 # therefore we 'temporary' make the key not expired and restore a backup after signing
1082 cp "${REXKEY}.sec" "$SECEXPIREBAK"
1083 cp "${REXKEY}.pub" "$PUBEXPIREBAK"
1084 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
1085 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
1086 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1087 cp "$SECUNEXPIRED" "${REXKEY}.sec"
1088 cp "$PUBUNEXPIRED" "${REXKEY}.pub"
1090 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg
2>&1; then
1094 cp "${REXKEY}.sec" "$SECUNEXPIRED"
1095 cp "${REXKEY}.pub" "$PUBUNEXPIRED"
1098 for RELEASE
in $(find "${REPODIR}/" -name Release); do
1099 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output "${RELEASE}.gpg" "${RELEASE}"
1100 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
1101 $GPG --default-key "$SIGNER" --clearsign --output "$INRELEASE" "$RELEASE"
1102 # we might have set a specific date for the Release file, so copy it
1103 touch -d "$(stat --format "%y" ${RELEASE})" "${RELEASE}.gpg" "${INRELEASE}"
1105 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1106 mv -f "$SECEXPIREBAK" "${REXKEY}.sec"
1107 mv -f "$PUBEXPIREBAK" "${REXKEY}.pub"
1112 redatereleasefiles
() {
1113 local DATE
="$(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
1114 for release
in $(find aptarchive/ -name 'Release'); do
1115 sed -i "s/^Date: .*$/Date: ${DATE}/" "$release"
1116 touch -d "$DATE" "$release"
1118 signreleasefiles
"${2:-Joe Sixpack}"
1122 local WEBSERVER
="${3:-http://localhost:${APTHTTPPORT}}"
1124 if [ "$1" = '--no-check' ]; then
1128 local DOWNLOG
='rootdir/tmp/download-testfile.log'
1129 local STATUS
='downloaded/webserverconfig.status'
1130 rm -f "$STATUS" "$DOWNLOG"
1131 # very very basic URI encoding
1133 if [ -n "$2" ]; then
1134 msgtest
"Set webserver config option '${1}' to" "$2"
1135 URI
="${WEBSERVER}/_config/set/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
1137 msgtest
'Clear webserver config option' "${1}"
1138 URI
="${WEBSERVER}/_config/clear/$(echo "${1}" | sed -e 's/\//%2f/g')"
1140 if downloadfile
"$URI" "$STATUS" > "$DOWNLOG"; then
1143 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.output"
1144 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1145 msgfailoutput
'' "$OUTPUT"
1147 $NOCHECK || testwebserverlaststatuscode
'200'
1150 rewritesourceslist
() {
1151 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
1152 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1153 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:${APTHTTPPORT}/#${1}#" -e "s#https://localhost:${APTHTTPSPORT}/#${1}#"
1157 # wait for up to 10s for a pid file to appear to avoid possible race
1158 # when a helper is started and dosn't write the PID quick enough
1161 for i
in $(seq 10); do
1162 if test -s "$PIDFILE"; then
1167 msgdie
"waiting for $PIDFILE failed"
1171 changetowebserver
() {
1173 if [ "$1" != '--no-rewrite' ]; then
1178 if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
1180 local LOG
="webserver.log"
1181 if ! aptwebserver
--port 0 -o aptwebserver
::fork
=1 -o aptwebserver
::portfile
='aptwebserver.port' "$@" >$LOG 2>&1 ; then
1185 waitforpidfile aptwebserver.pid
1186 local PID
="$(cat aptwebserver.pid)"
1187 if [ -z "$PID" ]; then
1188 msgdie
'Could not fork aptwebserver successfully'
1190 addtrap
"kill $PID;"
1191 waitforpidfile aptwebserver.port
1192 APTHTTPPORT
="$(cat aptwebserver.port)"
1193 if [ -z "$APTHTTPPORT" ]; then
1194 msgdie
'Could not get port for aptwebserver successfully'
1198 msgdie
'You have to build aptwerbserver or install a webserver'
1200 if [ "$REWRTE" != 'yes' ]; then
1201 rewritesourceslist
"http://localhost:${APTHTTPPORT}/"
1205 changetohttpswebserver
() {
1206 if ! which stunnel4
>/dev
/null
; then
1207 msgdie
'You need to install stunnel4 for https testcases'
1209 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1210 changetowebserver
--no-rewrite "$@"
1212 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1213 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1218 connect = $APTHTTPPORT
1219 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
1220 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
1221 waitforpidfile
"${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1222 local PID
="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
1223 if [ -z "$PID" ]; then
1224 msgdie
'Could not fork stunnel4 successfully'
1226 addtrap
'prefix' "kill ${PID};"
1227 APTHTTPSPORT
="$(lsof -i | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
1228 webserverconfig
'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
1229 rewritesourceslist
"https://localhost:${APTHTTPSPORT}/"
1233 mkdir -p rootdir
/media
/cdrom
/.disk
1234 local CD
="$(readlink -f rootdir/media/cdrom)"
1235 cat > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
<<EOF
1236 acquire::cdrom::mount "${CD}";
1237 acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}";
1238 acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted";
1239 acquire::cdrom::autodetect 0;
1241 echo -n "$1" > "${CD}/.disk/info"
1242 if [ ! -d aptarchive
/dists
]; then
1243 msgdie
'Flat file archive cdroms can not be created currently'
1246 mv aptarchive
/dists
"$CD"
1247 ln -s "$(readlink -f ./incoming)" "$CD/pool"
1248 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
1249 # start with an unmounted disk
1250 mv "${CD}" "${CD}-unmounted"
1251 # we don't want the disk to be modifiable
1252 addtrap
'prefix' "chmod -f -R +w \"$PWD/rootdir/media/cdrom/dists/\" \"$PWD/rootdir/media/cdrom-unmounted/dists/\" || true;"
1253 chmod -R 555 rootdir
/media
/cdrom
-unmounted/dists
1257 local PROTO
="${1%%:*}"
1258 if ! apthelper
-o Debug
::Acquire
::${PROTO}=1 -o Debug
::pkgAcquire
::Worker
=1 \
1259 download
-file "$1" "$2" "$3" 2>&1 ; then
1262 # only if the file exists the download was successful
1263 if [ -r "$2" ]; then
1271 local DIFFTEXT
="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1272 if [ -n "$DIFFTEXT" ]; then
1274 echo >&2 "$DIFFTEXT"
1282 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
1283 local COMPAREFILE
="$1"
1285 if "$@" 2>&1 | checkdiff
"$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1288 echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
1289 cat "$COMPAREFILE" >>"${OUTPUT}"
1290 msgfailoutput
'' "$OUTPUT" "$@"
1295 msggroup
'testfileequal'
1296 local MSG
='Test for correctness of file'
1297 if [ "$1" = '--nomsg' ]; then
1303 if [ -n "$MSG" ]; then
1304 msgtest
"$MSG" "$FILE"
1306 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
1307 if [ -z "$*" ]; then
1308 testoutputequal
"$FILE" echo -n ''
1310 testoutputequal
"$FILE" echo "$*"
1316 msggroup
'testempty'
1317 msgtest
"Test for no output of" "$*"
1318 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1319 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test ! -s "$COMPAREFILE"; then
1322 msgfailoutput
'' "$COMPAREFILE" "$@"
1324 aptautotest
'testempty' "$@"
1328 msggroup
'testnotempty'
1329 msgtest
"Test for some output of" "$*"
1330 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile"
1331 if ("$@" >"$COMPAREFILE" 2>&1 || true
) && test -s "$COMPAREFILE"; then
1334 msgfailoutput
'' "$COMPAREFILE" "$@"
1336 aptautotest
'testnotempty' "$@"
1341 msggroup
'testequal'
1342 local MSG
='Test of equality of'
1343 if [ "$1" = '--nomsg' ]; then
1348 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1349 echo "$1" > "$COMPAREFILE"
1352 if [ -n "$MSG" ]; then
1355 testoutputequal
"$COMPAREFILE" "$@"
1356 aptautotest
'testequal' "$@"
1361 msggroup
'testequalor2'
1362 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1363 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1364 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1365 echo "$1" > "$COMPAREFILE1"
1366 echo "$2" > "$COMPAREFILE2"
1368 msgtest
"Test for equality OR of" "$*"
1369 "$@" >"$COMPAREAGAINST" 2>&1 || true
1370 if checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >/dev
/null
2>&1 || \
1371 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >/dev
/null
2>&1
1375 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1376 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1377 checkdiff
"$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1378 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1379 checkdiff
"$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1380 msgfailoutput
'' "$OUTPUT"
1382 aptautotest
'testequalor2' "$@"
1387 msggroup
'testshowvirtual'
1388 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1391 while [ -n "$1" ]; do
1393 N: Can't select versions from package '$1' as it is purely virtual"
1394 PACKAGE
="${PACKAGE} $1"
1397 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1399 N: No packages found"
1400 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1401 local ARCH
="$(getarchitecture 'native')"
1402 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1403 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1404 testoutputequal
"$COMPAREFILE" aptcache show
-q=0 "$PACKAGE"
1409 msggroup
'testnopackage'
1410 msgtest
"Test for non-existent packages" "apt-cache show $*"
1411 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1412 if [ -n "$SHOWPKG" ]; then
1413 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1414 echo "$SHOWPKG" >"$OUTPUT"
1415 msgfailoutput
'' "$OUTPUT"
1423 msggroup
'testdpkgstatus'
1427 msgtest
"Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1428 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1429 if [ "$PKGS" != $NR ]; then
1430 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1431 echo "$PKGS" >"$OUTPUT"
1432 dpkg
-l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1433 msgfailoutput
'' "$OUTPUT"
1440 testdpkginstalled
() {
1441 msggroup
'testdpkginstalled'
1442 testdpkgstatus
'ii' "$#" "$@"
1446 testdpkgnotinstalled
() {
1447 msggroup
'testdpkgnotinstalled'
1448 testdpkgstatus
'ii' '0' "$@"
1453 msggroup
'testmarkedauto'
1454 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1455 if [ -n "$1" ]; then
1456 msgtest
'Test for correctly marked as auto-installed' "$*"
1457 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1459 msgtest
'Test for correctly marked as auto-installed' 'no package'
1460 echo -n > "$COMPAREFILE"
1462 testoutputequal
"$COMPAREFILE" aptmark showauto
1465 testmarkedmanual
() {
1466 msggroup
'testmarkedmanual'
1467 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1468 if [ -n "$1" ]; then
1469 msgtest
'Test for correctly marked as manually installed' "$*"
1470 while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE"
1472 msgtest
'Test for correctly marked as manually installed' 'no package'
1473 echo -n > "$COMPAREFILE"
1475 testoutputequal
"$COMPAREFILE" aptmark showmanual
1480 msgreportheader
'msgfailoutput'
1484 if [ "$1" = 'grep' ]; then
1486 while [ -n "$2" ]; do shift; done
1487 echo "#### Complete file: $1 ####"
1488 cat >&2 "$1" || true
1489 echo '#### grep output ####'
1490 elif [ "$1" = 'test' ]; then
1492 # doesn't support ! or non-file flags
1493 msgfailoutputstatfile
() {
1494 local FILEFLAGS
='^-[bcdefgGhkLOprsStuwx]$'
1495 if expr match
"$1" "$FILEFLAGS" >/dev
/null
; then
1496 echo "#### stat(2) of file: $2 ####"
1498 if test -e "$2"; then
1499 echo "#### Complete file: $2 ####"
1500 cat >&2 "$2" || true
1504 msgfailoutputstatfile
"$2" "$3"
1505 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1507 msgfailoutputstatfile
"$2" "$3"
1509 echo '#### test output ####'
1516 msggroup
'testsuccess'
1517 if [ "$1" = '--nomsg' ]; then
1520 msgtest
'Test for successful execution of' "$*"
1522 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1523 if "$@" >"${OUTPUT}" 2>&1; then
1524 if expr match
"$1" '^apt.*' >/dev
/null
; then
1525 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1526 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1527 elif grep -E '^[WE]: ' "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1528 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1529 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1530 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev
/null
2>&1; then
1533 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1536 msgfailoutput
'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1546 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1548 aptautotest
'testsuccess' "$@"
1552 msggroup
'testwarning'
1553 if [ "$1" = '--nomsg' ]; then
1556 msgtest
'Test for successful execution with warnings of' "$*"
1558 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1559 if "$@" >"${OUTPUT}" 2>&1; then
1560 if expr match
"$1" '^apt.*' >/dev
/null
; then
1561 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1562 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1563 elif grep -q -E '^E: ' "$OUTPUT"; then
1564 msgfailoutput
'successful run, but output contains errors' "$OUTPUT" "$@"
1565 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1566 msgfailoutput
'successful run, but output contains no warnings' "$OUTPUT" "$@"
1575 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1577 aptautotest
'testwarning' "$@"
1581 msggroup
'testfailure'
1582 if [ "$1" = '--nomsg' ]; then
1585 msgtest
'Test for failure in execution of' "$*"
1587 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1588 if "$@" >"${OUTPUT}" 2>&1; then
1590 msgfailoutput
"exitcode $EXITCODE" "$OUTPUT" "$@"
1593 if expr match
"$1" '^apt.*' >/dev
/null
; then
1594 if [ "$1" = 'aptkey' ]; then
1595 if grep -q -E " Can't check signature: " "$OUTPUT" || \
1596 grep -q -E " BAD signature from " "$OUTPUT"; then
1599 msgfailoutput
"run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1602 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1603 msgfailoutput
'compiler detected undefined behavior' "$OUTPUT" "$@"
1604 elif grep -q -E '==ERROR' "$OUTPUT"; then
1605 msgfailoutput
'compiler sanitizers reported errors' "$OUTPUT" "$@"
1606 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1607 msgfailoutput
"run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1616 aptautotest
'testfailure' "$@"
1620 testreturnstateequal
() {
1622 msggroup
"${STATE}equal"
1623 if [ "$2" != '--nomsg' ]; then
1627 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1631 "$STATE" --nomsg "$@"
1632 testfileequal
"${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
1636 testsuccessequal
() {
1637 testreturnstateequal
'testsuccess' "$@"
1639 testwarningequal
() {
1640 testreturnstateequal
'testwarning' "$@"
1642 testfailureequal
() {
1643 testreturnstateequal
'testfailure' "$@"
1647 msggroup
'testfailuremsg'
1651 msgtest
'Check that the output of the previous failed command has expected' 'failures and warnings'
1652 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1653 grep '^\(W\|E\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1654 testoutputequal
"$COMPAREFILE" echo "$CMP"
1659 msggroup
'testfilestats'
1660 msgtest
"Test that file $1 has $2 $3" "$4"
1661 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1664 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1667 echo -n "stat(1) reports for $2: "
1668 stat
--format "$2" "$1" || true
1670 msgfailoutput
'' "$OUTPUT"
1674 testaccessrights
() {
1675 msggroup
'testaccessrights'
1676 testfilestats
"$1" '%a' '=' "$2"
1680 testwebserverlaststatuscode
() {
1681 msggroup
'testwebserverlaststatuscode'
1682 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1683 local STATUS
='downloaded/webserverstatus-statusfile.log'
1684 rm -f "$DOWNLOG" "$STATUS"
1685 msgtest
'Test last status code from the webserver was' "$1"
1686 if downloadfile
"http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1689 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1691 if [ -n "$2" ]; then
1693 echo >&2 '#### Additionally provided output files contain:'
1696 echo >&2 '#### Download log of the status code:'
1699 msgfailoutput
"Status was $(cat "$STATUS")" "$OUTPUT"
1705 echo "STOPPED execution. Press enter to continue"
1710 listcurrentlistsdirectory
() {
1712 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 -type d
| while read line
; do
1713 stat
--format '%U:%G:%a:%n' "$line"
1715 find rootdir
/var
/lib
/apt
/lists
-maxdepth 1 \
! -type d
| while read line
; do
1716 stat
--format '%U:%G:%a:%s:%y:%n' "$line"
1721 ### convenience hacks ###
1723 # creating some directories by hand is a tedious task, so make it look simple
1724 if [ "$*" = '-p rootdir/var/lib/apt/lists' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" ] ||
1725 [ "$*" = '-p rootdir/var/lib/apt/lists/partial' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" ]; then
1726 # only the last directory created by mkdir is effected by the -m !
1727 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1728 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1729 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1730 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1731 if [ "$(id -u)" = '0' ]; then
1732 chown _apt
:root
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1739 ### The following tests are run by most test methods automatically to check
1740 ### general things about commands executed without writing the test every time.
1746 local AUTOTEST
="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d '-')"
1747 if command -v $AUTOTEST >/dev
/null
; then
1749 # save and restore the *.output files from other tests
1750 # as we might otherwise override them in these automatic tests
1751 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1752 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before"
1753 mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1754 $AUTOTEST "$TESTCALL" "$@"
1755 rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1756 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest"
1757 mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp"
1761 aptautotest_aptget_update
() {
1763 while [ -n "$2" ]; do
1764 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1767 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1768 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1769 testfilestats
"${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1770 # all copied files are properly chmodded
1771 local backupIFS
="$IFS"
1772 IFS
="$(printf "\n\b")"
1773 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1774 testfilestats
"$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1777 if [ "$TESTCALL" = 'testsuccess' ]; then
1778 # failure cases can retain partial files and such
1779 testempty
find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \
( -name 'lock' -o -name '*.FAILED' \
)
1782 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; }
1783 aptautotest_aptcdrom_add
() { aptautotest_aptget_update
"$@"; }
1785 testaptautotestnodpkgwarning
() {
1787 while [ -n "$2" ]; do
1788 if expr match
"$2" '^-[a-z]*s' >/dev
/null
2>&1; then return; fi # simulation mode
1789 if expr match
"$2" '^-dy\?' >/dev
/null
2>&1; then return; fi # download-only mode
1792 testfailure
grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1795 aptautotest_aptget_install
() { testaptautotestnodpkgwarning
"$@"; }
1796 aptautotest_aptget_remove
() { testaptautotestnodpkgwarning
"$@"; }
1797 aptautotest_aptget_purge
() { testaptautotestnodpkgwarning
"$@"; }
1798 aptautotest_apt_install
() { testaptautotestnodpkgwarning
"$@"; }
1799 aptautotest_apt_remove
() { testaptautotestnodpkgwarning
"$@"; }
1800 aptautotest_apt_purge
() { testaptautotestnodpkgwarning
"$@"; }