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