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