]> git.saurik.com Git - apt.git/blob - test/integration/framework
Merge branch 'debian/sid' into debian/experimental
[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 ${METHODSDIR} 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 COMPRESS_TYPE="${10:-gzip}"
381 local DISTSECTION
382 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
383 DISTSECTION="main"
384 else
385 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
386 fi
387 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
388
389 msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}"
390 mkdir -p $BUILDDIR/debian/source
391 echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
392 echo "#!/bin/sh
393 echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
394
395 echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
396 echo "$NAME ($VERSION) $RELEASE; urgency=low
397
398 * Initial release
399
400 -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
401 echo "Source: $NAME
402 Section: $SECTION
403 Priority: $PRIORITY
404 Maintainer: Joe Sixpack <joe@example.org>
405 Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
406 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
407 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
408 echo "
409 Package: $NAME" >> ${BUILDDIR}/debian/control
410
411 if [ "$ARCH" = 'all' ]; then
412 echo "Architecture: all" >> ${BUILDDIR}/debian/control
413 else
414 echo "Architecture: any" >> ${BUILDDIR}/debian/control
415 fi
416 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
417 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
418 echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
419
420 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
421 (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' \
422 | while read SRC; do
423 echo "pool/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
424 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
425 # gpg --yes --secret-keyring ./keys/joesixpack.sec \
426 # --keyring ./keys/joesixpack.pub --default-key 'Joe Sixpack' \
427 # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
428 # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
429 # fi
430 done
431
432 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
433 rm -rf ${BUILDDIR}/debian/tmp
434 mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
435 cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}
436 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}
437 if [ -n "$FILE_TREE" ]; then
438 cp -ar "$FILE_TREE" ${BUILDDIR}/debian/tmp
439 fi
440
441 (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch)
442 (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
443 local LOG="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
444 # ensure the right permissions as dpkg-deb ensists
445 chmod 755 ${BUILDDIR}/debian/tmp/DEBIAN
446 if ! dpkg-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/.. >$LOG 2>&1; then
447 cat $LOG
448 false
449 fi
450 rm $LOG
451 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist
452 done
453
454 mkdir -p ${BUILDDIR}/../${NAME}_${VERSION}
455 cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}/
456 cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}.changelog
457 rm -rf "${BUILDDIR}"
458 msgdone "info"
459 }
460
461 buildpackage() {
462 local BUILDDIR=$1
463 local RELEASE=$2
464 local SECTION=$3
465 local ARCH=$(getarchitecture $4)
466 local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
467 local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
468 msgninfo "Build package ${PKGNAME} for ${RELEASE} in ${SECTION}… "
469 cd $BUILDDIR
470 if [ "$ARCH" = "all" ]; then
471 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
472 fi
473 if ! dpkg-buildpackage -uc -us -a$ARCH >$BUILDLOG 2>&1 ; then
474 cat $BUILDLOG
475 false
476 fi
477 local PKGS="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
478 local SRCS="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
479 cd - > /dev/null
480 for PKG in $PKGS; do
481 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist
482 done
483 for SRC in $SRCS; do
484 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist
485 done
486 msgdone "info"
487 }
488
489 buildaptarchive() {
490 if [ -d incoming ]; then
491 buildaptarchivefromincoming "$@"
492 else
493 buildaptarchivefromfiles "$@"
494 fi
495 }
496
497 createaptftparchiveconfig() {
498 local COMPRESSORS="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
499 COMPRESSORS="${COMPRESSORS%* }"
500 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' ' ')"
501 if [ -z "$ARCHS" ]; then
502 # the pool is empty, so we will operate on faked packages - let us use the configured archs
503 ARCHS="$(getarchitectures)"
504 fi
505 echo -n 'Dir {
506 ArchiveDir "' >> ftparchive.conf
507 echo -n $(readlink -f .) >> ftparchive.conf
508 echo -n '";
509 CacheDir "' >> ftparchive.conf
510 echo -n $(readlink -f ..) >> ftparchive.conf
511 echo -n '";
512 FileListDir "' >> ftparchive.conf
513 echo -n $(readlink -f pool/) >> ftparchive.conf
514 echo -n '";
515 };
516 Default {
517 Packages::Compress "'"$COMPRESSORS"'";
518 Sources::Compress "'"$COMPRESSORS"'";
519 Contents::Compress "'"$COMPRESSORS"'";
520 Translation::Compress "'"$COMPRESSORS"'";
521 LongDescription "false";
522 };
523 TreeDefault {
524 Directory "pool/";
525 SrcDirectory "pool/";
526 };
527 APT {
528 FTPArchive {
529 Release {
530 Origin "joesixpack";
531 Label "apttestcases";
532 Suite "unstable";
533 Description "repository with dummy packages";
534 Architectures "' >> ftparchive.conf
535 echo -n "$ARCHS" >> ftparchive.conf
536 echo 'source";
537 };
538 };
539 };' >> ftparchive.conf
540 for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
541 echo -n 'tree "dists/' >> ftparchive.conf
542 echo -n "$DIST" >> ftparchive.conf
543 echo -n '" {
544 Architectures "' >> ftparchive.conf
545 echo -n "$ARCHS" >> ftparchive.conf
546 echo -n 'source";
547 FileList "' >> ftparchive.conf
548 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
549 echo -n '";
550 SourceFileList "' >> ftparchive.conf
551 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
552 echo -n '";
553 Sections "' >> ftparchive.conf
554 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
555 echo '";
556 };' >> ftparchive.conf
557 done
558 }
559
560 buildaptftparchivedirectorystructure() {
561 local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
562 for DIST in $DISTS; do
563 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
564 for SECTION in $SECTIONS; do
565 local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
566 for ARCH in $ARCHS; do
567 mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH}
568 done
569 mkdir -p dists/${DIST}/${SECTION}/source
570 mkdir -p dists/${DIST}/${SECTION}/i18n
571 done
572 done
573 }
574
575 insertpackage() {
576 local RELEASE="$1"
577 local NAME="$2"
578 local ARCH="$3"
579 local VERSION="$4"
580 local DEPENDENCIES="$5"
581 local PRIORITY="${6:-optional}"
582 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
583 If you find such a package installed on your system,
584 something went horribly wrong! They are autogenerated
585 und used only by testcases and surf no other propose…"}"
586 local ARCHS=""
587 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
588 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
589 ARCHS="$(getarchitectures)"
590 else
591 ARCHS="$arch"
592 fi
593 for BUILDARCH in $ARCHS; do
594 local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
595 mkdir -p $PPATH aptarchive/dists/${RELEASE}/main/source
596 touch aptarchive/dists/${RELEASE}/main/source/Sources
597 local FILE="${PPATH}/Packages"
598 echo "Package: $NAME
599 Priority: $PRIORITY
600 Section: other
601 Installed-Size: 42
602 Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
603 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
604 echo "Version: $VERSION
605 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
606 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
607 echo "Description: $DESCRIPTION" >> $FILE
608 echo >> $FILE
609 done
610 done
611 }
612
613 insertsource() {
614 local RELEASE="$1"
615 local NAME="$2"
616 local ARCH="$3"
617 local VERSION="$4"
618 local DEPENDENCIES="$5"
619 local ARCHS=""
620 local SPATH="aptarchive/dists/${RELEASE}/main/source"
621 mkdir -p $SPATH
622 local FILE="${SPATH}/Sources"
623 echo "Package: $NAME
624 Binary: $NAME
625 Version: $VERSION
626 Maintainer: Joe Sixpack <joe@example.org>
627 Architecture: $ARCH" >> $FILE
628 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
629 echo "Files:
630 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
631 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
632 " >> $FILE
633 }
634
635 insertinstalledpackage() {
636 local NAME="$1"
637 local ARCH="$2"
638 local VERSION="$3"
639 local DEPENDENCIES="$4"
640 local PRIORITY="${5:-optional}"
641 local STATUS="${6:-install ok installed}"
642 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
643 If you find such a package installed on your system,
644 something went horribly wrong! They are autogenerated
645 und used only by testcases and surf no other propose…"}"
646
647 local FILE='rootdir/var/lib/dpkg/status'
648 local INFO='rootdir/var/lib/dpkg/info'
649 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
650 echo "Package: $NAME
651 Status: $STATUS
652 Priority: $PRIORITY
653 Section: other
654 Installed-Size: 42
655 Maintainer: Joe Sixpack <joe@example.org>
656 Version: $VERSION" >> $FILE
657 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
658 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
659 echo "Description: $DESCRIPTION" >> $FILE
660 echo >> $FILE
661 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
662 echo -n > ${INFO}/${NAME}:${arch}.list
663 else
664 echo -n > ${INFO}/${NAME}.list
665 fi
666 done
667 }
668
669
670 buildaptarchivefromincoming() {
671 msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
672 cd aptarchive
673 [ -e pool ] || ln -s ../incoming pool
674 [ -e ftparchive.conf ] || createaptftparchiveconfig
675 [ -e dists ] || buildaptftparchivedirectorystructure
676 msgninfo "\tGenerate Packages, Sources and Contents files… "
677 aptftparchive -qq generate ftparchive.conf
678 cd - > /dev/null
679 msgdone "info"
680 generatereleasefiles
681 }
682
683 buildaptarchivefromfiles() {
684 msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
685 find aptarchive -name 'Packages' -o -name 'Sources' | while read line; do
686 msgninfo "\t${line} file… "
687 compressfile "$line" "$1"
688 msgdone "info"
689 done
690 generatereleasefiles "$@"
691 }
692
693 compressfile() {
694 cat ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | while read compressor extension command; do
695 if [ "$compressor" = '.' ]; then
696 if [ -n "$2" ]; then
697 touch -d "$2" "$1"
698 fi
699 continue
700 fi
701 cat "$1" | $command > "${1}.${extension}"
702 if [ -n "$2" ]; then
703 touch -d "$2" "${1}.${extension}"
704 fi
705 done
706 }
707
708 # can be overridden by testcases for their pleasure
709 getcodenamefromsuite() {
710 case "$1" in
711 unstable) echo 'sid';;
712 *) echo -n "$1";;
713 esac
714 }
715 getreleaseversionfromsuite() { true; }
716 getlabelfromsuite() { true; }
717
718 generatereleasefiles() {
719 # $1 is the Date header and $2 is the ValidUntil header to be set
720 # both should be given in notation date/touch can understand
721 msgninfo "\tGenerate Release files… "
722 if [ -e aptarchive/dists ]; then
723 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
724 local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
725 local CODENAME="$(getcodenamefromsuite $SUITE)"
726 local VERSION="$(getreleaseversionfromsuite $SUITE)"
727 local LABEL="$(getlabelfromsuite $SUITE)"
728 if [ -n "$VERSION" ]; then
729 VERSION="-o APT::FTPArchive::Release::Version=${VERSION}"
730 fi
731 if [ -n "$LABEL" ]; then
732 LABEL="-o APT::FTPArchive::Release::Label=${LABEL}"
733 fi
734 aptftparchive -qq release $dir \
735 -o APT::FTPArchive::Release::Suite="${SUITE}" \
736 -o APT::FTPArchive::Release::Codename="${CODENAME}" \
737 ${LABEL} \
738 ${VERSION} \
739 | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
740 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
741 sed -i '/^Date: / a\
742 NotAutomatic: yes' $dir/Release
743 fi
744 if [ -n "$1" -a "$1" != "now" ]; then
745 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
746 fi
747 if [ -n "$2" ]; then
748 sed -i "/^Date: / a\
749 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
750 fi
751 done
752 else
753 aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
754 fi
755 if [ -n "$1" -a "$1" != "now" ]; then
756 for release in $(find ./aptarchive -name 'Release'); do
757 touch -d "$1" $release
758 done
759 fi
760 msgdone "info"
761 }
762
763 setupdistsaptarchive() {
764 local APTARCHIVE=$(readlink -f ./aptarchive)
765 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
766 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
767 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
768 SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
769 msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
770 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
771 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
772 msgdone "info"
773 done
774 }
775
776 setupflataptarchive() {
777 local APTARCHIVE=$(readlink -f ./aptarchive)
778 if [ -f ${APTARCHIVE}/Packages ]; then
779 msgninfo "\tadd deb sources.list line… "
780 echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
781 msgdone "info"
782 else
783 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
784 fi
785 if [ -f ${APTARCHIVE}/Sources ]; then
786 msgninfo "\tadd deb-src sources.list line… "
787 echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
788 msgdone "info"
789 else
790 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
791 fi
792 }
793
794 setupaptarchive() {
795 buildaptarchive
796 if [ -e aptarchive/dists ]; then
797 setupdistsaptarchive
798 else
799 setupflataptarchive
800 fi
801 signreleasefiles
802 if [ "$1" != '--no-update' ]; then
803 msgninfo "\tSync APT's cache with the archive… "
804 aptget update -qq
805 msgdone "info"
806 fi
807 }
808
809 signreleasefiles() {
810 local SIGNER="${1:-Joe Sixpack}"
811 local GPG="gpg --batch --yes"
812 msgninfo "\tSign archive with $SIGNER key… "
813 local REXKEY='keys/rexexpired'
814 local SECEXPIREBAK="${REXKEY}.sec.bak"
815 local PUBEXPIREBAK="${REXKEY}.pub.bak"
816 if [ "${SIGNER}" = 'Rex Expired' ]; then
817 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
818 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
819 # therefore we 'temporary' make the key not expired and restore a backup after signing
820 cp ${REXKEY}.sec $SECEXPIREBAK
821 cp ${REXKEY}.pub $PUBEXPIREBAK
822 local SECUNEXPIRED="${REXKEY}.sec.unexpired"
823 local PUBUNEXPIRED="${REXKEY}.pub.unexpired"
824 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
825 cp $SECUNEXPIRED ${REXKEY}.sec
826 cp $PUBUNEXPIRED ${REXKEY}.pub
827 else
828 printf "expire\n1w\nsave\n" | $GPG --keyring ${REXKEY}.pub --secret-keyring ${REXKEY}.sec --command-fd 0 --edit-key "${SIGNER}" >/dev/null 2>&1 || true
829 cp ${REXKEY}.sec $SECUNEXPIRED
830 cp ${REXKEY}.pub $PUBUNEXPIRED
831 fi
832 fi
833 for KEY in $(find keys/ -name '*.sec'); do
834 GPG="$GPG --secret-keyring $KEY"
835 done
836 for KEY in $(find keys/ -name '*.pub'); do
837 GPG="$GPG --keyring $KEY"
838 done
839 for RELEASE in $(find aptarchive/ -name Release); do
840 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg ${RELEASE}
841 local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
842 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
843 # we might have set a specific date for the Release file, so copy it
844 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg ${INRELEASE}
845 done
846 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
847 mv -f $SECEXPIREBAK ${REXKEY}.sec
848 mv -f $PUBEXPIREBAK ${REXKEY}.pub
849 fi
850 msgdone "info"
851 }
852
853 webserverconfig() {
854 msgtest "Set webserver config option '${1}' to" "$2"
855 downloadfile "http://localhost:8080/_config/set/${1}/${2}" '/dev/null' >/dev/null
856 local DOWNLOG='download-testfile.log'
857 rm -f "$DOWNLOG"
858 local STATUS="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.status"
859 downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
860 if [ "$(cat "$STATUS")" = '200' ]; then
861 msgpass
862 else
863 cat >&2 "$DOWNLOG"
864 msgfail "Statuscode was $(cat "$STATUS")"
865 fi
866 rm "$STATUS"
867 }
868
869 rewritesourceslist() {
870 local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
871 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
872 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#http://localhost:4433/#${1}#"
873 done
874 }
875
876 changetowebserver() {
877 if [ "$1" != '--no-rewrite' ]; then
878 rewritesourceslist 'http://localhost:8080/'
879 else
880 shift
881 fi
882 if test -x ${APTWEBSERVERBINDIR}/aptwebserver; then
883 cd aptarchive
884 local LOG="webserver.log"
885 if ! aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1 ; then
886 cat $LOG
887 false
888 fi
889 local PID="$(cat aptwebserver.pid)"
890 if [ -z "$PID" ]; then
891 msgdie 'Could not fork aptwebserver successfully'
892 fi
893 addtrap "kill $PID;"
894 cd - > /dev/null
895 else
896 msgdie 'You have to build aptwerbserver or install a webserver'
897 fi
898 }
899
900 changetohttpswebserver() {
901 if ! which stunnel4 >/dev/null; then
902 msgdie 'You need to install stunnel4 for https testcases'
903 fi
904 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
905 changetowebserver --no-rewrite "$@"
906 fi
907 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
908 cert = ${TESTDIRECTORY}/apt.pem
909 output = /dev/null
910
911 [https]
912 accept = 4433
913 connect = 8080
914 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
915 stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
916 local PID="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
917 addtrap 'prefix' "kill ${PID};"
918 rewritesourceslist 'https://localhost:4433/'
919 }
920
921 changetocdrom() {
922 mkdir -p rootdir/media/cdrom/.disk
923 local CD="$(readlink -f rootdir/media/cdrom)"
924 echo "acquire::cdrom::mount \"${CD}\";" > rootdir/etc/apt/apt.conf.d/00cdrom
925 echo 'acquire::cdrom::autodetect 0;' >> rootdir/etc/apt/apt.conf.d/00cdrom
926 echo -n "$1" > ${CD}/.disk/info
927 if [ ! -d aptarchive/dists ]; then
928 msgdie 'Flat file archive cdroms can not be created currently'
929 return 1
930 fi
931 mv aptarchive/dists $CD
932 ln -s "$(readlink -f ./incoming)" $CD/pool
933 find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete
934 }
935
936 downloadfile() {
937 PROTO="$(echo "$1" | cut -d':' -f 1)"
938 if [ ! -x "${METHODSDIR}/${PROTO}" ]; then
939 msgwarn "can not find ${METHODSDIR}/${PROTO}"
940 return 1
941 fi
942 local DOWNLOG="${TMPWORKINGDIRECTORY}/download.log"
943 rm -f "$DOWNLOG"
944 touch "$DOWNLOG"
945 {
946 echo "601 Configuration
947 Config-Item: Acquire::https::CaInfo=${TESTDIR}/apt.pem
948 Config-Item: Debug::Acquire::${PROTO}=1
949
950 600 Acquire URI
951 URI: $1
952 Filename: ${2}
953 "
954 # simple worker keeping stdin open until we are done (201) or error (400)
955 # and requesting new URIs on try-agains/redirects in-between
956 { tail -n 999 -f "$DOWNLOG" & echo "TAILPID: $!"; } | while read f1 f2; do
957 if [ "$f1" = 'TAILPID:' ]; then
958 TAILPID="$f2"
959 elif [ "$f1" = 'New-URI:' ]; then
960 echo "600 Acquire URI
961 URI: $f2
962 Filename: ${2}
963 "
964 elif [ "$f1" = '201' ] || [ "$f1" = '400' ]; then
965 # tail would only die on next read – which never happens
966 test -z "$TAILPID" || kill -s HUP "$TAILPID"
967 break
968 fi
969 done
970 } | LD_LIBRARY_PATH=${BUILDDIRECTORY} ${METHODSDIR}/${PROTO} 2>&1 | tee "$DOWNLOG"
971 rm "$DOWNLOG"
972 # only if the file exists the download was successful
973 if [ -e "$2" ]; then
974 return 0
975 else
976 return 1
977 fi
978 }
979
980 checkdiff() {
981 local DIFFTEXT="$(command diff -u "$@" | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
982 if [ -n "$DIFFTEXT" ]; then
983 echo
984 echo "$DIFFTEXT"
985 return 1
986 else
987 return 0
988 fi
989 }
990
991 testfileequal() {
992 local FILE="$1"
993 shift
994 msgtest "Test for correctness of file" "$FILE"
995 if [ -z "$*" ]; then
996 echo -n "" | checkdiff $FILE - && msgpass || msgfail
997 else
998 echo "$*" | checkdiff $FILE - && msgpass || msgfail
999 fi
1000 }
1001
1002 testempty() {
1003 msgtest "Test for no output of" "$*"
1004 test -z "$($* 2>&1)" && msgpass || msgfail
1005 }
1006
1007 testequal() {
1008 local MSG='Test of equality of'
1009 if [ "$1" = '--nomsg' ]; then
1010 MSG=''
1011 shift
1012 fi
1013
1014 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1015 echo "$1" > $COMPAREFILE
1016 shift
1017
1018 if [ -n "$MSG" ]; then
1019 msgtest "$MSG" "$*"
1020 fi
1021 $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
1022 }
1023
1024 testequalor2() {
1025 local COMPAREFILE1="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1026 local COMPAREFILE2="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1027 local COMPAREAGAINST="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1028 echo "$1" > $COMPAREFILE1
1029 echo "$2" > $COMPAREFILE2
1030 shift 2
1031 msgtest "Test for equality OR of" "$*"
1032 $* >$COMPAREAGAINST 2>&1 || true
1033 (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
1034 checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
1035 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
1036 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
1037 msgfail )
1038 }
1039
1040 testshowvirtual() {
1041 local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
1042 local PACKAGE="$1"
1043 shift
1044 while [ -n "$1" ]; do
1045 VIRTUAL="${VIRTUAL}
1046 N: Can't select versions from package '$1' as it is purely virtual"
1047 PACKAGE="${PACKAGE} $1"
1048 shift
1049 done
1050 msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
1051 VIRTUAL="${VIRTUAL}
1052 N: No packages found"
1053 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1054 local ARCH="$(getarchitecture 'native')"
1055 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1056 aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
1057 }
1058
1059 testnopackage() {
1060 msgtest "Test for non-existent packages" "apt-cache show $*"
1061 local SHOWPKG="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1062 if [ -n "$SHOWPKG" ]; then
1063 echo
1064 echo "$SHOWPKG"
1065 msgfail
1066 return 1
1067 fi
1068 msgpass
1069 }
1070
1071 testdpkginstalled() {
1072 msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
1073 local PKGS="$(dpkg -l "$@" 2>/dev/null | grep '^i' | wc -l)"
1074 if [ "$PKGS" != $# ]; then
1075 echo $PKGS
1076 dpkg -l "$@" | grep '^[a-z]'
1077 msgfail
1078 return 1
1079 fi
1080 msgpass
1081 }
1082
1083 testdpkgnotinstalled() {
1084 msgtest "Test for correctly not-installed package(s) with" "dpkg -l $*"
1085 local PKGS="$(dpkg -l "$@" 2> /dev/null | grep '^i' | wc -l)"
1086 if [ "$PKGS" != 0 ]; then
1087 echo
1088 dpkg -l "$@" | grep '^[a-z]'
1089 msgfail
1090 return 1
1091 fi
1092 msgpass
1093 }
1094
1095 testmarkedauto() {
1096 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1097 if [ -n "$1" ]; then
1098 msgtest 'Test for correctly marked as auto-installed' "$*"
1099 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1100 else
1101 msgtest 'Test for correctly marked as auto-installed' 'no package'
1102 echo -n > $COMPAREFILE
1103 fi
1104 aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
1105 }
1106
1107 testsuccess() {
1108 if [ "$1" = '--nomsg' ]; then
1109 shift
1110 else
1111 msgtest 'Test for successful execution of' "$*"
1112 fi
1113 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1114 if $@ >${OUTPUT} 2>&1; then
1115 msgpass
1116 else
1117 echo
1118 cat $OUTPUT
1119 msgfail
1120 fi
1121 }
1122
1123 testfailure() {
1124 if [ "$1" = '--nomsg' ]; then
1125 shift
1126 else
1127 msgtest 'Test for failure in execution of' "$*"
1128 fi
1129 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1130 if $@ >${OUTPUT} 2>&1; then
1131 echo
1132 cat $OUTPUT
1133 msgfail
1134 else
1135 msgpass
1136 fi
1137 }
1138
1139 pause() {
1140 echo "STOPPED execution. Press enter to continue"
1141 local IGNORE
1142 read IGNORE
1143 }