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