]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh -- # no runable script, just for vi | |
2 | ||
3 | EXIT_CODE=0 | |
4 | ||
5 | # we all like colorful messages | |
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 | |
19 | ||
20 | msgdie() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; } | |
21 | msgwarn() { echo "${CWARNING}W: $1${CNORMAL}" >&2; } | |
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}"; } | |
26 | msgnwarn() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; } | |
27 | msgnmsg() { echo -n "${CMSG}$1${CNORMAL}"; } | |
28 | msgninfo() { echo -n "${CINFO}I: $1${CNORMAL}"; } | |
29 | msgndebug() { echo -n "${CDEBUG}D: $1${CNORMAL}"; } | |
30 | msgtest() { | |
31 | while [ -n "$1" ]; do | |
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} " | |
34 | shift | |
35 | if [ -n "$1" ]; then shift; else break; fi | |
36 | done | |
37 | echo -n "…${CNORMAL} " | |
38 | } | |
39 | msgpass() { echo "${CPASS}PASS${CNORMAL}"; } | |
40 | msgskip() { echo "${CWARNING}SKIP${CNORMAL}" >&2; } | |
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 | } | |
46 | ||
47 | # enable / disable Debugging | |
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; } | |
59 | msgtest() { true; } | |
60 | msgpass() { echo -n " ${CPASS}P${CNORMAL}"; } | |
61 | msgskip() { echo -n " ${CWARNING}S${CNORMAL}" >&2; } | |
62 | if [ -n "$CFAIL" ]; then | |
63 | msgfail() { echo -n " ${CFAIL}FAIL${CNORMAL}" >&2; EXIT_CODE=$((EXIT_CODE+1)); } | |
64 | else | |
65 | msgfail() { echo -n " ###FAILED###" >&2; EXIT_CODE=$((EXIT_CODE+1)); } | |
66 | fi | |
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 | |
84 | echo "${CDONE}DONE${CNORMAL}"; | |
85 | fi | |
86 | } | |
87 | ||
88 | runapt() { | |
89 | msgdebug "Executing: ${CCMD}$*${CDEBUG} " | |
90 | local CMD="$1" | |
91 | shift | |
92 | if [ -f ./aptconfig.conf ]; then | |
93 | MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@" | |
94 | elif [ -f ../aptconfig.conf ]; then | |
95 | MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@" | |
96 | else | |
97 | MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@" | |
98 | fi | |
99 | } | |
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 "$@"; } | |
107 | aptwebserver() { | |
108 | LD_LIBRARY_PATH=${APTWEBSERVERBINDIR} ${APTWEBSERVERBINDIR}/aptwebserver "$@"; | |
109 | } | |
110 | dpkg() { | |
111 | command dpkg --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log "$@" | |
112 | } | |
113 | aptitude() { | |
114 | if [ -f ./aptconfig.conf ]; then | |
115 | APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} command aptitude "$@" | |
116 | elif [ -f ../aptconfig.conf ]; then | |
117 | APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} command aptitude "$@" | |
118 | else | |
119 | LD_LIBRARY_PATH=${BUILDDIRECTORY} command aptitude "$@" | |
120 | fi | |
121 | } | |
122 | gdb() { | |
123 | echo "gdb: run »$*«" | |
124 | APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} command gdb ${BUILDDIRECTORY}/$1 --args "$@" | |
125 | } | |
126 | http() { | |
127 | LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods/http | |
128 | } | |
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 | } | |
136 | ||
137 | exitwithstatus() { | |
138 | # error if we about to overflow, but ... | |
139 | # "255 failures ought to be enough for everybody" | |
140 | if [ $EXIT_CODE -gt 255 ]; then | |
141 | msgdie "Total failure count $EXIT_CODE too big" | |
142 | fi | |
143 | exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255)); | |
144 | } | |
145 | ||
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 | ||
156 | addtrap() { | |
157 | if [ "$1" = 'prefix' ]; then | |
158 | CURRENTTRAP="$2 $CURRENTTRAP" | |
159 | else | |
160 | CURRENTTRAP="$CURRENTTRAP $1" | |
161 | fi | |
162 | trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM | |
163 | } | |
164 | ||
165 | setupenvironment() { | |
166 | TMPWORKINGDIRECTORY=$(mktemp -d) | |
167 | TESTDIRECTORY=$(readlink -f $(dirname $0)) | |
168 | msgninfo "Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… " | |
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"} | |
173 | APTWEBSERVERBINDIR=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"} | |
174 | test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first" | |
175 | # ----- | |
176 | ||
177 | addtrap "cd /; rm -rf $TMPWORKINGDIRECTORY;" | |
178 | cd $TMPWORKINGDIRECTORY | |
179 | mkdir rootdir aptarchive keys | |
180 | cd rootdir | |
181 | mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d | |
182 | mkdir -p var/cache var/lib var/log | |
183 | mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers | |
184 | touch var/lib/dpkg/available | |
185 | mkdir -p usr/lib/apt | |
186 | ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods | |
187 | cd .. | |
188 | local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/') | |
189 | if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then | |
190 | cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages | |
191 | fi | |
192 | local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/') | |
193 | if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then | |
194 | cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources | |
195 | fi | |
196 | cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys/ | |
197 | ln -s ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg | |
198 | echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf | |
199 | echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf | |
200 | echo "Debug::NoLocking \"true\";" >> aptconfig.conf | |
201 | echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf | |
202 | echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf | |
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 | |
208 | if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then | |
209 | echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf # Added to test multiarch before dpkg is ready for it… | |
210 | fi | |
211 | echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf | |
212 | echo 'quiet::NoUpdate "true";' >> aptconfig.conf | |
213 | echo "Acquire::https::CaInfo \"${TESTDIR}/apt.pem\";" > rootdir/etc/apt/apt.conf.d/99https | |
214 | export LC_ALL=C.UTF-8 | |
215 | export PATH="${PATH}:/usr/local/sbin:/usr/sbin:/sbin" | |
216 | configcompression '.' 'gz' #'bz2' 'lzma' 'xz' | |
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 | ||
231 | msgdone "info" | |
232 | } | |
233 | ||
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 | |
240 | dpkg --print-architecture | |
241 | fi | |
242 | else | |
243 | echo $1 | |
244 | fi | |
245 | } | |
246 | ||
247 | getarchitectures() { | |
248 | echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')" | |
249 | } | |
250 | ||
251 | configarchitecture() { | |
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 | |
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 | |
271 | rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg | |
272 | if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then | |
273 | local ARCHS="$(getarchitectures)" | |
274 | if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then | |
275 | DPKGARCH="$(dpkg --print-architecture)" | |
276 | for ARCH in ${ARCHS}; do | |
277 | if [ "${ARCH}" != "${DPKGARCH}" ]; then | |
278 | if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then | |
279 | # old-style used e.g. in Ubuntu-P – and as it seems travis | |
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 | |
282 | fi | |
283 | fi | |
284 | done | |
285 | if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then | |
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' | |
289 | fi | |
290 | fi | |
291 | fi | |
292 | } | |
293 | ||
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 | ||
308 | setupsimplenativepackage() { | |
309 | local NAME="$1" | |
310 | local ARCH="$2" | |
311 | local VERSION="$3" | |
312 | local RELEASE="${4:-unstable}" | |
313 | local DEPENDENCIES="$5" | |
314 | local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} | |
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 | ||
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 | |
326 | local BUILDDIR=incoming/${NAME}-${VERSION} | |
327 | mkdir -p ${BUILDDIR}/debian/source | |
328 | cd ${BUILDDIR} | |
329 | echo "* most suckless software product ever" > FEATURES | |
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 | |
332 | ||
333 | * Initial release | |
334 | ||
335 | -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog | |
336 | test -e debian/control || echo "Source: $NAME | |
337 | Section: $SECTION | |
338 | Priority: optional | |
339 | Maintainer: Joe Sixpack <joe@example.org> | |
340 | Build-Depends: debhelper (>= 7) | |
341 | Standards-Version: 3.9.1 | |
342 | ||
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 | |
349 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control | |
350 | echo "Description: $DESCRIPTION" >> debian/control | |
351 | ||
352 | test -e debian/compat || echo "7" > debian/compat | |
353 | test -e debian/source/format || echo "3.0 (native)" > debian/source/format | |
354 | test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules | |
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" | |
364 | local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} | |
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 | ||
369 | local SECTION="${7:-others}" | |
370 | local PRIORITY="${8:-optional}" | |
371 | local FILE_TREE="$9" | |
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 | |
378 | local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION} | |
379 | ||
380 | msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… " | |
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 | |
394 | Priority: $PRIORITY | |
395 | Maintainer: Joe Sixpack <joe@example.org> | |
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 | |
401 | ||
402 | if [ "$ARCH" = 'all' ]; then | |
403 | echo "Architecture: all" >> ${BUILDDIR}/debian/control | |
404 | else | |
405 | echo "Architecture: any" >> ${BUILDDIR}/debian/control | |
406 | fi | |
407 | local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')" | |
408 | test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control | |
409 | echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control | |
410 | ||
411 | echo '3.0 (native)' > ${BUILDDIR}/debian/source/format | |
412 | (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' \ | |
413 | | while read SRC; do | |
414 | echo "pool/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist | |
415 | # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then | |
416 | # gpg --yes --secret-keyring ./keys/joesixpack.sec \ | |
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 | |
421 | done | |
422 | ||
423 | for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do | |
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} | |
428 | if [ -n "$FILE_TREE" ]; then | |
429 | cp -ar "$FILE_TREE" ${BUILDDIR}/debian/tmp | |
430 | fi | |
431 | ||
432 | (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch) | |
433 | (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums) | |
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 | |
440 | echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist | |
441 | done | |
442 | ||
443 | mkdir -p ${BUILDDIR}/../${NAME}_${VERSION} | |
444 | cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}/ | |
445 | cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}.changelog | |
446 | rm -rf "${BUILDDIR}" | |
447 | msgdone "info" | |
448 | } | |
449 | ||
450 | buildpackage() { | |
451 | local BUILDDIR=$1 | |
452 | local RELEASE=$2 | |
453 | local SECTION=$3 | |
454 | local ARCH=$(getarchitecture $4) | |
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}… " | |
458 | cd $BUILDDIR | |
459 | if [ "$ARCH" = "all" ]; then | |
460 | ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)" | |
461 | fi | |
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._+~-]*$')" | |
468 | cd - > /dev/null | |
469 | for PKG in $PKGS; do | |
470 | echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist | |
471 | done | |
472 | for SRC in $SRCS; do | |
473 | echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist | |
474 | done | |
475 | msgdone "info" | |
476 | } | |
477 | ||
478 | buildaptarchive() { | |
479 | if [ -d incoming ]; then | |
480 | buildaptarchivefromincoming "$@" | |
481 | else | |
482 | buildaptarchivefromfiles "$@" | |
483 | fi | |
484 | } | |
485 | ||
486 | createaptftparchiveconfig() { | |
487 | local COMPRESSORS="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')" | |
488 | COMPRESSORS="${COMPRESSORS%* }" | |
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' ' ')" | |
490 | if [ -z "$ARCHS" ]; then | |
491 | # the pool is empty, so we will operate on faked packages - let us use the configured archs | |
492 | ARCHS="$(getarchitectures)" | |
493 | fi | |
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 '"; | |
501 | FileListDir "' >> ftparchive.conf | |
502 | echo -n $(readlink -f pool/) >> ftparchive.conf | |
503 | echo -n '"; | |
504 | }; | |
505 | Default { | |
506 | Packages::Compress "'"$COMPRESSORS"'"; | |
507 | Sources::Compress "'"$COMPRESSORS"'"; | |
508 | Contents::Compress "'"$COMPRESSORS"'"; | |
509 | Translation::Compress "'"$COMPRESSORS"'"; | |
510 | LongDescription "false"; | |
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 | |
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 '" { | |
533 | Architectures "' >> ftparchive.conf | |
534 | echo -n "$ARCHS" >> ftparchive.conf | |
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 '"; | |
545 | };' >> ftparchive.conf | |
546 | done | |
547 | } | |
548 | ||
549 | buildaptftparchivedirectorystructure() { | |
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 | |
561 | done | |
562 | } | |
563 | ||
564 | insertpackage() { | |
565 | local RELEASE="$1" | |
566 | local NAME="$2" | |
567 | local ARCH="$3" | |
568 | local VERSION="$4" | |
569 | local DEPENDENCIES="$5" | |
570 | local PRIORITY="${6:-optional}" | |
571 | local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} | |
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…"}" | |
575 | local ARCHS="" | |
576 | for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do | |
577 | if [ "$arch" = 'all' -o "$arch" = 'none' ]; then | |
578 | ARCHS="$(getarchitectures)" | |
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 | |
589 | Section: other | |
590 | Installed-Size: 42 | |
591 | Maintainer: Joe Sixpack <joe@example.org>" >> $FILE | |
592 | test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE | |
593 | echo "Version: $VERSION | |
594 | Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE | |
595 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE | |
596 | echo "Description: $DESCRIPTION" >> $FILE | |
597 | echo >> $FILE | |
598 | done | |
599 | done | |
600 | } | |
601 | ||
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 | |
620 | d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz | |
621 | " >> $FILE | |
622 | } | |
623 | ||
624 | insertinstalledpackage() { | |
625 | local NAME="$1" | |
626 | local ARCH="$2" | |
627 | local VERSION="$3" | |
628 | local DEPENDENCIES="$4" | |
629 | local PRIORITY="${5:-optional}" | |
630 | local STATUS="${6:-install ok installed}" | |
631 | local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed | |
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 | ||
636 | local FILE='rootdir/var/lib/dpkg/status' | |
637 | local INFO='rootdir/var/lib/dpkg/info' | |
638 | for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do | |
639 | echo "Package: $NAME | |
640 | Status: $STATUS | |
641 | Priority: $PRIORITY | |
642 | Section: other | |
643 | Installed-Size: 42 | |
644 | Maintainer: Joe Sixpack <joe@example.org> | |
645 | Version: $VERSION" >> $FILE | |
646 | test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE | |
647 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE | |
648 | echo "Description: $DESCRIPTION" >> $FILE | |
649 | echo >> $FILE | |
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 | |
655 | done | |
656 | } | |
657 | ||
658 | ||
659 | buildaptarchivefromincoming() { | |
660 | msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…" | |
661 | cd aptarchive | |
662 | [ -e pool ] || ln -s ../incoming pool | |
663 | [ -e ftparchive.conf ] || createaptftparchiveconfig | |
664 | [ -e dists ] || buildaptftparchivedirectorystructure | |
665 | msgninfo "\tGenerate Packages, Sources and Contents files… " | |
666 | aptftparchive -qq generate ftparchive.conf | |
667 | cd - > /dev/null | |
668 | msgdone "info" | |
669 | generatereleasefiles | |
670 | } | |
671 | ||
672 | buildaptarchivefromfiles() { | |
673 | msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…" | |
674 | find aptarchive -name 'Packages' -o -name 'Sources' | while read line; do | |
675 | msgninfo "\t${line} file… " | |
676 | compressfile "$line" "$1" | |
677 | msgdone "info" | |
678 | done | |
679 | generatereleasefiles "$@" | |
680 | } | |
681 | ||
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 | ||
697 | # can be overridden by testcases for their pleasure | |
698 | getcodenamefromsuite() { | |
699 | case "$1" in | |
700 | unstable) echo 'sid';; | |
701 | *) echo -n "$1";; | |
702 | esac | |
703 | } | |
704 | getreleaseversionfromsuite() { true; } | |
705 | getlabelfromsuite() { true; } | |
706 | ||
707 | generatereleasefiles() { | |
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 | |
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 | |
713 | local SUITE="$(echo "$dir" | cut -d'/' -f 4)" | |
714 | local CODENAME="$(getcodenamefromsuite $SUITE)" | |
715 | local VERSION="$(getreleaseversionfromsuite $SUITE)" | |
716 | local LABEL="$(getlabelfromsuite $SUITE)" | |
717 | if [ -n "$VERSION" ]; then | |
718 | VERSION="-o APT::FTPArchive::Release::Version=${VERSION}" | |
719 | fi | |
720 | if [ -n "$LABEL" ]; then | |
721 | LABEL="-o APT::FTPArchive::Release::Label=${LABEL}" | |
722 | fi | |
723 | aptftparchive -qq release $dir \ | |
724 | -o APT::FTPArchive::Release::Suite="${SUITE}" \ | |
725 | -o APT::FTPArchive::Release::Codename="${CODENAME}" \ | |
726 | ${LABEL} \ | |
727 | ${VERSION} \ | |
728 | | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference | |
729 | if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then | |
730 | sed -i '/^Date: / a\ | |
731 | NotAutomatic: yes' $dir/Release | |
732 | fi | |
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 | |
740 | done | |
741 | else | |
742 | aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference | |
743 | fi | |
744 | if [ -n "$1" -a "$1" != "now" ]; then | |
745 | for release in $(find ./aptarchive -name 'Release'); do | |
746 | touch -d "$1" $release | |
747 | done | |
748 | fi | |
749 | msgdone "info" | |
750 | } | |
751 | ||
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() { | |
766 | local APTARCHIVE=$(readlink -f ./aptarchive) | |
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 | |
781 | } | |
782 | ||
783 | setupaptarchive() { | |
784 | buildaptarchive | |
785 | if [ -e aptarchive/dists ]; then | |
786 | setupdistsaptarchive | |
787 | else | |
788 | setupflataptarchive | |
789 | fi | |
790 | signreleasefiles | |
791 | if [ "$1" != '--no-update' ]; then | |
792 | msgninfo "\tSync APT's cache with the archive… " | |
793 | aptget update -qq | |
794 | msgdone "info" | |
795 | fi | |
796 | } | |
797 | ||
798 | signreleasefiles() { | |
799 | local SIGNER="${1:-Joe Sixpack}" | |
800 | local GPG="gpg --batch --yes" | |
801 | msgninfo "\tSign archive with $SIGNER key… " | |
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 | |
822 | for KEY in $(find keys/ -name '*.sec'); do | |
823 | GPG="$GPG --secret-keyring $KEY" | |
824 | done | |
825 | for KEY in $(find keys/ -name '*.pub'); do | |
826 | GPG="$GPG --keyring $KEY" | |
827 | done | |
828 | for RELEASE in $(find aptarchive/ -name Release); do | |
829 | $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg ${RELEASE} | |
830 | local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')" | |
831 | $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE | |
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} | |
834 | done | |
835 | if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then | |
836 | mv -f $SECEXPIREBAK ${REXKEY}.sec | |
837 | mv -f $PUBEXPIREBAK ${REXKEY}.pub | |
838 | fi | |
839 | msgdone "info" | |
840 | } | |
841 | ||
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" | |
847 | local STATUS="$(mktemp)" | |
848 | addtrap "rm $STATUS;" | |
849 | downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" | |
850 | if [ "$(cat "$STATUS")" = '200' ]; then | |
851 | msgpass | |
852 | else | |
853 | cat >&2 "$DOWNLOG" | |
854 | msgfail "Statuscode was $(cat "$STATUS")" | |
855 | fi | |
856 | } | |
857 | ||
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 | ||
865 | changetowebserver() { | |
866 | if [ "$1" != '--no-rewrite' ]; then | |
867 | rewritesourceslist 'http://localhost:8080/' | |
868 | else | |
869 | shift | |
870 | fi | |
871 | if test -x ${APTWEBSERVERBINDIR}/aptwebserver; then | |
872 | cd aptarchive | |
873 | local LOG="$(mktemp)" | |
874 | addtrap "rm $LOG;" | |
875 | if ! aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1 ; then | |
876 | cat $LOG | |
877 | false | |
878 | fi | |
879 | local PID="$(cat aptwebserver.pid)" | |
880 | if [ -z "$PID" ]; then | |
881 | msgdie 'Could not fork aptwebserver successfully' | |
882 | fi | |
883 | addtrap "kill $PID;" | |
884 | cd - > /dev/null | |
885 | else | |
886 | msgdie 'You have to build aptwerbserver or install a webserver' | |
887 | fi | |
888 | } | |
889 | ||
890 | changetohttpswebserver() { | |
891 | if ! which stunnel4 >/dev/null; then | |
892 | msgdie 'You need to install stunnel4 for https testcases' | |
893 | fi | |
894 | if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then | |
895 | changetowebserver --no-rewrite | |
896 | fi | |
897 | echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid | |
898 | cert = ${TESTDIRECTORY}/apt.pem | |
899 | output = /dev/null | |
900 | ||
901 | [https] | |
902 | accept = 4433 | |
903 | connect = 8080 | |
904 | " > ${TMPWORKINGDIRECTORY}/stunnel.conf | |
905 | stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf" | |
906 | local PID="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)" | |
907 | addtrap 'prefix' "kill ${PID};" | |
908 | rewritesourceslist 'https://localhost:4433/' | |
909 | } | |
910 | ||
911 | changetocdrom() { | |
912 | mkdir -p rootdir/media/cdrom/.disk | |
913 | local CD="$(readlink -f rootdir/media/cdrom)" | |
914 | echo "acquire::cdrom::mount \"${CD}\";" > rootdir/etc/apt/apt.conf.d/00cdrom | |
915 | echo 'acquire::cdrom::autodetect 0;' >> rootdir/etc/apt/apt.conf.d/00cdrom | |
916 | echo -n "$1" > ${CD}/.disk/info | |
917 | if [ ! -d aptarchive/dists ]; then | |
918 | msgdie 'Flat file archive cdroms can not be created currently' | |
919 | return 1 | |
920 | fi | |
921 | mv aptarchive/dists $CD | |
922 | ln -s "$(readlink -f ./incoming)" $CD/pool | |
923 | find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete | |
924 | } | |
925 | ||
926 | downloadfile() { | |
927 | PROTO="$(echo "$1" | cut -d':' -f 1)" | |
928 | local DOWNLOG="${TMPWORKINGDIRECTORY}/download.log" | |
929 | rm -f "$DOWNLOG" | |
930 | touch "$DOWNLOG" | |
931 | { | |
932 | echo "601 Configuration | |
933 | Config-Item: Acquire::https::CaInfo=${TESTDIR}/apt.pem | |
934 | Config-Item: Debug::Acquire::${PROTO}=1 | |
935 | ||
936 | 600 Acquire URI | |
937 | URI: $1 | |
938 | Filename: ${2} | |
939 | " | |
940 | # simple worker keeping stdin open until we are done (201) or error (400) | |
941 | # and requesting new URIs on try-agains/redirects inbetween | |
942 | { tail -n 999 -f "$DOWNLOG" & echo "TAILPID: $!"; } | while read f1 f2; do | |
943 | if [ "$f1" = 'TAILPID:' ]; then | |
944 | TAILPID="$f2" | |
945 | elif [ "$f1" = 'New-URI:' ]; then | |
946 | echo "600 Acquire URI | |
947 | URI: $f2 | |
948 | Filename: ${2} | |
949 | " | |
950 | elif [ "$f1" = '201' ] || [ "$f1" = '400' ]; then | |
951 | # tail would only die on next read – which never happens | |
952 | test -z "$TAILPID" || kill -s HUP "$TAILPID" | |
953 | break | |
954 | fi | |
955 | done | |
956 | } | LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods/${PROTO} 2>&1 | tee "$DOWNLOG" | |
957 | rm "$DOWNLOG" | |
958 | # only if the file exists the download was successful | |
959 | if [ -e "$2" ]; then | |
960 | return 0 | |
961 | else | |
962 | return 1 | |
963 | fi | |
964 | } | |
965 | ||
966 | checkdiff() { | |
967 | local DIFFTEXT="$(command diff -u "$@" | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')" | |
968 | if [ -n "$DIFFTEXT" ]; then | |
969 | echo | |
970 | echo "$DIFFTEXT" | |
971 | return 1 | |
972 | else | |
973 | return 0 | |
974 | fi | |
975 | } | |
976 | ||
977 | testfileequal() { | |
978 | local FILE="$1" | |
979 | shift | |
980 | msgtest "Test for correctness of file" "$FILE" | |
981 | if [ -z "$*" ]; then | |
982 | echo -n "" | checkdiff $FILE - && msgpass || msgfail | |
983 | else | |
984 | echo "$*" | checkdiff $FILE - && msgpass || msgfail | |
985 | fi | |
986 | } | |
987 | ||
988 | testempty() { | |
989 | msgtest "Test for no output of" "$*" | |
990 | test -z "$($* 2>&1)" && msgpass || msgfail | |
991 | } | |
992 | ||
993 | testequal() { | |
994 | local COMPAREFILE=$(mktemp) | |
995 | addtrap "rm $COMPAREFILE;" | |
996 | echo "$1" > $COMPAREFILE | |
997 | shift | |
998 | msgtest "Test for equality of" "$*" | |
999 | $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail | |
1000 | } | |
1001 | ||
1002 | testequalor2() { | |
1003 | local COMPAREFILE1=$(mktemp) | |
1004 | local COMPAREFILE2=$(mktemp) | |
1005 | local COMPAREAGAINST=$(mktemp) | |
1006 | addtrap "rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;" | |
1007 | echo "$1" > $COMPAREFILE1 | |
1008 | echo "$2" > $COMPAREFILE2 | |
1009 | shift 2 | |
1010 | msgtest "Test for equality OR of" "$*" | |
1011 | $* >$COMPAREAGAINST 2>&1 || true | |
1012 | (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null || | |
1013 | checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass || | |
1014 | ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \ | |
1015 | "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" && | |
1016 | msgfail ) | |
1017 | } | |
1018 | ||
1019 | testshowvirtual() { | |
1020 | local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual" | |
1021 | local PACKAGE="$1" | |
1022 | shift | |
1023 | while [ -n "$1" ]; do | |
1024 | VIRTUAL="${VIRTUAL} | |
1025 | N: Can't select versions from package '$1' as it is purely virtual" | |
1026 | PACKAGE="${PACKAGE} $1" | |
1027 | shift | |
1028 | done | |
1029 | msgtest "Test for virtual packages" "apt-cache show $PACKAGE" | |
1030 | VIRTUAL="${VIRTUAL} | |
1031 | N: No packages found" | |
1032 | local COMPAREFILE=$(mktemp) | |
1033 | addtrap "rm $COMPAREFILE;" | |
1034 | local ARCH="$(getarchitecture 'native')" | |
1035 | echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE | |
1036 | aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail | |
1037 | } | |
1038 | ||
1039 | testnopackage() { | |
1040 | msgtest "Test for non-existent packages" "apt-cache show $*" | |
1041 | local SHOWPKG="$(aptcache show "$@" 2>&1 | grep '^Package: ')" | |
1042 | if [ -n "$SHOWPKG" ]; then | |
1043 | echo | |
1044 | echo "$SHOWPKG" | |
1045 | msgfail | |
1046 | return 1 | |
1047 | fi | |
1048 | msgpass | |
1049 | } | |
1050 | ||
1051 | testdpkginstalled() { | |
1052 | msgtest "Test for correctly installed package(s) with" "dpkg -l $*" | |
1053 | local PKGS="$(dpkg -l "$@" 2>/dev/null | grep '^i' | wc -l)" | |
1054 | if [ "$PKGS" != $# ]; then | |
1055 | echo $PKGS | |
1056 | dpkg -l "$@" | grep '^[a-z]' | |
1057 | msgfail | |
1058 | return 1 | |
1059 | fi | |
1060 | msgpass | |
1061 | } | |
1062 | ||
1063 | testdpkgnotinstalled() { | |
1064 | msgtest "Test for correctly not-installed package(s) with" "dpkg -l $*" | |
1065 | local PKGS="$(dpkg -l "$@" 2> /dev/null | grep '^i' | wc -l)" | |
1066 | if [ "$PKGS" != 0 ]; then | |
1067 | echo | |
1068 | dpkg -l "$@" | grep '^[a-z]' | |
1069 | msgfail | |
1070 | return 1 | |
1071 | fi | |
1072 | msgpass | |
1073 | } | |
1074 | ||
1075 | testmarkedauto() { | |
1076 | local COMPAREFILE=$(mktemp) | |
1077 | addtrap "rm $COMPAREFILE;" | |
1078 | if [ -n "$1" ]; then | |
1079 | msgtest 'Test for correctly marked as auto-installed' "$*" | |
1080 | while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE | |
1081 | else | |
1082 | msgtest 'Test for correctly marked as auto-installed' 'no package' | |
1083 | echo -n > $COMPAREFILE | |
1084 | fi | |
1085 | aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail | |
1086 | } | |
1087 | ||
1088 | testsuccess() { | |
1089 | if [ "$1" = '--nomsg' ]; then | |
1090 | shift | |
1091 | else | |
1092 | msgtest 'Test for successful execution of' "$*" | |
1093 | fi | |
1094 | local OUTPUT=$(mktemp) | |
1095 | addtrap "rm $OUTPUT;" | |
1096 | if $@ >${OUTPUT} 2>&1; then | |
1097 | msgpass | |
1098 | else | |
1099 | echo | |
1100 | cat $OUTPUT | |
1101 | msgfail | |
1102 | fi | |
1103 | } | |
1104 | ||
1105 | testfailure() { | |
1106 | if [ "$1" = '--nomsg' ]; then | |
1107 | shift | |
1108 | else | |
1109 | msgtest 'Test for failure in execution of' "$*" | |
1110 | fi | |
1111 | local OUTPUT=$(mktemp) | |
1112 | addtrap "rm $OUTPUT;" | |
1113 | if $@ >${OUTPUT} 2>&1; then | |
1114 | echo | |
1115 | cat $OUTPUT | |
1116 | msgfail | |
1117 | else | |
1118 | msgpass | |
1119 | fi | |
1120 | } | |
1121 | ||
1122 | pause() { | |
1123 | echo "STOPPED execution. Press enter to continue" | |
1124 | local IGNORE | |
1125 | read IGNORE | |
1126 | } |