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