]> git.saurik.com Git - apt.git/blob - test/integration/framework
hide Translation-* in 'apt-cache policy' output
[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 \"${METHODSDIR}\";" >> 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 ARCH="$2"
524 local VERSION="$3"
525 local RELEASE="${4:-unstable}"
526 local DEPENDENCIES="$5"
527 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
528 If you find such a package installed on your system,
529 something went horribly wrong! They are autogenerated
530 und used only by testcases and surf no other propose…"}"
531
532 local SECTION="${7:-others}"
533 local PRIORITY="${8:-optional}"
534 local FILE_TREE="$9"
535 local COMPRESS_TYPE="${10:-gzip}"
536 local DISTSECTION
537 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
538 DISTSECTION="main"
539 else
540 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
541 fi
542 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
543
544 msgtest "Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
545 mkdir -p $BUILDDIR/debian/source
546 echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
547 echo "#!/bin/sh
548 echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
549
550 echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
551 echo "$NAME ($VERSION) $RELEASE; urgency=low
552
553 * Initial release
554
555 -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
556 echo "Source: $NAME
557 Section: $SECTION
558 Priority: $PRIORITY
559 Maintainer: Joe Sixpack <joe@example.org>
560 Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
561 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
562 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
563 echo "
564 Package: $NAME" >> ${BUILDDIR}/debian/control
565
566 if [ "$ARCH" = 'all' ]; then
567 echo "Architecture: all" >> ${BUILDDIR}/debian/control
568 else
569 echo "Architecture: any" >> ${BUILDDIR}/debian/control
570 fi
571 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
572 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
573 echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
574
575 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
576 cd ${BUILDDIR}/..
577 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
578 cd - >/dev/null
579 sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' ${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output \
580 | while read SRC; do
581 echo "pool/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
582 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
583 # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
584 # adv --yes --default-key 'Joe Sixpack' \
585 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
586 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
587 # fi
588 done
589
590 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
591 msgtest "Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
592 rm -rf ${BUILDDIR}/debian/tmp
593 mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
594 cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}
595 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}
596 if [ -n "$FILE_TREE" ]; then
597 cp -ar "$FILE_TREE" ${BUILDDIR}/debian/tmp
598 fi
599
600 (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch)
601 (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
602 local LOG="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
603 # ensure the right permissions as dpkg-deb ensists
604 chmod 755 ${BUILDDIR}/debian/tmp/DEBIAN
605 testsuccess --nomsg dpkg-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/..
606 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist
607 done
608
609 mkdir -p ${BUILDDIR}/../${NAME}_${VERSION}
610 cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}/
611 cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}.changelog
612 rm -rf "${BUILDDIR}"
613 msgdone "info"
614 }
615
616 buildpackage() {
617 local BUILDDIR=$1
618 local RELEASE=$2
619 local SECTION=$3
620 local ARCH=$(getarchitecture $4)
621 local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
622 local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
623 msgtest "Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
624 cd $BUILDDIR
625 if [ "$ARCH" = "all" ]; then
626 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
627 fi
628 testsuccess --nomsg dpkg-buildpackage -uc -us -a$ARCH
629 cp ${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output $BUILDLOG
630 local PKGS="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
631 local SRCS="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
632 cd - > /dev/null
633 for PKG in $PKGS; do
634 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist
635 done
636 for SRC in $SRCS; do
637 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist
638 done
639 }
640
641 buildaptarchive() {
642 if [ -d incoming ]; then
643 buildaptarchivefromincoming "$@"
644 else
645 buildaptarchivefromfiles "$@"
646 fi
647 }
648
649 createaptftparchiveconfig() {
650 local COMPRESSORS="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
651 local COMPRESSORS="${COMPRESSORS%* }"
652 local ARCHS="$(getarchitectures)"
653 echo -n 'Dir {
654 ArchiveDir "' >> ftparchive.conf
655 echo -n $(readlink -f .) >> ftparchive.conf
656 echo -n '";
657 CacheDir "' >> ftparchive.conf
658 echo -n $(readlink -f ..) >> ftparchive.conf
659 echo -n '";
660 FileListDir "' >> ftparchive.conf
661 echo -n $(readlink -f pool/) >> ftparchive.conf
662 echo -n '";
663 };
664 Default {
665 Packages::Compress "'"$COMPRESSORS"'";
666 Sources::Compress "'"$COMPRESSORS"'";
667 Contents::Compress "'"$COMPRESSORS"'";
668 Translation::Compress "'"$COMPRESSORS"'";
669 LongDescription "false";
670 };
671 TreeDefault {
672 Directory "pool/";
673 SrcDirectory "pool/";
674 };
675 APT {
676 FTPArchive {
677 Release {
678 Origin "joesixpack";
679 Label "apttestcases";
680 Suite "unstable";
681 Description "repository with dummy packages";
682 Architectures "' >> ftparchive.conf
683 echo -n "$ARCHS" >> ftparchive.conf
684 echo 'source";
685 };
686 };
687 };' >> ftparchive.conf
688 for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
689 echo -n 'tree "dists/' >> ftparchive.conf
690 echo -n "$DIST" >> ftparchive.conf
691 echo -n '" {
692 Architectures "' >> ftparchive.conf
693 echo -n "$ARCHS" >> ftparchive.conf
694 echo -n 'source";
695 FileList "' >> ftparchive.conf
696 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
697 echo -n '";
698 SourceFileList "' >> ftparchive.conf
699 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
700 echo -n '";
701 Sections "' >> ftparchive.conf
702 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
703 echo '";
704 };' >> ftparchive.conf
705 done
706 }
707
708 buildaptftparchivedirectorystructure() {
709 local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
710 for DIST in $DISTS; do
711 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
712 for SECTION in $SECTIONS; do
713 local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
714 for ARCH in $ARCHS; do
715 mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH}
716 done
717 mkdir -p dists/${DIST}/${SECTION}/source
718 mkdir -p dists/${DIST}/${SECTION}/i18n
719 done
720 done
721 }
722
723 insertpackage() {
724 local RELEASES="$1"
725 local NAME="$2"
726 local ARCH="$3"
727 local VERSION="$4"
728 local DEPENDENCIES="$5"
729 local PRIORITY="${6:-optional}"
730 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
731 If you find such a package installed on your system,
732 something went horribly wrong! They are autogenerated
733 und used only by testcases and surf no other propose…"}"
734 local ARCHS=""
735 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
736 if [ "$RELEASE" = 'installed' ]; then
737 insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
738 continue
739 fi
740 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
741 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
742 ARCHS="$(getarchitectures)"
743 else
744 ARCHS="$arch"
745 fi
746 for BUILDARCH in $ARCHS; do
747 local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
748 mkdir -p $PPATH
749 local FILE="${PPATH}/Packages"
750 echo "Package: $NAME
751 Priority: $PRIORITY
752 Section: other
753 Installed-Size: 42
754 Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
755 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
756 echo "Version: $VERSION
757 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
758 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
759 echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)" >> $FILE
760 echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)" >> $FILE
761 echo >> $FILE
762 done
763 done
764 mkdir -p aptarchive/dists/${RELEASE}/main/source aptarchive/dists/${RELEASE}/main/i18n
765 touch aptarchive/dists/${RELEASE}/main/source/Sources
766 echo "Package: $NAME
767 Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
768 Description-en: $DESCRIPTION
769 " >> aptarchive/dists/${RELEASE}/main/i18n/Translation-en
770 done
771 }
772
773 insertsource() {
774 local RELEASE="$1"
775 local NAME="$2"
776 local ARCH="$3"
777 local VERSION="$4"
778 local DEPENDENCIES="$5"
779 local ARCHS=""
780 local SPATH="aptarchive/dists/${RELEASE}/main/source"
781 mkdir -p $SPATH
782 local FILE="${SPATH}/Sources"
783 echo "Package: $NAME
784 Binary: $NAME
785 Version: $VERSION
786 Maintainer: Joe Sixpack <joe@example.org>
787 Architecture: $ARCH" >> $FILE
788 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
789 echo "Files:
790 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
791 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
792 " >> $FILE
793 }
794
795 insertinstalledpackage() {
796 local NAME="$1"
797 local ARCH="$2"
798 local VERSION="$3"
799 local DEPENDENCIES="$4"
800 local PRIORITY="${5:-optional}"
801 local STATUS="${6:-install ok installed}"
802 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
803 If you find such a package installed on your system,
804 something went horribly wrong! They are autogenerated
805 und used only by testcases and surf no other propose…"}"
806
807 local FILE='rootdir/var/lib/dpkg/status'
808 local INFO='rootdir/var/lib/dpkg/info'
809 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
810 echo "Package: $NAME
811 Status: $STATUS
812 Priority: $PRIORITY
813 Section: other
814 Installed-Size: 42
815 Maintainer: Joe Sixpack <joe@example.org>
816 Version: $VERSION" >> $FILE
817 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
818 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
819 echo "Description: $DESCRIPTION" >> $FILE
820 echo >> $FILE
821 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
822 echo -n > ${INFO}/${NAME}:${arch}.list
823 else
824 echo -n > ${INFO}/${NAME}.list
825 fi
826 done
827 }
828
829
830 buildaptarchivefromincoming() {
831 msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
832 cd aptarchive
833 [ -e pool ] || ln -s ../incoming pool
834 [ -e ftparchive.conf ] || createaptftparchiveconfig
835 [ -e dists ] || buildaptftparchivedirectorystructure
836 msgninfo "\tGenerate Packages, Sources and Contents files… "
837 testsuccess aptftparchive generate ftparchive.conf
838 cd - > /dev/null
839 msgdone "info"
840 generatereleasefiles "$@"
841 }
842
843 buildaptarchivefromfiles() {
844 msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
845 local DIR='aptarchive'
846 if [ -d "${DIR}/dists" ]; then DIR="${DIR}/dists"; fi
847 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do
848 msgninfo "\t${line} file… "
849 compressfile "$line" "$1"
850 msgdone "info"
851 done
852 generatereleasefiles "$@"
853 }
854
855 compressfile() {
856 cat ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | while read compressor extension command; do
857 if [ "$compressor" = '.' ]; then
858 if [ -n "$2" ]; then
859 touch -d "$2" "$1"
860 fi
861 continue
862 fi
863 cat "$1" | $command > "${1}.${extension}"
864 if [ -n "$2" ]; then
865 touch -d "$2" "${1}.${extension}"
866 fi
867 done
868 }
869
870 # can be overridden by testcases for their pleasure
871 getcodenamefromsuite() {
872 case "$1" in
873 unstable) echo 'sid';;
874 *) echo -n "$1";;
875 esac
876 }
877 getreleaseversionfromsuite() { true; }
878 getlabelfromsuite() { true; }
879
880 generatereleasefiles() {
881 # $1 is the Date header and $2 is the ValidUntil header to be set
882 # both should be given in notation date/touch can understand
883 msgninfo "\tGenerate Release files… "
884 if [ -e aptarchive/dists ]; then
885 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
886 local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
887 local CODENAME="$(getcodenamefromsuite $SUITE)"
888 local VERSION="$(getreleaseversionfromsuite $SUITE)"
889 local LABEL="$(getlabelfromsuite $SUITE)"
890 if [ -n "$VERSION" ]; then
891 VERSION="-o APT::FTPArchive::Release::Version=${VERSION}"
892 fi
893 if [ -n "$LABEL" ]; then
894 LABEL="-o APT::FTPArchive::Release::Label=${LABEL}"
895 fi
896 aptftparchive -qq release $dir \
897 -o APT::FTPArchive::Release::Suite="${SUITE}" \
898 -o APT::FTPArchive::Release::Codename="${CODENAME}" \
899 ${LABEL} \
900 ${VERSION} \
901 | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
902 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
903 sed -i '/^Date: / a\
904 NotAutomatic: yes' $dir/Release
905 fi
906 if [ -n "$1" -a "$1" != "now" ]; then
907 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
908 fi
909 if [ -n "$2" ]; then
910 sed -i "/^Date: / a\
911 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
912 fi
913 done
914 else
915 aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
916 fi
917 if [ -n "$1" -a "$1" != "now" ]; then
918 for release in $(find ./aptarchive -name 'Release'); do
919 touch -d "$1" $release
920 done
921 fi
922 msgdone "info"
923 }
924
925 setupdistsaptarchive() {
926 local APTARCHIVE=$(readlink -f ./aptarchive)
927 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
928 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
929 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
930 SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
931 msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
932 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
933 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
934 msgdone "info"
935 done
936 }
937
938 setupflataptarchive() {
939 local APTARCHIVE=$(readlink -f ./aptarchive)
940 if [ -f ${APTARCHIVE}/Packages ]; then
941 msgninfo "\tadd deb sources.list line… "
942 echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
943 msgdone "info"
944 else
945 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
946 fi
947 if [ -f ${APTARCHIVE}/Sources ]; then
948 msgninfo "\tadd deb-src sources.list line… "
949 echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
950 msgdone "info"
951 else
952 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
953 fi
954 }
955
956 setupaptarchive() {
957 local NOUPDATE=0
958 if [ "$1" = '--no-update' ]; then
959 NOUPDATE=1
960 shift
961 fi
962 buildaptarchive "$@"
963 if [ -e aptarchive/dists ]; then
964 setupdistsaptarchive
965 else
966 setupflataptarchive
967 fi
968 signreleasefiles 'Joe Sixpack'
969 if [ "1" != "$NOUPDATE" ]; then
970 testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true
971 fi
972 }
973
974 signreleasefiles() {
975 local SIGNER="${1:-Joe Sixpack}"
976 local REPODIR="${2:-aptarchive}"
977 local KEY="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
978 local GPG="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
979 msgninfo "\tSign archive with $SIGNER key $KEY… "
980 local REXKEY='keys/rexexpired'
981 local SECEXPIREBAK="${REXKEY}.sec.bak"
982 local PUBEXPIREBAK="${REXKEY}.pub.bak"
983 if [ "${SIGNER}" = 'Rex Expired' ]; then
984 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
985 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
986 # therefore we 'temporary' make the key not expired and restore a backup after signing
987 cp ${REXKEY}.sec $SECEXPIREBAK
988 cp ${REXKEY}.pub $PUBEXPIREBAK
989 local SECUNEXPIRED="${REXKEY}.sec.unexpired"
990 local PUBUNEXPIRED="${REXKEY}.pub.unexpired"
991 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
992 cp $SECUNEXPIRED ${REXKEY}.sec
993 cp $PUBUNEXPIRED ${REXKEY}.pub
994 else
995 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then
996 cat setexpire.gpg
997 exit 1
998 fi
999 cp ${REXKEY}.sec $SECUNEXPIRED
1000 cp ${REXKEY}.pub $PUBUNEXPIRED
1001 fi
1002 fi
1003 for RELEASE in $(find ${REPODIR}/ -name Release); do
1004 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg ${RELEASE}
1005 local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
1006 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
1007 # we might have set a specific date for the Release file, so copy it
1008 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg ${INRELEASE}
1009 done
1010 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1011 mv -f $SECEXPIREBAK ${REXKEY}.sec
1012 mv -f $PUBEXPIREBAK ${REXKEY}.pub
1013 fi
1014 msgdone "info"
1015 }
1016
1017 redatereleasefiles() {
1018 local DATE="$(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
1019 for release in $(find aptarchive/ -name 'Release'); do
1020 sed -i "s/^Date: .*$/Date: ${DATE}/" $release
1021 touch -d "$DATE" $release
1022 done
1023 signreleasefiles "${2:-Joe Sixpack}"
1024 }
1025
1026 webserverconfig() {
1027 local WEBSERVER="${3:-http://localhost:8080}"
1028 local NOCHECK=false
1029 if [ "$1" = '--no-check' ]; then
1030 NOCHECK=true
1031 shift
1032 fi
1033 local DOWNLOG='rootdir/tmp/download-testfile.log'
1034 local STATUS='downloaded/webserverconfig.status'
1035 rm -f "$STATUS" "$DOWNLOG"
1036 local URI
1037 if [ -n "$2" ]; then
1038 msgtest "Set webserver config option '${1}' to" "$2"
1039 URI="${WEBSERVER}/_config/set/${1}/${2}"
1040 else
1041 msgtest 'Clear webserver config option' "${1}"
1042 URI="${WEBSERVER}/_config/clear/${1}"
1043 fi
1044 if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then
1045 msgpass
1046 else
1047 cat "$DOWNLOG" "$STATUS" || true
1048 msgfail
1049 fi
1050 $NOCHECK || testwebserverlaststatuscode '200'
1051 }
1052
1053 rewritesourceslist() {
1054 local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
1055 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
1056 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#https://localhost:4433/#${1}#"
1057 done
1058 }
1059
1060 # wait for up to 10s for a pid file to appear to avoid possible race
1061 # when a helper is started and dosn't write the PID quick enough
1062 waitforpidfile() {
1063 local PIDFILE="$1"
1064 for i in $(seq 10); do
1065 if test -s "$PIDFILE"; then
1066 return 0
1067 fi
1068 sleep 1
1069 done
1070 msgdie "waiting for $PIDFILE failed"
1071 return 1
1072 }
1073
1074 changetowebserver() {
1075 if [ "$1" != '--no-rewrite' ]; then
1076 rewritesourceslist 'http://localhost:8080/'
1077 else
1078 shift
1079 fi
1080 if test -x ${APTWEBSERVERBINDIR}/aptwebserver; then
1081 cd aptarchive
1082 local LOG="webserver.log"
1083 if ! aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1 ; then
1084 cat $LOG
1085 false
1086 fi
1087 waitforpidfile aptwebserver.pid
1088 local PID="$(cat aptwebserver.pid)"
1089 if [ -z "$PID" ]; then
1090 msgdie 'Could not fork aptwebserver successfully'
1091 fi
1092 addtrap "kill $PID;"
1093 cd - > /dev/null
1094 else
1095 msgdie 'You have to build aptwerbserver or install a webserver'
1096 fi
1097 }
1098
1099 changetohttpswebserver() {
1100 if ! which stunnel4 >/dev/null; then
1101 msgdie 'You need to install stunnel4 for https testcases'
1102 fi
1103 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
1104 changetowebserver --no-rewrite "$@"
1105 fi
1106 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
1107 cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
1108 output = /dev/null
1109
1110 [https]
1111 accept = 4433
1112 connect = 8080
1113 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
1114 stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
1115 waitforpidfile "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
1116 local PID="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
1117 if [ -z "$PID" ]; then
1118 msgdie 'Could not fork stunnel4 successfully'
1119 fi
1120 addtrap 'prefix' "kill ${PID};"
1121 rewritesourceslist 'https://localhost:4433/'
1122 }
1123
1124 changetocdrom() {
1125 mkdir -p rootdir/media/cdrom/.disk
1126 local CD="$(readlink -f rootdir/media/cdrom)"
1127 echo "acquire::cdrom::mount \"${CD}\";
1128 acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
1129 acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
1130 acquire::cdrom::autodetect 0;" > rootdir/etc/apt/apt.conf.d/00cdrom
1131 echo -n "$1" > ${CD}/.disk/info
1132 if [ ! -d aptarchive/dists ]; then
1133 msgdie 'Flat file archive cdroms can not be created currently'
1134 return 1
1135 fi
1136 mv aptarchive/dists "$CD"
1137 ln -s "$(readlink -f ./incoming)" $CD/pool
1138 find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete
1139 # start with an unmounted disk
1140 mv "${CD}" "${CD}-unmounted"
1141 # we don't want the disk to be modifiable
1142 addtrap 'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
1143 chmod -R 555 rootdir/media/cdrom-unmounted/dists
1144 }
1145
1146 downloadfile() {
1147 local PROTO="${1%%:*}"
1148 if ! apthelper -o Debug::Acquire::${PROTO}=1 -o Debug::pkgAcquire::Worker=1 \
1149 download-file "$1" "$2" "$3" 2>&1 ; then
1150 return 1
1151 fi
1152 # only if the file exists the download was successful
1153 if [ -r "$2" ]; then
1154 return 0
1155 else
1156 return 1
1157 fi
1158 }
1159
1160 checkdiff() {
1161 local DIFFTEXT="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
1162 if [ -n "$DIFFTEXT" ]; then
1163 echo >&2
1164 echo >&2 "$DIFFTEXT"
1165 return 1
1166 else
1167 return 0
1168 fi
1169 }
1170
1171 testfileequal() {
1172 local FILE="$1"
1173 shift
1174 msgtest "Test for correctness of file" "$FILE"
1175 if [ -z "$*" ]; then
1176 echo -n "" | checkdiff - $FILE && msgpass || msgfail
1177 else
1178 echo "$*" | checkdiff - $FILE && msgpass || msgfail
1179 fi
1180 }
1181
1182 testempty() {
1183 msgtest "Test for no output of" "$*"
1184 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1185 if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
1186 msgpass
1187 else
1188 echo
1189 cat $COMPAREFILE
1190 msgfail
1191 fi
1192 aptautotest 'testempty' "$@"
1193 }
1194
1195 testequal() {
1196 local MSG='Test of equality of'
1197 if [ "$1" = '--nomsg' ]; then
1198 MSG=''
1199 shift
1200 fi
1201
1202 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1203 echo "$1" > $COMPAREFILE
1204 shift
1205
1206 if [ -n "$MSG" ]; then
1207 msgtest "$MSG" "$*"
1208 fi
1209 "$@" 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
1210 aptautotest 'testequal' "$@"
1211 }
1212
1213 testequalor2() {
1214 local COMPAREFILE1="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1215 local COMPAREFILE2="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1216 local COMPAREAGAINST="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1217 echo "$1" > $COMPAREFILE1
1218 echo "$2" > $COMPAREFILE2
1219 shift 2
1220 msgtest "Test for equality OR of" "$*"
1221 "$@" >$COMPAREAGAINST 2>&1 || true
1222 if checkdiff $COMPAREFILE1 $COMPAREAGAINST >/dev/null 2>&1 || \
1223 checkdiff $COMPAREFILE2 $COMPAREAGAINST >/dev/null 2>&1
1224 then
1225 msgpass
1226 else
1227 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
1228 checkdiff $COMPAREFILE1 $COMPAREAGAINST || true
1229 echo -n "${CINFO}Diff against OR 2${CNORMAL}"
1230 checkdiff $COMPAREFILE2 $COMPAREAGAINST || true
1231 msgfail
1232 fi
1233 aptautotest 'testequalor2' "$@"
1234 }
1235
1236 testshowvirtual() {
1237 local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
1238 local PACKAGE="$1"
1239 shift
1240 while [ -n "$1" ]; do
1241 VIRTUAL="${VIRTUAL}
1242 N: Can't select versions from package '$1' as it is purely virtual"
1243 PACKAGE="${PACKAGE} $1"
1244 shift
1245 done
1246 msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
1247 VIRTUAL="${VIRTUAL}
1248 N: No packages found"
1249 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1250 local ARCH="$(getarchitecture 'native')"
1251 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1252 aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
1253 }
1254
1255 testnopackage() {
1256 msgtest "Test for non-existent packages" "apt-cache show $*"
1257 local SHOWPKG="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1258 if [ -n "$SHOWPKG" ]; then
1259 echo >&2
1260 echo >&2 "$SHOWPKG"
1261 msgfail
1262 else
1263 msgpass
1264 fi
1265 }
1266
1267 testdpkgstatus() {
1268 local STATE="$1"
1269 local NR="$2"
1270 shift 2
1271 msgtest "Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1272 local PKGS="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1273 if [ "$PKGS" != $NR ]; then
1274 echo >&2 $PKGS
1275 dpkg -l "$@" | grep '^[a-z]' >&2
1276 msgfail
1277 else
1278 msgpass
1279 fi
1280 }
1281
1282 testdpkginstalled() {
1283 testdpkgstatus 'ii' "$#" "$@"
1284 }
1285
1286 testdpkgnotinstalled() {
1287 testdpkgstatus 'ii' '0' "$@"
1288 }
1289
1290 testmarkedauto() {
1291 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1292 if [ -n "$1" ]; then
1293 msgtest 'Test for correctly marked as auto-installed' "$*"
1294 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1295 else
1296 msgtest 'Test for correctly marked as auto-installed' 'no package'
1297 echo -n > $COMPAREFILE
1298 fi
1299 aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
1300 }
1301
1302 msgfailoutput() {
1303 local MSG="$1"
1304 local OUTPUT="$2"
1305 shift 2
1306 echo >&2
1307 if [ "$1" = 'grep' ]; then
1308 while [ -n "$2" ]; do shift; done
1309 echo "#### Complete file: $1 ####"
1310 cat >&2 "$1" || true
1311 echo '#### grep output ####'
1312 elif [ "$1" = 'test' ]; then
1313 # doesn't support ! or non-file flags
1314 msgfailoutputstatfile() {
1315 local FILEFLAGS='^-[bcdefgGhkLOprsStuwx]$'
1316 if expr match "$1" "$FILEFLAGS" >/dev/null; then
1317 echo "#### stat(2) of file: $2 ####"
1318 stat "$2" || true
1319 fi
1320 }
1321 msgfailoutputstatfile "$2" "$3"
1322 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1323 shift 3
1324 msgfailoutputstatfile "$2" "$3"
1325 done
1326 echo '#### test output ####'
1327 fi
1328 cat >&2 $OUTPUT
1329 msgfail "$MSG"
1330 }
1331
1332 testsuccess() {
1333 if [ "$1" = '--nomsg' ]; then
1334 shift
1335 else
1336 msgtest 'Test for successful execution of' "$*"
1337 fi
1338 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1339 if "$@" >${OUTPUT} 2>&1; then
1340 if expr match "$1" '^apt.*' >/dev/null; then
1341 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1342 msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
1343 elif grep -q -E '^[WE]: ' "$OUTPUT"; then
1344 msgfailoutput 'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1345 else
1346 msgpass
1347 fi
1348 else
1349 msgpass
1350 fi
1351 else
1352 local EXITCODE=$?
1353 msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
1354 fi
1355 aptautotest 'testsuccess' "$@"
1356 }
1357 testwarning() {
1358 if [ "$1" = '--nomsg' ]; then
1359 shift
1360 else
1361 msgtest 'Test for successful execution with warnings of' "$*"
1362 fi
1363 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1364 if "$@" >${OUTPUT} 2>&1; then
1365 if expr match "$1" '^apt.*' >/dev/null; then
1366 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1367 msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
1368 elif grep -q -E '^E: ' "$OUTPUT"; then
1369 msgfailoutput 'successful run, but output contains errors' "$OUTPUT" "$@"
1370 elif ! grep -q -E '^W: ' "$OUTPUT"; then
1371 msgfailoutput 'successful run, but output contains no warnings' "$OUTPUT" "$@"
1372 else
1373 msgpass
1374 fi
1375 else
1376 msgpass
1377 fi
1378 else
1379 local EXITCODE=$?
1380 echo >&2
1381 cat >&2 $OUTPUT
1382 msgfail "exitcode $EXITCODE"
1383 fi
1384 aptautotest 'testwarning' "$@"
1385 }
1386 testfailure() {
1387 if [ "$1" = '--nomsg' ]; then
1388 shift
1389 else
1390 msgtest 'Test for failure in execution of' "$*"
1391 fi
1392 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1393 if "$@" >${OUTPUT} 2>&1; then
1394 local EXITCODE=$?
1395 msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
1396 else
1397 local EXITCODE=$?
1398 if expr match "$1" '^apt.*' >/dev/null; then
1399 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1400 msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
1401 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1402 msgfailoutput "run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1403 else
1404 msgpass
1405 fi
1406 else
1407 msgpass
1408 fi
1409 fi
1410 aptautotest 'testfailure' "$@"
1411 }
1412
1413 testsuccessequal() {
1414 local CMP="$1"
1415 shift
1416 testsuccess "$@"
1417 testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$CMP"
1418 }
1419 testwarningequal() {
1420 local CMP="$1"
1421 shift
1422 testwarning "$@"
1423 testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" "$CMP"
1424 }
1425 testfailureequal() {
1426 local CMP="$1"
1427 shift
1428 testfailure "$@"
1429 testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" "$CMP"
1430 }
1431
1432 testfailuremsg() {
1433 local CMP="$1"
1434 shift
1435 testfailure "$@"
1436 msgtest 'Check that the output of the previous failed command has expected' 'failures and warnings'
1437 grep '^\(W\|E\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailureequal.output" 2>&1 || true
1438 if echo "$CMP" | checkdiff - "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailureequal.output"; then
1439 msgpass
1440 else
1441 echo '### Complete output ###'
1442 cat "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1443 msgfail
1444 fi
1445 }
1446
1447 testfilestats() {
1448 msgtest "Test that file $1 has $2 $3" "$4"
1449 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
1450 msgpass
1451 else
1452 echo >&2
1453 ls -ld >&2 "$1"
1454 echo -n >&2 "stat(1) reports for $2: "
1455 stat --format "$2" "$1"
1456 msgfail
1457 fi
1458 }
1459 testaccessrights() {
1460 testfilestats "$1" '%a' '=' "$2"
1461 }
1462
1463 testwebserverlaststatuscode() {
1464 local DOWNLOG='rootdir/tmp/webserverstatus-testfile.log'
1465 local STATUS='downloaded/webserverstatus-statusfile.log'
1466 rm -f "$DOWNLOG" "$STATUS"
1467 msgtest 'Test last status code from the webserver was' "$1"
1468 if downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
1469 msgpass
1470 else
1471 echo >&2
1472 if [ -n "$2" ]; then
1473 shift
1474 echo >&2 '#### Additionally provided output files contain:'
1475 cat >&2 "$@"
1476 fi
1477 echo >&2 '#### Download log of the status code:'
1478 cat >&2 "$DOWNLOG"
1479 msgfail "Status was $(cat "$STATUS")"
1480 fi
1481 }
1482
1483 pause() {
1484 echo "STOPPED execution. Press enter to continue"
1485 local IGNORE
1486 read IGNORE
1487 }
1488
1489 listcurrentlistsdirectory() {
1490 {
1491 find rootdir/var/lib/apt/lists -maxdepth 1 -type d | while read line; do
1492 stat --format '%U:%G:%a:%n' "$line"
1493 done
1494 find rootdir/var/lib/apt/lists -maxdepth 1 \! -type d | while read line; do
1495 stat --format '%U:%G:%a:%s:%y:%n' "$line"
1496 done
1497 } | sort
1498 }
1499
1500 ### convinience hacks ###
1501 mkdir() {
1502 # creating some directories by hand is a tedious task, so make it look simple
1503 if [ "$*" = '-p rootdir/var/lib/apt/lists' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" ] ||
1504 [ "$*" = '-p rootdir/var/lib/apt/lists/partial' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" ]; then
1505 # only the last directory created by mkdir is effected by the -m !
1506 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1507 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1508 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1509 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1510 if [ "$(id -u)" = '0' ]; then
1511 chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1512 fi
1513 else
1514 command mkdir "$@"
1515 fi
1516 }
1517
1518 ### The following tests are run by most test methods automatically to check
1519 ### general things about commands executed without writing the test every time.
1520
1521 aptautotest() {
1522 local TESTCALL="$1"
1523 local CMD="$2"
1524 local FIRSTOPT="$3"
1525 local AUTOTEST="aptautotest_$(basename "$CMD" | tr -d '-')_$(echo "$FIRSTOPT" | tr -d '-')"
1526 if command -v $AUTOTEST >/dev/null; then
1527 shift 3
1528 # save and restore the *.output files from other tests
1529 # as we might otherwise override them in these automatic tests
1530 rm -rf ${TMPWORKINGDIRECTORY}/rootdir/tmp-before
1531 mv ${TMPWORKINGDIRECTORY}/rootdir/tmp ${TMPWORKINGDIRECTORY}/rootdir/tmp-before
1532 mkdir ${TMPWORKINGDIRECTORY}/rootdir/tmp
1533 $AUTOTEST "$TESTCALL" "$@"
1534 rm -rf ${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest
1535 mv ${TMPWORKINGDIRECTORY}/rootdir/tmp ${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest
1536 mv ${TMPWORKINGDIRECTORY}/rootdir/tmp-before ${TMPWORKINGDIRECTORY}/rootdir/tmp
1537 fi
1538 }
1539
1540 aptautotest_aptget_update() {
1541 local TESTCALL="$1"
1542 while [ -n "$2" ]; do
1543 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1544 shift
1545 done
1546 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1547 testfilestats "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1548 testfilestats "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1549 # all copied files are properly chmodded
1550 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
1551 testfilestats "$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
1552 done
1553 if [ "$TESTCALL" = 'testsuccess' ]; then
1554 # failure cases can retain partial files and such
1555 testempty find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \( -name 'lock' -o -name '*.FAILED' \)
1556 fi
1557 }
1558 aptautotest_apt_update() { aptautotest_aptget_update "$@"; }
1559 aptautotest_aptcdrom_add() { aptautotest_aptget_update "$@"; }
1560
1561 testaptautotestnodpkgwarning() {
1562 local TESTCALL="$1"
1563 while [ -n "$2" ]; do
1564 if expr match "$2" '^-[a-z]*s' >/dev/null 2>&1; then return; fi # simulation mode
1565 if expr match "$2" '^-dy\?' >/dev/null 2>&1; then return; fi # download-only mode
1566 shift
1567 done
1568 testfailure grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1569 }
1570
1571 aptautotest_aptget_install() { testaptautotestnodpkgwarning "$@"; }
1572 aptautotest_aptget_remove() { testaptautotestnodpkgwarning "$@"; }
1573 aptautotest_aptget_purge() { testaptautotestnodpkgwarning "$@"; }
1574 aptautotest_apt_install() { testaptautotestnodpkgwarning "$@"; }
1575 aptautotest_apt_remove() { testaptautotestnodpkgwarning "$@"; }
1576 aptautotest_apt_purge() { testaptautotestnodpkgwarning "$@"; }