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