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