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