]> git.saurik.com Git - apt.git/blame - test/integration/framework
use clock() as source for SRV randomness
[apt.git] / test / integration / framework
CommitLineData
8d876415
DK
1#!/bin/sh -- # no runable script, just for vi
2
5d76cee1 3EXIT_CODE=0
8c1dd12c 4
68042532
DK
5while [ -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 else
13 echo >&2 "WARNING: Unknown parameter »$1« will be ignored"
14 fi
15 shift
16done
17export MSGLEVEL="${MSGLEVEL:-3}"
18
8d876415 19# we all like colorful messages
a09f6eb8 20if [ "$MSGCOLOR" != 'NO' ] && [ "$MSGCOLOR" != 'ALWAYS' ]; then
27cb4f6c 21 if [ ! -t 1 ]; then # but check that we output to a terminal
1290422a
DK
22 export MSGCOLOR='NO'
23 fi
24fi
25
26
27if [ "$MSGCOLOR" != 'NO' ]; then
28 CERROR="\033[1;31m" # red
29 CWARNING="\033[1;33m" # yellow
30 CMSG="\033[1;32m" # green
31 CINFO="\033[1;96m" # light blue
32 CDEBUG="\033[1;94m" # blue
33 CNORMAL="\033[0;39m" # default system console color
34 CDONE="\033[1;32m" # green
35 CPASS="\033[1;32m" # green
36 CFAIL="\033[1;31m" # red
37 CCMD="\033[1;35m" # pink
682a3bf7 38fi
8d876415 39
de81b2e2
DK
40msgprintf() {
41 local START="$1"
42 local MIDDLE="$2"
43 local END="$3"
44 shift 3
45 if [ -n "$1" ]; then
46 printf "$START " "$1"
d73840dc 47 shift
de81b2e2 48 while [ -n "$1" ]; do
03aa0847 49 printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghs]\)#apt-\1#')"
de81b2e2
DK
50 shift
51 done
52 fi
53 printf "${END}"
2a2a7ef4 54}
de81b2e2
DK
55msgdie() { msgprintf "${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; }
56msgwarn() { msgprintf "${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; }
57msgmsg() { msgprintf "${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; }
58msginfo() { msgprintf "${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; }
59msgdebug() { msgprintf "${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; }
60msgdone() { msgprintf "${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; }
61msgnwarn() { msgprintf "${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; }
62msgnmsg() { msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@"; }
63msgninfo() { msgprintf "${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
64msgndebug() { msgprintf "${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
65msgtest() { msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
3c528b91 66msgpass() { printf "${CPASS}PASS${CNORMAL}\n"; }
68ba0b7f 67msgskip() {
68042532
DK
68 if [ -n "$MSGTEST_MSG" ]; then
69 echo -n "$MSGTEST_MSG"
70 unset MSGTEST_MSG
71 fi
68ba0b7f
DK
72 if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
73 else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
74}
5229b285 75msgfail() {
68042532 76 if [ -n "$MSGTEST_MSG" ]; then
9beb11aa
DK
77 if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then
78 echo "Part of the test group: $MSGTEST_GRP"
79 fi
68042532
DK
80 echo -n "$MSGTEST_MSG"
81 unset MSGTEST_MSG
82 fi
83 if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
3c528b91 84 else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
03aa0847
DK
85 if [ -n "$APT_DEBUG_TESTS" ]; then
86 $SHELL
87 fi
5229b285
DK
88 EXIT_CODE=$((EXIT_CODE+1));
89}
9beb11aa
DK
90MSGGROUP_LEVEL=0
91msggroup() {
92 if [ -n "$1" ]; then
93 if [ $MSGGROUP_LEVEL = 0 ]; then
94 MSGTEST_GRP='NEXT'
95 fi
96 MSGGROUP_LEVEL=$((MSGGROUP_LEVEL+1));
97 else
98 MSGGROUP_LEVEL=$((MSGGROUP_LEVEL-1));
99 if [ $MSGGROUP_LEVEL = 0 ]; then
100 unset MSGTEST_GRP
101 fi
102 fi
103}
8d876415
DK
104
105# enable / disable Debugging
fc89263e
DK
106if [ $MSGLEVEL -le 0 ]; then
107 msgdie() { true; }
108fi
109if [ $MSGLEVEL -le 1 ]; then
110 msgwarn() { true; }
111 msgnwarn() { true; }
112fi
113if [ $MSGLEVEL -le 2 ]; then
114 msgmsg() { true; }
115 msgnmsg() { true; }
9beb11aa
DK
116 msgtest() {
117 MSGTEST_MSG="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")"
118 if [ "$MSGTEST_GRP" = 'NEXT' ]; then
119 MSGTEST_GRP="$MSGTEST_MSG"
120 fi
121 }
3c528b91 122 msgpass() { printf " ${CPASS}P${CNORMAL}"; }
fc89263e
DK
123fi
124if [ $MSGLEVEL -le 3 ]; then
125 msginfo() { true; }
126 msgninfo() { true; }
127fi
128if [ $MSGLEVEL -le 4 ]; then
129 msgdebug() { true; }
130 msgndebug() { true; }
131fi
132msgdone() {
133 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
134 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
135 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
136 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
137 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
138 true;
139 else
3c528b91 140 printf "${CDONE}DONE${CNORMAL}\n";
fc89263e
DK
141 fi
142}
e43a426e
MV
143getaptconfig() {
144 if [ -f ./aptconfig.conf ]; then
5465192b 145 echo "$(readlink -f ./aptconfig.conf)"
e43a426e 146 elif [ -f ../aptconfig.conf ]; then
5465192b
DK
147 echo "$(readlink -f ../aptconfig.conf)"
148 elif [ -f ../../aptconfig.conf ]; then
149 echo "$(readlink -f ../../aptconfig.conf)"
150 elif [ -f "${TMPWORKINGDIRECTORY}/aptconfig.conf" ]; then
151 echo "$(readlink -f "${TMPWORKINGDIRECTORY}/aptconfig.conf")"
152 fi
e43a426e 153}
8d876415
DK
154runapt() {
155 msgdebug "Executing: ${CCMD}$*${CDEBUG} "
846856f4
DK
156 local CMD="$1"
157 shift
3b8eb3bc 158 case $CMD in
a311fb96 159 sh|aptitude|*/*|command) ;;
3b8eb3bc
DK
160 *) CMD="${BUILDDIRECTORY}/$CMD";;
161 esac
a311fb96 162 MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH=${LIBRARYPATH} $CMD "$@"
8d876415 163}
846856f4
DK
164aptconfig() { runapt apt-config "$@"; }
165aptcache() { runapt apt-cache "$@"; }
166aptcdrom() { runapt apt-cdrom "$@"; }
167aptget() { runapt apt-get "$@"; }
168aptftparchive() { runapt apt-ftparchive "$@"; }
169aptkey() { runapt apt-key "$@"; }
170aptmark() { runapt apt-mark "$@"; }
4f6d26b4 171aptsortpkgs() { runapt apt-sortpkgs "$@"; }
796673c3 172apt() { runapt apt "$@"; }
3b8eb3bc
DK
173apthelper() { runapt "${APTHELPERBINDIR}/apt-helper" "$@"; }
174aptwebserver() { runapt "${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
175aptitude() { runapt aptitude "$@"; }
8d50b63f 176aptextracttemplates() { runapt apt-extracttemplates "$@"; }
3082603f 177aptinternalsolver() { runapt "${APTINTERNALSOLVER}" "$@"; }
ad7e0941 178aptdumpsolver() { runapt "${APTDUMPSOLVER}" "$@"; }
3b8eb3bc 179
158fda31 180dpkg() {
b0be0e09 181 "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@"
158fda31 182}
ce7f128c
DK
183dpkgcheckbuilddeps() {
184 command dpkg-checkbuilddeps --admindir=${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg "$@"
b6b5a542 185}
3fa950f1 186gdb() {
b07aeb1a
DK
187 local CMD
188 case "$1" in
189 aptget) CMD="apt-get";;
190 aptcache) CMD="apt-cache";;
5465192b
DK
191 aptcdrom) CMD="apt-cdrom";;
192 aptconfig) CMD="apt-config";;
b07aeb1a
DK
193 aptmark) CMD="apt-mark";;
194 apthelper) CMD="apt-helper";;
3d8232bf 195 aptftparchive) CMD="apt-ftparchive";;
b07aeb1a
DK
196 *) CMD="$1";;
197 esac
ce928105 198 shift
a311fb96 199 runapt command gdb --quiet -ex run "${BUILDDIRECTORY}/$CMD" --args "${BUILDDIRECTORY}/$CMD" "$@"
ae99ce2e 200}
8d876415 201
8c1dd12c 202exitwithstatus() {
f91bd741
MV
203 # error if we about to overflow, but ...
204 # "255 failures ought to be enough for everybody"
5d76cee1
MV
205 if [ $EXIT_CODE -gt 255 ]; then
206 msgdie "Total failure count $EXIT_CODE too big"
f91bd741 207 fi
5d76cee1 208 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
8c1dd12c
MV
209}
210
804d4a0d
DK
211shellsetedetector() {
212 local exit_status=$?
213 if [ "$exit_status" != '0' ]; then
3c528b91 214 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
804d4a0d
DK
215 if [ "$EXIT_CODE" = '0' ]; then
216 EXIT_CODE="$exit_status"
217 fi
218 fi
219}
220
b720d0bd 221addtrap() {
8437b7d4
DK
222 if [ "$1" = 'prefix' ]; then
223 CURRENTTRAP="$2 $CURRENTTRAP"
224 else
225 CURRENTTRAP="$CURRENTTRAP $1"
226 fi
804d4a0d 227 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
b720d0bd 228}
8d876415
DK
229
230setupenvironment() {
0d303f17
DK
231 # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
232 if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
233 unset TMPDIR
234 fi
75954ae2 235 TMPWORKINGDIRECTORY=$(mktemp -d)
5684f71f 236 addtrap "cd /; rm -rf $TMPWORKINGDIRECTORY;"
68042532 237 msgninfo "Preparing environment for $(basename $0) in ${TMPWORKINGDIRECTORY}…"
5c0dd6fc 238
03aa0847 239 mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
68ba0b7f
DK
240 if [ "$(id -u)" = '0' ]; then
241 # relax permissions so that running as root with user switching works
242 umask 022
03aa0847
DK
243 chmod 711 "$TMPWORKINGDIRECTORY"
244 chown _apt:root "${TMPWORKINGDIRECTORY}/downloaded"
68ba0b7f
DK
245 fi
246
5684f71f 247 TESTDIRECTORY=$(readlink -f $(dirname $0))
5c0dd6fc 248 # allow overriding the default BUILDDIR location
e8fb1cdf 249 SOURCEDIRECTORY=${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}
5c0dd6fc 250 BUILDDIRECTORY=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
3b8eb3bc 251 LIBRARYPATH=${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}
5c0dd6fc 252 METHODSDIR=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
e43a426e 253 APTHELPERBINDIR=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}
c035b655 254 APTWEBSERVERBINDIR=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
3082603f 255 APTINTERNALSOLVER=${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}
ad7e0941 256 APTDUMPSOLVER=${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}
8d876415 257 test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
5c0dd6fc
MV
258 # -----
259
8d876415 260 cd $TMPWORKINGDIRECTORY
cd725954 261 mkdir rootdir aptarchive keys
8d876415 262 cd rootdir
b29c3712 263 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
8fe964f1 264 mkdir -p usr/bin var/cache var/lib var/log tmp
cffea9af 265 mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
cd725954 266 touch var/lib/dpkg/available
8d876415 267 mkdir -p usr/lib/apt
9082a1fc 268 ln -s ${METHODSDIR} usr/lib/apt/methods
1f6cf9e7
DK
269 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
270 mkdir -p usr/lib/apt/solvers
271 ln -s "${BUILDDIRECTORY}/apt-dump-solver" usr/lib/apt/solvers/dump
272 ln -s "${BUILDDIRECTORY}/apt-internal-solver" usr/lib/apt/solvers/apt
273 echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" > etc/apt/apt.conf.d/externalsolver.conf
274 fi
291a386f
MV
275 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
276 # system
277 if [ -e ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove ]; then
278 ln -s ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove etc/apt/apt.conf.d/01autoremove
279 else
280 ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
281 fi
8d876415 282 cd ..
2c6baa5a 283 local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
53ea1b56
DK
284 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
285 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
8f8169ac 286 fi
4a4ea26c 287 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
53ea1b56
DK
288 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
289 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
8f8169ac 290 fi
53ea1b56 291 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys/
5684f71f 292 chmod 644 $(find keys -name '*.pub' -o -name '*.sec')
cd725954 293 ln -s ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
d6cf2345 294
cffea9af 295 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
94eb3bee 296 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
8d876415 297 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
9d2a8a73 298 echo "Dir::Bin::Methods \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/methods\";" >> aptconfig.conf
68ba0b7f
DK
299 # store apt-key were we can access it, even if we run it as a different user
300 # destroys coverage reporting though, so just do it for root for now
301 if [ "$(id -u)" = '0' ]; then
302 cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
303 chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
304 echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
305 else
306 echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
307 fi
b0be0e09 308
d61960d9 309 cat << EOF > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg"
b0be0e09
DK
310#!/bin/sh
311set -e
312if [ -r "${TMPWORKINGDIRECTORY}/noopchroot.so" ]; then
313 if [ -n "\$LD_PRELOAD" ]; then
314 export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so \${LD_PRELOAD}"
315 else
316 export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so"
317 fi
318fi
319exec fakeroot dpkg --root="${TMPWORKINGDIRECTORY}/rootdir" \\
320 --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log \\
321 --force-not-root --force-bad-path "\$@"
322EOF
b0be0e09
DK
323 chmod +x "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg"
324 echo "Dir::Bin::dpkg \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg\";" > rootdir/etc/apt/apt.conf.d/99dpkg
325
533fe3d1
DK
326 {
327 if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
328 echo "DPKG::options:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
329 fi
330 echo 'quiet::NoUpdate "true";'
331 echo 'quiet::NoStatistic "true";'
332 # too distracting for users, but helpful to detect changes
333 echo 'Acquire::Progress::Ignore::ShowErrorText "true";'
334 echo 'Acquire::Progress::Diffpercent "true";'
335 # in testcases, it can appear as if localhost has a rotation setup,
336 # hide this as we can't really deal with it properly
337 echo 'Acquire::Failure::ShowIP "false";'
338 } >> aptconfig.conf
d6cf2345 339
68ba0b7f
DK
340 cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
341 if [ "$(id -u)" = '0' ]; then
342 chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
343 fi
344 echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir/etc/apt/apt.conf.d/99https
d6cf2345 345 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
276e51dd 346 configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
77a45beb 347
4bb006d1
DK
348 # create some files in /tmp and look at user/group to get what this means
349 TEST_DEFAULT_USER="$USER"
350 if [ "$(uname)" = 'GNU/kFreeBSD' ]; then
351 TEST_DEFAULT_GROUP='root'
352 else
353 TEST_DEFAULT_GROUP="$USER"
354 fi
355
d4f4bcf7
MV
356 # Acquire::AllowInsecureRepositories=false is not yet the default
357 # but we want it to be the default soon
358 configallowinsecurerepositories "false";
359
ce7f128c 360 # cleanup the environment a bit
8c617819
MV
361 # prefer our apt binaries over the system apt binaries
362 export PATH="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
be233796 363 export LC_ALL=C.UTF-8
3b8eb3bc 364 unset LANGUAGE APT_CONFIG
ce7f128c 365 unset GREP_OPTIONS DEB_BUILD_PROFILES
8d876415
DK
366 msgdone "info"
367}
368
ea65d079
DK
369getarchitecture() {
370 if [ "$1" = "native" -o -z "$1" ]; then
371 eval `aptconfig shell ARCH APT::Architecture`
372 if [ -n "$ARCH" ]; then
373 echo $ARCH
374 else
5834d7a1 375 dpkg --print-architecture
ea65d079
DK
376 fi
377 else
378 echo $1
379 fi
380}
381
53ea1b56 382getarchitectures() {
081c9d44 383 aptconfig dump --no-empty --format '%v%n' APT::Architecture APT::Architectures | sort -u | tr '\n' ' '
53ea1b56
DK
384}
385
3dcdc1f9
DK
386getarchitecturesfromcommalist() {
387 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
388}
389
8d876415 390configarchitecture() {
18908589
DK
391 {
392 echo "APT::Architecture \"$(getarchitecture $1)\";"
393 while [ -n "$1" ]; do
394 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
395 shift
396 done
397 } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
53ea1b56
DK
398 configdpkg
399}
400
401configdpkg() {
402 if [ ! -e rootdir/var/lib/dpkg/status ]; then
403 local STATUSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
404 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
405 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
406 else
407 echo -n > rootdir/var/lib/dpkg/status
408 fi
409 fi
18908589 410 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
846856f4 411 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
53ea1b56
DK
412 local ARCHS="$(getarchitectures)"
413 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
414 DPKGARCH="$(dpkg --print-architecture)"
415 for ARCH in ${ARCHS}; do
feae193b 416 if [ "${ARCH}" != "${DPKGARCH}" ]; then
18908589 417 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
feae193b 418 # old-style used e.g. in Ubuntu-P – and as it seems travis
18908589
DK
419 echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
420 echo "DPKG::options:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
feae193b
DK
421 fi
422 fi
53ea1b56
DK
423 done
424 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
05343a22
DK
425 # dpkg doesn't really check the version as long as it is fully installed,
426 # but just to be sure we choose one above the required version
427 insertinstalledpackage 'dpkg' "all" '1.16.2+fake'
53ea1b56
DK
428 fi
429 fi
430 fi
8d876415
DK
431}
432
0c787570
DK
433configdpkgnoopchroot() {
434 # create a library to noop chroot() and rewrite maintainer script executions
435 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
436 # chroot directory dpkg could chroot into to execute the maintainer scripts
437 msgtest 'Building library to preload to make maintainerscript work in' 'dpkg'
438 cat << EOF > noopchroot.c
439#define _GNU_SOURCE
440#include <stdio.h>
441#include <stdlib.h>
442#include <string.h>
443#include <dlfcn.h>
444
445static char * chrootdir = NULL;
446
447int chroot(const char *path) {
448 printf("WARNING: CHROOTing to %s was ignored!\n", path);
449 free(chrootdir);
450 chrootdir = strdup(path);
451 return 0;
452}
453int execvp(const char *file, char *const argv[]) {
454 static int (*func_execvp) (const char *, char * const []) = NULL;
455 if (func_execvp == NULL)
456 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp");
457 if (chrootdir == NULL || strncmp(file, "/var/lib/dpkg/", strlen("/var/lib/dpkg/")) != 0)
458 return func_execvp(file, argv);
459 printf("REWRITE execvp call %s into %s\n", file, chrootdir);
460 char newfile[strlen(chrootdir) + strlen(file)];
461 strcpy(newfile, chrootdir);
462 strcat(newfile, file);
b0be0e09
DK
463 char const * const baseadmindir = "/var/lib/dpkg";
464 char admindir[strlen(chrootdir) + strlen(baseadmindir)];
465 strcpy(admindir, chrootdir);
466 strcat(admindir, baseadmindir);
467 setenv("DPKG_ADMINDIR", admindir, 1);
0c787570
DK
468 return func_execvp(newfile, argv);
469}
470EOF
471 testsuccess --nomsg gcc -fPIC -shared -o noopchroot.so noopchroot.c -ldl
0c787570
DK
472}
473
d4f4bcf7
MV
474configallowinsecurerepositories() {
475 echo "Acquire::AllowInsecureRepositories \"$1\";" > rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf
476
477}
478
276e51dd
DK
479configcompression() {
480 while [ -n "$1" ]; do
481 case "$1" in
3c528b91
MO
482 '.') printf ".\t.\tcat\n";;
483 'gz') printf "gzip\tgz\tgzip\n";;
484 'bz2') printf "bzip2\tbz2\tbzip2\n";;
485 'lzma') printf "lzma\tlzma\txz --format=lzma\n";;
486 'xz') printf "xz\txz\txz\n";;
487 *) printf "$1\t$1\t$1\n";;
276e51dd
DK
488 esac
489 shift
490 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
491}
492
5f982b9d
DK
493forcecompressor() {
494 COMPRESSOR="$1"
495 COMPRESSOR_CMD="$1"
496 case $COMPRESSOR in
497 gzip) COMPRESS='gz';;
498 bzip2) COMPRESS='bz2';;
499 lzma) COMPRESS='lzma';;
500 xz) COMPRESS='xz';;
501 *) msgdie "Compressor $COMPRESSOR is unknown to framework, so can't be forced by forcecompressor!";;
502 esac
503 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
504 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
505Dir::Bin::uncompressed \"/does/not/exist\";
506Dir::Bin::gzip \"/does/not/exist\";
507Dir::Bin::bzip2 \"/does/not/exist\";
508Dir::Bin::lzma \"/does/not/exist\";
509Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
510 if [ -e "/bin/${COMPRESSOR}" ]; then
511 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
512 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
513 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
514 elif [ "${COMPRESSOR}" = 'lzma' ]; then
515 echo 'Dir::Bin::xz "/usr/bin/xz";' >> "$CONFFILE"
516 COMPRESSOR_CMD='xz --format=lzma'
517 else
518 msgtest 'Test for availability of compressor' "${COMPRESSOR}"
68042532 519 msgfail "${COMPRESSOR} not available"
5f982b9d
DK
520 fi
521}
522
75954ae2 523setupsimplenativepackage() {
ce9864a8
DK
524 local NAME="$1"
525 local ARCH="$2"
526 local VERSION="$3"
527 local RELEASE="${4:-unstable}"
528 local DEPENDENCIES="$5"
14109555 529 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
18908589
DK
530 If you find such a package installed on your system,
531 something went horribly wrong! They are autogenerated
532 und used only by testcases and surf no other propose…"}"
533
b7899b00
DK
534 local SECTION="${7:-others}"
535 local DISTSECTION
536 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
537 DISTSECTION="main"
538 else
539 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
540 fi
ce9864a8
DK
541 local BUILDDIR=incoming/${NAME}-${VERSION}
542 mkdir -p ${BUILDDIR}/debian/source
543 cd ${BUILDDIR}
544 echo "* most suckless software product ever" > FEATURES
b7899b00
DK
545 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
546 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
ce9864a8
DK
547
548 * Initial release
549
b7899b00
DK
550 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
551 test -e debian/control || echo "Source: $NAME
552Section: $SECTION
ce9864a8
DK
553Priority: optional
554Maintainer: Joe Sixpack <joe@example.org>
555Build-Depends: debhelper (>= 7)
556Standards-Version: 3.9.1
557
875bcb36
DK
558Package: $NAME" > debian/control
559 if [ "$ARCH" = 'all' ]; then
560 echo "Architecture: all" >> debian/control
561 else
562 echo "Architecture: any" >> debian/control
563 fi
ce9864a8 564 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
18908589
DK
565 echo "Description: $DESCRIPTION" >> debian/control
566
b7899b00
DK
567 test -e debian/compat || echo "7" > debian/compat
568 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
ce9864a8 569 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
75954ae2
DK
570 cd - > /dev/null
571}
572
573buildsimplenativepackage() {
574 local NAME="$1"
d56e2917
DK
575 local NM
576 if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then
577 NM="$(echo "$NAME" | cut -c 1-4)"
578 else
579 NM="$(echo "$NAME" | cut -c 1)"
580 fi
75954ae2
DK
581 local ARCH="$2"
582 local VERSION="$3"
583 local RELEASE="${4:-unstable}"
584 local DEPENDENCIES="$5"
14109555 585 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
18908589
DK
586 If you find such a package installed on your system,
587 something went horribly wrong! They are autogenerated
588 und used only by testcases and surf no other propose…"}"
589
75954ae2 590 local SECTION="${7:-others}"
d67004e0 591 local PRIORITY="${8:-optional}"
42c1513b 592 local FILE_TREE="$9"
adff049d 593 local COMPRESS_TYPE="${10:-gzip}"
75954ae2
DK
594 local DISTSECTION
595 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
596 DISTSECTION="main"
597 else
598 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
599 fi
5a635ee4 600 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
b761356f 601
0c787570 602 msgtest "Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME"
b761356f
DK
603 mkdir -p $BUILDDIR/debian/source
604 echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
605 echo "#!/bin/sh
606echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
607
608 echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
609 echo "$NAME ($VERSION) $RELEASE; urgency=low
610
611 * Initial release
612
613 -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
614 echo "Source: $NAME
d67004e0 615Priority: $PRIORITY
b761356f 616Maintainer: Joe Sixpack <joe@example.org>
01f520ce 617Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
3cbeed98
DK
618 if [ "$SECTION" != '<none>' ]; then
619 echo "Section: $SECTION" >> ${BUILDDIR}/debian/control
620 fi
01f520ce
DK
621 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
622 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
623 echo "
624Package: $NAME" >> ${BUILDDIR}/debian/control
b761356f 625
875bcb36
DK
626 if [ "$ARCH" = 'all' ]; then
627 echo "Architecture: all" >> ${BUILDDIR}/debian/control
628 else
629 echo "Architecture: any" >> ${BUILDDIR}/debian/control
630 fi
01f520ce
DK
631 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
632 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
18908589 633 echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
01f520ce 634
b761356f 635 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
0c787570
DK
636 cd ${BUILDDIR}/..
637 testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION}
638 cd - >/dev/null
639 sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' ${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output \
f1828b69 640 | while read SRC; do
5a635ee4 641 echo "pool/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
f1828b69 642# if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
33a22672 643# aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
bd7fb5aa 644# adv --yes --default-key 'Joe Sixpack' \
f1828b69
DK
645# --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
646# mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
647# fi
b761356f 648 done
84aa13f4 649
3dcdc1f9 650 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
0c787570 651 msgtest "Build binary package for ${RELEASE} in ${SECTION}" "$NAME"
84aa13f4
DK
652 rm -rf ${BUILDDIR}/debian/tmp
653 mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
654 cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}
655 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}
42c1513b
MV
656 if [ -n "$FILE_TREE" ]; then
657 cp -ar "$FILE_TREE" ${BUILDDIR}/debian/tmp
658 fi
42c1513b 659
84aa13f4
DK
660 (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch)
661 (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
846856f4 662 local LOG="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
d56e2917 663 # ensure the right permissions as dpkg-deb insists
eb9dee96 664 chmod 755 ${BUILDDIR}/debian/tmp/DEBIAN
0c787570 665 testsuccess --nomsg dpkg-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/..
84aa13f4
DK
666 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist
667 done
668
d56e2917
DK
669 local CHANGEPATH="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}"
670 mkdir -p $CHANGEPATH
671 cp ${BUILDDIR}/debian/changelog $CHANGEPATH
5a635ee4 672 rm -rf "${BUILDDIR}"
b761356f 673 msgdone "info"
75954ae2
DK
674}
675
676buildpackage() {
677 local BUILDDIR=$1
678 local RELEASE=$2
679 local SECTION=$3
ea65d079 680 local ARCH=$(getarchitecture $4)
846856f4
DK
681 local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
682 local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
0c787570 683 msgtest "Build package for ${RELEASE} in ${SECTION}" "$PKGNAME"
75954ae2
DK
684 cd $BUILDDIR
685 if [ "$ARCH" = "all" ]; then
686 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
687 fi
0c787570
DK
688 testsuccess --nomsg dpkg-buildpackage -uc -us -a$ARCH
689 cp ${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output $BUILDLOG
846856f4
DK
690 local PKGS="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
691 local SRCS="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
ce9864a8 692 cd - > /dev/null
b7899b00 693 for PKG in $PKGS; do
75954ae2 694 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist
b7899b00
DK
695 done
696 for SRC in $SRCS; do
75954ae2 697 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist
b7899b00 698 done
ce9864a8
DK
699}
700
701buildaptarchive() {
ce9864a8 702 if [ -d incoming ]; then
846856f4 703 buildaptarchivefromincoming "$@"
ce9864a8 704 else
846856f4 705 buildaptarchivefromfiles "$@"
ce9864a8
DK
706 fi
707}
708
709createaptftparchiveconfig() {
276e51dd 710 local COMPRESSORS="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
016bea82
DK
711 local COMPRESSORS="${COMPRESSORS%* }"
712 local ARCHS="$(getarchitectures)"
ce9864a8
DK
713 echo -n 'Dir {
714 ArchiveDir "' >> ftparchive.conf
715 echo -n $(readlink -f .) >> ftparchive.conf
716 echo -n '";
717 CacheDir "' >> ftparchive.conf
718 echo -n $(readlink -f ..) >> ftparchive.conf
719 echo -n '";
b7899b00
DK
720 FileListDir "' >> ftparchive.conf
721 echo -n $(readlink -f pool/) >> ftparchive.conf
722 echo -n '";
723};
724Default {
276e51dd
DK
725 Packages::Compress "'"$COMPRESSORS"'";
726 Sources::Compress "'"$COMPRESSORS"'";
727 Contents::Compress "'"$COMPRESSORS"'";
728 Translation::Compress "'"$COMPRESSORS"'";
18331adf 729 LongDescription "false";
ce9864a8
DK
730};
731TreeDefault {
732 Directory "pool/";
733 SrcDirectory "pool/";
734};
735APT {
736 FTPArchive {
737 Release {
738 Origin "joesixpack";
739 Label "apttestcases";
740 Suite "unstable";
741 Description "repository with dummy packages";
742 Architectures "' >> ftparchive.conf
743 echo -n "$ARCHS" >> ftparchive.conf
744 echo 'source";
745 };
746 };
747};' >> ftparchive.conf
b7899b00
DK
748 for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
749 echo -n 'tree "dists/' >> ftparchive.conf
750 echo -n "$DIST" >> ftparchive.conf
751 echo -n '" {
ce9864a8
DK
752 Architectures "' >> ftparchive.conf
753 echo -n "$ARCHS" >> ftparchive.conf
b7899b00
DK
754 echo -n 'source";
755 FileList "' >> ftparchive.conf
756 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
757 echo -n '";
758 SourceFileList "' >> ftparchive.conf
759 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
760 echo -n '";
761 Sections "' >> ftparchive.conf
762 echo -n "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')" >> ftparchive.conf
763 echo '";
ce9864a8 764};' >> ftparchive.conf
b7899b00 765 done
ce9864a8
DK
766}
767
768buildaptftparchivedirectorystructure() {
b7899b00
DK
769 local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
770 for DIST in $DISTS; do
771 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
772 for SECTION in $SECTIONS; do
773 local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
774 for ARCH in $ARCHS; do
775 mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH}
776 done
777 mkdir -p dists/${DIST}/${SECTION}/source
778 mkdir -p dists/${DIST}/${SECTION}/i18n
779 done
ce9864a8 780 done
ce9864a8
DK
781}
782
9b78cda6 783insertpackage() {
10e100e5 784 local RELEASES="$1"
9b78cda6
DK
785 local NAME="$2"
786 local ARCH="$3"
787 local VERSION="$4"
788 local DEPENDENCIES="$5"
d67004e0 789 local PRIORITY="${6:-optional}"
10e100e5 790 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES}
18908589
DK
791 If you find such a package installed on your system,
792 something went horribly wrong! They are autogenerated
793 und used only by testcases and surf no other propose…"}"
d67004e0 794 local ARCHS=""
10e100e5
DK
795 for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
796 if [ "$RELEASE" = 'installed' ]; then
797 insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7"
798 continue
d67004e0 799 fi
10e100e5
DK
800 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
801 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
802 ARCHS="$(getarchitectures)"
803 else
804 ARCHS="$arch"
805 fi
806 for BUILDARCH in $ARCHS; do
807 local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
808 mkdir -p $PPATH
809 local FILE="${PPATH}/Packages"
810 echo "Package: $NAME
d67004e0 811Priority: $PRIORITY
9b78cda6 812Section: other
2c085486 813Installed-Size: 42
c919ad6e 814Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
10e100e5
DK
815 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
816 echo "Version: $VERSION
d67004e0 817Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
10e100e5
DK
818 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
819 echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)" >> $FILE
820 echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)" >> $FILE
821 echo >> $FILE
822 done
d67004e0 823 done
10e100e5
DK
824 mkdir -p aptarchive/dists/${RELEASE}/main/source aptarchive/dists/${RELEASE}/main/i18n
825 touch aptarchive/dists/${RELEASE}/main/source/Sources
826 echo "Package: $NAME
0e0d9919
DK
827Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)
828Description-en: $DESCRIPTION
829" >> aptarchive/dists/${RELEASE}/main/i18n/Translation-en
10e100e5 830 done
9b78cda6
DK
831}
832
234675b7
DK
833insertsource() {
834 local RELEASE="$1"
835 local NAME="$2"
836 local ARCH="$3"
837 local VERSION="$4"
838 local DEPENDENCIES="$5"
a8275acf 839 local BINARY="${6:-$NAME}"
234675b7
DK
840 local ARCHS=""
841 local SPATH="aptarchive/dists/${RELEASE}/main/source"
842 mkdir -p $SPATH
843 local FILE="${SPATH}/Sources"
9d2a8a73
DK
844 local DSCFILE="${NAME}_${VERSION}.dsc"
845 local TARFILE="${NAME}_${VERSION}.tar.gz"
234675b7 846 echo "Package: $NAME
a8275acf 847Binary: $BINARY
234675b7
DK
848Version: $VERSION
849Maintainer: Joe Sixpack <joe@example.org>
850Architecture: $ARCH" >> $FILE
851 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
852 echo "Files:
9d2a8a73
DK
853 $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) $DSCFILE
854 $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) $TARFILE
55ae7a51
MV
855Checksums-Sha256:
856 $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) $DSCFILE
857 $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) $TARFILE
d5dea0be 858" >> $FILE
234675b7
DK
859}
860
dfc2b1be
DK
861insertinstalledpackage() {
862 local NAME="$1"
863 local ARCH="$2"
864 local VERSION="$3"
865 local DEPENDENCIES="$4"
d67004e0 866 local PRIORITY="${5:-optional}"
d4b4e5ea 867 local STATUS="${6:-install ok installed}"
14109555 868 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
18908589
DK
869 If you find such a package installed on your system,
870 something went horribly wrong! They are autogenerated
871 und used only by testcases and surf no other propose…"}"
872
53ea1b56
DK
873 local FILE='rootdir/var/lib/dpkg/status'
874 local INFO='rootdir/var/lib/dpkg/info'
3dcdc1f9 875 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
d67004e0 876 echo "Package: $NAME
d4b4e5ea 877Status: $STATUS
d67004e0 878Priority: $PRIORITY
dfc2b1be
DK
879Section: other
880Installed-Size: 42
881Maintainer: Joe Sixpack <joe@example.org>
dfc2b1be 882Version: $VERSION" >> $FILE
c919ad6e 883 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
d67004e0 884 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
18908589
DK
885 echo "Description: $DESCRIPTION" >> $FILE
886 echo >> $FILE
53ea1b56
DK
887 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
888 echo -n > ${INFO}/${NAME}:${arch}.list
889 else
890 echo -n > ${INFO}/${NAME}.list
891 fi
d67004e0 892 done
dfc2b1be
DK
893}
894
895
ce9864a8 896buildaptarchivefromincoming() {
3cbbda3c 897 msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
ce9864a8
DK
898 cd aptarchive
899 [ -e pool ] || ln -s ../incoming pool
900 [ -e ftparchive.conf ] || createaptftparchiveconfig
901 [ -e dists ] || buildaptftparchivedirectorystructure
b7899b00 902 msgninfo "\tGenerate Packages, Sources and Contents files… "
31be38d2 903 testsuccess aptftparchive generate ftparchive.conf
ce9864a8
DK
904 cd - > /dev/null
905 msgdone "info"
4dbfe436 906 generatereleasefiles "$@"
ce9864a8
DK
907}
908
909buildaptarchivefromfiles() {
3cbbda3c 910 msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
8d041b4f
DK
911 local DIR='aptarchive'
912 if [ -d "${DIR}/dists" ]; then DIR="${DIR}/dists"; fi
913 find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do
9b78cda6 914 msgninfo "\t${line} file… "
276e51dd 915 compressfile "$line" "$1"
8d876415 916 msgdone "info"
9b78cda6 917 done
e3c62328 918 generatereleasefiles "$@"
9b78cda6
DK
919}
920
276e51dd
DK
921compressfile() {
922 cat ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | while read compressor extension command; do
923 if [ "$compressor" = '.' ]; then
924 if [ -n "$2" ]; then
925 touch -d "$2" "$1"
926 fi
927 continue
928 fi
929 cat "$1" | $command > "${1}.${extension}"
930 if [ -n "$2" ]; then
931 touch -d "$2" "${1}.${extension}"
932 fi
933 done
934}
935
a3bbbab7 936# can be overridden by testcases for their pleasure
bf9e7447
DK
937getcodenamefromsuite() {
938 case "$1" in
939 unstable) echo 'sid';;
940 *) echo -n "$1";;
941 esac
942}
a3bbbab7 943getreleaseversionfromsuite() { true; }
718f797c 944getlabelfromsuite() { true; }
d56e2917 945getoriginfromsuite() { true; }
a3bbbab7 946
9b78cda6 947generatereleasefiles() {
884a4c0a
DK
948 # $1 is the Date header and $2 is the ValidUntil header to be set
949 # both should be given in notation date/touch can understand
9b78cda6
DK
950 msgninfo "\tGenerate Release files… "
951 if [ -e aptarchive/dists ]; then
952 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
a3bbbab7
DK
953 local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
954 local CODENAME="$(getcodenamefromsuite $SUITE)"
955 local VERSION="$(getreleaseversionfromsuite $SUITE)"
718f797c 956 local LABEL="$(getlabelfromsuite $SUITE)"
d56e2917 957 local ORIGIN="$(getoriginfromsuite $SUITE)"
884a4c0a 958 if [ -n "$VERSION" ]; then
718f797c
DK
959 VERSION="-o APT::FTPArchive::Release::Version=${VERSION}"
960 fi
961 if [ -n "$LABEL" ]; then
962 LABEL="-o APT::FTPArchive::Release::Label=${LABEL}"
a3bbbab7 963 fi
d56e2917
DK
964 if [ -n "$ORIGIN" ]; then
965 ORIGIN="-o APT::FTPArchive::Release::Origin=${ORIGIN}"
966 fi
884a4c0a
DK
967 aptftparchive -qq release $dir \
968 -o APT::FTPArchive::Release::Suite="${SUITE}" \
969 -o APT::FTPArchive::Release::Codename="${CODENAME}" \
718f797c 970 ${LABEL} \
d56e2917 971 ${ORIGIN} \
884a4c0a
DK
972 ${VERSION} \
973 | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
a3bbbab7 974 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
35faae11
DK
975 sed -i '/^Date: / a\
976NotAutomatic: yes' $dir/Release
977 fi
884a4c0a
DK
978 if [ -n "$1" -a "$1" != "now" ]; then
979 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
980 fi
981 if [ -n "$2" ]; then
982 sed -i "/^Date: / a\
983Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
984 fi
9b78cda6
DK
985 done
986 else
987 aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
8d876415 988 fi
884a4c0a 989 if [ -n "$1" -a "$1" != "now" ]; then
fe0f7911
DK
990 for release in $(find ./aptarchive -name 'Release'); do
991 touch -d "$1" $release
992 done
8d876415 993 fi
b7899b00 994 msgdone "info"
8d876415
DK
995}
996
b7899b00
DK
997setupdistsaptarchive() {
998 local APTARCHIVE=$(readlink -f ./aptarchive)
999 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
1000 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
1001 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
1002 SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
1003 msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
1004 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
1005 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
1006 msgdone "info"
1007 done
1008}
1009
1010setupflataptarchive() {
ce9864a8 1011 local APTARCHIVE=$(readlink -f ./aptarchive)
8d876415
DK
1012 if [ -f ${APTARCHIVE}/Packages ]; then
1013 msgninfo "\tadd deb sources.list line… "
1014 echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
1015 msgdone "info"
1016 else
1017 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
1018 fi
1019 if [ -f ${APTARCHIVE}/Sources ]; then
1020 msgninfo "\tadd deb-src sources.list line… "
1021 echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
1022 msgdone "info"
1023 else
1024 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
1025 fi
b7899b00
DK
1026}
1027
1028setupaptarchive() {
4dbfe436
DK
1029 local NOUPDATE=0
1030 if [ "$1" = '--no-update' ]; then
1031 NOUPDATE=1
1032 shift
1033 fi
1034 buildaptarchive "$@"
b7899b00
DK
1035 if [ -e aptarchive/dists ]; then
1036 setupdistsaptarchive
1037 else
1038 setupflataptarchive
1039 fi
9d653a6d 1040 signreleasefiles 'Joe Sixpack'
4dbfe436 1041 if [ "1" != "$NOUPDATE" ]; then
5684f71f 1042 testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true
b2ea1a47 1043 fi
8d876415
DK
1044}
1045
f213b6ea
DK
1046signreleasefiles() {
1047 local SIGNER="${1:-Joe Sixpack}"
07cb47e7 1048 local REPODIR="${2:-aptarchive}"
f1e1abd8 1049 local KEY="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
33a22672 1050 local GPG="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
f1e1abd8 1051 msgninfo "\tSign archive with $SIGNER key $KEY… "
29a59c46
DK
1052 local REXKEY='keys/rexexpired'
1053 local SECEXPIREBAK="${REXKEY}.sec.bak"
1054 local PUBEXPIREBAK="${REXKEY}.pub.bak"
1055 if [ "${SIGNER}" = 'Rex Expired' ]; then
1056 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
1057 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
1058 # therefore we 'temporary' make the key not expired and restore a backup after signing
1059 cp ${REXKEY}.sec $SECEXPIREBAK
1060 cp ${REXKEY}.pub $PUBEXPIREBAK
1061 local SECUNEXPIRED="${REXKEY}.sec.unexpired"
1062 local PUBUNEXPIRED="${REXKEY}.pub.unexpired"
1063 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
1064 cp $SECUNEXPIRED ${REXKEY}.sec
1065 cp $PUBUNEXPIRED ${REXKEY}.pub
1066 else
f1e1abd8
DK
1067 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then
1068 cat setexpire.gpg
1069 exit 1
1070 fi
29a59c46
DK
1071 cp ${REXKEY}.sec $SECUNEXPIRED
1072 cp ${REXKEY}.pub $PUBUNEXPIRED
1073 fi
1074 fi
07cb47e7 1075 for RELEASE in $(find ${REPODIR}/ -name Release); do
29a59c46 1076 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg ${RELEASE}
e3c62328 1077 local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
29a59c46 1078 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
e3c62328
DK
1079 # we might have set a specific date for the Release file, so copy it
1080 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg ${INRELEASE}
f213b6ea 1081 done
29a59c46
DK
1082 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
1083 mv -f $SECEXPIREBAK ${REXKEY}.sec
1084 mv -f $PUBEXPIREBAK ${REXKEY}.pub
1085 fi
f213b6ea
DK
1086 msgdone "info"
1087}
1088
8eafc759
DK
1089redatereleasefiles() {
1090 local DATE="$(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
1091 for release in $(find aptarchive/ -name 'Release'); do
1092 sed -i "s/^Date: .*$/Date: ${DATE}/" $release
1093 touch -d "$DATE" $release
1094 done
1095 signreleasefiles "${2:-Joe Sixpack}"
1096}
1097
f2c0ec8b 1098webserverconfig() {
ba6b79bd 1099 local WEBSERVER="${3:-http://localhost:8080}"
b0314abb
DK
1100 local NOCHECK=false
1101 if [ "$1" = '--no-check' ]; then
1102 NOCHECK=true
1103 shift
1104 fi
0d58c26a 1105 local DOWNLOG='rootdir/tmp/download-testfile.log'
b0314abb 1106 local STATUS='downloaded/webserverconfig.status'
0d58c26a 1107 rm -f "$STATUS" "$DOWNLOG"
b0314abb
DK
1108 local URI
1109 if [ -n "$2" ]; then
1110 msgtest "Set webserver config option '${1}' to" "$2"
ba6b79bd 1111 URI="${WEBSERVER}/_config/set/${1}/${2}"
b0314abb
DK
1112 else
1113 msgtest 'Clear webserver config option' "${1}"
ba6b79bd 1114 URI="${WEBSERVER}/_config/clear/${1}"
b0314abb
DK
1115 fi
1116 if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then
f2c0ec8b
DK
1117 msgpass
1118 else
68042532
DK
1119 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.output"
1120 cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true
1121 msgfailoutput '' "$OUTPUT"
f2c0ec8b 1122 fi
b0314abb 1123 $NOCHECK || testwebserverlaststatuscode '200'
f2c0ec8b
DK
1124}
1125
fd46d305
DK
1126rewritesourceslist() {
1127 local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
1128 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
b0314abb 1129 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#https://localhost:4433/#${1}#"
fd46d305
DK
1130 done
1131}
1132
5572f6bd
MV
1133# wait for up to 10s for a pid file to appear to avoid possible race
1134# when a helper is started and dosn't write the PID quick enough
1135waitforpidfile() {
1136 local PIDFILE="$1"
1137 for i in $(seq 10); do
1138 if test -s "$PIDFILE"; then
1139 return 0
1140 fi
1141 sleep 1
1142 done
1143 msgdie "waiting for $PIDFILE failed"
1144 return 1
1145}
1146
f213b6ea 1147changetowebserver() {
23af9f40
DK
1148 if [ "$1" != '--no-rewrite' ]; then
1149 rewritesourceslist 'http://localhost:8080/'
1150 else
1151 shift
1152 fi
5c0dd6fc 1153 if test -x ${APTWEBSERVERBINDIR}/aptwebserver; then
fbd29dd6 1154 cd aptarchive
a0db467c
DK
1155 local LOG="webserver.log"
1156 if ! aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1 ; then
bee0670b
DK
1157 cat $LOG
1158 false
1159 fi
5572f6bd 1160 waitforpidfile aptwebserver.pid
e3c62328
DK
1161 local PID="$(cat aptwebserver.pid)"
1162 if [ -z "$PID" ]; then
1163 msgdie 'Could not fork aptwebserver successfully'
1164 fi
1165 addtrap "kill $PID;"
fbd29dd6 1166 cd - > /dev/null
c5bcc607 1167 else
fbd29dd6 1168 msgdie 'You have to build aptwerbserver or install a webserver'
f213b6ea 1169 fi
fd46d305
DK
1170}
1171
1172changetohttpswebserver() {
1173 if ! which stunnel4 >/dev/null; then
1174 msgdie 'You need to install stunnel4 for https testcases'
1175 fi
1176 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
dc95fee1 1177 changetowebserver --no-rewrite "$@"
fd46d305
DK
1178 fi
1179 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
68ba0b7f 1180cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
23af9f40 1181output = /dev/null
fd46d305
DK
1182
1183[https]
1184accept = 4433
1185connect = 8080
1186" > ${TMPWORKINGDIRECTORY}/stunnel.conf
1187 stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
5572f6bd 1188 waitforpidfile "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
fd46d305 1189 local PID="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
5572f6bd
MV
1190 if [ -z "$PID" ]; then
1191 msgdie 'Could not fork stunnel4 successfully'
1192 fi
fd46d305
DK
1193 addtrap 'prefix' "kill ${PID};"
1194 rewritesourceslist 'https://localhost:4433/'
f213b6ea
DK
1195}
1196
c45233ea
DK
1197changetocdrom() {
1198 mkdir -p rootdir/media/cdrom/.disk
1199 local CD="$(readlink -f rootdir/media/cdrom)"
a0975c8d
DK
1200 echo "acquire::cdrom::mount \"${CD}\";
1201acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
1202acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
1203acquire::cdrom::autodetect 0;" > rootdir/etc/apt/apt.conf.d/00cdrom
c45233ea
DK
1204 echo -n "$1" > ${CD}/.disk/info
1205 if [ ! -d aptarchive/dists ]; then
1206 msgdie 'Flat file archive cdroms can not be created currently'
1207 return 1
1208 fi
a0975c8d 1209 mv aptarchive/dists "$CD"
c45233ea
DK
1210 ln -s "$(readlink -f ./incoming)" $CD/pool
1211 find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete
a0975c8d
DK
1212 # start with an unmounted disk
1213 mv "${CD}" "${CD}-unmounted"
1214 # we don't want the disk to be modifiable
1215 addtrap 'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
b0314abb 1216 chmod -R 555 rootdir/media/cdrom-unmounted/dists
c45233ea
DK
1217}
1218
fd46d305 1219downloadfile() {
ed793a19 1220 local PROTO="${1%%:*}"
27925d82 1221 if ! apthelper -o Debug::Acquire::${PROTO}=1 -o Debug::pkgAcquire::Worker=1 \
dcbb364f 1222 download-file "$1" "$2" "$3" 2>&1 ; then
27925d82
DK
1223 return 1
1224 fi
fd46d305 1225 # only if the file exists the download was successful
b0314abb 1226 if [ -r "$2" ]; then
fd46d305
DK
1227 return 0
1228 else
1229 return 1
1230 fi
1231}
1232
f213b6ea 1233checkdiff() {
03aa0847 1234 local DIFFTEXT="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
8d876415 1235 if [ -n "$DIFFTEXT" ]; then
0d58c26a
DK
1236 echo >&2
1237 echo >&2 "$DIFFTEXT"
8d876415
DK
1238 return 1
1239 else
1240 return 0
1241 fi
1242}
1243
75954ae2 1244testfileequal() {
9beb11aa 1245 msggroup "$0"
e6a12ff7
DK
1246 local MSG='Test for correctness of file'
1247 if [ "$1" = '--nomsg' ]; then
1248 MSG=''
1249 shift
1250 fi
75954ae2
DK
1251 local FILE="$1"
1252 shift
e6a12ff7
DK
1253 if [ -n "$MSG" ]; then
1254 msgtest "$MSG" "$FILE"
1255 fi
68042532 1256 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
75954ae2 1257 if [ -z "$*" ]; then
68042532
DK
1258 if echo -n "" | checkdiff - $FILE >"$OUTPUT" 2>&1; then
1259 msgpass
1260 else
1261 msgfailoutput '' "$OUTPUT"
1262 fi
75954ae2 1263 else
68042532
DK
1264 if echo "$*" | checkdiff - $FILE >"$OUTPUT" 2>&1; then
1265 msgpass
1266 else
1267 msgfailoutput '' "$OUTPUT"
1268 fi
75954ae2 1269 fi
9beb11aa 1270 msggroup
75954ae2
DK
1271}
1272
b855a400 1273testempty() {
9beb11aa 1274 msggroup "$0"
b855a400 1275 msgtest "Test for no output of" "$*"
859093da 1276 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
ab25bf1f 1277 if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
859093da
DK
1278 msgpass
1279 else
68042532 1280 msgfailoutput '' "$COMPAREFILE"
859093da 1281 fi
ab25bf1f 1282 aptautotest 'testempty' "$@"
9beb11aa 1283 msggroup
b855a400
DK
1284}
1285
f74a6fa1 1286testequal() {
9beb11aa 1287 msggroup "$0"
f74a6fa1
DK
1288 local MSG='Test of equality of'
1289 if [ "$1" = '--nomsg' ]; then
1290 MSG=''
1291 shift
1292 fi
1293
03938280 1294 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
8d876415
DK
1295 echo "$1" > $COMPAREFILE
1296 shift
d2d68aaf 1297
f74a6fa1
DK
1298 if [ -n "$MSG" ]; then
1299 msgtest "$MSG" "$*"
1300 fi
68042532
DK
1301 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1302 if "$@" 2>&1 | checkdiff $COMPAREFILE - >"$OUTPUT" 2>&1; then
1303 msgpass
1304 else
1305 msgfailoutput '' "$OUTPUT"
1306 fi
ab25bf1f 1307 aptautotest 'testequal' "$@"
9beb11aa 1308 msggroup
8d876415
DK
1309}
1310
685625bd 1311testequalor2() {
9beb11aa 1312 msggroup "$0"
03938280
DK
1313 local COMPAREFILE1="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1314 local COMPAREFILE2="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1315 local COMPAREAGAINST="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
685625bd
DK
1316 echo "$1" > $COMPAREFILE1
1317 echo "$2" > $COMPAREFILE2
1318 shift 2
1319 msgtest "Test for equality OR of" "$*"
ab25bf1f 1320 "$@" >$COMPAREAGAINST 2>&1 || true
0d58c26a
DK
1321 if checkdiff $COMPAREFILE1 $COMPAREAGAINST >/dev/null 2>&1 || \
1322 checkdiff $COMPAREFILE2 $COMPAREAGAINST >/dev/null 2>&1
1323 then
0caa5a4c
DK
1324 msgpass
1325 else
68042532
DK
1326 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
1327 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1
1328 checkdiff "$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1329 echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1
1330 checkdiff "$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true
1331 msgfailoutput '' "$OUTPUT"
0caa5a4c 1332 fi
ab25bf1f 1333 aptautotest 'testequalor2' "$@"
9beb11aa 1334 msggroup
685625bd
DK
1335}
1336
8d876415 1337testshowvirtual() {
9beb11aa 1338 msggroup "$0"
edc0ef10 1339 local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
8d876415
DK
1340 local PACKAGE="$1"
1341 shift
1342 while [ -n "$1" ]; do
1343 VIRTUAL="${VIRTUAL}
edc0ef10 1344N: Can't select versions from package '$1' as it is purely virtual"
8d876415
DK
1345 PACKAGE="${PACKAGE} $1"
1346 shift
1347 done
1348 msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
1349 VIRTUAL="${VIRTUAL}
4bec02c2 1350N: No packages found"
03938280 1351 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
ea65d079 1352 local ARCH="$(getarchitecture 'native')"
68042532
DK
1353 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
1354 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
1355 if aptcache show -q=0 "$PACKAGE" 2>&1 | checkdiff "$COMPAREFILE" - >"$OUTPUT" 2>&1; then
1356 msgpass
1357 else
1358 msgfailoutput '' "$OUTPUT"
1359 fi
9beb11aa 1360 msggroup
8d876415
DK
1361}
1362
1363testnopackage() {
9beb11aa 1364 msggroup "$0"
8d876415 1365 msgtest "Test for non-existent packages" "apt-cache show $*"
846856f4 1366 local SHOWPKG="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
8d876415 1367 if [ -n "$SHOWPKG" ]; then
68042532
DK
1368 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1369 echo "$SHOWPKG" >"$OUTPUT"
1370 msgfailoutput '' "$OUTPUT"
0d58c26a
DK
1371 else
1372 msgpass
8d876415 1373 fi
9beb11aa 1374 msggroup
8d876415 1375}
01a6e24c 1376
ecb777dd 1377testdpkgstatus() {
9beb11aa 1378 msggroup "$0"
ecb777dd
DK
1379 local STATE="$1"
1380 local NR="$2"
1381 shift 2
1382 msgtest "Test that $NR package(s) are in state $STATE with" "dpkg -l $*"
1383 local PKGS="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)"
1384 if [ "$PKGS" != $NR ]; then
68042532
DK
1385 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output"
1386 echo "$PKGS" >"$OUTPUT"
1387 dpkg -l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true
1388 msgfailoutput '' "$OUTPUT"
0d58c26a
DK
1389 else
1390 msgpass
01a6e24c 1391 fi
9beb11aa 1392 msggroup
01a6e24c
DK
1393}
1394
ecb777dd 1395testdpkginstalled() {
9beb11aa 1396 msggroup "$0"
ecb777dd 1397 testdpkgstatus 'ii' "$#" "$@"
9beb11aa 1398 msggroup
ecb777dd
DK
1399}
1400
5cf733e1 1401testdpkgnotinstalled() {
9beb11aa 1402 msggroup "$0"
ecb777dd 1403 testdpkgstatus 'ii' '0' "$@"
9beb11aa 1404 msggroup
01a6e24c 1405}
ec7f904e
DK
1406
1407testmarkedauto() {
9beb11aa 1408 msggroup "$0"
03938280 1409 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
ec7f904e
DK
1410 if [ -n "$1" ]; then
1411 msgtest 'Test for correctly marked as auto-installed' "$*"
1412 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1413 else
1414 msgtest 'Test for correctly marked as auto-installed' 'no package'
c98fb5e0 1415 echo -n > $COMPAREFILE
ec7f904e 1416 fi
68042532
DK
1417 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.output"
1418 if aptmark showauto 2>&1 | checkdiff $COMPAREFILE - >"$OUTPUT" 2>&1; then
1419 msgpass
1420 else
1421 msgfailoutput '' "$OUTPUT"
1422 fi
9beb11aa 1423 msggroup
ec7f904e 1424}
7c2cc4a7 1425testmarkedmanual() {
9beb11aa 1426 msggroup "$0"
7c2cc4a7
DK
1427 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
1428 if [ -n "$1" ]; then
1429 msgtest 'Test for correctly marked as manually installed' "$*"
1430 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1431 else
1432 msgtest 'Test for correctly marked as manually installed' 'no package'
1433 echo -n > $COMPAREFILE
1434 fi
68042532
DK
1435 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.output"
1436 if aptmark showmanual 2>&1 | checkdiff $COMPAREFILE - >"$OUTPUT" 2>&1; then
1437 msgpass
1438 else
1439 msgfailoutput '' "$OUTPUT"
1440 fi
9beb11aa 1441 msggroup
7c2cc4a7 1442}
89a1aa5d 1443
e52aad52 1444msgfailoutput() {
68042532
DK
1445 if [ -n "$MSGTEST_MSG" ]; then
1446 echo
9beb11aa
DK
1447 if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then
1448 echo "${CFAIL}Part of the test group: $MSGTEST_GRP"
1449 fi
68042532
DK
1450 echo -n "$MSGTEST_MSG"
1451 unset MSGTEST_MSG
1452 fi
e52aad52
DK
1453 local MSG="$1"
1454 local OUTPUT="$2"
1455 shift 2
e52aad52 1456 if [ "$1" = 'grep' ]; then
68042532 1457 echo >&2
e52aad52
DK
1458 while [ -n "$2" ]; do shift; done
1459 echo "#### Complete file: $1 ####"
1460 cat >&2 "$1" || true
1461 echo '#### grep output ####'
1462 elif [ "$1" = 'test' ]; then
68042532 1463 echo >&2
e52aad52
DK
1464 # doesn't support ! or non-file flags
1465 msgfailoutputstatfile() {
1466 local FILEFLAGS='^-[bcdefgGhkLOprsStuwx]$'
1467 if expr match "$1" "$FILEFLAGS" >/dev/null; then
1468 echo "#### stat(2) of file: $2 ####"
1469 stat "$2" || true
1470 fi
1471 }
1472 msgfailoutputstatfile "$2" "$3"
1473 while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do
1474 shift 3
1475 msgfailoutputstatfile "$2" "$3"
1476 done
1477 echo '#### test output ####'
1478 fi
1479 cat >&2 $OUTPUT
1480 msgfail "$MSG"
1481}
1482
0440d936 1483testsuccess() {
9beb11aa 1484 msggroup "$0"
0440d936
DK
1485 if [ "$1" = '--nomsg' ]; then
1486 shift
1487 else
1488 msgtest 'Test for successful execution of' "$*"
1489 fi
03938280 1490 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
4fa34122
DK
1491 if "$@" >${OUTPUT} 2>&1; then
1492 if expr match "$1" '^apt.*' >/dev/null; then
e52aad52
DK
1493 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1494 msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
3261271e
DK
1495 elif grep -E '^[WE]: ' "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
1496 if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
1497 if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
1498 | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev/null 2>&1; then
1499 msgpass
1500 else
1501 msgfailoutput 'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1502 fi
1503 else
1504 msgfailoutput 'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
1505 fi
4fa34122
DK
1506 else
1507 msgpass
1508 fi
1509 else
1510 msgpass
1511 fi
1512 else
1513 local EXITCODE=$?
e52aad52 1514 msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
4fa34122
DK
1515 fi
1516 aptautotest 'testsuccess' "$@"
9beb11aa 1517 msggroup
4fa34122
DK
1518}
1519testwarning() {
9beb11aa 1520 msggroup "$0"
4fa34122
DK
1521 if [ "$1" = '--nomsg' ]; then
1522 shift
1523 else
1524 msgtest 'Test for successful execution with warnings of' "$*"
1525 fi
25b86db1 1526 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output"
1df24acf
DK
1527 if "$@" >${OUTPUT} 2>&1; then
1528 if expr match "$1" '^apt.*' >/dev/null; then
e52aad52
DK
1529 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1530 msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
1531 elif grep -q -E '^E: ' "$OUTPUT"; then
1532 msgfailoutput 'successful run, but output contains errors' "$OUTPUT" "$@"
4fa34122 1533 elif ! grep -q -E '^W: ' "$OUTPUT"; then
e52aad52 1534 msgfailoutput 'successful run, but output contains no warnings' "$OUTPUT" "$@"
1df24acf
DK
1535 else
1536 msgpass
1537 fi
1538 else
1539 msgpass
1540 fi
0440d936 1541 else
07cb47e7 1542 local EXITCODE=$?
68042532 1543 msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
0440d936 1544 fi
4fa34122 1545 aptautotest 'testwarning' "$@"
9beb11aa 1546 msggroup
0440d936 1547}
0440d936 1548testfailure() {
9beb11aa 1549 msggroup "$0"
0440d936
DK
1550 if [ "$1" = '--nomsg' ]; then
1551 shift
1552 else
889b0072 1553 msgtest 'Test for failure in execution of' "$*"
0440d936 1554 fi
03938280 1555 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1df24acf 1556 if "$@" >${OUTPUT} 2>&1; then
07cb47e7 1557 local EXITCODE=$?
e52aad52 1558 msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
0440d936 1559 else
1df24acf
DK
1560 local EXITCODE=$?
1561 if expr match "$1" '^apt.*' >/dev/null; then
b0d40854
DK
1562 if [ "$1" = 'aptkey' ]; then
1563 if grep -q -E " Can't check signature: " "$OUTPUT" || \
1564 grep -q -E " BAD signature from " "$OUTPUT"; then
1565 msgpass
1566 else
1567 msgfailoutput "run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@"
1568 fi
1df24acf 1569 else
b0d40854
DK
1570 if grep -q -E ' runtime error: ' "$OUTPUT"; then
1571 msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
1572 elif grep -q -E '==ERROR' "$OUTPUT"; then
1573 msgfailoutput 'compiler sanitizers reported errors' "$OUTPUT" "$@"
1574 elif ! grep -q -E '^E: ' "$OUTPUT"; then
1575 msgfailoutput "run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@"
1576 else
1577 msgpass
1578 fi
1df24acf
DK
1579 fi
1580 else
1581 msgpass
1582 fi
0440d936 1583 fi
ab25bf1f 1584 aptautotest 'testfailure' "$@"
9beb11aa 1585 msggroup
0440d936
DK
1586}
1587
25b86db1 1588testsuccessequal() {
9beb11aa 1589 msggroup "$0"
25b86db1
DK
1590 local CMP="$1"
1591 shift
1592 testsuccess "$@"
1593 testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$CMP"
9beb11aa 1594 msggroup
25b86db1
DK
1595}
1596testwarningequal() {
9beb11aa 1597 msggroup "$0"
25b86db1
DK
1598 local CMP="$1"
1599 shift
1600 testwarning "$@"
1601 testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" "$CMP"
9beb11aa 1602 msggroup
25b86db1
DK
1603}
1604testfailureequal() {
9beb11aa 1605 msggroup "$0"
25b86db1
DK
1606 local CMP="$1"
1607 shift
1608 testfailure "$@"
1609 testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" "$CMP"
9beb11aa 1610 msggroup
25b86db1
DK
1611}
1612
27925d82 1613testfailuremsg() {
9beb11aa 1614 msggroup "$0"
27925d82
DK
1615 local CMP="$1"
1616 shift
1617 testfailure "$@"
1618 msgtest 'Check that the output of the previous failed command has expected' 'failures and warnings'
68042532
DK
1619 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
1620 grep '^\(W\|E\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
1621 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.output"
1622 if echo "$CMP" | checkdiff - "${COMPAREFILE}" >"$OUTPUT" 2>&1; then
27925d82
DK
1623 msgpass
1624 else
68042532
DK
1625 echo '### Complete output ###' >"$OUTPUT"
1626 cat "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" >"$OUTPUT"
1627 msgfailoutput '' "$OUTPUT"
27925d82 1628 fi
9beb11aa 1629 msggroup
27925d82 1630}
25b86db1 1631
de81b2e2 1632testfilestats() {
9beb11aa 1633 msggroup "$0"
de81b2e2
DK
1634 msgtest "Test that file $1 has $2 $3" "$4"
1635 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
5684f71f
DK
1636 msgpass
1637 else
68042532
DK
1638 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output"
1639 {
1640 ls -ld "$1" || true
1641 echo -n "stat(1) reports for $2: "
1642 stat --format "$2" "$1" || true
1643 } >"$OUTPUT" 2>&1
1644 msgfailoutput '' "$OUTPUT"
5684f71f 1645 fi
9beb11aa 1646 msggroup
5684f71f 1647}
de81b2e2 1648testaccessrights() {
9beb11aa 1649 msggroup "$0"
de81b2e2 1650 testfilestats "$1" '%a' '=' "$2"
9beb11aa 1651 msggroup
de81b2e2 1652}
5684f71f 1653
0d58c26a 1654testwebserverlaststatuscode() {
9beb11aa 1655 msggroup "$0"
0d58c26a 1656 local DOWNLOG='rootdir/tmp/webserverstatus-testfile.log'
03aa0847 1657 local STATUS='downloaded/webserverstatus-statusfile.log'
0d58c26a
DK
1658 rm -f "$DOWNLOG" "$STATUS"
1659 msgtest 'Test last status code from the webserver was' "$1"
b0314abb 1660 if downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
0d58c26a
DK
1661 msgpass
1662 else
68042532
DK
1663 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"
1664 {
1665 if [ -n "$2" ]; then
1666 shift
1667 echo >&2 '#### Additionally provided output files contain:'
1668 cat >&2 "$@"
1669 fi
1670 echo >&2 '#### Download log of the status code:'
1671 cat >&2 "$DOWNLOG"
1672 } >"$OUTPUT" 2>&1
1673 msgfailoutput "Status was $(cat "$STATUS")" "$OUTPUT"
0d58c26a 1674 fi
9beb11aa 1675 msggroup
0d58c26a
DK
1676}
1677
89a1aa5d
DK
1678pause() {
1679 echo "STOPPED execution. Press enter to continue"
1680 local IGNORE
1681 read IGNORE
1682}
ab25bf1f 1683
846bc058 1684listcurrentlistsdirectory() {
ba6b79bd
DK
1685 {
1686 find rootdir/var/lib/apt/lists -maxdepth 1 -type d | while read line; do
1687 stat --format '%U:%G:%a:%n' "$line"
1688 done
1689 find rootdir/var/lib/apt/lists -maxdepth 1 \! -type d | while read line; do
1690 stat --format '%U:%G:%a:%s:%y:%n' "$line"
1691 done
1692 } | sort
846bc058
DK
1693}
1694
3a8776a3 1695### convenience hacks ###
8fe964f1
DK
1696mkdir() {
1697 # creating some directories by hand is a tedious task, so make it look simple
1698 if [ "$*" = '-p rootdir/var/lib/apt/lists' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" ] ||
1699 [ "$*" = '-p rootdir/var/lib/apt/lists/partial' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" ]; then
1700 # only the last directory created by mkdir is effected by the -m !
1701 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
1702 command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"
1703 command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1704 touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock"
1705 if [ "$(id -u)" = '0' ]; then
1706 chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial"
1707 fi
1708 else
1709 command mkdir "$@"
1710 fi
1711}
1712
ab25bf1f
DK
1713### The following tests are run by most test methods automatically to check
1714### general things about commands executed without writing the test every time.
1715
1716aptautotest() {
1717 local TESTCALL="$1"
1718 local CMD="$2"
1719 local FIRSTOPT="$3"
1720 local AUTOTEST="aptautotest_$(basename "$CMD" | tr -d '-')_$(echo "$FIRSTOPT" | tr -d '-')"
1721 if command -v $AUTOTEST >/dev/null; then
1722 shift 3
1723 # save and restore the *.output files from other tests
1724 # as we might otherwise override them in these automatic tests
03aa0847
DK
1725 rm -rf ${TMPWORKINGDIRECTORY}/rootdir/tmp-before
1726 mv ${TMPWORKINGDIRECTORY}/rootdir/tmp ${TMPWORKINGDIRECTORY}/rootdir/tmp-before
1727 mkdir ${TMPWORKINGDIRECTORY}/rootdir/tmp
ab25bf1f 1728 $AUTOTEST "$TESTCALL" "$@"
03aa0847
DK
1729 rm -rf ${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest
1730 mv ${TMPWORKINGDIRECTORY}/rootdir/tmp ${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest
1731 mv ${TMPWORKINGDIRECTORY}/rootdir/tmp-before ${TMPWORKINGDIRECTORY}/rootdir/tmp
ab25bf1f
DK
1732 fi
1733}
1734
1735aptautotest_aptget_update() {
59148d96
DK
1736 local TESTCALL="$1"
1737 while [ -n "$2" ]; do
1738 if [ "$2" = '--print-uris' ]; then return; fi # simulation mode
1739 shift
1740 done
ab25bf1f 1741 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
4bb006d1
DK
1742 testfilestats "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
1743 testfilestats "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755"
ab25bf1f 1744 # all copied files are properly chmodded
146f7715 1745 for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do
4bb006d1 1746 testfilestats "$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644"
ab25bf1f 1747 done
59148d96 1748 if [ "$TESTCALL" = 'testsuccess' ]; then
146f7715
DK
1749 # failure cases can retain partial files and such
1750 testempty find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \( -name 'lock' -o -name '*.FAILED' \)
1751 fi
ab25bf1f
DK
1752}
1753aptautotest_apt_update() { aptautotest_aptget_update "$@"; }
d84da499 1754aptautotest_aptcdrom_add() { aptautotest_aptget_update "$@"; }
016bea82
DK
1755
1756testaptautotestnodpkgwarning() {
1757 local TESTCALL="$1"
1758 while [ -n "$2" ]; do
6bf93605
DK
1759 if expr match "$2" '^-[a-z]*s' >/dev/null 2>&1; then return; fi # simulation mode
1760 if expr match "$2" '^-dy\?' >/dev/null 2>&1; then return; fi # download-only mode
016bea82
DK
1761 shift
1762 done
1763 testfailure grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output"
1764}
1765
1766aptautotest_aptget_install() { testaptautotestnodpkgwarning "$@"; }
1767aptautotest_aptget_remove() { testaptautotestnodpkgwarning "$@"; }
1768aptautotest_aptget_purge() { testaptautotestnodpkgwarning "$@"; }
1769aptautotest_apt_install() { testaptautotestnodpkgwarning "$@"; }
1770aptautotest_apt_remove() { testaptautotestnodpkgwarning "$@"; }
1771aptautotest_apt_purge() { testaptautotestnodpkgwarning "$@"; }