]> git.saurik.com Git - apt.git/blame - test/integration/framework
Merge remote-tracking branch 'mvo/debian/sid' into debian/sid
[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
8d876415 205 export LC_ALL=C
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"
18908589
DK
291 local DESCRIPTION="${6:-"Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
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"
18908589
DK
341 local DESCRIPTION="${6:-"Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
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}"
18908589
DK
538 local DESCRIPTION="${7:-"Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
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}"
18908589
DK
598 local DESCRIPTION="${7:-"Description: an autogenerated dummy ${NAME}=${VERSION}/installed
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
DK
664# can be overridden by testcases for their pleasure
665getcodenamefromsuite() { echo -n "$1"; }
666getreleaseversionfromsuite() { true; }
718f797c 667getlabelfromsuite() { true; }
a3bbbab7 668
9b78cda6 669generatereleasefiles() {
884a4c0a
DK
670 # $1 is the Date header and $2 is the ValidUntil header to be set
671 # both should be given in notation date/touch can understand
9b78cda6
DK
672 msgninfo "\tGenerate Release files… "
673 if [ -e aptarchive/dists ]; then
674 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
a3bbbab7
DK
675 local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
676 local CODENAME="$(getcodenamefromsuite $SUITE)"
677 local VERSION="$(getreleaseversionfromsuite $SUITE)"
718f797c 678 local LABEL="$(getlabelfromsuite $SUITE)"
884a4c0a 679 if [ -n "$VERSION" ]; then
718f797c
DK
680 VERSION="-o APT::FTPArchive::Release::Version=${VERSION}"
681 fi
682 if [ -n "$LABEL" ]; then
683 LABEL="-o APT::FTPArchive::Release::Label=${LABEL}"
a3bbbab7 684 fi
884a4c0a
DK
685 aptftparchive -qq release $dir \
686 -o APT::FTPArchive::Release::Suite="${SUITE}" \
687 -o APT::FTPArchive::Release::Codename="${CODENAME}" \
718f797c 688 ${LABEL} \
884a4c0a
DK
689 ${VERSION} \
690 | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
a3bbbab7 691 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
35faae11
DK
692 sed -i '/^Date: / a\
693NotAutomatic: yes' $dir/Release
694 fi
884a4c0a
DK
695 if [ -n "$1" -a "$1" != "now" ]; then
696 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
697 fi
698 if [ -n "$2" ]; then
699 sed -i "/^Date: / a\
700Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
701 fi
9b78cda6
DK
702 done
703 else
704 aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
8d876415 705 fi
884a4c0a 706 if [ -n "$1" -a "$1" != "now" ]; then
fe0f7911
DK
707 for release in $(find ./aptarchive -name 'Release'); do
708 touch -d "$1" $release
709 done
8d876415 710 fi
b7899b00 711 msgdone "info"
8d876415
DK
712}
713
b7899b00
DK
714setupdistsaptarchive() {
715 local APTARCHIVE=$(readlink -f ./aptarchive)
716 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
717 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
718 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
719 SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
720 msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
721 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
722 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
723 msgdone "info"
724 done
725}
726
727setupflataptarchive() {
ce9864a8 728 local APTARCHIVE=$(readlink -f ./aptarchive)
8d876415
DK
729 if [ -f ${APTARCHIVE}/Packages ]; then
730 msgninfo "\tadd deb sources.list line… "
731 echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
732 msgdone "info"
733 else
734 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
735 fi
736 if [ -f ${APTARCHIVE}/Sources ]; then
737 msgninfo "\tadd deb-src sources.list line… "
738 echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
739 msgdone "info"
740 else
741 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
742 fi
b7899b00
DK
743}
744
745setupaptarchive() {
746 buildaptarchive
747 if [ -e aptarchive/dists ]; then
748 setupdistsaptarchive
749 else
750 setupflataptarchive
751 fi
f213b6ea 752 signreleasefiles
b2ea1a47
DK
753 if [ "$1" != '--no-update' ]; then
754 msgninfo "\tSync APT's cache with the archive… "
755 aptget update -qq
756 msgdone "info"
757 fi
8d876415
DK
758}
759
f213b6ea
DK
760signreleasefiles() {
761 local SIGNER="${1:-Joe Sixpack}"
29a59c46 762 local GPG="gpg --batch --yes --no-default-keyring --trustdb-name rootdir/etc/apt/trustdb.gpg"
f213b6ea 763 msgninfo "\tSign archive with $SIGNER key… "
29a59c46
DK
764 local REXKEY='keys/rexexpired'
765 local SECEXPIREBAK="${REXKEY}.sec.bak"
766 local PUBEXPIREBAK="${REXKEY}.pub.bak"
767 if [ "${SIGNER}" = 'Rex Expired' ]; then
768 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
769 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
770 # therefore we 'temporary' make the key not expired and restore a backup after signing
771 cp ${REXKEY}.sec $SECEXPIREBAK
772 cp ${REXKEY}.pub $PUBEXPIREBAK
773 local SECUNEXPIRED="${REXKEY}.sec.unexpired"
774 local PUBUNEXPIRED="${REXKEY}.pub.unexpired"
775 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
776 cp $SECUNEXPIRED ${REXKEY}.sec
777 cp $PUBUNEXPIRED ${REXKEY}.pub
778 else
779 printf "expire\n1w\nsave\n" | $GPG --keyring ${REXKEY}.pub --secret-keyring ${REXKEY}.sec --command-fd 0 --edit-key "${SIGNER}" >/dev/null 2>&1 || true
780 cp ${REXKEY}.sec $SECUNEXPIRED
781 cp ${REXKEY}.pub $PUBUNEXPIRED
782 fi
783 fi
f213b6ea 784 for KEY in $(find keys/ -name '*.sec'); do
29a59c46 785 GPG="$GPG --secret-keyring $KEY"
f213b6ea 786 done
f213b6ea 787 for KEY in $(find keys/ -name '*.pub'); do
29a59c46 788 GPG="$GPG --keyring $KEY"
f213b6ea
DK
789 done
790 for RELEASE in $(find aptarchive/ -name Release); do
29a59c46 791 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg ${RELEASE}
e3c62328 792 local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
29a59c46 793 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
e3c62328
DK
794 # we might have set a specific date for the Release file, so copy it
795 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg ${INRELEASE}
f213b6ea 796 done
29a59c46
DK
797 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
798 mv -f $SECEXPIREBAK ${REXKEY}.sec
799 mv -f $PUBEXPIREBAK ${REXKEY}.pub
800 fi
f213b6ea
DK
801 msgdone "info"
802}
803
f2c0ec8b
DK
804webserverconfig() {
805 msgtest "Set webserver config option '${1}' to" "$2"
806 downloadfile "http://localhost:8080/_config/set/${1}/${2}" '/dev/null' >/dev/null
807 local DOWNLOG='download-testfile.log'
808 rm -f "$DOWNLOG"
809 local STATUS="$(mktemp)"
810 addtrap "rm $STATUS;"
811 downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
812 if [ "$(cat "$STATUS")" = '200' ]; then
813 msgpass
814 else
815 cat >&2 "$DOWNLOG"
816 msgfail "Statuscode was $(cat "$STATUS")"
817 fi
818}
819
fd46d305
DK
820rewritesourceslist() {
821 local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
822 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
823 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#http://localhost:4433/#${1}#"
824 done
825}
826
f213b6ea 827changetowebserver() {
23af9f40
DK
828 if [ "$1" != '--no-rewrite' ]; then
829 rewritesourceslist 'http://localhost:8080/'
830 else
831 shift
832 fi
fbd29dd6 833 local LOG='/dev/null'
5c0dd6fc 834 if test -x ${APTWEBSERVERBINDIR}/aptwebserver; then
fbd29dd6 835 cd aptarchive
5c0dd6fc 836 aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1
e3c62328
DK
837 local PID="$(cat aptwebserver.pid)"
838 if [ -z "$PID" ]; then
839 msgdie 'Could not fork aptwebserver successfully'
840 fi
841 addtrap "kill $PID;"
fbd29dd6 842 cd - > /dev/null
c5bcc607 843 else
fbd29dd6 844 msgdie 'You have to build aptwerbserver or install a webserver'
f213b6ea 845 fi
fd46d305
DK
846}
847
848changetohttpswebserver() {
849 if ! which stunnel4 >/dev/null; then
850 msgdie 'You need to install stunnel4 for https testcases'
851 fi
852 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
853 changetowebserver --no-rewrite
854 fi
855 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
856cert = ${TESTDIRECTORY}/apt.pem
23af9f40 857output = /dev/null
fd46d305
DK
858
859[https]
860accept = 4433
861connect = 8080
862" > ${TMPWORKINGDIRECTORY}/stunnel.conf
863 stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
864 local PID="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
865 addtrap 'prefix' "kill ${PID};"
866 rewritesourceslist 'https://localhost:4433/'
f213b6ea
DK
867}
868
c45233ea
DK
869changetocdrom() {
870 mkdir -p rootdir/media/cdrom/.disk
871 local CD="$(readlink -f rootdir/media/cdrom)"
872 echo "acquire::cdrom::mount \"${CD}\";" > rootdir/etc/apt/apt.conf.d/00cdrom
873 echo 'acquire::cdrom::autodetect 0;' >> rootdir/etc/apt/apt.conf.d/00cdrom
874 echo -n "$1" > ${CD}/.disk/info
875 if [ ! -d aptarchive/dists ]; then
876 msgdie 'Flat file archive cdroms can not be created currently'
877 return 1
878 fi
879 mv aptarchive/dists $CD
880 ln -s "$(readlink -f ./incoming)" $CD/pool
881 find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete
882}
883
fd46d305
DK
884downloadfile() {
885 PROTO="$(echo "$1" | cut -d':' -f 1)"
886 local DOWNLOG="${TMPWORKINGDIRECTORY}/download.log"
887 rm -f "$DOWNLOG"
888 touch "$DOWNLOG"
889 {
890 echo "601 Configuration
891Config-Item: Acquire::https::CaInfo=${TESTDIR}/apt.pem
892Config-Item: Debug::Acquire::${PROTO}=1
893
894600 Acquire URI
895URI: $1
896Filename: ${2}
897"
898 # simple worker keeping stdin open until we are done (201) or error (400)
899 # and requesting new URIs on try-agains/redirects inbetween
900 { tail -n 999 -f "$DOWNLOG" & echo "TAILPID: $!"; } | while read f1 f2; do
901 if [ "$f1" = 'TAILPID:' ]; then
902 TAILPID="$f2"
903 elif [ "$f1" = 'New-URI:' ]; then
904 echo "600 Acquire URI
905URI: $f2
906Filename: ${2}
907"
908 elif [ "$f1" = '201' ] || [ "$f1" = '400' ]; then
909 # tail would only die on next read – which never happens
910 test -z "$TAILPID" || kill -s HUP "$TAILPID"
911 break
912 fi
913 done
914 } | LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods/${PROTO} 2>&1 | tee "$DOWNLOG"
915 rm "$DOWNLOG"
916 # only if the file exists the download was successful
917 if [ -e "$2" ]; then
918 return 0
919 else
920 return 1
921 fi
922}
923
f213b6ea 924checkdiff() {
8d876415
DK
925 local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
926 if [ -n "$DIFFTEXT" ]; then
927 echo
928 echo "$DIFFTEXT"
929 return 1
930 else
931 return 0
932 fi
933}
934
75954ae2
DK
935testfileequal() {
936 local FILE="$1"
937 shift
938 msgtest "Test for correctness of file" "$FILE"
939 if [ -z "$*" ]; then
f213b6ea 940 echo -n "" | checkdiff $FILE - && msgpass || msgfail
75954ae2 941 else
f213b6ea 942 echo "$*" | checkdiff $FILE - && msgpass || msgfail
75954ae2
DK
943 fi
944}
945
b855a400
DK
946testempty() {
947 msgtest "Test for no output of" "$*"
948 test -z "$($* 2>&1)" && msgpass || msgfail
949}
950
8d876415
DK
951testequal() {
952 local COMPAREFILE=$(mktemp)
b720d0bd 953 addtrap "rm $COMPAREFILE;"
8d876415
DK
954 echo "$1" > $COMPAREFILE
955 shift
956 msgtest "Test for equality of" "$*"
f213b6ea 957 $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
8d876415
DK
958}
959
685625bd
DK
960testequalor2() {
961 local COMPAREFILE1=$(mktemp)
962 local COMPAREFILE2=$(mktemp)
963 local COMPAREAGAINST=$(mktemp)
b720d0bd 964 addtrap "rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
685625bd
DK
965 echo "$1" > $COMPAREFILE1
966 echo "$2" > $COMPAREFILE2
967 shift 2
968 msgtest "Test for equality OR of" "$*"
18908589 969 $* >$COMPAREAGAINST 2>&1 || true
f213b6ea
DK
970 (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
971 checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
972 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
973 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
685625bd
DK
974 msgfail )
975}
976
8d876415 977testshowvirtual() {
edc0ef10 978 local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
8d876415
DK
979 local PACKAGE="$1"
980 shift
981 while [ -n "$1" ]; do
982 VIRTUAL="${VIRTUAL}
edc0ef10 983N: Can't select versions from package '$1' as it is purely virtual"
8d876415
DK
984 PACKAGE="${PACKAGE} $1"
985 shift
986 done
987 msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
988 VIRTUAL="${VIRTUAL}
4bec02c2 989N: No packages found"
8d876415 990 local COMPAREFILE=$(mktemp)
b720d0bd 991 addtrap "rm $COMPAREFILE;"
ea65d079 992 local ARCH="$(getarchitecture 'native')"
8d876415 993 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
e8379ba3 994 aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
8d876415
DK
995}
996
997testnopackage() {
998 msgtest "Test for non-existent packages" "apt-cache show $*"
999 local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')"
1000 if [ -n "$SHOWPKG" ]; then
1001 echo
1002 echo "$SHOWPKG"
1003 msgfail
1004 return 1
1005 fi
1006 msgpass
1007}
01a6e24c
DK
1008
1009testdpkginstalled() {
1010 msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
c919ad6e 1011 local PKGS="$(dpkg -l $* 2>/dev/null | grep '^i' | wc -l)"
87bc1c45 1012 if [ "$PKGS" != $# ]; then
01a6e24c
DK
1013 echo $PKGS
1014 dpkg -l $* | grep '^[a-z]'
1015 msgfail
1016 return 1
1017 fi
1018 msgpass
1019}
1020
5cf733e1
DK
1021testdpkgnotinstalled() {
1022 msgtest "Test for correctly not-installed package(s) with" "dpkg -l $*"
87bc1c45 1023 local PKGS="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)"
01a6e24c
DK
1024 if [ "$PKGS" != 0 ]; then
1025 echo
1026 dpkg -l $* | grep '^[a-z]'
1027 msgfail
1028 return 1
1029 fi
1030 msgpass
1031}
ec7f904e
DK
1032
1033testmarkedauto() {
1034 local COMPAREFILE=$(mktemp)
1035 addtrap "rm $COMPAREFILE;"
1036 if [ -n "$1" ]; then
1037 msgtest 'Test for correctly marked as auto-installed' "$*"
1038 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1039 else
1040 msgtest 'Test for correctly marked as auto-installed' 'no package'
c98fb5e0 1041 echo -n > $COMPAREFILE
ec7f904e
DK
1042 fi
1043 aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
1044}
89a1aa5d 1045
0440d936
DK
1046testsuccess() {
1047 if [ "$1" = '--nomsg' ]; then
1048 shift
1049 else
1050 msgtest 'Test for successful execution of' "$*"
1051 fi
1052 local OUTPUT=$(mktemp)
1053 addtrap "rm $OUTPUT;"
1054 if $@ >${OUTPUT} 2>&1; then
1055 msgpass
1056 else
1057 echo
1058 cat $OUTPUT
1059 msgfail
1060 fi
1061}
1062
1063testfailure() {
1064 if [ "$1" = '--nomsg' ]; then
1065 shift
1066 else
1067 msgtest 'Test for failure in execution of' "$*"
1068 fi
1069 local OUTPUT=$(mktemp)
1070 addtrap "rm $OUTPUT;"
1071 if $@ >${OUTPUT} 2>&1; then
1072 echo
1073 cat $OUTPUT
1074 msgfail
1075 else
1076 msgpass
1077 fi
1078}
1079
89a1aa5d
DK
1080pause() {
1081 echo "STOPPED execution. Press enter to continue"
1082 local IGNORE
1083 read IGNORE
1084}