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