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