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