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