tests: rm pkgcache.bin in 719263 test
[ntk/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
682a3bf7
DK
6if expr match "$(readlink -f /proc/$$/fd/1)" '/dev/pts/[0-9]\+' > /dev/null && \
7 expr match "$(readlink -f /proc/$$/fd/2)" '/dev/pts/[0-9]\+' > /dev/null; then
8 CERROR="\e[1;31m" # red
9 CWARNING="\e[1;33m" # yellow
10 CMSG="\e[1;32m" # green
11 CINFO="\e[1;96m" # light blue
12 CDEBUG="\e[1;94m" # blue
13 CNORMAL="\e[0;39m" # default system console color
14 CDONE="\e[1;32m" # green
15 CPASS="\e[1;32m" # green
16 CFAIL="\e[1;31m" # red
17 CCMD="\e[1;35m" # pink
18fi
8d876415
DK
19
20msgdie() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; }
21msgwarn() { echo "${CWARNING}W: $1${CNORMAL}" >&2; }
22msgmsg() { echo "${CMSG}$1${CNORMAL}" >&2; }
23msginfo() { echo "${CINFO}I: $1${CNORMAL}" >&2; }
24msgdebug() { echo "${CDEBUG}D: $1${CNORMAL}" >&2; }
25msgdone() { echo "${CDONE}DONE${CNORMAL}" >&2; }
26msgnwarn() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; }
27msgnmsg() { echo -n "${CMSG}$1${CNORMAL}" >&2; }
28msgninfo() { echo -n "${CINFO}I: $1${CNORMAL}" >&2; }
29msgndebug() { echo -n "${CDEBUG}D: $1${CNORMAL}" >&2; }
2a2a7ef4
DK
30msgtest() {
31 while [ -n "$1" ]; do
32 echo -n "${CINFO}$1${CCMD} " >&2;
33 echo -n "$(echo "$2" | sed -e 's/^aptc/apt-c/' -e 's/^aptg/apt-g/' -e 's/^aptf/apt-f/')${CINFO} " >&2;
d73840dc
DK
34 shift
35 if [ -n "$1" ]; then shift; else break; fi
2a2a7ef4
DK
36 done
37 echo -n "…${CNORMAL} " >&2;
38}
8d876415
DK
39msgpass() { echo "${CPASS}PASS${CNORMAL}" >&2; }
40msgskip() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
5229b285
DK
41msgfail() {
42 if [ $# -gt 0 ]; then echo "${CFAIL}FAIL: $*${CNORMAL}" >&2;
43 else echo "${CFAIL}FAIL${CNORMAL}" >&2; fi
44 EXIT_CODE=$((EXIT_CODE+1));
45}
8d876415
DK
46
47# enable / disable Debugging
fc89263e
DK
48MSGLEVEL=${MSGLEVEL:-3}
49if [ $MSGLEVEL -le 0 ]; then
50 msgdie() { true; }
51fi
52if [ $MSGLEVEL -le 1 ]; then
53 msgwarn() { true; }
54 msgnwarn() { true; }
55fi
56if [ $MSGLEVEL -le 2 ]; then
57 msgmsg() { true; }
58 msgnmsg() { true; }
39cc8228
DK
59 msgtest() { true; }
60 msgpass() { echo -n " ${CPASS}P${CNORMAL}" >&2; }
61 msgskip() { echo -n " ${CWARNING}S${CNORMAL}" >&2; }
682a3bf7 62 if [ -n "$CFAIL" ]; then
5229b285 63 msgfail() { echo -n " ${CFAIL}FAIL${CNORMAL}" >&2; EXIT_CODE=$((EXIT_CODE+1)); }
682a3bf7 64 else
5229b285 65 msgfail() { echo -n " ###FAILED###" >&2; EXIT_CODE=$((EXIT_CODE+1)); }
682a3bf7 66 fi
fc89263e
DK
67fi
68if [ $MSGLEVEL -le 3 ]; then
69 msginfo() { true; }
70 msgninfo() { true; }
71fi
72if [ $MSGLEVEL -le 4 ]; then
73 msgdebug() { true; }
74 msgndebug() { true; }
75fi
76msgdone() {
77 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
78 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
79 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
80 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
81 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
82 true;
83 else
84 echo "${CDONE}DONE${CNORMAL}" >&2;
85 fi
86}
8d876415
DK
87
88runapt() {
89 msgdebug "Executing: ${CCMD}$*${CDEBUG} "
7d0627b6 90 if [ -f ./aptconfig.conf ]; then
037374fe
DK
91 MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
92 elif [ -f ../aptconfig.conf ]; then
93 MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
7d0627b6 94 else
037374fe 95 MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
7d0627b6 96 fi
8d876415
DK
97}
98aptconfig() { runapt apt-config $*; }
99aptcache() { runapt apt-cache $*; }
c45233ea 100aptcdrom() { runapt apt-cdrom $*; }
8d876415
DK
101aptget() { runapt apt-get $*; }
102aptftparchive() { runapt apt-ftparchive $*; }
1f8b2599 103aptkey() { runapt apt-key $*; }
ec7f904e 104aptmark() { runapt apt-mark $*; }
158fda31
DK
105dpkg() {
106 $(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log $*
107}
b6b5a542
DK
108aptitude() {
109 if [ -f ./aptconfig.conf ]; then
110 APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $*
111 elif [ -f ../aptconfig.conf ]; then
112 APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $*
113 else
114 LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $*
115 fi
116}
3fa950f1
DK
117gdb() {
118 echo "gdb: run »$*«"
6161edd7 119 APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which gdb) ${BUILDDIRECTORY}/$1 --args $*
3fa950f1 120}
ae99ce2e
DK
121http() {
122 LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods/http
123}
8d876415 124
8c1dd12c 125exitwithstatus() {
f91bd741
MV
126 # error if we about to overflow, but ...
127 # "255 failures ought to be enough for everybody"
5d76cee1
MV
128 if [ $EXIT_CODE -gt 255 ]; then
129 msgdie "Total failure count $EXIT_CODE too big"
f91bd741 130 fi
5d76cee1 131 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
8c1dd12c
MV
132}
133
804d4a0d
DK
134shellsetedetector() {
135 local exit_status=$?
136 if [ "$exit_status" != '0' ]; then
137 echo >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}"
138 if [ "$EXIT_CODE" = '0' ]; then
139 EXIT_CODE="$exit_status"
140 fi
141 fi
142}
143
b720d0bd 144addtrap() {
8437b7d4
DK
145 if [ "$1" = 'prefix' ]; then
146 CURRENTTRAP="$2 $CURRENTTRAP"
147 else
148 CURRENTTRAP="$CURRENTTRAP $1"
149 fi
804d4a0d 150 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
b720d0bd 151}
8d876415
DK
152
153setupenvironment() {
75954ae2 154 TMPWORKINGDIRECTORY=$(mktemp -d)
53ea1b56 155 TESTDIRECTORY=$(readlink -f $(dirname $0))
3cbbda3c 156 msgninfo "Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
53ea1b56 157 BUILDDIRECTORY="${TESTDIRECTORY}/../../build/bin"
8d876415 158 test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
8437b7d4 159 addtrap "cd /; rm -rf $TMPWORKINGDIRECTORY;"
8d876415 160 cd $TMPWORKINGDIRECTORY
cd725954 161 mkdir rootdir aptarchive keys
8d876415 162 cd rootdir
b29c3712
DK
163 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
164 mkdir -p var/cache var/lib var/log
cffea9af 165 mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
cd725954 166 touch var/lib/dpkg/available
8d876415
DK
167 mkdir -p usr/lib/apt
168 ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods
169 cd ..
2c6baa5a 170 local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
53ea1b56
DK
171 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
172 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
8f8169ac 173 fi
4a4ea26c 174 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
53ea1b56
DK
175 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
176 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
8f8169ac 177 fi
53ea1b56 178 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys/
cd725954 179 ln -s ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
cffea9af 180 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
94eb3bee 181 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
8d876415
DK
182 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
183 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
f425d4d5 184 echo "Dir::Bin::Methods \"${BUILDDIRECTORY}/methods\";" >> aptconfig.conf
cffea9af
DK
185 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
186 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
187 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
188 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
189 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
7a2690a3 190 if ! $(which dpkg) --assert-multi-arch >/dev/null 2>&1; then
53ea1b56
DK
191 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf # Added to test multiarch before dpkg is ready for it…
192 fi
cffea9af 193 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
2c085486 194 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
23af9f40 195 echo "Acquire::https::CaInfo \"${TESTDIR}/apt.pem\";" > rootdir/etc/apt/apt.conf.d/99https
8d876415 196 export LC_ALL=C
7f52cf7b 197 export PATH="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
276e51dd 198 configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
8d876415
DK
199 msgdone "info"
200}
201
ea65d079
DK
202getarchitecture() {
203 if [ "$1" = "native" -o -z "$1" ]; then
204 eval `aptconfig shell ARCH APT::Architecture`
205 if [ -n "$ARCH" ]; then
206 echo $ARCH
207 else
5834d7a1 208 dpkg --print-architecture
ea65d079
DK
209 fi
210 else
211 echo $1
212 fi
213}
214
53ea1b56
DK
215getarchitectures() {
216 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
217}
218
8d876415 219configarchitecture() {
18908589
DK
220 {
221 echo "APT::Architecture \"$(getarchitecture $1)\";"
222 while [ -n "$1" ]; do
223 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
224 shift
225 done
226 } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
53ea1b56
DK
227 configdpkg
228}
229
230configdpkg() {
231 if [ ! -e rootdir/var/lib/dpkg/status ]; then
232 local STATUSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
233 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
234 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
235 else
236 echo -n > rootdir/var/lib/dpkg/status
237 fi
238 fi
18908589 239 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
7a2690a3 240 if $(which dpkg) --assert-multi-arch >/dev/null 2>&1; then
53ea1b56
DK
241 local ARCHS="$(getarchitectures)"
242 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
243 DPKGARCH="$(dpkg --print-architecture)"
244 for ARCH in ${ARCHS}; do
feae193b 245 if [ "${ARCH}" != "${DPKGARCH}" ]; then
18908589 246 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
feae193b 247 # old-style used e.g. in Ubuntu-P – and as it seems travis
18908589
DK
248 echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
249 echo "DPKG::options:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
feae193b
DK
250 fi
251 fi
53ea1b56
DK
252 done
253 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
05343a22
DK
254 # dpkg doesn't really check the version as long as it is fully installed,
255 # but just to be sure we choose one above the required version
256 insertinstalledpackage 'dpkg' "all" '1.16.2+fake'
53ea1b56
DK
257 fi
258 fi
259 fi
8d876415
DK
260}
261
276e51dd
DK
262configcompression() {
263 while [ -n "$1" ]; do
264 case "$1" in
265 '.') echo ".\t.\tcat";;
266 'gz') echo "gzip\tgz\tgzip";;
267 'bz2') echo "bzip2\tbz2\tbzip2";;
268 'lzma') echo "lzma\tlzma\txz --format=lzma";;
269 'xz') echo "xz\txz\txz";;
270 *) echo "$1\t$1\t$1";;
271 esac
272 shift
273 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
274}
275
75954ae2 276setupsimplenativepackage() {
ce9864a8
DK
277 local NAME="$1"
278 local ARCH="$2"
279 local VERSION="$3"
280 local RELEASE="${4:-unstable}"
281 local DEPENDENCIES="$5"
18908589
DK
282 local DESCRIPTION="${6:-"Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
283 If you find such a package installed on your system,
284 something went horribly wrong! They are autogenerated
285 und used only by testcases and surf no other propose…"}"
286
b7899b00
DK
287 local SECTION="${7:-others}"
288 local DISTSECTION
289 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
290 DISTSECTION="main"
291 else
292 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
293 fi
ce9864a8
DK
294 local BUILDDIR=incoming/${NAME}-${VERSION}
295 mkdir -p ${BUILDDIR}/debian/source
296 cd ${BUILDDIR}
297 echo "* most suckless software product ever" > FEATURES
b7899b00
DK
298 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
299 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
ce9864a8
DK
300
301 * Initial release
302
b7899b00
DK
303 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
304 test -e debian/control || echo "Source: $NAME
305Section: $SECTION
ce9864a8
DK
306Priority: optional
307Maintainer: Joe Sixpack <joe@example.org>
308Build-Depends: debhelper (>= 7)
309Standards-Version: 3.9.1
310
875bcb36
DK
311Package: $NAME" > debian/control
312 if [ "$ARCH" = 'all' ]; then
313 echo "Architecture: all" >> debian/control
314 else
315 echo "Architecture: any" >> debian/control
316 fi
ce9864a8 317 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
18908589
DK
318 echo "Description: $DESCRIPTION" >> debian/control
319
b7899b00
DK
320 test -e debian/compat || echo "7" > debian/compat
321 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
ce9864a8 322 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
75954ae2
DK
323 cd - > /dev/null
324}
325
326buildsimplenativepackage() {
327 local NAME="$1"
328 local ARCH="$2"
329 local VERSION="$3"
330 local RELEASE="${4:-unstable}"
331 local DEPENDENCIES="$5"
18908589
DK
332 local DESCRIPTION="${6:-"Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
333 If you find such a package installed on your system,
334 something went horribly wrong! They are autogenerated
335 und used only by testcases and surf no other propose…"}"
336
75954ae2 337 local SECTION="${7:-others}"
d67004e0 338 local PRIORITY="${8:-optional}"
42c1513b 339 local FILE_TREE="$9"
75954ae2
DK
340 local DISTSECTION
341 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
342 DISTSECTION="main"
343 else
344 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
345 fi
5a635ee4 346 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
b761356f 347
18331adf 348 msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… "
b761356f
DK
349 mkdir -p $BUILDDIR/debian/source
350 echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
351 echo "#!/bin/sh
352echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
353
354 echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
355 echo "$NAME ($VERSION) $RELEASE; urgency=low
356
357 * Initial release
358
359 -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
360 echo "Source: $NAME
361Section: $SECTION
d67004e0 362Priority: $PRIORITY
b761356f 363Maintainer: Joe Sixpack <joe@example.org>
01f520ce
DK
364Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
365 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
366 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
367 echo "
368Package: $NAME" >> ${BUILDDIR}/debian/control
b761356f 369
875bcb36
DK
370 if [ "$ARCH" = 'all' ]; then
371 echo "Architecture: all" >> ${BUILDDIR}/debian/control
372 else
373 echo "Architecture: any" >> ${BUILDDIR}/debian/control
374 fi
01f520ce
DK
375 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
376 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
18908589 377 echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
01f520ce 378
b761356f 379 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
f1828b69
DK
380 (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' \
381 | while read SRC; do
5a635ee4 382 echo "pool/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
f1828b69
DK
383# if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
384# gpg --yes --no-default-keyring --secret-keyring ./keys/joesixpack.sec \
385# --keyring ./keys/joesixpack.pub --default-key 'Joe Sixpack' \
386# --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
387# mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
388# fi
b761356f 389 done
84aa13f4 390
ea65d079 391 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
84aa13f4
DK
392 rm -rf ${BUILDDIR}/debian/tmp
393 mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
394 cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}
395 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}
42c1513b
MV
396 if [ -n "$FILE_TREE" ]; then
397 cp -ar "$FILE_TREE" ${BUILDDIR}/debian/tmp
398 fi
42c1513b 399
84aa13f4
DK
400 (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch)
401 (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
84aa13f4
DK
402 dpkg-deb --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/.. 2> /dev/null > /dev/null
403 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist
404 done
405
13845042
DK
406 mkdir -p ${BUILDDIR}/../${NAME}_${VERSION}
407 cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}/
408 cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}.changelog
5a635ee4 409 rm -rf "${BUILDDIR}"
b761356f 410 msgdone "info"
75954ae2
DK
411}
412
413buildpackage() {
414 local BUILDDIR=$1
415 local RELEASE=$2
416 local SECTION=$3
ea65d079 417 local ARCH=$(getarchitecture $4)
75954ae2
DK
418 msgninfo "Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… "
419 cd $BUILDDIR
420 if [ "$ARCH" = "all" ]; then
421 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
422 fi
b7899b00
DK
423 local BUILT="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
424 local PKGS="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
5ed56f93 425 local SRCS="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
ce9864a8 426 cd - > /dev/null
b7899b00 427 for PKG in $PKGS; do
75954ae2 428 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist
b7899b00
DK
429 done
430 for SRC in $SRCS; do
75954ae2 431 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist
b7899b00 432 done
cffea9af 433 msgdone "info"
ce9864a8
DK
434}
435
436buildaptarchive() {
ce9864a8
DK
437 if [ -d incoming ]; then
438 buildaptarchivefromincoming $*
439 else
440 buildaptarchivefromfiles $*
441 fi
442}
443
444createaptftparchiveconfig() {
276e51dd
DK
445 local COMPRESSORS="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
446 COMPRESSORS="${COMPRESSORS%* }"
ce9864a8 447 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
448 if [ -z "$ARCHS" ]; then
449 # the pool is empty, so we will operate on faked packages - let us use the configured archs
53ea1b56 450 ARCHS="$(getarchitectures)"
158fda31 451 fi
ce9864a8
DK
452 echo -n 'Dir {
453 ArchiveDir "' >> ftparchive.conf
454 echo -n $(readlink -f .) >> ftparchive.conf
455 echo -n '";
456 CacheDir "' >> ftparchive.conf
457 echo -n $(readlink -f ..) >> ftparchive.conf
458 echo -n '";
b7899b00
DK
459 FileListDir "' >> ftparchive.conf
460 echo -n $(readlink -f pool/) >> ftparchive.conf
461 echo -n '";
462};
463Default {
276e51dd
DK
464 Packages::Compress "'"$COMPRESSORS"'";
465 Sources::Compress "'"$COMPRESSORS"'";
466 Contents::Compress "'"$COMPRESSORS"'";
467 Translation::Compress "'"$COMPRESSORS"'";
18331adf 468 LongDescription "false";
ce9864a8
DK
469};
470TreeDefault {
471 Directory "pool/";
472 SrcDirectory "pool/";
473};
474APT {
475 FTPArchive {
476 Release {
477 Origin "joesixpack";
478 Label "apttestcases";
479 Suite "unstable";
480 Description "repository with dummy packages";
481 Architectures "' >> ftparchive.conf
482 echo -n "$ARCHS" >> ftparchive.conf
483 echo 'source";
484 };
485 };
486};' >> ftparchive.conf
b7899b00
DK
487 for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
488 echo -n 'tree "dists/' >> ftparchive.conf
489 echo -n "$DIST" >> ftparchive.conf
490 echo -n '" {
ce9864a8
DK
491 Architectures "' >> ftparchive.conf
492 echo -n "$ARCHS" >> ftparchive.conf
b7899b00
DK
493 echo -n 'source";
494 FileList "' >> ftparchive.conf
495 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
496 echo -n '";
497 SourceFileList "' >> ftparchive.conf
498 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
499 echo -n '";
500 Sections "' >> ftparchive.conf
501 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
502 echo '";
ce9864a8 503};' >> ftparchive.conf
b7899b00 504 done
ce9864a8
DK
505}
506
507buildaptftparchivedirectorystructure() {
b7899b00
DK
508 local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
509 for DIST in $DISTS; do
510 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
511 for SECTION in $SECTIONS; do
512 local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
513 for ARCH in $ARCHS; do
514 mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH}
515 done
516 mkdir -p dists/${DIST}/${SECTION}/source
517 mkdir -p dists/${DIST}/${SECTION}/i18n
518 done
ce9864a8 519 done
ce9864a8
DK
520}
521
9b78cda6
DK
522insertpackage() {
523 local RELEASE="$1"
524 local NAME="$2"
525 local ARCH="$3"
526 local VERSION="$4"
527 local DEPENDENCIES="$5"
d67004e0 528 local PRIORITY="${6:-optional}"
18908589
DK
529 local DESCRIPTION="${7:-"Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
530 If you find such a package installed on your system,
531 something went horribly wrong! They are autogenerated
532 und used only by testcases and surf no other propose…"}"
d67004e0 533 local ARCHS=""
ea65d079 534 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
c919ad6e 535 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
53ea1b56 536 ARCHS="$(getarchitectures)"
d67004e0
DK
537 else
538 ARCHS="$arch"
539 fi
540 for BUILDARCH in $ARCHS; do
541 local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
542 mkdir -p $PPATH aptarchive/dists/${RELEASE}/main/source
543 touch aptarchive/dists/${RELEASE}/main/source/Sources
544 local FILE="${PPATH}/Packages"
545 echo "Package: $NAME
546Priority: $PRIORITY
9b78cda6 547Section: other
2c085486 548Installed-Size: 42
c919ad6e
DK
549Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
550 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
551 echo "Version: $VERSION
d67004e0
DK
552Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
553 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
18908589 554 echo "Description: $DESCRIPTION" >> $FILE
8ba17539 555 echo >> $FILE
d67004e0 556 done
9b78cda6
DK
557 done
558}
559
234675b7
DK
560insertsource() {
561 local RELEASE="$1"
562 local NAME="$2"
563 local ARCH="$3"
564 local VERSION="$4"
565 local DEPENDENCIES="$5"
566 local ARCHS=""
567 local SPATH="aptarchive/dists/${RELEASE}/main/source"
568 mkdir -p $SPATH
569 local FILE="${SPATH}/Sources"
570 echo "Package: $NAME
571Binary: $NAME
572Version: $VERSION
573Maintainer: Joe Sixpack <joe@example.org>
574Architecture: $ARCH" >> $FILE
575 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
576 echo "Files:
577 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
d5dea0be
DK
578 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
579" >> $FILE
234675b7
DK
580}
581
dfc2b1be
DK
582insertinstalledpackage() {
583 local NAME="$1"
584 local ARCH="$2"
585 local VERSION="$3"
586 local DEPENDENCIES="$4"
d67004e0 587 local PRIORITY="${5:-optional}"
d4b4e5ea 588 local STATUS="${6:-install ok installed}"
18908589
DK
589 local DESCRIPTION="${7:-"Description: an autogenerated dummy ${NAME}=${VERSION}/installed
590 If you find such a package installed on your system,
591 something went horribly wrong! They are autogenerated
592 und used only by testcases and surf no other propose…"}"
593
53ea1b56
DK
594 local FILE='rootdir/var/lib/dpkg/status'
595 local INFO='rootdir/var/lib/dpkg/info'
ea65d079 596 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
d67004e0 597 echo "Package: $NAME
d4b4e5ea 598Status: $STATUS
d67004e0 599Priority: $PRIORITY
dfc2b1be
DK
600Section: other
601Installed-Size: 42
602Maintainer: Joe Sixpack <joe@example.org>
dfc2b1be 603Version: $VERSION" >> $FILE
c919ad6e 604 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
d67004e0 605 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
18908589
DK
606 echo "Description: $DESCRIPTION" >> $FILE
607 echo >> $FILE
53ea1b56
DK
608 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
609 echo -n > ${INFO}/${NAME}:${arch}.list
610 else
611 echo -n > ${INFO}/${NAME}.list
612 fi
d67004e0 613 done
dfc2b1be
DK
614}
615
616
ce9864a8 617buildaptarchivefromincoming() {
3cbbda3c 618 msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
ce9864a8
DK
619 cd aptarchive
620 [ -e pool ] || ln -s ../incoming pool
621 [ -e ftparchive.conf ] || createaptftparchiveconfig
622 [ -e dists ] || buildaptftparchivedirectorystructure
b7899b00 623 msgninfo "\tGenerate Packages, Sources and Contents files… "
ce9864a8 624 aptftparchive -qq generate ftparchive.conf
ce9864a8
DK
625 cd - > /dev/null
626 msgdone "info"
9b78cda6 627 generatereleasefiles
ce9864a8
DK
628}
629
630buildaptarchivefromfiles() {
3cbbda3c 631 msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
9b78cda6
DK
632 find aptarchive -name 'Packages' -o -name 'Sources' | while read line; do
633 msgninfo "\t${line} file… "
276e51dd 634 compressfile "$line" "$1"
8d876415 635 msgdone "info"
9b78cda6 636 done
e3c62328 637 generatereleasefiles "$@"
9b78cda6
DK
638}
639
276e51dd
DK
640compressfile() {
641 cat ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | while read compressor extension command; do
642 if [ "$compressor" = '.' ]; then
643 if [ -n "$2" ]; then
644 touch -d "$2" "$1"
645 fi
646 continue
647 fi
648 cat "$1" | $command > "${1}.${extension}"
649 if [ -n "$2" ]; then
650 touch -d "$2" "${1}.${extension}"
651 fi
652 done
653}
654
a3bbbab7
DK
655# can be overridden by testcases for their pleasure
656getcodenamefromsuite() { echo -n "$1"; }
657getreleaseversionfromsuite() { true; }
718f797c 658getlabelfromsuite() { true; }
a3bbbab7 659
9b78cda6 660generatereleasefiles() {
884a4c0a
DK
661 # $1 is the Date header and $2 is the ValidUntil header to be set
662 # both should be given in notation date/touch can understand
9b78cda6
DK
663 msgninfo "\tGenerate Release files… "
664 if [ -e aptarchive/dists ]; then
665 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
a3bbbab7
DK
666 local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
667 local CODENAME="$(getcodenamefromsuite $SUITE)"
668 local VERSION="$(getreleaseversionfromsuite $SUITE)"
718f797c 669 local LABEL="$(getlabelfromsuite $SUITE)"
884a4c0a 670 if [ -n "$VERSION" ]; then
718f797c
DK
671 VERSION="-o APT::FTPArchive::Release::Version=${VERSION}"
672 fi
673 if [ -n "$LABEL" ]; then
674 LABEL="-o APT::FTPArchive::Release::Label=${LABEL}"
a3bbbab7 675 fi
884a4c0a
DK
676 aptftparchive -qq release $dir \
677 -o APT::FTPArchive::Release::Suite="${SUITE}" \
678 -o APT::FTPArchive::Release::Codename="${CODENAME}" \
718f797c 679 ${LABEL} \
884a4c0a
DK
680 ${VERSION} \
681 | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
a3bbbab7 682 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
35faae11
DK
683 sed -i '/^Date: / a\
684NotAutomatic: yes' $dir/Release
685 fi
884a4c0a
DK
686 if [ -n "$1" -a "$1" != "now" ]; then
687 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
688 fi
689 if [ -n "$2" ]; then
690 sed -i "/^Date: / a\
691Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
692 fi
9b78cda6
DK
693 done
694 else
695 aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
8d876415 696 fi
884a4c0a 697 if [ -n "$1" -a "$1" != "now" ]; then
fe0f7911
DK
698 for release in $(find ./aptarchive -name 'Release'); do
699 touch -d "$1" $release
700 done
8d876415 701 fi
b7899b00 702 msgdone "info"
8d876415
DK
703}
704
b7899b00
DK
705setupdistsaptarchive() {
706 local APTARCHIVE=$(readlink -f ./aptarchive)
707 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
708 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
709 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
710 SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
711 msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
712 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
713 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
714 msgdone "info"
715 done
716}
717
718setupflataptarchive() {
ce9864a8 719 local APTARCHIVE=$(readlink -f ./aptarchive)
8d876415
DK
720 if [ -f ${APTARCHIVE}/Packages ]; then
721 msgninfo "\tadd deb sources.list line… "
722 echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
723 msgdone "info"
724 else
725 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
726 fi
727 if [ -f ${APTARCHIVE}/Sources ]; then
728 msgninfo "\tadd deb-src sources.list line… "
729 echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
730 msgdone "info"
731 else
732 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
733 fi
b7899b00
DK
734}
735
736setupaptarchive() {
737 buildaptarchive
738 if [ -e aptarchive/dists ]; then
739 setupdistsaptarchive
740 else
741 setupflataptarchive
742 fi
f213b6ea 743 signreleasefiles
b2ea1a47
DK
744 if [ "$1" != '--no-update' ]; then
745 msgninfo "\tSync APT's cache with the archive… "
746 aptget update -qq
747 msgdone "info"
748 fi
8d876415
DK
749}
750
f213b6ea
DK
751signreleasefiles() {
752 local SIGNER="${1:-Joe Sixpack}"
29a59c46 753 local GPG="gpg --batch --yes --no-default-keyring --trustdb-name rootdir/etc/apt/trustdb.gpg"
f213b6ea 754 msgninfo "\tSign archive with $SIGNER key… "
29a59c46
DK
755 local REXKEY='keys/rexexpired'
756 local SECEXPIREBAK="${REXKEY}.sec.bak"
757 local PUBEXPIREBAK="${REXKEY}.pub.bak"
758 if [ "${SIGNER}" = 'Rex Expired' ]; then
759 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
760 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
761 # therefore we 'temporary' make the key not expired and restore a backup after signing
762 cp ${REXKEY}.sec $SECEXPIREBAK
763 cp ${REXKEY}.pub $PUBEXPIREBAK
764 local SECUNEXPIRED="${REXKEY}.sec.unexpired"
765 local PUBUNEXPIRED="${REXKEY}.pub.unexpired"
766 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
767 cp $SECUNEXPIRED ${REXKEY}.sec
768 cp $PUBUNEXPIRED ${REXKEY}.pub
769 else
770 printf "expire\n1w\nsave\n" | $GPG --keyring ${REXKEY}.pub --secret-keyring ${REXKEY}.sec --command-fd 0 --edit-key "${SIGNER}" >/dev/null 2>&1 || true
771 cp ${REXKEY}.sec $SECUNEXPIRED
772 cp ${REXKEY}.pub $PUBUNEXPIRED
773 fi
774 fi
f213b6ea 775 for KEY in $(find keys/ -name '*.sec'); do
29a59c46 776 GPG="$GPG --secret-keyring $KEY"
f213b6ea 777 done
f213b6ea 778 for KEY in $(find keys/ -name '*.pub'); do
29a59c46 779 GPG="$GPG --keyring $KEY"
f213b6ea
DK
780 done
781 for RELEASE in $(find aptarchive/ -name Release); do
29a59c46 782 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg ${RELEASE}
e3c62328 783 local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
29a59c46 784 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
e3c62328
DK
785 # we might have set a specific date for the Release file, so copy it
786 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg ${INRELEASE}
f213b6ea 787 done
29a59c46
DK
788 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
789 mv -f $SECEXPIREBAK ${REXKEY}.sec
790 mv -f $PUBEXPIREBAK ${REXKEY}.pub
791 fi
f213b6ea
DK
792 msgdone "info"
793}
794
fd46d305
DK
795rewritesourceslist() {
796 local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
797 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
798 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#http://localhost:4433/#${1}#"
799 done
800}
801
f213b6ea 802changetowebserver() {
23af9f40
DK
803 if [ "$1" != '--no-rewrite' ]; then
804 rewritesourceslist 'http://localhost:8080/'
805 else
806 shift
807 fi
fbd29dd6
DK
808 local LOG='/dev/null'
809 if test -x ${BUILDDIRECTORY}/aptwebserver; then
810 cd aptarchive
e3c62328
DK
811 LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1
812 local PID="$(cat aptwebserver.pid)"
813 if [ -z "$PID" ]; then
814 msgdie 'Could not fork aptwebserver successfully'
815 fi
816 addtrap "kill $PID;"
fbd29dd6 817 cd - > /dev/null
c5bcc607 818 else
fbd29dd6 819 msgdie 'You have to build aptwerbserver or install a webserver'
f213b6ea 820 fi
fd46d305
DK
821}
822
823changetohttpswebserver() {
824 if ! which stunnel4 >/dev/null; then
825 msgdie 'You need to install stunnel4 for https testcases'
826 fi
827 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
828 changetowebserver --no-rewrite
829 fi
830 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
831cert = ${TESTDIRECTORY}/apt.pem
23af9f40 832output = /dev/null
fd46d305
DK
833
834[https]
835accept = 4433
836connect = 8080
837" > ${TMPWORKINGDIRECTORY}/stunnel.conf
838 stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
839 local PID="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
840 addtrap 'prefix' "kill ${PID};"
841 rewritesourceslist 'https://localhost:4433/'
f213b6ea
DK
842}
843
c45233ea
DK
844changetocdrom() {
845 mkdir -p rootdir/media/cdrom/.disk
846 local CD="$(readlink -f rootdir/media/cdrom)"
847 echo "acquire::cdrom::mount \"${CD}\";" > rootdir/etc/apt/apt.conf.d/00cdrom
848 echo 'acquire::cdrom::autodetect 0;' >> rootdir/etc/apt/apt.conf.d/00cdrom
849 echo -n "$1" > ${CD}/.disk/info
850 if [ ! -d aptarchive/dists ]; then
851 msgdie 'Flat file archive cdroms can not be created currently'
852 return 1
853 fi
854 mv aptarchive/dists $CD
855 ln -s "$(readlink -f ./incoming)" $CD/pool
856 find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete
857}
858
fd46d305
DK
859downloadfile() {
860 PROTO="$(echo "$1" | cut -d':' -f 1)"
861 local DOWNLOG="${TMPWORKINGDIRECTORY}/download.log"
862 rm -f "$DOWNLOG"
863 touch "$DOWNLOG"
864 {
865 echo "601 Configuration
866Config-Item: Acquire::https::CaInfo=${TESTDIR}/apt.pem
867Config-Item: Debug::Acquire::${PROTO}=1
868
869600 Acquire URI
870URI: $1
871Filename: ${2}
872"
873 # simple worker keeping stdin open until we are done (201) or error (400)
874 # and requesting new URIs on try-agains/redirects inbetween
875 { tail -n 999 -f "$DOWNLOG" & echo "TAILPID: $!"; } | while read f1 f2; do
876 if [ "$f1" = 'TAILPID:' ]; then
877 TAILPID="$f2"
878 elif [ "$f1" = 'New-URI:' ]; then
879 echo "600 Acquire URI
880URI: $f2
881Filename: ${2}
882"
883 elif [ "$f1" = '201' ] || [ "$f1" = '400' ]; then
884 # tail would only die on next read – which never happens
885 test -z "$TAILPID" || kill -s HUP "$TAILPID"
886 break
887 fi
888 done
889 } | LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods/${PROTO} 2>&1 | tee "$DOWNLOG"
890 rm "$DOWNLOG"
891 # only if the file exists the download was successful
892 if [ -e "$2" ]; then
893 return 0
894 else
895 return 1
896 fi
897}
898
f213b6ea 899checkdiff() {
8d876415
DK
900 local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
901 if [ -n "$DIFFTEXT" ]; then
902 echo
903 echo "$DIFFTEXT"
904 return 1
905 else
906 return 0
907 fi
908}
909
75954ae2
DK
910testfileequal() {
911 local FILE="$1"
912 shift
913 msgtest "Test for correctness of file" "$FILE"
914 if [ -z "$*" ]; then
f213b6ea 915 echo -n "" | checkdiff $FILE - && msgpass || msgfail
75954ae2 916 else
f213b6ea 917 echo "$*" | checkdiff $FILE - && msgpass || msgfail
75954ae2
DK
918 fi
919}
920
b855a400
DK
921testempty() {
922 msgtest "Test for no output of" "$*"
923 test -z "$($* 2>&1)" && msgpass || msgfail
924}
925
8d876415
DK
926testequal() {
927 local COMPAREFILE=$(mktemp)
b720d0bd 928 addtrap "rm $COMPAREFILE;"
8d876415
DK
929 echo "$1" > $COMPAREFILE
930 shift
931 msgtest "Test for equality of" "$*"
f213b6ea 932 $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
8d876415
DK
933}
934
685625bd
DK
935testequalor2() {
936 local COMPAREFILE1=$(mktemp)
937 local COMPAREFILE2=$(mktemp)
938 local COMPAREAGAINST=$(mktemp)
b720d0bd 939 addtrap "rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
685625bd
DK
940 echo "$1" > $COMPAREFILE1
941 echo "$2" > $COMPAREFILE2
942 shift 2
943 msgtest "Test for equality OR of" "$*"
18908589 944 $* >$COMPAREAGAINST 2>&1 || true
f213b6ea
DK
945 (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
946 checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
947 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
948 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
685625bd
DK
949 msgfail )
950}
951
8d876415 952testshowvirtual() {
edc0ef10 953 local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
8d876415
DK
954 local PACKAGE="$1"
955 shift
956 while [ -n "$1" ]; do
957 VIRTUAL="${VIRTUAL}
edc0ef10 958N: Can't select versions from package '$1' as it is purely virtual"
8d876415
DK
959 PACKAGE="${PACKAGE} $1"
960 shift
961 done
962 msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
963 VIRTUAL="${VIRTUAL}
4bec02c2 964N: No packages found"
8d876415 965 local COMPAREFILE=$(mktemp)
b720d0bd 966 addtrap "rm $COMPAREFILE;"
ea65d079 967 local ARCH="$(getarchitecture 'native')"
8d876415 968 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
e8379ba3 969 aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
8d876415
DK
970}
971
972testnopackage() {
973 msgtest "Test for non-existent packages" "apt-cache show $*"
974 local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')"
975 if [ -n "$SHOWPKG" ]; then
976 echo
977 echo "$SHOWPKG"
978 msgfail
979 return 1
980 fi
981 msgpass
982}
01a6e24c
DK
983
984testdpkginstalled() {
985 msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
c919ad6e 986 local PKGS="$(dpkg -l $* 2>/dev/null | grep '^i' | wc -l)"
87bc1c45 987 if [ "$PKGS" != $# ]; then
01a6e24c
DK
988 echo $PKGS
989 dpkg -l $* | grep '^[a-z]'
990 msgfail
991 return 1
992 fi
993 msgpass
994}
995
5cf733e1
DK
996testdpkgnotinstalled() {
997 msgtest "Test for correctly not-installed package(s) with" "dpkg -l $*"
87bc1c45 998 local PKGS="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)"
01a6e24c
DK
999 if [ "$PKGS" != 0 ]; then
1000 echo
1001 dpkg -l $* | grep '^[a-z]'
1002 msgfail
1003 return 1
1004 fi
1005 msgpass
1006}
ec7f904e
DK
1007
1008testmarkedauto() {
1009 local COMPAREFILE=$(mktemp)
1010 addtrap "rm $COMPAREFILE;"
1011 if [ -n "$1" ]; then
1012 msgtest 'Test for correctly marked as auto-installed' "$*"
1013 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1014 else
1015 msgtest 'Test for correctly marked as auto-installed' 'no package'
c98fb5e0 1016 echo -n > $COMPAREFILE
ec7f904e
DK
1017 fi
1018 aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
1019}
89a1aa5d 1020
0440d936
DK
1021testsuccess() {
1022 if [ "$1" = '--nomsg' ]; then
1023 shift
1024 else
1025 msgtest 'Test for successful execution of' "$*"
1026 fi
1027 local OUTPUT=$(mktemp)
1028 addtrap "rm $OUTPUT;"
1029 if $@ >${OUTPUT} 2>&1; then
1030 msgpass
1031 else
1032 echo
1033 cat $OUTPUT
1034 msgfail
1035 fi
1036}
1037
1038testfailure() {
1039 if [ "$1" = '--nomsg' ]; then
1040 shift
1041 else
1042 msgtest 'Test for failure in execution of' "$*"
1043 fi
1044 local OUTPUT=$(mktemp)
1045 addtrap "rm $OUTPUT;"
1046 if $@ >${OUTPUT} 2>&1; then
1047 echo
1048 cat $OUTPUT
1049 msgfail
1050 else
1051 msgpass
1052 fi
1053}
1054
89a1aa5d
DK
1055pause() {
1056 echo "STOPPED execution. Press enter to continue"
1057 local IGNORE
1058 read IGNORE
1059}