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