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