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