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