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