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