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