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