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