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