1 #!/bin/sh -- # no runable script, just for vi
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
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; }
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;
35 if [ -n "$1" ]; then shift; else break; fi
37 echo -n "…${CNORMAL} " >&2;
39 msgpass
() { echo "${CPASS}PASS${CNORMAL}" >&2; }
40 msgskip
() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
42 if [ $# -gt 0 ]; then echo "${CFAIL}FAIL: $*${CNORMAL}" >&2;
43 else echo "${CFAIL}FAIL${CNORMAL}" >&2; fi
44 EXIT_CODE
=$((EXIT_CODE+1));
47 # enable / disable Debugging
48 MSGLEVEL
=${MSGLEVEL:-3}
49 if [ $MSGLEVEL -le 0 ]; then
52 if [ $MSGLEVEL -le 1 ]; then
56 if [ $MSGLEVEL -le 2 ]; then
60 msgpass
() { echo -n " ${CPASS}P${CNORMAL}" >&2; }
61 msgskip
() { echo -n " ${CWARNING}S${CNORMAL}" >&2; }
62 if [ -n "$CFAIL" ]; then
63 msgfail
() { echo -n " ${CFAIL}FAIL${CNORMAL}" >&2; EXIT_CODE
=$((EXIT_CODE+1)); }
65 msgfail
() { echo -n " ###FAILED###" >&2; EXIT_CODE
=$((EXIT_CODE+1)); }
68 if [ $MSGLEVEL -le 3 ]; then
72 if [ $MSGLEVEL -le 4 ]; then
77 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
78 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
79 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
80 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
81 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
84 echo "${CDONE}DONE${CNORMAL}" >&2;
89 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
90 if [ -f .
/aptconfig.conf
]; then
91 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
92 elif [ -f ..
/aptconfig.conf
]; then
93 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
=..
/aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
95 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
98 aptconfig
() { runapt apt
-config $
*; }
99 aptcache
() { runapt apt
-cache $
*; }
100 aptcdrom
() { runapt apt
-cdrom $
*; }
101 aptget
() { runapt apt
-get $
*; }
102 aptftparchive
() { runapt apt
-ftparchive $
*; }
103 aptkey
() { runapt apt
-key $
*; }
104 aptmark
() { runapt apt
-mark $
*; }
106 LD_LIBRARY_PATH
=${APTWEBSERVERBINDIR} ${APTWEBSERVERBINDIR}/aptwebserver $
*;
109 $(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir
--force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir
/var
/log
/dpkg.log $
*
112 if [ -f .
/aptconfig.conf
]; then
113 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which aptitude) $
*
114 elif [ -f ..
/aptconfig.conf
]; then
115 APT_CONFIG
=..
/aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which aptitude) $
*
117 LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which aptitude) $
*
122 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which gdb) ${BUILDDIRECTORY}/$1 --args $
*
125 LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods
/http
128 # see apt-key for the whole trickery. Setup is done in setupenvironment
129 command gpg
--ignore-time-conflict --no-options --no-default-keyring \
130 --homedir "${TMPWORKINGDIRECTORY}/gnupghome" \
131 --no-auto-check-trustdb --trust-model always \
136 # error if we about to overflow, but ...
137 # "255 failures ought to be enough for everybody"
138 if [ $EXIT_CODE -gt 255 ]; then
139 msgdie
"Total failure count $EXIT_CODE too big"
141 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
144 shellsetedetector
() {
146 if [ "$exit_status" != '0' ]; then
147 echo >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}"
148 if [ "$EXIT_CODE" = '0' ]; then
149 EXIT_CODE
="$exit_status"
155 if [ "$1" = 'prefix' ]; then
156 CURRENTTRAP
="$2 $CURRENTTRAP"
158 CURRENTTRAP
="$CURRENTTRAP $1"
160 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
164 TMPWORKINGDIRECTORY
=$(mktemp -d)
165 TESTDIRECTORY
=$(readlink -f $(dirname $0))
166 msgninfo
"Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
168 # allow overriding the default BUILDDIR location
169 BUILDDIRECTORY
=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
170 METHODSDIR
=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
171 APTWEBSERVERBINDIR
=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
172 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
175 addtrap
"cd /; rm -rf $TMPWORKINGDIRECTORY;"
176 cd $TMPWORKINGDIRECTORY
177 mkdir rootdir aptarchive keys
179 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
180 mkdir -p var
/cache var
/lib var
/log
181 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
182 touch var
/lib
/dpkg
/available
184 ln -s ${BUILDDIRECTORY}/methods usr
/lib
/apt
/methods
186 local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
187 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
188 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
190 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
191 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
192 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
194 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/
195 ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
196 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
197 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
198 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
199 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
200 echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
201 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
202 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
203 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
204 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
205 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
206 if ! $(which dpkg) --assert-multi-arch >/dev
/null
2>&1; then
207 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf
# Added to test multiarch before dpkg is ready for it…
209 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
210 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
211 echo "Acquire::https::CaInfo \"${TESTDIR}/apt.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
212 export LC_ALL
=C.UTF
-8
213 export PATH
="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
214 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
216 # gpg needs a trustdb to function, but it can't be invalid (not even empty)
217 # see also apt-key where this trickery comes from:
218 local TRUSTDBDIR
="${TMPWORKINGDIRECTORY}/gnupghome"
220 chmod 700 "$TRUSTDBDIR"
221 # We also don't use a secret keyring, of course, but gpg panics and
222 # implodes if there isn't one available - and writeable for imports
223 local SECRETKEYRING
="${TRUSTDBDIR}/secring.gpg"
225 # now create the trustdb with an (empty) dummy keyring
226 # newer gpg versions are fine without it, but play it safe for now
227 gpg
--quiet --check-trustdb --secret-keyring $SECRETKEYRING --keyring $SECRETKEYRING >/dev
/null
2>&1
233 if [ "$1" = "native" -o -z "$1" ]; then
234 eval `aptconfig shell ARCH APT::Architecture`
235 if [ -n "$ARCH" ]; then
238 dpkg
--print-architecture
246 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
249 configarchitecture
() {
251 echo "APT::Architecture \"$(getarchitecture $1)\";"
252 while [ -n "$1" ]; do
253 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
256 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
261 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
262 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
263 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
264 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
266 echo -n > rootdir/var/lib/dpkg/status
269 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
270 if $(which dpkg) --assert-multi-arch >/dev/null 2>&1; then
271 local ARCHS="$(getarchitectures)"
272 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
273 DPKGARCH="$(dpkg --print-architecture)"
274 for ARCH in ${ARCHS}; do
275 if [ "${ARCH}" != "${DPKGARCH}" ]; then
276 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
277 # old-style used e.g. in Ubuntu-P – and as it seems travis
278 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
279 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
283 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
284 # dpkg doesn't really check the version as long as it is fully installed,
285 # but just to be sure we choose one above the required version
286 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
292 configcompression() {
293 while [ -n "$1" ]; do
295 '.') echo ".
\t.
\tcat
";;
296 'gz') echo "gzip\tgz
\tgzip
";;
297 'bz2') echo "bzip2\tbz
2\tbzip
2";;
298 'lzma') echo "lzma
\tlzma
\txz
--format=lzma
";;
299 'xz') echo "xz
\txz
\txz
";;
300 *) echo "$1\t$1\t$1";;
303 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
306 setupsimplenativepackage() {
310 local RELEASE="${4:-unstable}"
311 local DEPENDENCIES="$5"
312 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
313 If you
find such a package installed on your system
,
314 something went horribly wrong
! They are autogenerated
315 und used only by testcases and surf no other propose…
"}"
317 local SECTION
="${7:-others}"
319 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
322 DISTSECTION
="$(echo "$SECTION" | cut -d'/' -f 1)"
324 local BUILDDIR
=incoming
/${NAME}-${VERSION}
325 mkdir -p ${BUILDDIR}/debian
/source
327 echo "* most suckless software product ever" > FEATURES
328 test -e debian
/copyright
|| echo "Copyleft by Joe Sixpack $(date +%Y)" > debian
/copyright
329 test -e debian
/changelog
|| echo "$NAME ($VERSION) $RELEASE; urgency=low
333 -- Joe Sixpack <joe@example.org> $(date -R)" > debian
/changelog
334 test -e debian
/control
|| echo "Source: $NAME
337 Maintainer: Joe Sixpack <joe@example.org>
338 Build-Depends: debhelper (>= 7)
339 Standards-Version: 3.9.1
341 Package: $NAME" > debian
/control
342 if [ "$ARCH" = 'all' ]; then
343 echo "Architecture: all" >> debian
/control
345 echo "Architecture: any" >> debian
/control
347 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian
/control
348 echo "Description: $DESCRIPTION" >> debian
/control
350 test -e debian
/compat
|| echo "7" > debian
/compat
351 test -e debian
/source
/format
|| echo "3.0 (native)" > debian
/source
/format
352 test -e debian
/rules
|| cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny debian
/rules
356 buildsimplenativepackage
() {
360 local RELEASE
="${4:-unstable}"
361 local DEPENDENCIES
="$5"
362 local DESCRIPTION
="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
363 If you find such a package installed on your system,
364 something went horribly wrong! They are autogenerated
365 und used only by testcases and surf no other propose…"}"
367 local SECTION="${7:-others}"
368 local PRIORITY="${8:-optional}"
371 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
374 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
376 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
378 msgninfo "Build package
${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}…
"
379 mkdir -p $BUILDDIR/debian/source
380 echo "* most suckless software product ever
" > ${BUILDDIR}/FEATURES
382 echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
384 echo "Copyleft by Joe Sixpack
$(date +%Y)" > ${BUILDDIR}/debian/copyright
385 echo "$NAME ($VERSION) $RELEASE; urgency
=low
389 -- Joe Sixpack
<joe@example.org
> $(date -R)" > ${BUILDDIR}/debian/changelog
393 Maintainer
: Joe Sixpack
<joe@example.org
>
394 Standards
-Version: 3.9.3" > ${BUILDDIR}/debian/control
395 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
396 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
398 Package
: $NAME" >> ${BUILDDIR}/debian/control
400 if [ "$ARCH" = 'all' ]; then
401 echo "Architecture
: all
" >> ${BUILDDIR}/debian/control
403 echo "Architecture
: any
" >> ${BUILDDIR}/debian/control
405 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
406 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
407 echo "Description
: $DESCRIPTION" >> ${BUILDDIR}/debian/control
409 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
410 (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' \
412 echo "pool
/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
413 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
414 # gpg --yes --secret-keyring ./keys/joesixpack.sec \
415 # --keyring ./keys/joesixpack.pub --default-key 'Joe Sixpack' \
416 # --clearsign -o "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
417 # mv "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
421 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
422 rm -rf ${BUILDDIR}/debian
/tmp
423 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
424 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
425 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
426 if [ -n "$FILE_TREE" ]; then
427 cp -ar "$FILE_TREE" ${BUILDDIR}/debian
/tmp
430 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
431 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
432 dpkg
-deb --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
2> /dev
/null
> /dev
/null
433 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
436 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
437 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
438 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
447 local ARCH
=$(getarchitecture $4)
448 msgninfo
"Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… "
450 if [ "$ARCH" = "all" ]; then
451 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
453 local BUILT
="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
454 local PKGS
="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
455 local SRCS
="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
458 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
461 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
467 if [ -d incoming
]; then
468 buildaptarchivefromincoming $
*
470 buildaptarchivefromfiles $
*
474 createaptftparchiveconfig
() {
475 local COMPRESSORS
="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
476 COMPRESSORS
="${COMPRESSORS%* }"
477 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' ' ')"
478 if [ -z "$ARCHS" ]; then
479 # the pool is empty, so we will operate on faked packages - let us use the configured archs
480 ARCHS
="$(getarchitectures)"
483 ArchiveDir "' >> ftparchive.conf
484 echo -n $(readlink -f .) >> ftparchive.conf
486 CacheDir "' >> ftparchive.conf
487 echo -n $(readlink -f ..) >> ftparchive.conf
489 FileListDir "' >> ftparchive.conf
490 echo -n $(readlink -f pool/) >> ftparchive.conf
494 Packages::Compress "'"$COMPRESSORS"'";
495 Sources::Compress "'"$COMPRESSORS"'";
496 Contents::Compress "'"$COMPRESSORS"'";
497 Translation::Compress "'"$COMPRESSORS"'";
498 LongDescription "false";
502 SrcDirectory "pool/";
508 Label "apttestcases";
510 Description "repository with dummy packages";
511 Architectures "' >> ftparchive.conf
512 echo -n "$ARCHS" >> ftparchive.conf
516 };' >> ftparchive.conf
517 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
518 echo -n 'tree "dists/' >> ftparchive.conf
519 echo -n "$DIST" >> ftparchive.conf
521 Architectures "' >> ftparchive.conf
522 echo -n "$ARCHS" >> ftparchive.conf
524 FileList "' >> ftparchive.conf
525 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
527 SourceFileList "' >> ftparchive.conf
528 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
530 Sections "' >> ftparchive.conf
531 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
533 };' >> ftparchive.conf
537 buildaptftparchivedirectorystructure
() {
538 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
539 for DIST
in $DISTS; do
540 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
541 for SECTION
in $SECTIONS; do
542 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
543 for ARCH
in $ARCHS; do
544 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
546 mkdir -p dists
/${DIST}/${SECTION}/source
547 mkdir -p dists
/${DIST}/${SECTION}/i18n
557 local DEPENDENCIES
="$5"
558 local PRIORITY
="${6:-optional}"
559 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
560 If you find such a package installed on your system,
561 something went horribly wrong! They are autogenerated
562 und used only by testcases and surf no other propose…"}"
564 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
565 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
566 ARCHS
="$(getarchitectures)"
570 for BUILDARCH
in $ARCHS; do
571 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
572 mkdir -p $PPATH aptarchive
/dists
/${RELEASE}/main
/source
573 touch aptarchive
/dists
/${RELEASE}/main
/source
/Sources
574 local FILE
="${PPATH}/Packages"
579 Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
580 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
581 echo "Version: $VERSION
582 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
583 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
584 echo "Description: $DESCRIPTION" >> $FILE
595 local DEPENDENCIES
="$5"
597 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
599 local FILE
="${SPATH}/Sources"
603 Maintainer: Joe Sixpack <joe@example.org>
604 Architecture: $ARCH" >> $FILE
605 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
607 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
608 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
612 insertinstalledpackage
() {
616 local DEPENDENCIES
="$4"
617 local PRIORITY
="${5:-optional}"
618 local STATUS
="${6:-install ok installed}"
619 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
620 If you find such a package installed on your system,
621 something went horribly wrong! They are autogenerated
622 und used only by testcases and surf no other propose…"}"
624 local FILE='rootdir/var/lib/dpkg/status'
625 local INFO='rootdir/var/lib/dpkg/info'
626 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
632 Maintainer: Joe Sixpack <joe@example.org>
633 Version: $VERSION" >> $FILE
634 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
635 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
636 echo "Description: $DESCRIPTION" >> $FILE
638 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
639 echo -n > ${INFO}/${NAME}:${arch}.list
641 echo -n > ${INFO}/${NAME}.list
647 buildaptarchivefromincoming
() {
648 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
650 [ -e pool
] || ln -s ..
/incoming pool
651 [ -e ftparchive.conf
] || createaptftparchiveconfig
652 [ -e dists
] || buildaptftparchivedirectorystructure
653 msgninfo
"\tGenerate Packages, Sources and Contents files… "
654 aptftparchive
-qq generate ftparchive.conf
660 buildaptarchivefromfiles
() {
661 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
662 find aptarchive
-name 'Packages' -o -name 'Sources' | while read line
; do
663 msgninfo
"\t${line} file… "
664 compressfile
"$line" "$1"
667 generatereleasefiles
"$@"
671 cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
| while read compressor extension
command; do
672 if [ "$compressor" = '.' ]; then
678 cat "$1" | $command > "${1}.${extension}"
680 touch -d "$2" "${1}.${extension}"
685 # can be overridden by testcases for their pleasure
686 getcodenamefromsuite
() {
688 unstable
) echo 'sid';;
692 getreleaseversionfromsuite
() { true
; }
693 getlabelfromsuite
() { true
; }
695 generatereleasefiles
() {
696 # $1 is the Date header and $2 is the ValidUntil header to be set
697 # both should be given in notation date/touch can understand
698 msgninfo
"\tGenerate Release files… "
699 if [ -e aptarchive
/dists
]; then
700 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
701 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
702 local CODENAME
="$(getcodenamefromsuite $SUITE)"
703 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
704 local LABEL
="$(getlabelfromsuite $SUITE)"
705 if [ -n "$VERSION" ]; then
706 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
708 if [ -n "$LABEL" ]; then
709 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
711 aptftparchive
-qq release
$dir \
712 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
713 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
716 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
717 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
719 NotAutomatic: yes' $dir/Release
721 if [ -n "$1" -a "$1" != "now" ]; then
722 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
726 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
730 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
732 if [ -n "$1" -a "$1" != "now" ]; then
733 for release
in $(find ./aptarchive -name 'Release'); do
734 touch -d "$1" $release
740 setupdistsaptarchive
() {
741 local APTARCHIVE
=$(readlink -f ./aptarchive)
742 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
743 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
744 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
745 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
746 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
747 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
748 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
753 setupflataptarchive
() {
754 local APTARCHIVE
=$(readlink -f ./aptarchive)
755 if [ -f ${APTARCHIVE}/Packages
]; then
756 msgninfo
"\tadd deb sources.list line… "
757 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
760 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
762 if [ -f ${APTARCHIVE}/Sources
]; then
763 msgninfo
"\tadd deb-src sources.list line… "
764 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
767 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
773 if [ -e aptarchive
/dists
]; then
779 if [ "$1" != '--no-update' ]; then
780 msgninfo
"\tSync APT's cache with the archive… "
787 local SIGNER
="${1:-Joe Sixpack}"
788 local GPG
="gpg --batch --yes"
789 msgninfo
"\tSign archive with $SIGNER key… "
790 local REXKEY
='keys/rexexpired'
791 local SECEXPIREBAK
="${REXKEY}.sec.bak"
792 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
793 if [ "${SIGNER}" = 'Rex Expired' ]; then
794 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
795 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
796 # therefore we 'temporary' make the key not expired and restore a backup after signing
797 cp ${REXKEY}.sec
$SECEXPIREBAK
798 cp ${REXKEY}.pub
$PUBEXPIREBAK
799 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
800 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
801 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
802 cp $SECUNEXPIRED ${REXKEY}.sec
803 cp $PUBUNEXPIRED ${REXKEY}.pub
805 printf "expire\n1w\nsave\n" | $GPG --keyring ${REXKEY}.pub
--secret-keyring ${REXKEY}.sec
--command-fd 0 --edit-key "${SIGNER}" >/dev
/null
2>&1 || true
806 cp ${REXKEY}.sec
$SECUNEXPIRED
807 cp ${REXKEY}.pub
$PUBUNEXPIRED
810 for KEY
in $(find keys/ -name '*.sec'); do
811 GPG
="$GPG --secret-keyring $KEY"
813 for KEY
in $(find keys/ -name '*.pub'); do
814 GPG
="$GPG --keyring $KEY"
816 for RELEASE
in $(find aptarchive/ -name Release); do
817 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
818 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
819 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
820 # we might have set a specific date for the Release file, so copy it
821 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
823 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
824 mv -f $SECEXPIREBAK ${REXKEY}.sec
825 mv -f $PUBEXPIREBAK ${REXKEY}.pub
831 msgtest
"Set webserver config option '${1}' to" "$2"
832 downloadfile
"http://localhost:8080/_config/set/${1}/${2}" '/dev/null' >/dev
/null
833 local DOWNLOG
='download-testfile.log'
835 local STATUS
="$(mktemp)"
836 addtrap
"rm $STATUS;"
837 downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
838 if [ "$(cat "$STATUS")" = '200' ]; then
842 msgfail
"Statuscode was $(cat "$STATUS")"
846 rewritesourceslist
() {
847 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
848 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
849 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#http://localhost:4433/#${1}#"
853 changetowebserver
() {
854 if [ "$1" != '--no-rewrite' ]; then
855 rewritesourceslist
'http://localhost:8080/'
859 if test -x ${APTWEBSERVERBINDIR}/aptwebserver
; then
861 local LOG
="$(mktemp)"
863 if ! aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1 ; then
867 local PID
="$(cat aptwebserver.pid)"
868 if [ -z "$PID" ]; then
869 msgdie
'Could not fork aptwebserver successfully'
874 msgdie
'You have to build aptwerbserver or install a webserver'
878 changetohttpswebserver
() {
879 if ! which stunnel4
>/dev
/null
; then
880 msgdie
'You need to install stunnel4 for https testcases'
882 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
883 changetowebserver
--no-rewrite
885 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
886 cert = ${TESTDIRECTORY}/apt.pem
892 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
893 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
894 local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
895 addtrap
'prefix' "kill ${PID};"
896 rewritesourceslist
'https://localhost:4433/'
900 mkdir -p rootdir
/media
/cdrom
/.disk
901 local CD
="$(readlink -f rootdir/media/cdrom)"
902 echo "acquire::cdrom::mount \"${CD}\";" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
903 echo 'acquire::cdrom::autodetect 0;' >> rootdir
/etc
/apt
/apt.conf.d
/00cdrom
904 echo -n "$1" > ${CD}/.disk
/info
905 if [ ! -d aptarchive
/dists
]; then
906 msgdie
'Flat file archive cdroms can not be created currently'
909 mv aptarchive
/dists
$CD
910 ln -s "$(readlink -f ./incoming)" $CD/pool
911 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
915 PROTO
="$(echo "$1" | cut -d':' -f 1)"
916 local DOWNLOG
="${TMPWORKINGDIRECTORY}/download.log"
920 echo "601 Configuration
921 Config-Item: Acquire::https::CaInfo=${TESTDIR}/apt.pem
922 Config-Item: Debug::Acquire::${PROTO}=1
928 # simple worker keeping stdin open until we are done (201) or error (400)
929 # and requesting new URIs on try-agains/redirects inbetween
930 { tail -n 999 -f "$DOWNLOG" & echo "TAILPID: $!"; } | while read f1 f2
; do
931 if [ "$f1" = 'TAILPID:' ]; then
933 elif [ "$f1" = 'New-URI:' ]; then
934 echo "600 Acquire URI
938 elif [ "$f1" = '201' ] || [ "$f1" = '400' ]; then
939 # tail would only die on next read – which never happens
940 test -z "$TAILPID" || kill -s HUP
"$TAILPID"
944 } | LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods
/${PROTO} 2>&1 | tee "$DOWNLOG"
946 # only if the file exists the download was successful
955 local DIFFTEXT
="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
956 if [ -n "$DIFFTEXT" ]; then
968 msgtest
"Test for correctness of file" "$FILE"
970 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
972 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
977 msgtest
"Test for no output of" "$*"
978 test -z "$($* 2>&1)" && msgpass
|| msgfail
982 local COMPAREFILE
=$(mktemp)
983 addtrap
"rm $COMPAREFILE;"
984 echo "$1" > $COMPAREFILE
986 msgtest
"Test for equality of" "$*"
987 $
* 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
991 local COMPAREFILE1
=$(mktemp)
992 local COMPAREFILE2
=$(mktemp)
993 local COMPAREAGAINST
=$(mktemp)
994 addtrap
"rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
995 echo "$1" > $COMPAREFILE1
996 echo "$2" > $COMPAREFILE2
998 msgtest
"Test for equality OR of" "$*"
999 $
* >$COMPAREAGAINST 2>&1 || true
1000 (checkdiff
$COMPAREFILE1 $COMPAREAGAINST 1> /dev
/null
||
1001 checkdiff
$COMPAREFILE2 $COMPAREAGAINST 1> /dev
/null
) && msgpass
||
1002 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
1003 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
1008 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1011 while [ -n "$1" ]; do
1013 N: Can't select versions from package '$1' as it is purely virtual"
1014 PACKAGE
="${PACKAGE} $1"
1017 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1019 N: No packages found"
1020 local COMPAREFILE
=$(mktemp)
1021 addtrap
"rm $COMPAREFILE;"
1022 local ARCH
="$(getarchitecture 'native')"
1023 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1024 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1028 msgtest
"Test for non-existent packages" "apt-cache show $*"
1029 local SHOWPKG
="$(aptcache show $* 2>&1 | grep '^Package: ')"
1030 if [ -n "$SHOWPKG" ]; then
1039 testdpkginstalled
() {
1040 msgtest
"Test for correctly installed package(s) with" "dpkg -l $*"
1041 local PKGS
="$(dpkg -l $* 2>/dev/null | grep '^i' | wc -l)"
1042 if [ "$PKGS" != $# ]; then
1044 dpkg
-l $
* | grep '^[a-z]'
1051 testdpkgnotinstalled
() {
1052 msgtest
"Test for correctly not-installed package(s) with" "dpkg -l $*"
1053 local PKGS
="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)"
1054 if [ "$PKGS" != 0 ]; then
1056 dpkg
-l $
* | grep '^[a-z]'
1064 local COMPAREFILE
=$(mktemp)
1065 addtrap
"rm $COMPAREFILE;"
1066 if [ -n "$1" ]; then
1067 msgtest
'Test for correctly marked as auto-installed' "$*"
1068 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1070 msgtest
'Test for correctly marked as auto-installed' 'no package'
1071 echo -n > $COMPAREFILE
1073 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1077 if [ "$1" = '--nomsg' ]; then
1080 msgtest
'Test for successful execution of' "$*"
1082 local OUTPUT
=$(mktemp)
1083 addtrap
"rm $OUTPUT;"
1084 if $@
>${OUTPUT} 2>&1; then
1094 if [ "$1" = '--nomsg' ]; then
1097 msgtest
'Test for failure in execution of' "$*"
1099 local OUTPUT
=$(mktemp)
1100 addtrap
"rm $OUTPUT;"
1101 if $@
>${OUTPUT} 2>&1; then
1111 echo "STOPPED execution. Press enter to continue"