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