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