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