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