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