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