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