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