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