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