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