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