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