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