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