]> git.saurik.com Git - apt.git/blame - test/integration/framework
releasing version 0.9.1
[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
05343a22
DK
210 # dpkg doesn't really check the version as long as it is fully installed,
211 # but just to be sure we choose one above the required version
212 insertinstalledpackage 'dpkg' "all" '1.16.2+fake'
53ea1b56
DK
213 fi
214 fi
215 fi
8d876415
DK
216}
217
75954ae2 218setupsimplenativepackage() {
ce9864a8
DK
219 local NAME="$1"
220 local ARCH="$2"
221 local VERSION="$3"
222 local RELEASE="${4:-unstable}"
223 local DEPENDENCIES="$5"
224 local DESCRIPTION="$6"
b7899b00
DK
225 local SECTION="${7:-others}"
226 local DISTSECTION
227 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
228 DISTSECTION="main"
229 else
230 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
231 fi
ce9864a8
DK
232 local BUILDDIR=incoming/${NAME}-${VERSION}
233 mkdir -p ${BUILDDIR}/debian/source
234 cd ${BUILDDIR}
235 echo "* most suckless software product ever" > FEATURES
b7899b00
DK
236 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
237 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
ce9864a8
DK
238
239 * Initial release
240
b7899b00
DK
241 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
242 test -e debian/control || echo "Source: $NAME
243Section: $SECTION
ce9864a8
DK
244Priority: optional
245Maintainer: Joe Sixpack <joe@example.org>
246Build-Depends: debhelper (>= 7)
247Standards-Version: 3.9.1
248
875bcb36
DK
249Package: $NAME" > debian/control
250 if [ "$ARCH" = 'all' ]; then
251 echo "Architecture: all" >> debian/control
252 else
253 echo "Architecture: any" >> debian/control
254 fi
ce9864a8
DK
255 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
256 if [ -z "$DESCRIPTION" ]; then
257 echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
258 If you find such a package installed on your system,
259 YOU did something horribly wrong! They are autogenerated
260 und used only by testcases for APT and surf no other propose…" >> debian/control
261 else
262 echo "Description: $DESCRIPTION" >> debian/control
263 fi
b7899b00
DK
264 test -e debian/compat || echo "7" > debian/compat
265 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
ce9864a8 266 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
75954ae2
DK
267 cd - > /dev/null
268}
269
270buildsimplenativepackage() {
271 local NAME="$1"
272 local ARCH="$2"
273 local VERSION="$3"
274 local RELEASE="${4:-unstable}"
275 local DEPENDENCIES="$5"
276 local DESCRIPTION="$6"
277 local SECTION="${7:-others}"
d67004e0 278 local PRIORITY="${8:-optional}"
75954ae2
DK
279 local DISTSECTION
280 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
281 DISTSECTION="main"
282 else
283 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
284 fi
5a635ee4 285 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
b761356f 286
18331adf 287 msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… "
b761356f
DK
288 mkdir -p $BUILDDIR/debian/source
289 echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
290 echo "#!/bin/sh
291echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
292
293 echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
294 echo "$NAME ($VERSION) $RELEASE; urgency=low
295
296 * Initial release
297
298 -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
299 echo "Source: $NAME
300Section: $SECTION
d67004e0 301Priority: $PRIORITY
b761356f
DK
302Maintainer: Joe Sixpack <joe@example.org>
303Standards-Version: 3.9.1
304
875bcb36
DK
305Package: $NAME" > ${BUILDDIR}/debian/control
306 if [ "$ARCH" = 'all' ]; then
307 echo "Architecture: all" >> ${BUILDDIR}/debian/control
308 else
309 echo "Architecture: any" >> ${BUILDDIR}/debian/control
310 fi
b761356f
DK
311 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> ${BUILDDIR}/debian/control
312 if [ -z "$DESCRIPTION" ]; then
313 echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
314 If you find such a package installed on your system,
315 YOU did something horribly wrong! They are autogenerated
316 und used only by testcases for APT and surf no other propose…" >> ${BUILDDIR}/debian/control
317 else
318 echo "Description: $DESCRIPTION" >> ${BUILDIR}/debian/control
319 fi
320 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
321 local SRCS="$( (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
b761356f 322 for SRC in $SRCS; do
5a635ee4 323 echo "pool/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
b761356f 324 done
84aa13f4 325
ea65d079 326 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
84aa13f4
DK
327 rm -rf ${BUILDDIR}/debian/tmp
328 mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
329 cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}
330 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}
331 (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch)
332 (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
333
334 dpkg-deb --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/.. 2> /dev/null > /dev/null
335 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist
336 done
337
13845042
DK
338 mkdir -p ${BUILDDIR}/../${NAME}_${VERSION}
339 cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}/
340 cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}.changelog
5a635ee4 341 rm -rf "${BUILDDIR}"
b761356f 342 msgdone "info"
75954ae2
DK
343}
344
345buildpackage() {
346 local BUILDDIR=$1
347 local RELEASE=$2
348 local SECTION=$3
ea65d079 349 local ARCH=$(getarchitecture $4)
75954ae2
DK
350 msgninfo "Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… "
351 cd $BUILDDIR
352 if [ "$ARCH" = "all" ]; then
353 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
354 fi
b7899b00
DK
355 local BUILT="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
356 local PKGS="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
5ed56f93 357 local SRCS="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
ce9864a8 358 cd - > /dev/null
b7899b00 359 for PKG in $PKGS; do
75954ae2 360 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist
b7899b00
DK
361 done
362 for SRC in $SRCS; do
75954ae2 363 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist
b7899b00 364 done
cffea9af 365 msgdone "info"
ce9864a8
DK
366}
367
368buildaptarchive() {
ce9864a8
DK
369 if [ -d incoming ]; then
370 buildaptarchivefromincoming $*
371 else
372 buildaptarchivefromfiles $*
373 fi
374}
375
376createaptftparchiveconfig() {
377 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
378 if [ -z "$ARCHS" ]; then
379 # the pool is empty, so we will operate on faked packages - let us use the configured archs
53ea1b56 380 ARCHS="$(getarchitectures)"
158fda31 381 fi
ce9864a8
DK
382 echo -n 'Dir {
383 ArchiveDir "' >> ftparchive.conf
384 echo -n $(readlink -f .) >> ftparchive.conf
385 echo -n '";
386 CacheDir "' >> ftparchive.conf
387 echo -n $(readlink -f ..) >> ftparchive.conf
388 echo -n '";
b7899b00
DK
389 FileListDir "' >> ftparchive.conf
390 echo -n $(readlink -f pool/) >> ftparchive.conf
391 echo -n '";
392};
393Default {
bc33e0f0
DK
394 Packages::Compress ". gzip bzip2 lzma xz";
395 Sources::Compress ". gzip bzip2 lzma xz";
396 Contents::Compress ". gzip bzip2 lzma xz";
b7080ced 397 Translation::Compress ". gzip bzip2 lzma xz";
18331adf 398 LongDescription "false";
ce9864a8
DK
399};
400TreeDefault {
401 Directory "pool/";
402 SrcDirectory "pool/";
403};
404APT {
405 FTPArchive {
406 Release {
407 Origin "joesixpack";
408 Label "apttestcases";
409 Suite "unstable";
410 Description "repository with dummy packages";
411 Architectures "' >> ftparchive.conf
412 echo -n "$ARCHS" >> ftparchive.conf
413 echo 'source";
414 };
415 };
416};' >> ftparchive.conf
b7899b00
DK
417 for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
418 echo -n 'tree "dists/' >> ftparchive.conf
419 echo -n "$DIST" >> ftparchive.conf
420 echo -n '" {
ce9864a8
DK
421 Architectures "' >> ftparchive.conf
422 echo -n "$ARCHS" >> ftparchive.conf
b7899b00
DK
423 echo -n 'source";
424 FileList "' >> ftparchive.conf
425 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
426 echo -n '";
427 SourceFileList "' >> ftparchive.conf
428 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
429 echo -n '";
430 Sections "' >> ftparchive.conf
431 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
432 echo '";
ce9864a8 433};' >> ftparchive.conf
b7899b00 434 done
ce9864a8
DK
435}
436
437buildaptftparchivedirectorystructure() {
b7899b00
DK
438 local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
439 for DIST in $DISTS; do
440 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
441 for SECTION in $SECTIONS; do
442 local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
443 for ARCH in $ARCHS; do
444 mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH}
445 done
446 mkdir -p dists/${DIST}/${SECTION}/source
447 mkdir -p dists/${DIST}/${SECTION}/i18n
448 done
ce9864a8 449 done
ce9864a8
DK
450}
451
9b78cda6
DK
452insertpackage() {
453 local RELEASE="$1"
454 local NAME="$2"
455 local ARCH="$3"
456 local VERSION="$4"
457 local DEPENDENCIES="$5"
d67004e0
DK
458 local PRIORITY="${6:-optional}"
459 local ARCHS=""
ea65d079 460 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
d67004e0 461 if [ "$arch" = "all" ]; then
53ea1b56 462 ARCHS="$(getarchitectures)"
d67004e0
DK
463 else
464 ARCHS="$arch"
465 fi
466 for BUILDARCH in $ARCHS; do
467 local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
468 mkdir -p $PPATH aptarchive/dists/${RELEASE}/main/source
469 touch aptarchive/dists/${RELEASE}/main/source/Sources
470 local FILE="${PPATH}/Packages"
471 echo "Package: $NAME
472Priority: $PRIORITY
9b78cda6 473Section: other
2c085486 474Installed-Size: 42
9b78cda6 475Maintainer: Joe Sixpack <joe@example.org>
d67004e0 476Architecture: $arch
2c085486 477Version: $VERSION
d67004e0
DK
478Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
479 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
480 echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
9b78cda6
DK
481 If you find such a package installed on your system,
482 YOU did something horribly wrong! They are autogenerated
483 und used only by testcases for APT and surf no other propose…
484" >> $FILE
d67004e0 485 done
9b78cda6
DK
486 done
487}
488
234675b7
DK
489insertsource() {
490 local RELEASE="$1"
491 local NAME="$2"
492 local ARCH="$3"
493 local VERSION="$4"
494 local DEPENDENCIES="$5"
495 local ARCHS=""
496 local SPATH="aptarchive/dists/${RELEASE}/main/source"
497 mkdir -p $SPATH
498 local FILE="${SPATH}/Sources"
499 echo "Package: $NAME
500Binary: $NAME
501Version: $VERSION
502Maintainer: Joe Sixpack <joe@example.org>
503Architecture: $ARCH" >> $FILE
504 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
505 echo "Files:
506 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
507 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz" >> $FILE
508}
509
dfc2b1be
DK
510insertinstalledpackage() {
511 local NAME="$1"
512 local ARCH="$2"
513 local VERSION="$3"
514 local DEPENDENCIES="$4"
d67004e0 515 local PRIORITY="${5:-optional}"
53ea1b56
DK
516 local FILE='rootdir/var/lib/dpkg/status'
517 local INFO='rootdir/var/lib/dpkg/info'
ea65d079 518 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
d67004e0 519 echo "Package: $NAME
dfc2b1be 520Status: install ok installed
d67004e0 521Priority: $PRIORITY
dfc2b1be
DK
522Section: other
523Installed-Size: 42
524Maintainer: Joe Sixpack <joe@example.org>
d67004e0 525Architecture: $arch
dfc2b1be 526Version: $VERSION" >> $FILE
d67004e0
DK
527 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
528 echo "Description: an autogenerated dummy ${NAME}=${VERSION}/installed
dfc2b1be
DK
529 If you find such a package installed on your system,
530 YOU did something horribly wrong! They are autogenerated
531 und used only by testcases for APT and surf no other propose…
532" >> $FILE
53ea1b56
DK
533 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
534 echo -n > ${INFO}/${NAME}:${arch}.list
535 else
536 echo -n > ${INFO}/${NAME}.list
537 fi
d67004e0 538 done
dfc2b1be
DK
539}
540
541
ce9864a8 542buildaptarchivefromincoming() {
3cbbda3c 543 msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
ce9864a8
DK
544 cd aptarchive
545 [ -e pool ] || ln -s ../incoming pool
546 [ -e ftparchive.conf ] || createaptftparchiveconfig
547 [ -e dists ] || buildaptftparchivedirectorystructure
b7899b00 548 msgninfo "\tGenerate Packages, Sources and Contents files… "
ce9864a8 549 aptftparchive -qq generate ftparchive.conf
ce9864a8
DK
550 cd - > /dev/null
551 msgdone "info"
9b78cda6 552 generatereleasefiles
ce9864a8
DK
553}
554
555buildaptarchivefromfiles() {
3cbbda3c 556 msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
9b78cda6
DK
557 find aptarchive -name 'Packages' -o -name 'Sources' | while read line; do
558 msgninfo "\t${line} file… "
559 cat ${line} | gzip > ${line}.gz
560 cat ${line} | bzip2 > ${line}.bz2
8bcbc694 561 cat ${line} | xz --format=lzma > ${line}.lzma
b7080ced 562 cat ${line} | xz > ${line}.xz
8d876415 563 msgdone "info"
9b78cda6
DK
564 done
565 generatereleasefiles
566}
567
a3bbbab7
DK
568# can be overridden by testcases for their pleasure
569getcodenamefromsuite() { echo -n "$1"; }
570getreleaseversionfromsuite() { true; }
718f797c 571getlabelfromsuite() { true; }
a3bbbab7 572
9b78cda6 573generatereleasefiles() {
884a4c0a
DK
574 # $1 is the Date header and $2 is the ValidUntil header to be set
575 # both should be given in notation date/touch can understand
9b78cda6
DK
576 msgninfo "\tGenerate Release files… "
577 if [ -e aptarchive/dists ]; then
578 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
a3bbbab7
DK
579 local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
580 local CODENAME="$(getcodenamefromsuite $SUITE)"
581 local VERSION="$(getreleaseversionfromsuite $SUITE)"
718f797c 582 local LABEL="$(getlabelfromsuite $SUITE)"
884a4c0a 583 if [ -n "$VERSION" ]; then
718f797c
DK
584 VERSION="-o APT::FTPArchive::Release::Version=${VERSION}"
585 fi
586 if [ -n "$LABEL" ]; then
587 LABEL="-o APT::FTPArchive::Release::Label=${LABEL}"
a3bbbab7 588 fi
884a4c0a
DK
589 aptftparchive -qq release $dir \
590 -o APT::FTPArchive::Release::Suite="${SUITE}" \
591 -o APT::FTPArchive::Release::Codename="${CODENAME}" \
718f797c 592 ${LABEL} \
884a4c0a
DK
593 ${VERSION} \
594 | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
a3bbbab7 595 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
35faae11
DK
596 sed -i '/^Date: / a\
597NotAutomatic: yes' $dir/Release
598 fi
884a4c0a
DK
599 if [ -n "$1" -a "$1" != "now" ]; then
600 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
601 fi
602 if [ -n "$2" ]; then
603 sed -i "/^Date: / a\
604Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
605 fi
9b78cda6
DK
606 done
607 else
608 aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
8d876415 609 fi
884a4c0a 610 if [ -n "$1" -a "$1" != "now" ]; then
fe0f7911
DK
611 for release in $(find ./aptarchive -name 'Release'); do
612 touch -d "$1" $release
613 done
8d876415 614 fi
b7899b00 615 msgdone "info"
8d876415
DK
616}
617
b7899b00
DK
618setupdistsaptarchive() {
619 local APTARCHIVE=$(readlink -f ./aptarchive)
620 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
621 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
622 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
623 SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
624 msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
625 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
626 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
627 msgdone "info"
628 done
629}
630
631setupflataptarchive() {
ce9864a8 632 local APTARCHIVE=$(readlink -f ./aptarchive)
8d876415
DK
633 if [ -f ${APTARCHIVE}/Packages ]; then
634 msgninfo "\tadd deb sources.list line… "
635 echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
636 msgdone "info"
637 else
638 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
639 fi
640 if [ -f ${APTARCHIVE}/Sources ]; then
641 msgninfo "\tadd deb-src sources.list line… "
642 echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
643 msgdone "info"
644 else
645 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
646 fi
b7899b00
DK
647}
648
649setupaptarchive() {
650 buildaptarchive
651 if [ -e aptarchive/dists ]; then
652 setupdistsaptarchive
653 else
654 setupflataptarchive
655 fi
f213b6ea 656 signreleasefiles
cd725954 657 msgninfo "\tSync APT's cache with the archive… "
8d876415 658 aptget update -qq
cd725954 659 msgdone "info"
8d876415
DK
660}
661
f213b6ea
DK
662signreleasefiles() {
663 local SIGNER="${1:-Joe Sixpack}"
664 msgninfo "\tSign archive with $SIGNER key… "
665 local SECKEYS=""
666 for KEY in $(find keys/ -name '*.sec'); do
667 SECKEYS="$SECKEYS --secret-keyring $KEY"
668 done
669 local PUBKEYS=""
670 for KEY in $(find keys/ -name '*.pub'); do
671 PUBKEYS="$PUBKEYS --keyring $KEY"
672 done
673 for RELEASE in $(find aptarchive/ -name Release); do
674 gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" -abs -o ${RELEASE}.gpg ${RELEASE}
fe0f7911 675 gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" --clearsign -o "$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')" $RELEASE
f213b6ea
DK
676 done
677 msgdone "info"
678}
679
680changetowebserver() {
681 if which weborf > /dev/null; then
682 weborf -xb aptarchive/ 2>&1 > /dev/null &
b720d0bd 683 addtrap "kill $!;"
6e7d39d0
DK
684 elif which gatling > /dev/null; then
685 cd aptarchive
686 gatling -p 8080 -F -S 2>&1 > /dev/null &
687 addtrap "kill $!;"
688 cd - > /dev/null
c5bcc607
DK
689 elif which lighttpd > /dev/null; then
690 echo "server.document-root = \"$(readlink -f ./aptarchive)\"
691server.port = 8080
692server.stat-cache-engine = \"disable\"" > lighttpd.conf
693 lighttpd -t -f lighttpd.conf >/dev/null || msgdie 'Can not change to webserver: our lighttpd config is invalid'
694 lighttpd -D -f lighttpd.conf 2>/dev/null >/dev/null &
695 addtrap "kill $!;"
696 else
697 msgdie 'You have to install weborf or lighttpd first'
698 return 1
f213b6ea 699 fi
c5bcc607
DK
700 local APTARCHIVE="file://$(readlink -f ./aptarchive)"
701 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
702 sed -i $LIST -e "s#$APTARCHIVE#http://localhost:8080/#"
703 done
704 return 0
f213b6ea
DK
705}
706
707checkdiff() {
8d876415
DK
708 local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
709 if [ -n "$DIFFTEXT" ]; then
710 echo
711 echo "$DIFFTEXT"
712 return 1
713 else
714 return 0
715 fi
716}
717
75954ae2
DK
718testfileequal() {
719 local FILE="$1"
720 shift
721 msgtest "Test for correctness of file" "$FILE"
722 if [ -z "$*" ]; then
f213b6ea 723 echo -n "" | checkdiff $FILE - && msgpass || msgfail
75954ae2 724 else
f213b6ea 725 echo "$*" | checkdiff $FILE - && msgpass || msgfail
75954ae2
DK
726 fi
727}
728
8d876415
DK
729testequal() {
730 local COMPAREFILE=$(mktemp)
b720d0bd 731 addtrap "rm $COMPAREFILE;"
8d876415
DK
732 echo "$1" > $COMPAREFILE
733 shift
734 msgtest "Test for equality of" "$*"
f213b6ea 735 $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
8d876415
DK
736}
737
685625bd
DK
738testequalor2() {
739 local COMPAREFILE1=$(mktemp)
740 local COMPAREFILE2=$(mktemp)
741 local COMPAREAGAINST=$(mktemp)
b720d0bd 742 addtrap "rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
685625bd
DK
743 echo "$1" > $COMPAREFILE1
744 echo "$2" > $COMPAREFILE2
745 shift 2
746 msgtest "Test for equality OR of" "$*"
747 $* 2>&1 1> $COMPAREAGAINST
f213b6ea
DK
748 (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
749 checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
750 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
751 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
685625bd
DK
752 msgfail )
753}
754
8d876415 755testshowvirtual() {
edc0ef10 756 local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
8d876415
DK
757 local PACKAGE="$1"
758 shift
759 while [ -n "$1" ]; do
760 VIRTUAL="${VIRTUAL}
edc0ef10 761N: Can't select versions from package '$1' as it is purely virtual"
8d876415
DK
762 PACKAGE="${PACKAGE} $1"
763 shift
764 done
765 msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
766 VIRTUAL="${VIRTUAL}
4bec02c2 767N: No packages found"
8d876415 768 local COMPAREFILE=$(mktemp)
b720d0bd 769 addtrap "rm $COMPAREFILE;"
ea65d079 770 local ARCH="$(getarchitecture 'native')"
8d876415 771 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
e8379ba3 772 aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
8d876415
DK
773}
774
775testnopackage() {
776 msgtest "Test for non-existent packages" "apt-cache show $*"
777 local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')"
778 if [ -n "$SHOWPKG" ]; then
779 echo
780 echo "$SHOWPKG"
781 msgfail
782 return 1
783 fi
784 msgpass
785}
01a6e24c
DK
786
787testdpkginstalled() {
788 msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
87bc1c45
DK
789 local PKGS="$(dpkg -l $* | grep '^i' | wc -l)"
790 if [ "$PKGS" != $# ]; then
01a6e24c
DK
791 echo $PKGS
792 dpkg -l $* | grep '^[a-z]'
793 msgfail
794 return 1
795 fi
796 msgpass
797}
798
5cf733e1
DK
799testdpkgnotinstalled() {
800 msgtest "Test for correctly not-installed package(s) with" "dpkg -l $*"
87bc1c45 801 local PKGS="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)"
01a6e24c
DK
802 if [ "$PKGS" != 0 ]; then
803 echo
804 dpkg -l $* | grep '^[a-z]'
805 msgfail
806 return 1
807 fi
808 msgpass
809}
ec7f904e
DK
810
811testmarkedauto() {
812 local COMPAREFILE=$(mktemp)
813 addtrap "rm $COMPAREFILE;"
814 if [ -n "$1" ]; then
815 msgtest 'Test for correctly marked as auto-installed' "$*"
816 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
817 else
818 msgtest 'Test for correctly marked as auto-installed' 'no package'
c98fb5e0 819 echo -n > $COMPAREFILE
ec7f904e
DK
820 fi
821 aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
822}
89a1aa5d
DK
823
824pause() {
825 echo "STOPPED execution. Press enter to continue"
826 local IGNORE
827 read IGNORE
828}