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