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