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