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