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