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