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