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