]> git.saurik.com Git - apt.git/blame - test/integration/framework
check for failure message in testsuccess/failure
[apt.git] / test / integration / framework
CommitLineData
8d876415
DK
1#!/bin/sh -- # no runable script, just for vi
2
5d76cee1 3EXIT_CODE=0
8c1dd12c 4
8d876415 5# we all like colorful messages
1290422a 6if [ "$MSGCOLOR" != 'NO' ]; then
27cb4f6c 7 if [ ! -t 1 ]; then # but check that we output to a terminal
1290422a
DK
8 export MSGCOLOR='NO'
9 fi
10fi
11
12
13if [ "$MSGCOLOR" != 'NO' ]; then
14 CERROR="\033[1;31m" # red
15 CWARNING="\033[1;33m" # yellow
16 CMSG="\033[1;32m" # green
17 CINFO="\033[1;96m" # light blue
18 CDEBUG="\033[1;94m" # blue
19 CNORMAL="\033[0;39m" # default system console color
20 CDONE="\033[1;32m" # green
21 CPASS="\033[1;32m" # green
22 CFAIL="\033[1;31m" # red
23 CCMD="\033[1;35m" # pink
682a3bf7 24fi
8d876415 25
de81b2e2
DK
26msgprintf() {
27 local START="$1"
28 local MIDDLE="$2"
29 local END="$3"
30 shift 3
31 if [ -n "$1" ]; then
32 printf "$START " "$1"
d73840dc 33 shift
de81b2e2
DK
34 while [ -n "$1" ]; do
35 printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cgfs]\)#apt-\1#')"
36 shift
37 done
38 fi
39 printf "${END}"
2a2a7ef4 40}
de81b2e2
DK
41msgdie() { msgprintf "${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; }
42msgwarn() { msgprintf "${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; }
43msgmsg() { msgprintf "${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; }
44msginfo() { msgprintf "${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; }
45msgdebug() { msgprintf "${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; }
46msgdone() { msgprintf "${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; }
47msgnwarn() { msgprintf "${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; }
48msgnmsg() { msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@"; }
49msgninfo() { msgprintf "${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
50msgndebug() { msgprintf "${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
51msgtest() { msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
3c528b91 52msgpass() { printf "${CPASS}PASS${CNORMAL}\n"; }
68ba0b7f
DK
53msgskip() {
54 if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
55 else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
56}
5229b285 57msgfail() {
3c528b91
MO
58 if [ $# -gt 0 ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
59 else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
4d0818cc
MV
60 if [ -n "$APT_DEBUG_TESTS" ]; then
61 bash
62 fi
5229b285
DK
63 EXIT_CODE=$((EXIT_CODE+1));
64}
8d876415
DK
65
66# enable / disable Debugging
fc89263e
DK
67MSGLEVEL=${MSGLEVEL:-3}
68if [ $MSGLEVEL -le 0 ]; then
69 msgdie() { true; }
70fi
71if [ $MSGLEVEL -le 1 ]; then
72 msgwarn() { true; }
73 msgnwarn() { true; }
74fi
75if [ $MSGLEVEL -le 2 ]; then
76 msgmsg() { true; }
77 msgnmsg() { true; }
39cc8228 78 msgtest() { true; }
3c528b91
MO
79 msgpass() { printf " ${CPASS}P${CNORMAL}"; }
80 msgskip() { printf " ${CWARNING}S${CNORMAL}" >&2; }
682a3bf7 81 if [ -n "$CFAIL" ]; then
3c528b91 82 msgfail() { printf " ${CFAIL}FAIL${CNORMAL}" >&2; EXIT_CODE=$((EXIT_CODE+1)); }
682a3bf7 83 else
3c528b91 84 msgfail() { printf " ###FAILED###" >&2; EXIT_CODE=$((EXIT_CODE+1)); }
682a3bf7 85 fi
fc89263e
DK
86fi
87if [ $MSGLEVEL -le 3 ]; then
88 msginfo() { true; }
89 msgninfo() { true; }
90fi
91if [ $MSGLEVEL -le 4 ]; then
92 msgdebug() { true; }
93 msgndebug() { true; }
94fi
95msgdone() {
96 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
97 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
98 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
99 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
100 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
101 true;
102 else
3c528b91 103 printf "${CDONE}DONE${CNORMAL}\n";
fc89263e
DK
104 fi
105}
e43a426e
MV
106getaptconfig() {
107 if [ -f ./aptconfig.conf ]; then
108 echo "./aptconfig.conf"
109 elif [ -f ../aptconfig.conf ]; then
110 echo "../aptconfig.conf"
111 fi
112}
8d876415
DK
113runapt() {
114 msgdebug "Executing: ${CCMD}$*${CDEBUG} "
846856f4
DK
115 local CMD="$1"
116 shift
3b8eb3bc 117 case $CMD in
a311fb96 118 sh|aptitude|*/*|command) ;;
3b8eb3bc
DK
119 *) CMD="${BUILDDIRECTORY}/$CMD";;
120 esac
a311fb96 121 MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH=${LIBRARYPATH} $CMD "$@"
8d876415 122}
846856f4
DK
123aptconfig() { runapt apt-config "$@"; }
124aptcache() { runapt apt-cache "$@"; }
125aptcdrom() { runapt apt-cdrom "$@"; }
126aptget() { runapt apt-get "$@"; }
127aptftparchive() { runapt apt-ftparchive "$@"; }
128aptkey() { runapt apt-key "$@"; }
129aptmark() { runapt apt-mark "$@"; }
4f6d26b4 130aptsortpkgs() { runapt apt-sortpkgs "$@"; }
796673c3 131apt() { runapt apt "$@"; }
3b8eb3bc
DK
132apthelper() { runapt "${APTHELPERBINDIR}/apt-helper" "$@"; }
133aptwebserver() { runapt "${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
134aptitude() { runapt aptitude "$@"; }
8d50b63f 135aptextracttemplates() { runapt apt-extracttemplates "$@"; }
3082603f 136aptinternalsolver() { runapt "${APTINTERNALSOLVER}" "$@"; }
3b8eb3bc 137
158fda31 138dpkg() {
846856f4 139 command dpkg --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log "$@"
158fda31 140}
ce7f128c
DK
141dpkgcheckbuilddeps() {
142 command dpkg-checkbuilddeps --admindir=${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg "$@"
b6b5a542 143}
3fa950f1 144gdb() {
a311fb96 145 local CMD="$1"
ce928105 146 shift
a311fb96 147 runapt command gdb --quiet -ex run "${BUILDDIRECTORY}/$CMD" --args "${BUILDDIRECTORY}/$CMD" "$@"
ae99ce2e 148}
8d876415 149
8c1dd12c 150exitwithstatus() {
f91bd741
MV
151 # error if we about to overflow, but ...
152 # "255 failures ought to be enough for everybody"
5d76cee1
MV
153 if [ $EXIT_CODE -gt 255 ]; then
154 msgdie "Total failure count $EXIT_CODE too big"
f91bd741 155 fi
5d76cee1 156 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
8c1dd12c
MV
157}
158
804d4a0d
DK
159shellsetedetector() {
160 local exit_status=$?
161 if [ "$exit_status" != '0' ]; then
3c528b91 162 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
804d4a0d
DK
163 if [ "$EXIT_CODE" = '0' ]; then
164 EXIT_CODE="$exit_status"
165 fi
166 fi
167}
168
b720d0bd 169addtrap() {
8437b7d4
DK
170 if [ "$1" = 'prefix' ]; then
171 CURRENTTRAP="$2 $CURRENTTRAP"
172 else
173 CURRENTTRAP="$CURRENTTRAP $1"
174 fi
804d4a0d 175 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
b720d0bd 176}
8d876415
DK
177
178setupenvironment() {
75954ae2 179 TMPWORKINGDIRECTORY=$(mktemp -d)
5684f71f 180 addtrap "cd /; rm -rf $TMPWORKINGDIRECTORY;"
3cbbda3c 181 msgninfo "Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
5c0dd6fc 182
68ba0b7f
DK
183 if [ "$(id -u)" = '0' ]; then
184 # relax permissions so that running as root with user switching works
185 umask 022
186 chmod o+rx "$TMPWORKINGDIRECTORY"
187 fi
188
5684f71f 189 TESTDIRECTORY=$(readlink -f $(dirname $0))
5c0dd6fc
MV
190 # allow overriding the default BUILDDIR location
191 BUILDDIRECTORY=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
3b8eb3bc 192 LIBRARYPATH=${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}
5c0dd6fc 193 METHODSDIR=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
e43a426e 194 APTHELPERBINDIR=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}
c035b655 195 APTWEBSERVERBINDIR=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
3082603f 196 APTINTERNALSOLVER=${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}
8d876415 197 test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
5c0dd6fc
MV
198 # -----
199
8d876415 200 cd $TMPWORKINGDIRECTORY
cd725954 201 mkdir rootdir aptarchive keys
8d876415 202 cd rootdir
b29c3712 203 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
68ba0b7f 204 mkdir -p usr/bin var/cache var/lib/apt var/log tmp
cffea9af 205 mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
cd725954 206 touch var/lib/dpkg/available
8d876415 207 mkdir -p usr/lib/apt
9082a1fc 208 ln -s ${METHODSDIR} usr/lib/apt/methods
1f6cf9e7
DK
209 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
210 mkdir -p usr/lib/apt/solvers
211 ln -s "${BUILDDIRECTORY}/apt-dump-solver" usr/lib/apt/solvers/dump
212 ln -s "${BUILDDIRECTORY}/apt-internal-solver" usr/lib/apt/solvers/apt
213 echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" > etc/apt/apt.conf.d/externalsolver.conf
214 fi
291a386f
MV
215 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
216 # system
217 if [ -e ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove ]; then
218 ln -s ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove etc/apt/apt.conf.d/01autoremove
219 else
220 ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
221 fi
8d876415 222 cd ..
2c6baa5a 223 local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
53ea1b56
DK
224 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
225 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
8f8169ac 226 fi
4a4ea26c 227 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
53ea1b56
DK
228 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
229 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
8f8169ac 230 fi
53ea1b56 231 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys/
5684f71f 232 chmod 644 $(find keys -name '*.pub' -o -name '*.sec')
cd725954 233 ln -s ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
d6cf2345 234
cffea9af 235 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
94eb3bee 236 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
8d876415
DK
237 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
238 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
5c0dd6fc 239 echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
68ba0b7f
DK
240 # store apt-key were we can access it, even if we run it as a different user
241 # destroys coverage reporting though, so just do it for root for now
242 if [ "$(id -u)" = '0' ]; then
243 cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
244 chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
245 echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
246 else
247 echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
248 fi
cffea9af
DK
249 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
250 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
251 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
252 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
253 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
846856f4 254 if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
53ea1b56
DK
255 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf # Added to test multiarch before dpkg is ready for it…
256 fi
cffea9af 257 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
2c085486 258 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
0c8171d7 259 echo 'quiet::NoStatistic "true";' >> aptconfig.conf
d6cf2345
DK
260 # too distracting for users, but helpful to detect changes
261 echo 'Acquire::Progress::Ignore::ShowErrorText "true";' >> aptconfig.conf
0045df3f
DK
262 # in testcases, it can appear as if localhost has a rotation setup,
263 # hide this as we can't really deal with it properly
264 echo 'Acquire::Failure::ShowIP "false";' >> aptconfig.conf
d6cf2345 265
68ba0b7f
DK
266 cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
267 if [ "$(id -u)" = '0' ]; then
268 chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
269 fi
270 echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir/etc/apt/apt.conf.d/99https
d6cf2345 271 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
276e51dd 272 configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
77a45beb 273
d4f4bcf7
MV
274 # Acquire::AllowInsecureRepositories=false is not yet the default
275 # but we want it to be the default soon
276 configallowinsecurerepositories "false";
277
ce7f128c 278 # cleanup the environment a bit
8c617819
MV
279 # prefer our apt binaries over the system apt binaries
280 export PATH="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
be233796 281 export LC_ALL=C.UTF-8
3b8eb3bc 282 unset LANGUAGE APT_CONFIG
ce7f128c
DK
283 unset GREP_OPTIONS DEB_BUILD_PROFILES
284
8d876415
DK
285 msgdone "info"
286}
287
ea65d079
DK
288getarchitecture() {
289 if [ "$1" = "native" -o -z "$1" ]; then
290 eval `aptconfig shell ARCH APT::Architecture`
291 if [ -n "$ARCH" ]; then
292 echo $ARCH
293 else
5834d7a1 294 dpkg --print-architecture
ea65d079
DK
295 fi
296 else
297 echo $1
298 fi
299}
300
53ea1b56
DK
301getarchitectures() {
302 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
303}
304
3dcdc1f9
DK
305getarchitecturesfromcommalist() {
306 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
307}
308
8d876415 309configarchitecture() {
18908589
DK
310 {
311 echo "APT::Architecture \"$(getarchitecture $1)\";"
312 while [ -n "$1" ]; do
313 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
314 shift
315 done
316 } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
53ea1b56
DK
317 configdpkg
318}
319
320configdpkg() {
321 if [ ! -e rootdir/var/lib/dpkg/status ]; then
322 local STATUSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
323 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
324 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
325 else
326 echo -n > rootdir/var/lib/dpkg/status
327 fi
328 fi
18908589 329 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
846856f4 330 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
53ea1b56
DK
331 local ARCHS="$(getarchitectures)"
332 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
333 DPKGARCH="$(dpkg --print-architecture)"
334 for ARCH in ${ARCHS}; do
feae193b 335 if [ "${ARCH}" != "${DPKGARCH}" ]; then
18908589 336 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
feae193b 337 # old-style used e.g. in Ubuntu-P – and as it seems travis
18908589
DK
338 echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
339 echo "DPKG::options:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
feae193b
DK
340 fi
341 fi
53ea1b56
DK
342 done
343 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
05343a22
DK
344 # dpkg doesn't really check the version as long as it is fully installed,
345 # but just to be sure we choose one above the required version
346 insertinstalledpackage 'dpkg' "all" '1.16.2+fake'
53ea1b56
DK
347 fi
348 fi
349 fi
8d876415
DK
350}
351
d4f4bcf7
MV
352configallowinsecurerepositories() {
353 echo "Acquire::AllowInsecureRepositories \"$1\";" > rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf
354
355}
356
276e51dd
DK
357configcompression() {
358 while [ -n "$1" ]; do
359 case "$1" in
3c528b91
MO
360 '.') printf ".\t.\tcat\n";;
361 'gz') printf "gzip\tgz\tgzip\n";;
362 'bz2') printf "bzip2\tbz2\tbzip2\n";;
363 'lzma') printf "lzma\tlzma\txz --format=lzma\n";;
364 'xz') printf "xz\txz\txz\n";;
365 *) printf "$1\t$1\t$1\n";;
276e51dd
DK
366 esac
367 shift
368 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
369}
370
5f982b9d
DK
371forcecompressor() {
372 COMPRESSOR="$1"
373 COMPRESSOR_CMD="$1"
374 case $COMPRESSOR in
375 gzip) COMPRESS='gz';;
376 bzip2) COMPRESS='bz2';;
377 lzma) COMPRESS='lzma';;
378 xz) COMPRESS='xz';;
379 *) msgdie "Compressor $COMPRESSOR is unknown to framework, so can't be forced by forcecompressor!";;
380 esac
381 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
382 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
383Dir::Bin::uncompressed \"/does/not/exist\";
384Dir::Bin::gzip \"/does/not/exist\";
385Dir::Bin::bzip2 \"/does/not/exist\";
386Dir::Bin::lzma \"/does/not/exist\";
387Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
388 if [ -e "/bin/${COMPRESSOR}" ]; then
389 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
390 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
391 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
392 elif [ "${COMPRESSOR}" = 'lzma' ]; then
393 echo 'Dir::Bin::xz "/usr/bin/xz";' >> "$CONFFILE"
394 COMPRESSOR_CMD='xz --format=lzma'
395 else
396 msgtest 'Test for availability of compressor' "${COMPRESSOR}"
397 msgfail
398 fi
399}
400
75954ae2 401setupsimplenativepackage() {
ce9864a8
DK
402 local NAME="$1"
403 local ARCH="$2"
404 local VERSION="$3"
405 local RELEASE="${4:-unstable}"
406 local DEPENDENCIES="$5"
14109555 407 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
18908589
DK
408 If you find such a package installed on your system,
409 something went horribly wrong! They are autogenerated
410 und used only by testcases and surf no other propose…"}"
411
b7899b00
DK
412 local SECTION="${7:-others}"
413 local DISTSECTION
414 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
415 DISTSECTION="main"
416 else
417 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
418 fi
ce9864a8
DK
419 local BUILDDIR=incoming/${NAME}-${VERSION}
420 mkdir -p ${BUILDDIR}/debian/source
421 cd ${BUILDDIR}
422 echo "* most suckless software product ever" > FEATURES
b7899b00
DK
423 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
424 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
ce9864a8
DK
425
426 * Initial release
427
b7899b00
DK
428 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
429 test -e debian/control || echo "Source: $NAME
430Section: $SECTION
ce9864a8
DK
431Priority: optional
432Maintainer: Joe Sixpack <joe@example.org>
433Build-Depends: debhelper (>= 7)
434Standards-Version: 3.9.1
435
875bcb36
DK
436Package: $NAME" > debian/control
437 if [ "$ARCH" = 'all' ]; then
438 echo "Architecture: all" >> debian/control
439 else
440 echo "Architecture: any" >> debian/control
441 fi
ce9864a8 442 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
18908589
DK
443 echo "Description: $DESCRIPTION" >> debian/control
444
b7899b00
DK
445 test -e debian/compat || echo "7" > debian/compat
446 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
ce9864a8 447 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
75954ae2
DK
448 cd - > /dev/null
449}
450
451buildsimplenativepackage() {
452 local NAME="$1"
453 local ARCH="$2"
454 local VERSION="$3"
455 local RELEASE="${4:-unstable}"
456 local DEPENDENCIES="$5"
14109555 457 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
18908589
DK
458 If you find such a package installed on your system,
459 something went horribly wrong! They are autogenerated
460 und used only by testcases and surf no other propose…"}"
461
75954ae2 462 local SECTION="${7:-others}"
d67004e0 463 local PRIORITY="${8:-optional}"
42c1513b 464 local FILE_TREE="$9"
adff049d 465 local COMPRESS_TYPE="${10:-gzip}"
75954ae2
DK
466 local DISTSECTION
467 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
468 DISTSECTION="main"
469 else
470 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
471 fi
5a635ee4 472 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
b761356f 473
18331adf 474 msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… "
b761356f
DK
475 mkdir -p $BUILDDIR/debian/source
476 echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
477 echo "#!/bin/sh
478echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
479
480 echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
481 echo "$NAME ($VERSION) $RELEASE; urgency=low
482
483 * Initial release
484
485 -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
486 echo "Source: $NAME
487Section: $SECTION
d67004e0 488Priority: $PRIORITY
b761356f 489Maintainer: Joe Sixpack <joe@example.org>
01f520ce
DK
490Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
491 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
492 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
493 echo "
494Package: $NAME" >> ${BUILDDIR}/debian/control
b761356f 495
875bcb36
DK
496 if [ "$ARCH" = 'all' ]; then
497 echo "Architecture: all" >> ${BUILDDIR}/debian/control
498 else
499 echo "Architecture: any" >> ${BUILDDIR}/debian/control
500 fi
01f520ce
DK
501 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
502 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
18908589 503 echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
01f520ce 504
b761356f 505 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
f1828b69
DK
506 (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' \
507 | while read SRC; do
5a635ee4 508 echo "pool/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
f1828b69 509# if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
33a22672 510# aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
bd7fb5aa 511# adv --yes --default-key 'Joe Sixpack' \
f1828b69
DK
512# --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
513# mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
514# fi
b761356f 515 done
84aa13f4 516
3dcdc1f9 517 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
84aa13f4
DK
518 rm -rf ${BUILDDIR}/debian/tmp
519 mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
520 cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}
521 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}
42c1513b
MV
522 if [ -n "$FILE_TREE" ]; then
523 cp -ar "$FILE_TREE" ${BUILDDIR}/debian/tmp
524 fi
42c1513b 525
84aa13f4
DK
526 (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch)
527 (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
846856f4 528 local LOG="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
eb9dee96
DK
529 # ensure the right permissions as dpkg-deb ensists
530 chmod 755 ${BUILDDIR}/debian/tmp/DEBIAN
adff049d 531 if ! dpkg-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/.. >$LOG 2>&1; then
846856f4
DK
532 cat $LOG
533 false
534 fi
535 rm $LOG
84aa13f4
DK
536 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist
537 done
538
13845042
DK
539 mkdir -p ${BUILDDIR}/../${NAME}_${VERSION}
540 cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}/
541 cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}.changelog
5a635ee4 542 rm -rf "${BUILDDIR}"
b761356f 543 msgdone "info"
75954ae2
DK
544}
545
546buildpackage() {
547 local BUILDDIR=$1
548 local RELEASE=$2
549 local SECTION=$3
ea65d079 550 local ARCH=$(getarchitecture $4)
846856f4
DK
551 local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
552 local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
553 msgninfo "Build package ${PKGNAME} for ${RELEASE} in ${SECTION}… "
75954ae2
DK
554 cd $BUILDDIR
555 if [ "$ARCH" = "all" ]; then
556 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
557 fi
846856f4
DK
558 if ! dpkg-buildpackage -uc -us -a$ARCH >$BUILDLOG 2>&1 ; then
559 cat $BUILDLOG
560 false
561 fi
562 local PKGS="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
563 local SRCS="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
ce9864a8 564 cd - > /dev/null
b7899b00 565 for PKG in $PKGS; do
75954ae2 566 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist
b7899b00
DK
567 done
568 for SRC in $SRCS; do
75954ae2 569 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist
b7899b00 570 done
cffea9af 571 msgdone "info"
ce9864a8
DK
572}
573
574buildaptarchive() {
ce9864a8 575 if [ -d incoming ]; then
846856f4 576 buildaptarchivefromincoming "$@"
ce9864a8 577 else
846856f4 578 buildaptarchivefromfiles "$@"
ce9864a8
DK
579 fi
580}
581
582createaptftparchiveconfig() {
276e51dd
DK
583 local COMPRESSORS="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
584 COMPRESSORS="${COMPRESSORS%* }"
ce9864a8 585 local ARCHS="$(find pool/ -name '*.deb' | grep -oE '_[a-z0-9-]+\.deb$' | sort | uniq | sed -e '/^_all.deb$/ d' -e 's#^_\([a-z0-9-]*\)\.deb$#\1#' | tr '\n' ' ')"
158fda31
DK
586 if [ -z "$ARCHS" ]; then
587 # the pool is empty, so we will operate on faked packages - let us use the configured archs
53ea1b56 588 ARCHS="$(getarchitectures)"
158fda31 589 fi
ce9864a8
DK
590 echo -n 'Dir {
591 ArchiveDir "' >> ftparchive.conf
592 echo -n $(readlink -f .) >> ftparchive.conf
593 echo -n '";
594 CacheDir "' >> ftparchive.conf
595 echo -n $(readlink -f ..) >> ftparchive.conf
596 echo -n '";
b7899b00
DK
597 FileListDir "' >> ftparchive.conf
598 echo -n $(readlink -f pool/) >> ftparchive.conf
599 echo -n '";
600};
601Default {
276e51dd
DK
602 Packages::Compress "'"$COMPRESSORS"'";
603 Sources::Compress "'"$COMPRESSORS"'";
604 Contents::Compress "'"$COMPRESSORS"'";
605 Translation::Compress "'"$COMPRESSORS"'";
18331adf 606 LongDescription "false";
ce9864a8
DK
607};
608TreeDefault {
609 Directory "pool/";
610 SrcDirectory "pool/";
611};
612APT {
613 FTPArchive {
614 Release {
615 Origin "joesixpack";
616 Label "apttestcases";
617 Suite "unstable";
618 Description "repository with dummy packages";
619 Architectures "' >> ftparchive.conf
620 echo -n "$ARCHS" >> ftparchive.conf
621 echo 'source";
622 };
623 };
624};' >> ftparchive.conf
b7899b00
DK
625 for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
626 echo -n 'tree "dists/' >> ftparchive.conf
627 echo -n "$DIST" >> ftparchive.conf
628 echo -n '" {
ce9864a8
DK
629 Architectures "' >> ftparchive.conf
630 echo -n "$ARCHS" >> ftparchive.conf
b7899b00
DK
631 echo -n 'source";
632 FileList "' >> ftparchive.conf
633 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
634 echo -n '";
635 SourceFileList "' >> ftparchive.conf
636 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
637 echo -n '";
638 Sections "' >> ftparchive.conf
639 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
640 echo '";
ce9864a8 641};' >> ftparchive.conf
b7899b00 642 done
ce9864a8
DK
643}
644
645buildaptftparchivedirectorystructure() {
b7899b00
DK
646 local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
647 for DIST in $DISTS; do
648 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
649 for SECTION in $SECTIONS; do
650 local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
651 for ARCH in $ARCHS; do
652 mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH}
653 done
654 mkdir -p dists/${DIST}/${SECTION}/source
655 mkdir -p dists/${DIST}/${SECTION}/i18n
656 done
ce9864a8 657 done
ce9864a8
DK
658}
659
9b78cda6
DK
660insertpackage() {
661 local RELEASE="$1"
662 local NAME="$2"
663 local ARCH="$3"
664 local VERSION="$4"
665 local DEPENDENCIES="$5"
d67004e0 666 local PRIORITY="${6:-optional}"
14109555 667 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
18908589
DK
668 If you find such a package installed on your system,
669 something went horribly wrong! They are autogenerated
670 und used only by testcases and surf no other propose…"}"
d67004e0 671 local ARCHS=""
3dcdc1f9 672 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
c919ad6e 673 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
53ea1b56 674 ARCHS="$(getarchitectures)"
d67004e0
DK
675 else
676 ARCHS="$arch"
677 fi
678 for BUILDARCH in $ARCHS; do
679 local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
680 mkdir -p $PPATH aptarchive/dists/${RELEASE}/main/source
681 touch aptarchive/dists/${RELEASE}/main/source/Sources
682 local FILE="${PPATH}/Packages"
683 echo "Package: $NAME
684Priority: $PRIORITY
9b78cda6 685Section: other
2c085486 686Installed-Size: 42
c919ad6e
DK
687Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
688 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
689 echo "Version: $VERSION
d67004e0
DK
690Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
691 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
18908589 692 echo "Description: $DESCRIPTION" >> $FILE
8ba17539 693 echo >> $FILE
d67004e0 694 done
9b78cda6
DK
695 done
696}
697
234675b7
DK
698insertsource() {
699 local RELEASE="$1"
700 local NAME="$2"
701 local ARCH="$3"
702 local VERSION="$4"
703 local DEPENDENCIES="$5"
704 local ARCHS=""
705 local SPATH="aptarchive/dists/${RELEASE}/main/source"
706 mkdir -p $SPATH
707 local FILE="${SPATH}/Sources"
708 echo "Package: $NAME
709Binary: $NAME
710Version: $VERSION
711Maintainer: Joe Sixpack <joe@example.org>
712Architecture: $ARCH" >> $FILE
713 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
714 echo "Files:
715 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
d5dea0be
DK
716 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
717" >> $FILE
234675b7
DK
718}
719
dfc2b1be
DK
720insertinstalledpackage() {
721 local NAME="$1"
722 local ARCH="$2"
723 local VERSION="$3"
724 local DEPENDENCIES="$4"
d67004e0 725 local PRIORITY="${5:-optional}"
d4b4e5ea 726 local STATUS="${6:-install ok installed}"
14109555 727 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
18908589
DK
728 If you find such a package installed on your system,
729 something went horribly wrong! They are autogenerated
730 und used only by testcases and surf no other propose…"}"
731
53ea1b56
DK
732 local FILE='rootdir/var/lib/dpkg/status'
733 local INFO='rootdir/var/lib/dpkg/info'
3dcdc1f9 734 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
d67004e0 735 echo "Package: $NAME
d4b4e5ea 736Status: $STATUS
d67004e0 737Priority: $PRIORITY
dfc2b1be
DK
738Section: other
739Installed-Size: 42
740Maintainer: Joe Sixpack <joe@example.org>
dfc2b1be 741Version: $VERSION" >> $FILE
c919ad6e 742 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
d67004e0 743 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
18908589
DK
744 echo "Description: $DESCRIPTION" >> $FILE
745 echo >> $FILE
53ea1b56
DK
746 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
747 echo -n > ${INFO}/${NAME}:${arch}.list
748 else
749 echo -n > ${INFO}/${NAME}.list
750 fi
d67004e0 751 done
dfc2b1be
DK
752}
753
754
ce9864a8 755buildaptarchivefromincoming() {
3cbbda3c 756 msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
ce9864a8
DK
757 cd aptarchive
758 [ -e pool ] || ln -s ../incoming pool
759 [ -e ftparchive.conf ] || createaptftparchiveconfig
760 [ -e dists ] || buildaptftparchivedirectorystructure
b7899b00 761 msgninfo "\tGenerate Packages, Sources and Contents files… "
ce9864a8 762 aptftparchive -qq generate ftparchive.conf
ce9864a8
DK
763 cd - > /dev/null
764 msgdone "info"
4dbfe436 765 generatereleasefiles "$@"
ce9864a8
DK
766}
767
768buildaptarchivefromfiles() {
3cbbda3c 769 msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
9b78cda6
DK
770 find aptarchive -name 'Packages' -o -name 'Sources' | while read line; do
771 msgninfo "\t${line} file… "
276e51dd 772 compressfile "$line" "$1"
8d876415 773 msgdone "info"
9b78cda6 774 done
e3c62328 775 generatereleasefiles "$@"
9b78cda6
DK
776}
777
276e51dd
DK
778compressfile() {
779 cat ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | while read compressor extension command; do
780 if [ "$compressor" = '.' ]; then
781 if [ -n "$2" ]; then
782 touch -d "$2" "$1"
783 fi
784 continue
785 fi
786 cat "$1" | $command > "${1}.${extension}"
787 if [ -n "$2" ]; then
788 touch -d "$2" "${1}.${extension}"
789 fi
790 done
791}
792
a3bbbab7 793# can be overridden by testcases for their pleasure
bf9e7447
DK
794getcodenamefromsuite() {
795 case "$1" in
796 unstable) echo 'sid';;
797 *) echo -n "$1";;
798 esac
799}
a3bbbab7 800getreleaseversionfromsuite() { true; }
718f797c 801getlabelfromsuite() { true; }
a3bbbab7 802
9b78cda6 803generatereleasefiles() {
884a4c0a
DK
804 # $1 is the Date header and $2 is the ValidUntil header to be set
805 # both should be given in notation date/touch can understand
9b78cda6
DK
806 msgninfo "\tGenerate Release files… "
807 if [ -e aptarchive/dists ]; then
808 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
a3bbbab7
DK
809 local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
810 local CODENAME="$(getcodenamefromsuite $SUITE)"
811 local VERSION="$(getreleaseversionfromsuite $SUITE)"
718f797c 812 local LABEL="$(getlabelfromsuite $SUITE)"
884a4c0a 813 if [ -n "$VERSION" ]; then
718f797c
DK
814 VERSION="-o APT::FTPArchive::Release::Version=${VERSION}"
815 fi
816 if [ -n "$LABEL" ]; then
817 LABEL="-o APT::FTPArchive::Release::Label=${LABEL}"
a3bbbab7 818 fi
884a4c0a
DK
819 aptftparchive -qq release $dir \
820 -o APT::FTPArchive::Release::Suite="${SUITE}" \
821 -o APT::FTPArchive::Release::Codename="${CODENAME}" \
718f797c 822 ${LABEL} \
884a4c0a
DK
823 ${VERSION} \
824 | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
a3bbbab7 825 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
35faae11
DK
826 sed -i '/^Date: / a\
827NotAutomatic: yes' $dir/Release
828 fi
884a4c0a
DK
829 if [ -n "$1" -a "$1" != "now" ]; then
830 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
831 fi
832 if [ -n "$2" ]; then
833 sed -i "/^Date: / a\
834Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
835 fi
9b78cda6
DK
836 done
837 else
838 aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
8d876415 839 fi
884a4c0a 840 if [ -n "$1" -a "$1" != "now" ]; then
fe0f7911
DK
841 for release in $(find ./aptarchive -name 'Release'); do
842 touch -d "$1" $release
843 done
8d876415 844 fi
b7899b00 845 msgdone "info"
8d876415
DK
846}
847
b7899b00
DK
848setupdistsaptarchive() {
849 local APTARCHIVE=$(readlink -f ./aptarchive)
850 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
851 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
852 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
853 SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
854 msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
855 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
856 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
857 msgdone "info"
858 done
859}
860
861setupflataptarchive() {
ce9864a8 862 local APTARCHIVE=$(readlink -f ./aptarchive)
8d876415
DK
863 if [ -f ${APTARCHIVE}/Packages ]; then
864 msgninfo "\tadd deb sources.list line… "
865 echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
866 msgdone "info"
867 else
868 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
869 fi
870 if [ -f ${APTARCHIVE}/Sources ]; then
871 msgninfo "\tadd deb-src sources.list line… "
872 echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
873 msgdone "info"
874 else
875 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
876 fi
b7899b00
DK
877}
878
879setupaptarchive() {
4dbfe436
DK
880 local NOUPDATE=0
881 if [ "$1" = '--no-update' ]; then
882 NOUPDATE=1
883 shift
884 fi
885 buildaptarchive "$@"
b7899b00
DK
886 if [ -e aptarchive/dists ]; then
887 setupdistsaptarchive
888 else
889 setupflataptarchive
890 fi
9d653a6d 891 signreleasefiles 'Joe Sixpack'
4dbfe436 892 if [ "1" != "$NOUPDATE" ]; then
5684f71f 893 testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true
b2ea1a47 894 fi
8d876415
DK
895}
896
f213b6ea
DK
897signreleasefiles() {
898 local SIGNER="${1:-Joe Sixpack}"
07cb47e7 899 local REPODIR="${2:-aptarchive}"
f1e1abd8 900 local KEY="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
33a22672 901 local GPG="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
f1e1abd8 902 msgninfo "\tSign archive with $SIGNER key $KEY… "
29a59c46
DK
903 local REXKEY='keys/rexexpired'
904 local SECEXPIREBAK="${REXKEY}.sec.bak"
905 local PUBEXPIREBAK="${REXKEY}.pub.bak"
906 if [ "${SIGNER}" = 'Rex Expired' ]; then
907 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
908 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
909 # therefore we 'temporary' make the key not expired and restore a backup after signing
910 cp ${REXKEY}.sec $SECEXPIREBAK
911 cp ${REXKEY}.pub $PUBEXPIREBAK
912 local SECUNEXPIRED="${REXKEY}.sec.unexpired"
913 local PUBUNEXPIRED="${REXKEY}.pub.unexpired"
914 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
915 cp $SECUNEXPIRED ${REXKEY}.sec
916 cp $PUBUNEXPIRED ${REXKEY}.pub
917 else
f1e1abd8
DK
918 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then
919 cat setexpire.gpg
920 exit 1
921 fi
29a59c46
DK
922 cp ${REXKEY}.sec $SECUNEXPIRED
923 cp ${REXKEY}.pub $PUBUNEXPIRED
924 fi
925 fi
07cb47e7 926 for RELEASE in $(find ${REPODIR}/ -name Release); do
29a59c46 927 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg ${RELEASE}
e3c62328 928 local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
29a59c46 929 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
e3c62328
DK
930 # we might have set a specific date for the Release file, so copy it
931 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg ${INRELEASE}
f213b6ea 932 done
29a59c46
DK
933 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
934 mv -f $SECEXPIREBAK ${REXKEY}.sec
935 mv -f $PUBEXPIREBAK ${REXKEY}.pub
936 fi
f213b6ea
DK
937 msgdone "info"
938}
939
f2c0ec8b
DK
940webserverconfig() {
941 msgtest "Set webserver config option '${1}' to" "$2"
0d58c26a
DK
942 local DOWNLOG='rootdir/tmp/download-testfile.log'
943 local STATUS='rootdir/tmp/webserverconfig.status'
944 rm -f "$STATUS" "$DOWNLOG"
945 if downloadfile "http://localhost:8080/_config/set/${1}/${2}" "$STATUS" > "$DOWNLOG"; then
f2c0ec8b
DK
946 msgpass
947 else
0d58c26a
DK
948 cat "$DOWNLOG" "$STATUS"
949 msgfail
f2c0ec8b 950 fi
0d58c26a 951 testwebserverlaststatuscode '200'
f2c0ec8b
DK
952}
953
fd46d305
DK
954rewritesourceslist() {
955 local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
956 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
957 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#http://localhost:4433/#${1}#"
958 done
959}
960
5572f6bd
MV
961# wait for up to 10s for a pid file to appear to avoid possible race
962# when a helper is started and dosn't write the PID quick enough
963waitforpidfile() {
964 local PIDFILE="$1"
965 for i in $(seq 10); do
966 if test -s "$PIDFILE"; then
967 return 0
968 fi
969 sleep 1
970 done
971 msgdie "waiting for $PIDFILE failed"
972 return 1
973}
974
f213b6ea 975changetowebserver() {
23af9f40
DK
976 if [ "$1" != '--no-rewrite' ]; then
977 rewritesourceslist 'http://localhost:8080/'
978 else
979 shift
980 fi
5c0dd6fc 981 if test -x ${APTWEBSERVERBINDIR}/aptwebserver; then
fbd29dd6 982 cd aptarchive
a0db467c
DK
983 local LOG="webserver.log"
984 if ! aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1 ; then
bee0670b
DK
985 cat $LOG
986 false
987 fi
5572f6bd 988 waitforpidfile aptwebserver.pid
e3c62328
DK
989 local PID="$(cat aptwebserver.pid)"
990 if [ -z "$PID" ]; then
991 msgdie 'Could not fork aptwebserver successfully'
992 fi
993 addtrap "kill $PID;"
fbd29dd6 994 cd - > /dev/null
c5bcc607 995 else
fbd29dd6 996 msgdie 'You have to build aptwerbserver or install a webserver'
f213b6ea 997 fi
fd46d305
DK
998}
999
1000changetohttpswebserver() {
1001 if ! which stunnel4 >/dev/null; then
1002 msgdie 'You need to install stunnel4 for https testcases'
1003 fi
1004 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
dc95fee1 1005 changetowebserver --no-rewrite "$@"
fd46d305
DK
1006 fi
1007 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
68ba0b7f 1008cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
23af9f40 1009output = /dev/null
fd46d305
DK
1010
1011[https]
1012accept = 4433
1013connect = 8080
1014" > ${TMPWORKINGDIRECTORY}/stunnel.conf
1015 stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
5572f6bd 1016 waitforpidfile "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
fd46d305 1017 local PID="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
5572f6bd
MV
1018 if [ -z "$PID" ]; then
1019 msgdie 'Could not fork stunnel4 successfully'
1020 fi
fd46d305
DK
1021 addtrap 'prefix' "kill ${PID};"
1022 rewritesourceslist 'https://localhost:4433/'
f213b6ea
DK
1023}
1024
c45233ea
DK
1025changetocdrom() {
1026 mkdir -p rootdir/media/cdrom/.disk
1027 local CD="$(readlink -f rootdir/media/cdrom)"
a0975c8d
DK
1028 echo "acquire::cdrom::mount \"${CD}\";
1029acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
1030acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
1031acquire::cdrom::autodetect 0;" > rootdir/etc/apt/apt.conf.d/00cdrom
c45233ea
DK
1032 echo -n "$1" > ${CD}/.disk/info
1033 if [ ! -d aptarchive/dists ]; then
1034 msgdie 'Flat file archive cdroms can not be created currently'
1035 return 1
1036 fi
a0975c8d 1037 mv aptarchive/dists "$CD"
c45233ea
DK
1038 ln -s "$(readlink -f ./incoming)" $CD/pool
1039 find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete
a0975c8d
DK
1040 # start with an unmounted disk
1041 mv "${CD}" "${CD}-unmounted"
1042 # we don't want the disk to be modifiable
1043 addtrap 'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
1044 chmod -R -w rootdir/media/cdrom-unmounted/dists
c45233ea
DK
1045}
1046
fd46d305 1047downloadfile() {
0d58c26a 1048 local PROTO="$(echo "$1" | cut -d':' -f 1 )"
3dcdc1f9 1049 apthelper -o Debug::Acquire::${PROTO}=1 \
0d58c26a 1050 download-file "$1" "$2" 2>&1 || true
fd46d305
DK
1051 # only if the file exists the download was successful
1052 if [ -e "$2" ]; then
1053 return 0
1054 else
1055 return 1
1056 fi
1057}
1058
f213b6ea 1059checkdiff() {
846856f4 1060 local DIFFTEXT="$(command diff -u "$@" | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
8d876415 1061 if [ -n "$DIFFTEXT" ]; then
0d58c26a
DK
1062 echo >&2
1063 echo >&2 "$DIFFTEXT"
8d876415
DK
1064 return 1
1065 else
1066 return 0
1067 fi
1068}
1069
75954ae2
DK
1070testfileequal() {
1071 local FILE="$1"
1072 shift
1073 msgtest "Test for correctness of file" "$FILE"
1074 if [ -z "$*" ]; then
f213b6ea 1075 echo -n "" | checkdiff $FILE - && msgpass || msgfail
75954ae2 1076 else
f213b6ea 1077 echo "$*" | checkdiff $FILE - && msgpass || msgfail
75954ae2
DK
1078 fi
1079}
1080
b855a400
DK
1081testempty() {
1082 msgtest "Test for no output of" "$*"
859093da 1083 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
ab25bf1f 1084 if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
859093da
DK
1085 msgpass
1086 else
1087 cat $COMPAREFILE
1088 msgfail
1089 fi
ab25bf1f 1090 aptautotest 'testempty' "$@"
b855a400
DK
1091}
1092
f74a6fa1
DK
1093testequal() {
1094 local MSG='Test of equality of'
1095 if [ "$1" = '--nomsg' ]; then
1096 MSG=''
1097 shift
1098 fi
1099
03938280 1100 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
8d876415
DK
1101 echo "$1" > $COMPAREFILE
1102 shift
d2d68aaf 1103
f74a6fa1
DK
1104 if [ -n "$MSG" ]; then
1105 msgtest "$MSG" "$*"
1106 fi
ab25bf1f
DK
1107 "$@" 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
1108 aptautotest 'testequal' "$@"
8d876415
DK
1109}
1110
685625bd 1111testequalor2() {
03938280
DK
1112 local COMPAREFILE1="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1113 local COMPAREFILE2="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1114 local COMPAREAGAINST="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
685625bd
DK
1115 echo "$1" > $COMPAREFILE1
1116 echo "$2" > $COMPAREFILE2
1117 shift 2
1118 msgtest "Test for equality OR of" "$*"
ab25bf1f 1119 "$@" >$COMPAREAGAINST 2>&1 || true
0d58c26a
DK
1120 if checkdiff $COMPAREFILE1 $COMPAREAGAINST >/dev/null 2>&1 || \
1121 checkdiff $COMPAREFILE2 $COMPAREAGAINST >/dev/null 2>&1
1122 then
0caa5a4c
DK
1123 msgpass
1124 else
1125 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
1126 checkdiff $COMPAREFILE1 $COMPAREAGAINST || true
1127 echo -n "${CINFO}Diff against OR 2${CNORMAL}"
1128 checkdiff $COMPAREFILE2 $COMPAREAGAINST || true
1129 msgfail
1130 fi
ab25bf1f 1131 aptautotest 'testequalor2' "$@"
685625bd
DK
1132}
1133
8d876415 1134testshowvirtual() {
edc0ef10 1135 local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
8d876415
DK
1136 local PACKAGE="$1"
1137 shift
1138 while [ -n "$1" ]; do
1139 VIRTUAL="${VIRTUAL}
edc0ef10 1140N: Can't select versions from package '$1' as it is purely virtual"
8d876415
DK
1141 PACKAGE="${PACKAGE} $1"
1142 shift
1143 done
1144 msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
1145 VIRTUAL="${VIRTUAL}
4bec02c2 1146N: No packages found"
03938280 1147 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
ea65d079 1148 local ARCH="$(getarchitecture 'native')"
8d876415 1149 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
e8379ba3 1150 aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
8d876415
DK
1151}
1152
1153testnopackage() {
1154 msgtest "Test for non-existent packages" "apt-cache show $*"
846856f4 1155 local SHOWPKG="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
8d876415 1156 if [ -n "$SHOWPKG" ]; then
0d58c26a
DK
1157 echo >&2
1158 echo >&2 "$SHOWPKG"
8d876415 1159 msgfail
0d58c26a
DK
1160 else
1161 msgpass
8d876415 1162 fi
8d876415 1163}
01a6e24c
DK
1164
1165testdpkginstalled() {
1166 msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
846856f4 1167 local PKGS="$(dpkg -l "$@" 2>/dev/null | grep '^i' | wc -l)"
87bc1c45 1168 if [ "$PKGS" != $# ]; then
0d58c26a
DK
1169 echo >&2 $PKGS
1170 dpkg -l "$@" | grep '^[a-z]' >&2
01a6e24c 1171 msgfail
0d58c26a
DK
1172 else
1173 msgpass
01a6e24c 1174 fi
01a6e24c
DK
1175}
1176
5cf733e1
DK
1177testdpkgnotinstalled() {
1178 msgtest "Test for correctly not-installed package(s) with" "dpkg -l $*"
846856f4 1179 local PKGS="$(dpkg -l "$@" 2> /dev/null | grep '^i' | wc -l)"
01a6e24c
DK
1180 if [ "$PKGS" != 0 ]; then
1181 echo
0d58c26a 1182 dpkg -l "$@" | grep '^[a-z]' >&2
01a6e24c 1183 msgfail
0d58c26a
DK
1184 else
1185 msgpass
01a6e24c 1186 fi
01a6e24c 1187}
ec7f904e
DK
1188
1189testmarkedauto() {
03938280 1190 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
ec7f904e
DK
1191 if [ -n "$1" ]; then
1192 msgtest 'Test for correctly marked as auto-installed' "$*"
1193 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1194 else
1195 msgtest 'Test for correctly marked as auto-installed' 'no package'
c98fb5e0 1196 echo -n > $COMPAREFILE
ec7f904e
DK
1197 fi
1198 aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
1199}
89a1aa5d 1200
0440d936
DK
1201testsuccess() {
1202 if [ "$1" = '--nomsg' ]; then
1203 shift
1204 else
1205 msgtest 'Test for successful execution of' "$*"
1206 fi
03938280 1207 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1df24acf
DK
1208 if "$@" >${OUTPUT} 2>&1; then
1209 if expr match "$1" '^apt.*' >/dev/null; then
1210 if grep -q -E '^E: ' "$OUTPUT"; then
1211 echo >&2
1212 cat >&2 $OUTPUT
1213 msgfail 'successful run, but output contains errors'
1214 else
1215 msgpass
1216 fi
1217 else
1218 msgpass
1219 fi
0440d936 1220 else
07cb47e7 1221 local EXITCODE=$?
0d58c26a
DK
1222 echo >&2
1223 cat >&2 $OUTPUT
07cb47e7 1224 msgfail "exitcode $EXITCODE"
0440d936 1225 fi
ab25bf1f 1226 aptautotest 'testsuccess' "$@"
0440d936
DK
1227}
1228
1229testfailure() {
1230 if [ "$1" = '--nomsg' ]; then
1231 shift
1232 else
889b0072 1233 msgtest 'Test for failure in execution of' "$*"
0440d936 1234 fi
03938280 1235 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1df24acf 1236 if "$@" >${OUTPUT} 2>&1; then
07cb47e7 1237 local EXITCODE=$?
0d58c26a
DK
1238 echo >&2
1239 cat >&2 $OUTPUT
07cb47e7 1240 msgfail "exitcode $EXITCODE"
0440d936 1241 else
1df24acf
DK
1242 local EXITCODE=$?
1243 if expr match "$1" '^apt.*' >/dev/null; then
1244 if ! grep -q -E '^E: ' "$OUTPUT"; then
1245 echo >&2
1246 cat >&2 $OUTPUT
1247 msgfail "run failed with exitcode ${EXITCODE}, but with no errors"
1248 else
1249 msgpass
1250 fi
1251 else
1252 msgpass
1253 fi
0440d936 1254 fi
ab25bf1f 1255 aptautotest 'testfailure' "$@"
0440d936
DK
1256}
1257
de81b2e2
DK
1258testfilestats() {
1259 msgtest "Test that file $1 has $2 $3" "$4"
1260 if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
5684f71f
DK
1261 msgpass
1262 else
1263 echo >&2
1264 ls -l >&2 "$1"
de81b2e2
DK
1265 echo -n >&2 "stat(1) reports for $2: "
1266 stat --format "$2" "$1"
5684f71f
DK
1267 msgfail
1268 fi
1269}
de81b2e2
DK
1270testaccessrights() {
1271 testfilestats "$1" '%a' '=' "$2"
1272}
5684f71f 1273
0d58c26a
DK
1274testwebserverlaststatuscode() {
1275 local DOWNLOG='rootdir/tmp/webserverstatus-testfile.log'
1276 local STATUS='rootdir/tmp/webserverstatus-statusfile.log'
1277 rm -f "$DOWNLOG" "$STATUS"
1278 msgtest 'Test last status code from the webserver was' "$1"
1279 downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
1280 if [ "$(cat "$STATUS")" = "$1" ]; then
1281 msgpass
1282 else
1283 echo >&2
1284 if [ -n "$2" ]; then
1285 shift
1286 echo >&2 '#### Additionally provided output files contain:'
1287 cat >&2 "$@"
1288 fi
1289 echo >&2 '#### Download log of the status code:'
1290 cat >&2 "$DOWNLOG"
1291 msgfail "Status was $(cat "$STATUS")"
1292 fi
1293}
1294
89a1aa5d
DK
1295pause() {
1296 echo "STOPPED execution. Press enter to continue"
1297 local IGNORE
1298 read IGNORE
1299}
ab25bf1f 1300
846bc058
DK
1301listcurrentlistsdirectory() {
1302 find rootdir/var/lib/apt/lists -maxdepth 1 -type d | while read line; do
1303 stat --format '%U:%G:%a:%n' "$line"
1304 done
1305 find rootdir/var/lib/apt/lists -maxdepth 1 \! -type d | while read line; do
1306 stat --format '%U:%G:%a:%s:%y:%n' "$line"
1307 done
1308}
1309
ab25bf1f
DK
1310### The following tests are run by most test methods automatically to check
1311### general things about commands executed without writing the test every time.
1312
1313aptautotest() {
1314 local TESTCALL="$1"
1315 local CMD="$2"
1316 local FIRSTOPT="$3"
1317 local AUTOTEST="aptautotest_$(basename "$CMD" | tr -d '-')_$(echo "$FIRSTOPT" | tr -d '-')"
1318 if command -v $AUTOTEST >/dev/null; then
1319 shift 3
1320 # save and restore the *.output files from other tests
1321 # as we might otherwise override them in these automatic tests
1322 rm -rf rootdir/tmp-before
1323 mv rootdir/tmp rootdir/tmp-before
1324 mkdir rootdir/tmp
1325 $AUTOTEST "$TESTCALL" "$@"
1326 rm -rf rootdir/tmp-aptautotest
1327 mv rootdir/tmp rootdir/tmp-aptautotest
1328 mv rootdir/tmp-before rootdir/tmp
1329 fi
1330}
1331
1332aptautotest_aptget_update() {
1333 if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
1334 # all copied files are properly chmodded
1335 find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -maxdepth 1 -type f | while read file; do
1336 testfilestats "$file" '%U:%G:%a' '=' "${USER}:${USER}:644"
1337 done
1338}
1339aptautotest_apt_update() { aptautotest_aptget_update "$@"; }