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