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