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