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