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