use C.UTF-8 in testcases as locale
[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 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() { echo -n "$1"; }
666 getreleaseversionfromsuite() { true; }
667 getlabelfromsuite() { true; }
668
669 generatereleasefiles() {
670 # $1 is the Date header and $2 is the ValidUntil header to be set
671 # both should be given in notation date/touch can understand
672 msgninfo "\tGenerate Release files… "
673 if [ -e aptarchive/dists ]; then
674 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
675 local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
676 local CODENAME="$(getcodenamefromsuite $SUITE)"
677 local VERSION="$(getreleaseversionfromsuite $SUITE)"
678 local LABEL="$(getlabelfromsuite $SUITE)"
679 if [ -n "$VERSION" ]; then
680 VERSION="-o APT::FTPArchive::Release::Version=${VERSION}"
681 fi
682 if [ -n "$LABEL" ]; then
683 LABEL="-o APT::FTPArchive::Release::Label=${LABEL}"
684 fi
685 aptftparchive -qq release $dir \
686 -o APT::FTPArchive::Release::Suite="${SUITE}" \
687 -o APT::FTPArchive::Release::Codename="${CODENAME}" \
688 ${LABEL} \
689 ${VERSION} \
690 | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
691 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
692 sed -i '/^Date: / a\
693 NotAutomatic: yes' $dir/Release
694 fi
695 if [ -n "$1" -a "$1" != "now" ]; then
696 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
697 fi
698 if [ -n "$2" ]; then
699 sed -i "/^Date: / a\
700 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
701 fi
702 done
703 else
704 aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
705 fi
706 if [ -n "$1" -a "$1" != "now" ]; then
707 for release in $(find ./aptarchive -name 'Release'); do
708 touch -d "$1" $release
709 done
710 fi
711 msgdone "info"
712 }
713
714 setupdistsaptarchive() {
715 local APTARCHIVE=$(readlink -f ./aptarchive)
716 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
717 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
718 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
719 SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
720 msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
721 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
722 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
723 msgdone "info"
724 done
725 }
726
727 setupflataptarchive() {
728 local APTARCHIVE=$(readlink -f ./aptarchive)
729 if [ -f ${APTARCHIVE}/Packages ]; then
730 msgninfo "\tadd deb sources.list line… "
731 echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
732 msgdone "info"
733 else
734 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
735 fi
736 if [ -f ${APTARCHIVE}/Sources ]; then
737 msgninfo "\tadd deb-src sources.list line… "
738 echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
739 msgdone "info"
740 else
741 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
742 fi
743 }
744
745 setupaptarchive() {
746 buildaptarchive
747 if [ -e aptarchive/dists ]; then
748 setupdistsaptarchive
749 else
750 setupflataptarchive
751 fi
752 signreleasefiles
753 if [ "$1" != '--no-update' ]; then
754 msgninfo "\tSync APT's cache with the archive… "
755 aptget update -qq
756 msgdone "info"
757 fi
758 }
759
760 signreleasefiles() {
761 local SIGNER="${1:-Joe Sixpack}"
762 local GPG="gpg --batch --yes --no-default-keyring --trustdb-name rootdir/etc/apt/trustdb.gpg"
763 msgninfo "\tSign archive with $SIGNER key… "
764 local REXKEY='keys/rexexpired'
765 local SECEXPIREBAK="${REXKEY}.sec.bak"
766 local PUBEXPIREBAK="${REXKEY}.pub.bak"
767 if [ "${SIGNER}" = 'Rex Expired' ]; then
768 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
769 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
770 # therefore we 'temporary' make the key not expired and restore a backup after signing
771 cp ${REXKEY}.sec $SECEXPIREBAK
772 cp ${REXKEY}.pub $PUBEXPIREBAK
773 local SECUNEXPIRED="${REXKEY}.sec.unexpired"
774 local PUBUNEXPIRED="${REXKEY}.pub.unexpired"
775 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
776 cp $SECUNEXPIRED ${REXKEY}.sec
777 cp $PUBUNEXPIRED ${REXKEY}.pub
778 else
779 printf "expire\n1w\nsave\n" | $GPG --keyring ${REXKEY}.pub --secret-keyring ${REXKEY}.sec --command-fd 0 --edit-key "${SIGNER}" >/dev/null 2>&1 || true
780 cp ${REXKEY}.sec $SECUNEXPIRED
781 cp ${REXKEY}.pub $PUBUNEXPIRED
782 fi
783 fi
784 for KEY in $(find keys/ -name '*.sec'); do
785 GPG="$GPG --secret-keyring $KEY"
786 done
787 for KEY in $(find keys/ -name '*.pub'); do
788 GPG="$GPG --keyring $KEY"
789 done
790 for RELEASE in $(find aptarchive/ -name Release); do
791 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg ${RELEASE}
792 local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
793 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
794 # we might have set a specific date for the Release file, so copy it
795 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg ${INRELEASE}
796 done
797 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
798 mv -f $SECEXPIREBAK ${REXKEY}.sec
799 mv -f $PUBEXPIREBAK ${REXKEY}.pub
800 fi
801 msgdone "info"
802 }
803
804 webserverconfig() {
805 msgtest "Set webserver config option '${1}' to" "$2"
806 downloadfile "http://localhost:8080/_config/set/${1}/${2}" '/dev/null' >/dev/null
807 local DOWNLOG='download-testfile.log'
808 rm -f "$DOWNLOG"
809 local STATUS="$(mktemp)"
810 addtrap "rm $STATUS;"
811 downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
812 if [ "$(cat "$STATUS")" = '200' ]; then
813 msgpass
814 else
815 cat >&2 "$DOWNLOG"
816 msgfail "Statuscode was $(cat "$STATUS")"
817 fi
818 }
819
820 rewritesourceslist() {
821 local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
822 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
823 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#http://localhost:4433/#${1}#"
824 done
825 }
826
827 changetowebserver() {
828 if [ "$1" != '--no-rewrite' ]; then
829 rewritesourceslist 'http://localhost:8080/'
830 else
831 shift
832 fi
833 local LOG='/dev/null'
834 if test -x ${APTWEBSERVERBINDIR}/aptwebserver; then
835 cd aptarchive
836 aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1
837 local PID="$(cat aptwebserver.pid)"
838 if [ -z "$PID" ]; then
839 msgdie 'Could not fork aptwebserver successfully'
840 fi
841 addtrap "kill $PID;"
842 cd - > /dev/null
843 else
844 msgdie 'You have to build aptwerbserver or install a webserver'
845 fi
846 }
847
848 changetohttpswebserver() {
849 if ! which stunnel4 >/dev/null; then
850 msgdie 'You need to install stunnel4 for https testcases'
851 fi
852 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
853 changetowebserver --no-rewrite
854 fi
855 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
856 cert = ${TESTDIRECTORY}/apt.pem
857 output = /dev/null
858
859 [https]
860 accept = 4433
861 connect = 8080
862 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
863 stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
864 local PID="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
865 addtrap 'prefix' "kill ${PID};"
866 rewritesourceslist 'https://localhost:4433/'
867 }
868
869 changetocdrom() {
870 mkdir -p rootdir/media/cdrom/.disk
871 local CD="$(readlink -f rootdir/media/cdrom)"
872 echo "acquire::cdrom::mount \"${CD}\";" > rootdir/etc/apt/apt.conf.d/00cdrom
873 echo 'acquire::cdrom::autodetect 0;' >> rootdir/etc/apt/apt.conf.d/00cdrom
874 echo -n "$1" > ${CD}/.disk/info
875 if [ ! -d aptarchive/dists ]; then
876 msgdie 'Flat file archive cdroms can not be created currently'
877 return 1
878 fi
879 mv aptarchive/dists $CD
880 ln -s "$(readlink -f ./incoming)" $CD/pool
881 find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete
882 }
883
884 downloadfile() {
885 PROTO="$(echo "$1" | cut -d':' -f 1)"
886 local DOWNLOG="${TMPWORKINGDIRECTORY}/download.log"
887 rm -f "$DOWNLOG"
888 touch "$DOWNLOG"
889 {
890 echo "601 Configuration
891 Config-Item: Acquire::https::CaInfo=${TESTDIR}/apt.pem
892 Config-Item: Debug::Acquire::${PROTO}=1
893
894 600 Acquire URI
895 URI: $1
896 Filename: ${2}
897 "
898 # simple worker keeping stdin open until we are done (201) or error (400)
899 # and requesting new URIs on try-agains/redirects inbetween
900 { tail -n 999 -f "$DOWNLOG" & echo "TAILPID: $!"; } | while read f1 f2; do
901 if [ "$f1" = 'TAILPID:' ]; then
902 TAILPID="$f2"
903 elif [ "$f1" = 'New-URI:' ]; then
904 echo "600 Acquire URI
905 URI: $f2
906 Filename: ${2}
907 "
908 elif [ "$f1" = '201' ] || [ "$f1" = '400' ]; then
909 # tail would only die on next read – which never happens
910 test -z "$TAILPID" || kill -s HUP "$TAILPID"
911 break
912 fi
913 done
914 } | LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods/${PROTO} 2>&1 | tee "$DOWNLOG"
915 rm "$DOWNLOG"
916 # only if the file exists the download was successful
917 if [ -e "$2" ]; then
918 return 0
919 else
920 return 1
921 fi
922 }
923
924 checkdiff() {
925 local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
926 if [ -n "$DIFFTEXT" ]; then
927 echo
928 echo "$DIFFTEXT"
929 return 1
930 else
931 return 0
932 fi
933 }
934
935 testfileequal() {
936 local FILE="$1"
937 shift
938 msgtest "Test for correctness of file" "$FILE"
939 if [ -z "$*" ]; then
940 echo -n "" | checkdiff $FILE - && msgpass || msgfail
941 else
942 echo "$*" | checkdiff $FILE - && msgpass || msgfail
943 fi
944 }
945
946 testempty() {
947 msgtest "Test for no output of" "$*"
948 test -z "$($* 2>&1)" && msgpass || msgfail
949 }
950
951 testequal() {
952 local COMPAREFILE=$(mktemp)
953 addtrap "rm $COMPAREFILE;"
954 echo "$1" > $COMPAREFILE
955 shift
956 msgtest "Test for equality of" "$*"
957 $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
958 }
959
960 testequalor2() {
961 local COMPAREFILE1=$(mktemp)
962 local COMPAREFILE2=$(mktemp)
963 local COMPAREAGAINST=$(mktemp)
964 addtrap "rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
965 echo "$1" > $COMPAREFILE1
966 echo "$2" > $COMPAREFILE2
967 shift 2
968 msgtest "Test for equality OR of" "$*"
969 $* >$COMPAREAGAINST 2>&1 || true
970 (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
971 checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
972 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
973 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
974 msgfail )
975 }
976
977 testshowvirtual() {
978 local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
979 local PACKAGE="$1"
980 shift
981 while [ -n "$1" ]; do
982 VIRTUAL="${VIRTUAL}
983 N: Can't select versions from package '$1' as it is purely virtual"
984 PACKAGE="${PACKAGE} $1"
985 shift
986 done
987 msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
988 VIRTUAL="${VIRTUAL}
989 N: No packages found"
990 local COMPAREFILE=$(mktemp)
991 addtrap "rm $COMPAREFILE;"
992 local ARCH="$(getarchitecture 'native')"
993 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
994 aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
995 }
996
997 testnopackage() {
998 msgtest "Test for non-existent packages" "apt-cache show $*"
999 local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')"
1000 if [ -n "$SHOWPKG" ]; then
1001 echo
1002 echo "$SHOWPKG"
1003 msgfail
1004 return 1
1005 fi
1006 msgpass
1007 }
1008
1009 testdpkginstalled() {
1010 msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
1011 local PKGS="$(dpkg -l $* 2>/dev/null | grep '^i' | wc -l)"
1012 if [ "$PKGS" != $# ]; then
1013 echo $PKGS
1014 dpkg -l $* | grep '^[a-z]'
1015 msgfail
1016 return 1
1017 fi
1018 msgpass
1019 }
1020
1021 testdpkgnotinstalled() {
1022 msgtest "Test for correctly not-installed package(s) with" "dpkg -l $*"
1023 local PKGS="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)"
1024 if [ "$PKGS" != 0 ]; then
1025 echo
1026 dpkg -l $* | grep '^[a-z]'
1027 msgfail
1028 return 1
1029 fi
1030 msgpass
1031 }
1032
1033 testmarkedauto() {
1034 local COMPAREFILE=$(mktemp)
1035 addtrap "rm $COMPAREFILE;"
1036 if [ -n "$1" ]; then
1037 msgtest 'Test for correctly marked as auto-installed' "$*"
1038 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1039 else
1040 msgtest 'Test for correctly marked as auto-installed' 'no package'
1041 echo -n > $COMPAREFILE
1042 fi
1043 aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
1044 }
1045
1046 testsuccess() {
1047 if [ "$1" = '--nomsg' ]; then
1048 shift
1049 else
1050 msgtest 'Test for successful execution of' "$*"
1051 fi
1052 local OUTPUT=$(mktemp)
1053 addtrap "rm $OUTPUT;"
1054 if $@ >${OUTPUT} 2>&1; then
1055 msgpass
1056 else
1057 echo
1058 cat $OUTPUT
1059 msgfail
1060 fi
1061 }
1062
1063 testfailure() {
1064 if [ "$1" = '--nomsg' ]; then
1065 shift
1066 else
1067 msgtest 'Test for failure in execution of' "$*"
1068 fi
1069 local OUTPUT=$(mktemp)
1070 addtrap "rm $OUTPUT;"
1071 if $@ >${OUTPUT} 2>&1; then
1072 echo
1073 cat $OUTPUT
1074 msgfail
1075 else
1076 msgpass
1077 fi
1078 }
1079
1080 pause() {
1081 echo "STOPPED execution. Press enter to continue"
1082 local IGNORE
1083 read IGNORE
1084 }