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