]> git.saurik.com Git - apt.git/blob - test/integration/framework
condense parallel requests with the same hashes to one
[apt.git] / test / integration / framework
1 #!/bin/sh -- # no runable script, just for vi
2
3 EXIT_CODE=0
4
5 # we all like colorful messages
6 if [ "$MSGCOLOR" != 'NO' ] && [ "$MSGCOLOR" != 'ALWAYS' ]; then
7 if [ ! -t 1 ]; then # but check that we output to a terminal
8 export MSGCOLOR='NO'
9 fi
10 fi
11
12
13 if [ "$MSGCOLOR" != 'NO' ]; then
14 CERROR="\033[1;31m" # red
15 CWARNING="\033[1;33m" # yellow
16 CMSG="\033[1;32m" # green
17 CINFO="\033[1;96m" # light blue
18 CDEBUG="\033[1;94m" # blue
19 CNORMAL="\033[0;39m" # default system console color
20 CDONE="\033[1;32m" # green
21 CPASS="\033[1;32m" # green
22 CFAIL="\033[1;31m" # red
23 CCMD="\033[1;35m" # pink
24 fi
25
26 msgprintf() {
27 local START="$1"
28 local MIDDLE="$2"
29 local END="$3"
30 shift 3
31 if [ -n "$1" ]; then
32 printf "$START " "$1"
33 shift
34 while [ -n "$1" ]; do
35 printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghs]\)#apt-\1#')"
36 shift
37 done
38 fi
39 printf "${END}"
40 }
41 msgdie() { msgprintf "${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; }
42 msgwarn() { msgprintf "${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; }
43 msgmsg() { msgprintf "${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; }
44 msginfo() { msgprintf "${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; }
45 msgdebug() { msgprintf "${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; }
46 msgdone() { msgprintf "${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; }
47 msgnwarn() { msgprintf "${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; }
48 msgnmsg() { msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@"; }
49 msgninfo() { msgprintf "${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
50 msgndebug() { msgprintf "${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
51 msgtest() { msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
52 msgpass() { printf "${CPASS}PASS${CNORMAL}\n"; }
53 msgskip() {
54 if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
55 else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
56 }
57 msgfail() {
58 if [ $# -gt 0 ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
59 else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
60 if [ -n "$APT_DEBUG_TESTS" ]; then
61 $SHELL
62 fi
63 EXIT_CODE=$((EXIT_CODE+1));
64 }
65
66 # enable / disable Debugging
67 MSGLEVEL=${MSGLEVEL:-3}
68 if [ $MSGLEVEL -le 0 ]; then
69 msgdie() { true; }
70 fi
71 if [ $MSGLEVEL -le 1 ]; then
72 msgwarn() { true; }
73 msgnwarn() { true; }
74 fi
75 if [ $MSGLEVEL -le 2 ]; then
76 msgmsg() { true; }
77 msgnmsg() { true; }
78 msgtest() { true; }
79 msgpass() { printf " ${CPASS}P${CNORMAL}"; }
80 fi
81 if [ $MSGLEVEL -le 3 ]; then
82 msginfo() { true; }
83 msgninfo() { true; }
84 fi
85 if [ $MSGLEVEL -le 4 ]; then
86 msgdebug() { true; }
87 msgndebug() { true; }
88 fi
89 msgdone() {
90 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
91 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
92 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
93 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
94 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
95 true;
96 else
97 printf "${CDONE}DONE${CNORMAL}\n";
98 fi
99 }
100 getaptconfig() {
101 if [ -f ./aptconfig.conf ]; then
102 echo "./aptconfig.conf"
103 elif [ -f ../aptconfig.conf ]; then
104 echo "../aptconfig.conf"
105 fi
106 }
107 runapt() {
108 msgdebug "Executing: ${CCMD}$*${CDEBUG} "
109 local CMD="$1"
110 shift
111 case $CMD in
112 sh|aptitude|*/*|command) ;;
113 *) CMD="${BUILDDIRECTORY}/$CMD";;
114 esac
115 MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH=${LIBRARYPATH} $CMD "$@"
116 }
117 aptconfig() { runapt apt-config "$@"; }
118 aptcache() { runapt apt-cache "$@"; }
119 aptcdrom() { runapt apt-cdrom "$@"; }
120 aptget() { runapt apt-get "$@"; }
121 aptftparchive() { runapt apt-ftparchive "$@"; }
122 aptkey() { runapt apt-key "$@"; }
123 aptmark() { runapt apt-mark "$@"; }
124 aptsortpkgs() { runapt apt-sortpkgs "$@"; }
125 apt() { runapt apt "$@"; }
126 apthelper() { runapt "${APTHELPERBINDIR}/apt-helper" "$@"; }
127 aptwebserver() { runapt "${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
128 aptitude() { runapt aptitude "$@"; }
129 aptextracttemplates() { runapt apt-extracttemplates "$@"; }
130 aptinternalsolver() { runapt "${APTINTERNALSOLVER}" "$@"; }
131 aptdumpsolver() { runapt "${APTDUMPSOLVER}" "$@"; }
132
133 dpkg() {
134 "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@"
135 }
136 dpkgcheckbuilddeps() {
137 command dpkg-checkbuilddeps --admindir=${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg "$@"
138 }
139 gdb() {
140 local CMD
141 case "$1" in
142 aptget) CMD="apt-get";;
143 aptcache) CMD="apt-cache";;
144 aptmark) CMD="apt-mark";;
145 apthelper) CMD="apt-helper";;
146 *) CMD="$1";;
147 esac
148 shift
149 runapt command gdb --quiet -ex run "${BUILDDIRECTORY}/$CMD" --args "${BUILDDIRECTORY}/$CMD" "$@"
150 }
151
152 exitwithstatus() {
153 # error if we about to overflow, but ...
154 # "255 failures ought to be enough for everybody"
155 if [ $EXIT_CODE -gt 255 ]; then
156 msgdie "Total failure count $EXIT_CODE too big"
157 fi
158 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
159 }
160
161 shellsetedetector() {
162 local exit_status=$?
163 if [ "$exit_status" != '0' ]; then
164 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
165 if [ "$EXIT_CODE" = '0' ]; then
166 EXIT_CODE="$exit_status"
167 fi
168 fi
169 }
170
171 addtrap() {
172 if [ "$1" = 'prefix' ]; then
173 CURRENTTRAP="$2 $CURRENTTRAP"
174 else
175 CURRENTTRAP="$CURRENTTRAP $1"
176 fi
177 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
178 }
179
180 setupenvironment() {
181 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
182 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
183 unset TMPDIR
184 fi
185 TMPWORKINGDIRECTORY=$(mktemp -d)
186 addtrap "cd /; rm -rf $TMPWORKINGDIRECTORY;"
187 msgninfo "Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
188
189 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
190 if [ "$(id -u)" = '0' ]; then
191 # relax permissions so that running as root with user switching works
192 umask 022
193 chmod 711 "$TMPWORKINGDIRECTORY"
194 chown _apt:root "${TMPWORKINGDIRECTORY}/downloaded"
195 fi
196
197 TESTDIRECTORY=$(readlink -f $(dirname $0))
198 # allow overriding the default BUILDDIR location
199 SOURCEDIRECTORY=${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}
200 BUILDDIRECTORY=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
201 LIBRARYPATH=${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}
202 METHODSDIR=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
203 APTHELPERBINDIR=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}
204 APTWEBSERVERBINDIR=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
205 APTINTERNALSOLVER=${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}
206 APTDUMPSOLVER=${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}
207 test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
208 # -----
209
210 cd $TMPWORKINGDIRECTORY
211 mkdir rootdir aptarchive keys
212 cd rootdir
213 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
214 mkdir -p usr/bin var/cache var/lib var/log tmp
215 mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
216 touch var/lib/dpkg/available
217 mkdir -p usr/lib/apt
218 ln -s ${METHODSDIR} usr/lib/apt/methods
219 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
220 mkdir -p usr/lib/apt/solvers
221 ln -s "${BUILDDIRECTORY}/apt-dump-solver" usr/lib/apt/solvers/dump
222 ln -s "${BUILDDIRECTORY}/apt-internal-solver" usr/lib/apt/solvers/apt
223 echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" > etc/apt/apt.conf.d/externalsolver.conf
224 fi
225 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
226 # system
227 if [ -e ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove ]; then
228 ln -s ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove etc/apt/apt.conf.d/01autoremove
229 else
230 ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
231 fi
232 cd ..
233 local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
234 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
235 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
236 fi
237 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
238 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
239 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
240 fi
241 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys/
242 chmod 644 $(find keys -name '*.pub' -o -name '*.sec')
243 ln -s ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
244
245 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
246 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
247 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
248 echo "Dir::Bin::Methods \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/methods\";" >> aptconfig.conf
249 # store apt-key were we can access it, even if we run it as a different user
250 # destroys coverage reporting though, so just do it for root for now
251 if [ "$(id -u)" = '0' ]; then
252 cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
253 chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
254 echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
255 else
256 echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
257 fi
258
259 cat << EOF > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg"
260 #!/bin/sh
261 set -e
262 if [ -r "${TMPWORKINGDIRECTORY}/noopchroot.so" ]; then
263 if [ -n "\$LD_PRELOAD" ]; then
264 export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so \${LD_PRELOAD}"
265 else
266 export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so"
267 fi
268 fi
269 exec fakeroot dpkg --root="${TMPWORKINGDIRECTORY}/rootdir" \\
270 --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log \\
271 --force-not-root --force-bad-path "\$@"
272 EOF
273 chmod +x "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg"
274 echo "Dir::Bin::dpkg \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg\";" > rootdir/etc/apt/apt.conf.d/99dpkg
275
276 if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
277 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf # Added to test multiarch before dpkg is ready for it…
278 fi
279 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
280 echo 'quiet::NoStatistic "true";' >> aptconfig.conf
281 # too distracting for users, but helpful to detect changes
282 echo 'Acquire::Progress::Ignore::ShowErrorText "true";' >> aptconfig.conf
283 # in testcases, it can appear as if localhost has a rotation setup,
284 # hide this as we can't really deal with it properly
285 echo 'Acquire::Failure::ShowIP "false";' >> aptconfig.conf
286
287 cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
288 if [ "$(id -u)" = '0' ]; then
289 chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
290 fi
291 echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir/etc/apt/apt.conf.d/99https
292 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
293 configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
294
295 # create some files in /tmp and look at user/group to get what this means
296 TEST_DEFAULT_USER="$USER"
297 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
298 TEST_DEFAULT_GROUP='root'
299 else
300 TEST_DEFAULT_GROUP="$USER"
301 fi
302
303 # Acquire::AllowInsecureRepositories=false is not yet the default
304 # but we want it to be the default soon
305 configallowinsecurerepositories "false";
306
307 # cleanup the environment a bit
308 # prefer our apt binaries over the system apt binaries
309 export PATH="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
310 export LC_ALL=C.UTF-8
311 unset LANGUAGE APT_CONFIG
312 unset GREP_OPTIONS DEB_BUILD_PROFILES
313
314 msgdone "info"
315 }
316
317 getarchitecture() {
318 if [ "$1" = "native" -o -z "$1" ]; then
319 eval `aptconfig shell ARCH APT::Architecture`
320 if [ -n "$ARCH" ]; then
321 echo $ARCH
322 else
323 dpkg --print-architecture
324 fi
325 else
326 echo $1
327 fi
328 }
329
330 getarchitectures() {
331 aptconfig dump --no-empty --format '%v%n' APT::Architecture APT::Architectures | sort -u | tr '\n' ' '
332 }
333
334 getarchitecturesfromcommalist() {
335 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
336 }
337
338 configarchitecture() {
339 {
340 echo "APT::Architecture \"$(getarchitecture $1)\";"
341 while [ -n "$1" ]; do
342 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
343 shift
344 done
345 } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
346 configdpkg
347 }
348
349 configdpkg() {
350 if [ ! -e rootdir/var/lib/dpkg/status ]; then
351 local STATUSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
352 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
353 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
354 else
355 echo -n > rootdir/var/lib/dpkg/status
356 fi
357 fi
358 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
359 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
360 local ARCHS="$(getarchitectures)"
361 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
362 DPKGARCH="$(dpkg --print-architecture)"
363 for ARCH in ${ARCHS}; do
364 if [ "${ARCH}" != "${DPKGARCH}" ]; then
365 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
366 # old-style used e.g. in Ubuntu-P – and as it seems travis
367 echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
368 echo "DPKG::options:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
369 fi
370 fi
371 done
372 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
373 # dpkg doesn't really check the version as long as it is fully installed,
374 # but just to be sure we choose one above the required version
375 insertinstalledpackage 'dpkg' "all" '1.16.2+fake'
376 fi
377 fi
378 fi
379 }
380
381 configdpkgnoopchroot() {
382 # create a library to noop chroot() and rewrite maintainer script executions
383 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
384 # chroot directory dpkg could chroot into to execute the maintainer scripts
385 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
386 cat << EOF > noopchroot.c
387 #define _GNU_SOURCE
388 #include <stdio.h>
389 #include <stdlib.h>
390 #include <string.h>
391 #include <dlfcn.h>
392
393 static char * chrootdir = NULL;
394
395 int chroot(const char *path) {
396 printf("WARNING: CHROOTing to %s was ignored!\n", path);
397 free(chrootdir);
398 chrootdir = strdup(path);
399 return 0;
400 }
401 int execvp(const char *file, char *const argv[]) {
402 static int (*func_execvp) (const char *, char * const []) = NULL;
403 if (func_execvp == NULL)
404 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp");
405 if (chrootdir == NULL || strncmp(file, "/var/lib/dpkg/", strlen("/var/lib/dpkg/")) != 0)
406 return func_execvp(file, argv);
407 printf("REWRITE execvp call %s into %s\n", file, chrootdir);
408 char newfile[strlen(chrootdir) + strlen(file)];
409 strcpy(newfile, chrootdir);
410 strcat(newfile, file);
411 char const * const baseadmindir = "/var/lib/dpkg";
412 char admindir[strlen(chrootdir) + strlen(baseadmindir)];
413 strcpy(admindir, chrootdir);
414 strcat(admindir, baseadmindir);
415 setenv("DPKG_ADMINDIR", admindir, 1);
416 return func_execvp(newfile, argv);
417 }
418 EOF
419 testsuccess --nomsg gcc -fPIC -shared -o noopchroot.so noopchroot.c -ldl
420 }
421
422 configallowinsecurerepositories() {
423 echo "Acquire::AllowInsecureRepositories \"$1\";" > rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf
424
425 }
426
427 configcompression() {
428 while [ -n "$1" ]; do
429 case "$1" in
430 '.') printf ".\t.\tcat\n";;
431 'gz') printf "gzip\tgz\tgzip\n";;
432 'bz2') printf "bzip2\tbz2\tbzip2\n";;
433 'lzma') printf "lzma\tlzma\txz --format=lzma\n";;
434 'xz') printf "xz\txz\txz\n";;
435 *) printf "$1\t$1\t$1\n";;
436 esac
437 shift
438 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
439 }
440
441 forcecompressor() {
442 COMPRESSOR="$1"
443 COMPRESSOR_CMD="$1"
444 case $COMPRESSOR in
445 gzip) COMPRESS='gz';;
446 bzip2) COMPRESS='bz2';;
447 lzma) COMPRESS='lzma';;
448 xz) COMPRESS='xz';;
449 *) msgdie "Compressor $COMPRESSOR is unknown to framework, so can't be forced by forcecompressor!";;
450 esac
451 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
452 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
453 Dir::Bin::uncompressed \"/does/not/exist\";
454 Dir::Bin::gzip \"/does/not/exist\";
455 Dir::Bin::bzip2 \"/does/not/exist\";
456 Dir::Bin::lzma \"/does/not/exist\";
457 Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
458 if [ -e "/bin/${COMPRESSOR}" ]; then
459 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
460 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
461 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
462 elif [ "${COMPRESSOR}" = 'lzma' ]; then
463 echo 'Dir::Bin::xz "/usr/bin/xz";' >> "$CONFFILE"
464 COMPRESSOR_CMD='xz --format=lzma'
465 else
466 msgtest 'Test for availability of compressor' "${COMPRESSOR}"
467 msgfail
468 fi
469 }
470
471 setupsimplenativepackage() {
472 local NAME="$1"
473 local ARCH="$2"
474 local VERSION="$3"
475 local RELEASE="${4:-unstable}"
476 local DEPENDENCIES="$5"
477 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
478 If you find such a package installed on your system,
479 something went horribly wrong! They are autogenerated
480 und used only by testcases and surf no other propose…"}"
481
482 local SECTION="${7:-others}"
483 local DISTSECTION
484 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
485 DISTSECTION="main"
486 else
487 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
488 fi
489 local BUILDDIR=incoming/${NAME}-${VERSION}
490 mkdir -p ${BUILDDIR}/debian/source
491 cd ${BUILDDIR}
492 echo "* most suckless software product ever" > FEATURES
493 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
494 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
495
496 * Initial release
497
498 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
499 test -e debian/control || echo "Source: $NAME
500 Section: $SECTION
501 Priority: optional
502 Maintainer: Joe Sixpack <joe@example.org>
503 Build-Depends: debhelper (>= 7)
504 Standards-Version: 3.9.1
505
506 Package: $NAME" > debian/control
507 if [ "$ARCH" = 'all' ]; then
508 echo "Architecture: all" >> debian/control
509 else
510 echo "Architecture: any" >> debian/control
511 fi
512 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
513 echo "Description: $DESCRIPTION" >> debian/control
514
515 test -e debian/compat || echo "7" > debian/compat
516 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
517 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
518 cd - > /dev/null
519 }
520
521 buildsimplenativepackage() {
522 local NAME="$1"
523 local NM
524 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then
525 NM="$(echo "$NAME" | cut -c 1-4)"
526 else
527 NM="$(echo "$NAME" | cut -c 1)"
528 fi
529 local ARCH="$2"
530 local VERSION="$3"
531 local RELEASE="${4:-unstable}"
532 local DEPENDENCIES="$5"
533 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
534 If you find such a package installed on your system,
535 something went horribly wrong! They are autogenerated
536 und used only by testcases and surf no other propose…"}"
537
538 local SECTION="${7:-others}"
539 local PRIORITY="${8:-optional}"
540 local FILE_TREE="$9"
541 local COMPRESS_TYPE="${10:-gzip}"
542 local DISTSECTION
543 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
544 DISTSECTION="main"
545 else
546 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
547 fi
548 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
549
550 msgtest "Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
551 mkdir -p $BUILDDIR/debian/source
552 echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
553 echo "#!/bin/sh
554 echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
555
556 echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
557 echo "$NAME ($VERSION) $RELEASE; urgency=low
558
559 * Initial release
560
561 -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
562 echo "Source: $NAME
563 Section: $SECTION
564 Priority: $PRIORITY
565 Maintainer: Joe Sixpack <joe@example.org>
566 Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
567 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
568 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
569 echo "
570 Package: $NAME" >> ${BUILDDIR}/debian/control
571
572 if [ "$ARCH" = 'all' ]; then
573 echo "Architecture: all" >> ${BUILDDIR}/debian/control
574 else
575 echo "Architecture: any" >> ${BUILDDIR}/debian/control
576 fi
577 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
578 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
579 echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
580
581 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
582 cd ${BUILDDIR}/..
583 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
584 cd - >/dev/null
585 sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' ${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output \
586 | while read SRC; do
587 echo "pool/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
588 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
589 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
590 # adv --yes --default-key 'Joe Sixpack' \
591 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
592 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
593 # fi
594 done
595
596 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
597 msgtest "Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
598 rm -rf ${BUILDDIR}/debian/tmp
599 mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
600 cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}
601 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}
602 if [ -n "$FILE_TREE" ]; then
603 cp -ar "$FILE_TREE" ${BUILDDIR}/debian/tmp
604 fi
605
606 (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch)
607 (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
608 local LOG="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
609 # ensure the right permissions as dpkg-deb insists
610 chmod 755 ${BUILDDIR}/debian/tmp/DEBIAN
611 testsuccess --nomsg dpkg-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/..
612 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist
613 done
614
615 local CHANGEPATH="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}"
616 mkdir -p $CHANGEPATH
617 cp ${BUILDDIR}/debian/changelog $CHANGEPATH
618 rm -rf "${BUILDDIR}"
619 msgdone "info"
620 }
621
622 buildpackage() {
623 local BUILDDIR=$1
624 local RELEASE=$2
625 local SECTION=$3
626 local ARCH=$(getarchitecture $4)
627 local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
628 local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
629 msgtest "Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
630 cd $BUILDDIR
631 if [ "$ARCH" = "all" ]; then
632 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
633 fi
634 testsuccess --nomsg dpkg-buildpackage -uc -us -a$ARCH
635 cp ${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output $BUILDLOG
636 local PKGS="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
637 local SRCS="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
638 cd - > /dev/null
639 for PKG in $PKGS; do
640 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist
641 done
642 for SRC in $SRCS; do
643 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist
644 done
645 }
646
647 buildaptarchive() {
648 if [ -d incoming ]; then
649 buildaptarchivefromincoming "$@"
650 else
651 buildaptarchivefromfiles "$@"
652 fi
653 }
654
655 createaptftparchiveconfig() {
656 local COMPRESSORS="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
657 local COMPRESSORS="${COMPRESSORS%* }"
658 local ARCHS="$(getarchitectures)"
659 echo -n 'Dir {
660 ArchiveDir "' >> ftparchive.conf
661 echo -n $(readlink -f .) >> ftparchive.conf
662 echo -n '";
663 CacheDir "' >> ftparchive.conf
664 echo -n $(readlink -f ..) >> ftparchive.conf
665 echo -n '";
666 FileListDir "' >> ftparchive.conf
667 echo -n $(readlink -f pool/) >> ftparchive.conf
668 echo -n '";
669 };
670 Default {
671 Packages::Compress "'"$COMPRESSORS"'";
672 Sources::Compress "'"$COMPRESSORS"'";
673 Contents::Compress "'"$COMPRESSORS"'";
674 Translation::Compress "'"$COMPRESSORS"'";
675 LongDescription "false";
676 };
677 TreeDefault {
678 Directory "pool/";
679 SrcDirectory "pool/";
680 };
681 APT {
682 FTPArchive {
683 Release {
684 Origin "joesixpack";
685 Label "apttestcases";
686 Suite "unstable";
687 Description "repository with dummy packages";
688 Architectures "' >> ftparchive.conf
689 echo -n "$ARCHS" >> ftparchive.conf
690 echo 'source";
691 };
692 };
693 };' >> ftparchive.conf
694 for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
695 echo -n 'tree "dists/' >> ftparchive.conf
696 echo -n "$DIST" >> ftparchive.conf
697 echo -n '" {
698 Architectures "' >> ftparchive.conf
699 echo -n "$ARCHS" >> ftparchive.conf
700 echo -n 'source";
701 FileList "' >> ftparchive.conf
702 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
703 echo -n '";
704 SourceFileList "' >> ftparchive.conf
705 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
706 echo -n '";
707 Sections "' >> ftparchive.conf
708 echo -n "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')" >> ftparchive.conf
709 echo '";
710 };' >> ftparchive.conf
711 done
712 }
713
714 buildaptftparchivedirectorystructure() {
715 local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
716 for DIST in $DISTS; do
717 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
718 for SECTION in $SECTIONS; do
719 local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
720 for ARCH in $ARCHS; do
721 mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH}
722 done
723 mkdir -p dists/${DIST}/${SECTION}/source
724 mkdir -p dists/${DIST}/${SECTION}/i18n
725 done
726 done
727 }
728
729 insertpackage() {
730 local RELEASES="$1"
731 local NAME="$2"
732 local ARCH="$3"
733 local VERSION="$4"
734 local DEPENDENCIES="$5"
735 local PRIORITY="${6:-optional}"
736 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
737 If you find such a package installed on your system,
738 something went horribly wrong! They are autogenerated
739 und used only by testcases and surf no other propose…"}"
740 local ARCHS=""
741 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
742 if [ "$RELEASE" = 'installed' ]; then
743 insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
744 continue
745 fi
746 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
747 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
748 ARCHS="$(getarchitectures)"
749 else
750 ARCHS="$arch"
751 fi
752 for BUILDARCH in $ARCHS; do
753 local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
754 mkdir -p $PPATH
755 local FILE="${PPATH}/Packages"
756 echo "Package: $NAME
757 Priority: $PRIORITY
758 Section: other
759 Installed-Size: 42
760 Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
761 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
762 echo "Version: $VERSION
763 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
764 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
765 echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)" >> $FILE
766 echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)" >> $FILE
767 echo >> $FILE
768 done
769 done
770 mkdir -p aptarchive/dists/${RELEASE}/main/source aptarchive/dists/${RELEASE}/main/i18n
771 touch aptarchive/dists/${RELEASE}/main/source/Sources
772 echo "Package: $NAME
773 Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
774 Description-en: $DESCRIPTION
775 " >> aptarchive/dists/${RELEASE}/main/i18n/Translation-en
776 done
777 }
778
779 insertsource() {
780 local RELEASE="$1"
781 local NAME="$2"
782 local ARCH="$3"
783 local VERSION="$4"
784 local DEPENDENCIES="$5"
785 local ARCHS=""
786 local SPATH="aptarchive/dists/${RELEASE}/main/source"
787 mkdir -p $SPATH
788 local FILE="${SPATH}/Sources"
789 local DSCFILE="${NAME}_${VERSION}.dsc"
790 local TARFILE="${NAME}_${VERSION}.tar.gz"
791 echo "Package: $NAME
792 Binary: $NAME
793 Version: $VERSION
794 Maintainer: Joe Sixpack <joe@example.org>
795 Architecture: $ARCH" >> $FILE
796 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
797 echo "Files:
798 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) $DSCFILE
799 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) $TARFILE
800 " >> $FILE
801 }
802
803 insertinstalledpackage() {
804 local NAME="$1"
805 local ARCH="$2"
806 local VERSION="$3"
807 local DEPENDENCIES="$4"
808 local PRIORITY="${5:-optional}"
809 local STATUS="${6:-install ok installed}"
810 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
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…"}"
814
815 local FILE='rootdir/var/lib/dpkg/status'
816 local INFO='rootdir/var/lib/dpkg/info'
817 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
818 echo "Package: $NAME
819 Status: $STATUS
820 Priority: $PRIORITY
821 Section: other
822 Installed-Size: 42
823 Maintainer: Joe Sixpack <joe@example.org>
824 Version: $VERSION" >> $FILE
825 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
826 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
827 echo "Description: $DESCRIPTION" >> $FILE
828 echo >> $FILE
829 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
830 echo -n > ${INFO}/${NAME}:${arch}.list
831 else
832 echo -n > ${INFO}/${NAME}.list
833 fi
834 done
835 }
836
837
838 buildaptarchivefromincoming() {
839 msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
840 cd aptarchive
841 [ -e pool ] || ln -s ../incoming pool
842 [ -e ftparchive.conf ] || createaptftparchiveconfig
843 [ -e dists ] || buildaptftparchivedirectorystructure
844 msgninfo "\tGenerate Packages, Sources and Contents files… "
845 testsuccess aptftparchive generate ftparchive.conf
846 cd - > /dev/null
847 msgdone "info"
848 generatereleasefiles "$@"
849 }
850
851 buildaptarchivefromfiles() {
852 msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
853 local DIR='aptarchive'
854 if [ -d "${DIR}/dists" ]; then DIR="${DIR}/dists"; fi
855 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do
856 msgninfo "\t${line} file… "
857 compressfile "$line" "$1"
858 msgdone "info"
859 done
860 generatereleasefiles "$@"
861 }
862
863 compressfile() {
864 cat ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | while read compressor extension command; do
865 if [ "$compressor" = '.' ]; then
866 if [ -n "$2" ]; then
867 touch -d "$2" "$1"
868 fi
869 continue
870 fi
871 cat "$1" | $command > "${1}.${extension}"
872 if [ -n "$2" ]; then
873 touch -d "$2" "${1}.${extension}"
874 fi
875 done
876 }
877
878 # can be overridden by testcases for their pleasure
879 getcodenamefromsuite() {
880 case "$1" in
881 unstable) echo 'sid';;
882 *) echo -n "$1";;
883 esac
884 }
885 getreleaseversionfromsuite() { true; }
886 getlabelfromsuite() { true; }
887 getoriginfromsuite() { true; }
888
889 generatereleasefiles() {
890 # $1 is the Date header and $2 is the ValidUntil header to be set
891 # both should be given in notation date/touch can understand
892 msgninfo "\tGenerate Release files… "
893 if [ -e aptarchive/dists ]; then
894 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
895 local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
896 local CODENAME="$(getcodenamefromsuite $SUITE)"
897 local VERSION="$(getreleaseversionfromsuite $SUITE)"
898 local LABEL="$(getlabelfromsuite $SUITE)"
899 local ORIGIN="$(getoriginfromsuite $SUITE)"
900 if [ -n "$VERSION" ]; then
901 VERSION="-o APT::FTPArchive::Release::Version=${VERSION}"
902 fi
903 if [ -n "$LABEL" ]; then
904 LABEL="-o APT::FTPArchive::Release::Label=${LABEL}"
905 fi
906 if [ -n "$ORIGIN" ]; then
907 ORIGIN="-o APT::FTPArchive::Release::Origin=${ORIGIN}"
908 fi
909 aptftparchive -qq release $dir \
910 -o APT::FTPArchive::Release::Suite="${SUITE}" \
911 -o APT::FTPArchive::Release::Codename="${CODENAME}" \
912 ${LABEL} \
913 ${ORIGIN} \
914 ${VERSION} \
915 | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
916 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
917 sed -i '/^Date: / a\
918 NotAutomatic: yes' $dir/Release
919 fi
920 if [ -n "$1" -a "$1" != "now" ]; then
921 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
922 fi
923 if [ -n "$2" ]; then
924 sed -i "/^Date: / a\
925 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
926 fi
927 done
928 else
929 aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
930 fi
931 if [ -n "$1" -a "$1" != "now" ]; then
932 for release in $(find ./aptarchive -name 'Release'); do
933 touch -d "$1" $release
934 done
935 fi
936 msgdone "info"
937 }
938
939 setupdistsaptarchive() {
940 local APTARCHIVE=$(readlink -f ./aptarchive)
941 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
942 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
943 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
944 SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
945 msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
946 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
947 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
948 msgdone "info"
949 done
950 }
951
952 setupflataptarchive() {
953 local APTARCHIVE=$(readlink -f ./aptarchive)
954 if [ -f ${APTARCHIVE}/Packages ]; then
955 msgninfo "\tadd deb sources.list line… "
956 echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
957 msgdone "info"
958 else
959 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
960 fi
961 if [ -f ${APTARCHIVE}/Sources ]; then
962 msgninfo "\tadd deb-src sources.list line… "
963 echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
964 msgdone "info"
965 else
966 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
967 fi
968 }
969
970 setupaptarchive() {
971 local NOUPDATE=0
972 if [ "$1" = '--no-update' ]; then
973 NOUPDATE=1
974 shift
975 fi
976 buildaptarchive "$@"
977 if [ -e aptarchive/dists ]; then
978 setupdistsaptarchive
979 else
980 setupflataptarchive
981 fi
982 signreleasefiles 'Joe Sixpack'
983 if [ "1" != "$NOUPDATE" ]; then
984 testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true
985 fi
986 }
987
988 signreleasefiles() {
989 local SIGNER="${1:-Joe Sixpack}"
990 local REPODIR="${2:-aptarchive}"
991 local KEY="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
992 local GPG="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
993 msgninfo "\tSign archive with $SIGNER key $KEY… "
994 local REXKEY='keys/rexexpired'
995 local SECEXPIREBAK="${REXKEY}.sec.bak"
996 local PUBEXPIREBAK="${REXKEY}.pub.bak"
997 if [ "${SIGNER}" = 'Rex Expired' ]; then
998 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
999 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1000 # therefore we 'temporary' make the key not expired and restore a backup after signing
1001 cp ${REXKEY}.sec $SECEXPIREBAK
1002 cp ${REXKEY}.pub $PUBEXPIREBAK
1003 local SECUNEXPIRED="${REXKEY}.sec.unexpired"
1004 local PUBUNEXPIRED="${REXKEY}.pub.unexpired"
1005 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1006 cp $SECUNEXPIRED ${REXKEY}.sec
1007 cp $PUBUNEXPIRED ${REXKEY}.pub
1008 else
1009 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then
1010 cat setexpire.gpg
1011 exit 1
1012 fi
1013 cp ${REXKEY}.sec $SECUNEXPIRED
1014 cp ${REXKEY}.pub $PUBUNEXPIRED
1015 fi
1016 fi
1017 for RELEASE in $(find ${REPODIR}/ -name Release); do
1018 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg ${RELEASE}
1019 local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
1020 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
1021 # we might have set a specific date for the Release file, so copy it
1022 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg ${INRELEASE}
1023 done
1024 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1025 mv -f $SECEXPIREBAK ${REXKEY}.sec
1026 mv -f $PUBEXPIREBAK ${REXKEY}.pub
1027 fi
1028 msgdone "info"
1029 }
1030
1031 redatereleasefiles() {
1032 local DATE="$(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
1033 for release in $(find aptarchive/ -name 'Release'); do
1034 sed -i "s/^Date: .*$/Date: ${DATE}/" $release
1035 touch -d "$DATE" $release
1036 done
1037 signreleasefiles "${2:-Joe Sixpack}"
1038 }
1039
1040 webserverconfig() {
1041 local WEBSERVER="${3:-http://localhost:8080}"
1042 local NOCHECK=false
1043 if [ "$1" = '--no-check' ]; then
1044 NOCHECK=true
1045 shift
1046 fi
1047 local DOWNLOG='rootdir/tmp/download-testfile.log'
1048 local STATUS='downloaded/webserverconfig.status'
1049 rm -f "$STATUS" "$DOWNLOG"
1050 local URI
1051 if [ -n "$2" ]; then
1052 msgtest "Set webserver config option '${1}' to" "$2"
1053 URI="${WEBSERVER}/_config/set/${1}/${2}"
1054 else
1055 msgtest 'Clear webserver config option' "${1}"
1056 URI="${WEBSERVER}/_config/clear/${1}"
1057 fi
1058 if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then
1059 msgpass
1060 else
1061 cat "$DOWNLOG" "$STATUS" || true
1062 msgfail
1063 fi
1064 $NOCHECK || testwebserverlaststatuscode '200'
1065 }
1066
1067 rewritesourceslist() {
1068 local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
1069 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1070 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#https://localhost:4433/#${1}#"
1071 done
1072 }
1073
1074 # wait for up to 10s for a pid file to appear to avoid possible race
1075 # when a helper is started and dosn't write the PID quick enough
1076 waitforpidfile() {
1077 local PIDFILE="$1"
1078 for i in $(seq 10); do
1079 if test -s "$PIDFILE"; then
1080 return 0
1081 fi
1082 sleep 1
1083 done
1084 msgdie "waiting for $PIDFILE failed"
1085 return 1
1086 }
1087
1088 changetowebserver() {
1089 if [ "$1" != '--no-rewrite' ]; then
1090 rewritesourceslist 'http://localhost:8080/'
1091 else
1092 shift
1093 fi
1094 if test -x ${APTWEBSERVERBINDIR}/aptwebserver; then
1095 cd aptarchive
1096 local LOG="webserver.log"
1097 if ! aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1 ; then
1098 cat $LOG
1099 false
1100 fi
1101 waitforpidfile aptwebserver.pid
1102 local PID="$(cat aptwebserver.pid)"
1103 if [ -z "$PID" ]; then
1104 msgdie 'Could not fork aptwebserver successfully'
1105 fi
1106 addtrap "kill $PID;"
1107 cd - > /dev/null
1108 else
1109 msgdie 'You have to build aptwerbserver or install a webserver'
1110 fi
1111 }
1112
1113 changetohttpswebserver() {
1114 if ! which stunnel4 >/dev/null; then
1115 msgdie 'You need to install stunnel4 for https testcases'
1116 fi
1117 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1118 changetowebserver --no-rewrite "$@"
1119 fi
1120 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1121 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1122 output = /dev/null
1123
1124 [https]
1125 accept = 4433
1126 connect = 8080
1127 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
1128 stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
1129 waitforpidfile "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1130 local PID="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
1131 if [ -z "$PID" ]; then
1132 msgdie 'Could not fork stunnel4 successfully'
1133 fi
1134 addtrap 'prefix' "kill ${PID};"
1135 rewritesourceslist 'https://localhost:4433/'
1136 }
1137
1138 changetocdrom() {
1139 mkdir -p rootdir/media/cdrom/.disk
1140 local CD="$(readlink -f rootdir/media/cdrom)"
1141 echo "acquire::cdrom::mount \"${CD}\";
1142 acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
1143 acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
1144 acquire::cdrom::autodetect 0;" > rootdir/etc/apt/apt.conf.d/00cdrom
1145 echo -n "$1" > ${CD}/.disk/info
1146 if [ ! -d aptarchive/dists ]; then
1147 msgdie 'Flat file archive cdroms can not be created currently'
1148 return 1
1149 fi
1150 mv aptarchive/dists "$CD"
1151 ln -s "$(readlink -f ./incoming)" $CD/pool
1152 find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete
1153 # start with an unmounted disk
1154 mv "${CD}" "${CD}-unmounted"
1155 # we don't want the disk to be modifiable
1156 addtrap 'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
1157 chmod -R 555 rootdir/media/cdrom-unmounted/dists
1158 }
1159
1160 downloadfile() {
1161 local PROTO="${1%%:*}"
1162 if ! apthelper -o Debug::Acquire::${PROTO}=1 -o Debug::pkgAcquire::Worker=1 \
1163 download-file "$1" "$2" "$3" 2>&1 ; then
1164 return 1
1165 fi
1166 # only if the file exists the download was successful
1167 if [ -r "$2" ]; then
1168 return 0
1169 else
1170 return 1
1171 fi
1172 }
1173
1174 checkdiff() {
1175 local DIFFTEXT="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1176 if [ -n "$DIFFTEXT" ]; then
1177 echo >&2
1178 echo >&2 "$DIFFTEXT"
1179 return 1
1180 else
1181 return 0
1182 fi
1183 }
1184
1185 testfileequal() {
1186 local FILE="$1"
1187 shift
1188 msgtest "Test for correctness of file" "$FILE"
1189 if [ -z "$*" ]; then
1190 echo -n "" | checkdiff - $FILE && msgpass || msgfail
1191 else
1192 echo "$*" | checkdiff - $FILE && msgpass || msgfail
1193 fi
1194 }
1195
1196 testempty() {
1197 msgtest "Test for no output of" "$*"
1198 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1199 if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
1200 msgpass
1201 else
1202 echo
1203 cat $COMPAREFILE
1204 msgfail
1205 fi
1206 aptautotest 'testempty' "$@"
1207 }
1208
1209 testequal() {
1210 local MSG='Test of equality of'
1211 if [ "$1" = '--nomsg' ]; then
1212 MSG=''
1213 shift
1214 fi
1215
1216 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1217 echo "$1" > $COMPAREFILE
1218 shift
1219
1220 if [ -n "$MSG" ]; then
1221 msgtest "$MSG" "$*"
1222 fi
1223 "$@" 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
1224 aptautotest 'testequal' "$@"
1225 }
1226
1227 testequalor2() {
1228 local COMPAREFILE1="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1229 local COMPAREFILE2="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1230 local COMPAREAGAINST="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1231 echo "$1" > $COMPAREFILE1
1232 echo "$2" > $COMPAREFILE2
1233 shift 2
1234 msgtest "Test for equality OR of" "$*"
1235 "$@" >$COMPAREAGAINST 2>&1 || true
1236 if checkdiff $COMPAREFILE1 $COMPAREAGAINST >/dev/null 2>&1 || \
1237 checkdiff $COMPAREFILE2 $COMPAREAGAINST >/dev/null 2>&1
1238 then
1239 msgpass
1240 else
1241 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
1242 checkdiff $COMPAREFILE1 $COMPAREAGAINST || true
1243 echo -n "${CINFO}Diff against OR 2${CNORMAL}"
1244 checkdiff $COMPAREFILE2 $COMPAREAGAINST || true
1245 msgfail
1246 fi
1247 aptautotest 'testequalor2' "$@"
1248 }
1249
1250 testshowvirtual() {
1251 local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
1252 local PACKAGE="$1"
1253 shift
1254 while [ -n "$1" ]; do
1255 VIRTUAL="${VIRTUAL}
1256 N: Can't select versions from package '$1' as it is purely virtual"
1257 PACKAGE="${PACKAGE} $1"
1258 shift
1259 done
1260 msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
1261 VIRTUAL="${VIRTUAL}
1262 N: No packages found"
1263 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1264 local ARCH="$(getarchitecture 'native')"
1265 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1266 aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
1267 }
1268
1269 testnopackage() {
1270 msgtest "Test for non-existent packages" "apt-cache show $*"
1271 local SHOWPKG="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1272 if [ -n "$SHOWPKG" ]; then
1273 echo >&2
1274 echo >&2 "$SHOWPKG"
1275 msgfail
1276 else
1277 msgpass
1278 fi
1279 }
1280
1281 testdpkgstatus() {
1282 local STATE="$1"
1283 local NR="$2"
1284 shift 2
1285 msgtest "Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1286 local PKGS="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1287 if [ "$PKGS" != $NR ]; then
1288 echo >&2 $PKGS
1289 dpkg -l "$@" | grep '^[a-z]' >&2
1290 msgfail
1291 else
1292 msgpass
1293 fi
1294 }
1295
1296 testdpkginstalled() {
1297 testdpkgstatus 'ii' "$#" "$@"
1298 }
1299
1300 testdpkgnotinstalled() {
1301 testdpkgstatus 'ii' '0' "$@"
1302 }
1303
1304 testmarkedauto() {
1305 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1306 if [ -n "$1" ]; then
1307 msgtest 'Test for correctly marked as auto-installed' "$*"
1308 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1309 else
1310 msgtest 'Test for correctly marked as auto-installed' 'no package'
1311 echo -n > $COMPAREFILE
1312 fi
1313 aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
1314 }
1315
1316 msgfailoutput() {
1317 local MSG="$1"
1318 local OUTPUT="$2"
1319 shift 2
1320 echo >&2
1321 if [ "$1" = 'grep' ]; then
1322 while [ -n "$2" ]; do shift; done
1323 echo "#### Complete file: $1 ####"
1324 cat >&2 "$1" || true
1325 echo '#### grep output ####'
1326 elif [ "$1" = 'test' ]; then
1327 # doesn't support ! or non-file flags
1328 msgfailoutputstatfile() {
1329 local FILEFLAGS='^-[bcdefgGhkLOprsStuwx]$'
1330 if expr match "$1" "$FILEFLAGS" >/dev/null; then
1331 echo "#### stat(2) of file: $2 ####"
1332 stat "$2" || true
1333 fi
1334 }
1335 msgfailoutputstatfile "$2" "$3"
1336 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1337 shift 3
1338 msgfailoutputstatfile "$2" "$3"
1339 done
1340 echo '#### test output ####'
1341 fi
1342 cat >&2 $OUTPUT
1343 msgfail "$MSG"
1344 }
1345
1346 testsuccess() {
1347 if [ "$1" = '--nomsg' ]; then
1348 shift
1349 else
1350 msgtest 'Test for successful execution of' "$*"
1351 fi
1352 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1353 if "$@" >${OUTPUT} 2>&1; then
1354 if expr match "$1" '^apt.*' >/dev/null; then
1355 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1356 msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
1357 elif grep -q -E '^[WE]: ' "$OUTPUT"; then
1358 msgfailoutput 'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1359 else
1360 msgpass
1361 fi
1362 else
1363 msgpass
1364 fi
1365 else
1366 local EXITCODE=$?
1367 msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
1368 fi
1369 aptautotest 'testsuccess' "$@"
1370 }
1371 testwarning() {
1372 if [ "$1" = '--nomsg' ]; then
1373 shift
1374 else
1375 msgtest 'Test for successful execution with warnings of' "$*"
1376 fi
1377 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1378 if "$@" >${OUTPUT} 2>&1; then
1379 if expr match "$1" '^apt.*' >/dev/null; then
1380 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1381 msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
1382 elif grep -q -E '^E: ' "$OUTPUT"; then
1383 msgfailoutput 'successful run, but output contains errors' "$OUTPUT" "$@"
1384 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1385 msgfailoutput 'successful run, but output contains no warnings' "$OUTPUT" "$@"
1386 else
1387 msgpass
1388 fi
1389 else
1390 msgpass
1391 fi
1392 else
1393 local EXITCODE=$?
1394 echo >&2
1395 cat >&2 $OUTPUT
1396 msgfail "exitcode $EXITCODE"
1397 fi
1398 aptautotest 'testwarning' "$@"
1399 }
1400 testfailure() {
1401 if [ "$1" = '--nomsg' ]; then
1402 shift
1403 else
1404 msgtest 'Test for failure in execution of' "$*"
1405 fi
1406 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1407 if "$@" >${OUTPUT} 2>&1; then
1408 local EXITCODE=$?
1409 msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
1410 else
1411 local EXITCODE=$?
1412 if expr match "$1" '^apt.*' >/dev/null; then
1413 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1414 msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
1415 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1416 msgfailoutput "run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1417 else
1418 msgpass
1419 fi
1420 else
1421 msgpass
1422 fi
1423 fi
1424 aptautotest 'testfailure' "$@"
1425 }
1426
1427 testsuccessequal() {
1428 local CMP="$1"
1429 shift
1430 testsuccess "$@"
1431 testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$CMP"
1432 }
1433 testwarningequal() {
1434 local CMP="$1"
1435 shift
1436 testwarning "$@"
1437 testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" "$CMP"
1438 }
1439 testfailureequal() {
1440 local CMP="$1"
1441 shift
1442 testfailure "$@"
1443 testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" "$CMP"
1444 }
1445
1446 testfailuremsg() {
1447 local CMP="$1"
1448 shift
1449 testfailure "$@"
1450 msgtest 'Check that the output of the previous failed command has expected' 'failures and warnings'
1451 grep '^\(W\|E\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailureequal.output" 2>&1 || true
1452 if echo "$CMP" | checkdiff - "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailureequal.output"; then
1453 msgpass
1454 else
1455 echo '### Complete output ###'
1456 cat "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1457 msgfail
1458 fi
1459 }
1460
1461 testfilestats() {
1462 msgtest "Test that file $1 has $2 $3" "$4"
1463 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1464 msgpass
1465 else
1466 echo >&2
1467 ls -ld >&2 "$1" || true
1468 echo -n >&2 "stat(1) reports for $2: "
1469 stat --format "$2" "$1" || true
1470 msgfail
1471 fi
1472 }
1473 testaccessrights() {
1474 testfilestats "$1" '%a' '=' "$2"
1475 }
1476
1477 testwebserverlaststatuscode() {
1478 local DOWNLOG='rootdir/tmp/webserverstatus-testfile.log'
1479 local STATUS='downloaded/webserverstatus-statusfile.log'
1480 rm -f "$DOWNLOG" "$STATUS"
1481 msgtest 'Test last status code from the webserver was' "$1"
1482 if downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1483 msgpass
1484 else
1485 echo >&2
1486 if [ -n "$2" ]; then
1487 shift
1488 echo >&2 '#### Additionally provided output files contain:'
1489 cat >&2 "$@"
1490 fi
1491 echo >&2 '#### Download log of the status code:'
1492 cat >&2 "$DOWNLOG"
1493 msgfail "Status was $(cat "$STATUS")"
1494 fi
1495 }
1496
1497 pause() {
1498 echo "STOPPED execution. Press enter to continue"
1499 local IGNORE
1500 read IGNORE
1501 }
1502
1503 listcurrentlistsdirectory() {
1504 {
1505 find rootdir/var/lib/apt/lists -maxdepth 1 -type d | while read line; do
1506 stat --format '%U:%G:%a:%n' "$line"
1507 done
1508 find rootdir/var/lib/apt/lists -maxdepth 1 \! -type d | while read line; do
1509 stat --format '%U:%G:%a:%s:%y:%n' "$line"
1510 done
1511 } | sort
1512 }
1513
1514 ### convinience hacks ###
1515 mkdir() {
1516 # creating some directories by hand is a tedious task, so make it look simple
1517 if [ "$*" = '-p rootdir/var/lib/apt/lists' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" ] ||
1518 [ "$*" = '-p rootdir/var/lib/apt/lists/partial' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" ]; then
1519 # only the last directory created by mkdir is effected by the -m !
1520 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1521 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1522 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1523 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1524 if [ "$(id -u)" = '0' ]; then
1525 chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1526 fi
1527 else
1528 command mkdir "$@"
1529 fi
1530 }
1531
1532 ### The following tests are run by most test methods automatically to check
1533 ### general things about commands executed without writing the test every time.
1534
1535 aptautotest() {
1536 local TESTCALL="$1"
1537 local CMD="$2"
1538 local FIRSTOPT="$3"
1539 local AUTOTEST="aptautotest_$(basename "$CMD" | tr -d '-')_$(echo "$FIRSTOPT" | tr -d '-')"
1540 if command -v $AUTOTEST >/dev/null; then
1541 shift 3
1542 # save and restore the *.output files from other tests
1543 # as we might otherwise override them in these automatic tests
1544 rm -rf ${TMPWORKINGDIRECTORY}/rootdir/tmp-before
1545 mv ${TMPWORKINGDIRECTORY}/rootdir/tmp ${TMPWORKINGDIRECTORY}/rootdir/tmp-before
1546 mkdir ${TMPWORKINGDIRECTORY}/rootdir/tmp
1547 $AUTOTEST "$TESTCALL" "$@"
1548 rm -rf ${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest
1549 mv ${TMPWORKINGDIRECTORY}/rootdir/tmp ${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest
1550 mv ${TMPWORKINGDIRECTORY}/rootdir/tmp-before ${TMPWORKINGDIRECTORY}/rootdir/tmp
1551 fi
1552 }
1553
1554 aptautotest_aptget_update() {
1555 local TESTCALL="$1"
1556 while [ -n "$2" ]; do
1557 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1558 shift
1559 done
1560 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1561 testfilestats "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1562 testfilestats "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1563 # all copied files are properly chmodded
1564 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1565 testfilestats "$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1566 done
1567 if [ "$TESTCALL" = 'testsuccess' ]; then
1568 # failure cases can retain partial files and such
1569 testempty find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \( -name 'lock' -o -name '*.FAILED' \)
1570 fi
1571 }
1572 aptautotest_apt_update() { aptautotest_aptget_update "$@"; }
1573 aptautotest_aptcdrom_add() { aptautotest_aptget_update "$@"; }
1574
1575 testaptautotestnodpkgwarning() {
1576 local TESTCALL="$1"
1577 while [ -n "$2" ]; do
1578 if expr match "$2" '^-[a-z]*s' >/dev/null 2>&1; then return; fi # simulation mode
1579 if expr match "$2" '^-dy\?' >/dev/null 2>&1; then return; fi # download-only mode
1580 shift
1581 done
1582 testfailure grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1583 }
1584
1585 aptautotest_aptget_install() { testaptautotestnodpkgwarning "$@"; }
1586 aptautotest_aptget_remove() { testaptautotestnodpkgwarning "$@"; }
1587 aptautotest_aptget_purge() { testaptautotestnodpkgwarning "$@"; }
1588 aptautotest_apt_install() { testaptautotestnodpkgwarning "$@"; }
1589 aptautotest_apt_remove() { testaptautotestnodpkgwarning "$@"; }
1590 aptautotest_apt_purge() { testaptautotestnodpkgwarning "$@"; }