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