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