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