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