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