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