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