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