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