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