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