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