1 #!/bin/sh -- # no runable script, just for vi
5 # we all like colorful messages
6 if [ "$MSGCOLOR" != 'NO' ]; then
7 if ! expr match
"$(readlink -f /proc/$$/fd/1)" '/dev/pts/[0-9]\+' > /dev
/null
; then
13 if [ "$MSGCOLOR" != 'NO' ]; then
14 CERROR
="\033[1;31m" # red
15 CWARNING
="\033[1;33m" # yellow
16 CMSG
="\033[1;32m" # green
17 CINFO
="\033[1;96m" # light blue
18 CDEBUG
="\033[1;94m" # blue
19 CNORMAL
="\033[0;39m" # default system console color
20 CDONE
="\033[1;32m" # green
21 CPASS
="\033[1;32m" # green
22 CFAIL
="\033[1;31m" # red
23 CCMD
="\033[1;35m" # pink
26 msgdie
() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; }
27 msgwarn
() { echo "${CWARNING}W: $1${CNORMAL}" >&2; }
28 msgmsg
() { echo "${CMSG}$1${CNORMAL}"; }
29 msginfo
() { echo "${CINFO}I: $1${CNORMAL}"; }
30 msgdebug
() { echo "${CDEBUG}D: $1${CNORMAL}"; }
31 msgdone
() { echo "${CDONE}DONE${CNORMAL}"; }
32 msgnwarn
() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; }
33 msgnmsg
() { echo -n "${CMSG}$1${CNORMAL}"; }
34 msgninfo
() { echo -n "${CINFO}I: $1${CNORMAL}"; }
35 msgndebug
() { echo -n "${CDEBUG}D: $1${CNORMAL}"; }
38 echo -n "${CINFO}$1${CCMD} "
39 echo -n "$(echo "$2" | sed -e 's/^aptc/apt-c/' -e 's/^aptg/apt-g/' -e 's/^aptf/apt-f/')${CINFO} "
41 if [ -n "$1" ]; then shift; else break; fi
43 echo -n "…${CNORMAL} "
45 msgpass
() { echo "${CPASS}PASS${CNORMAL}"; }
46 msgskip
() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
48 if [ $# -gt 0 ]; then echo "${CFAIL}FAIL: $*${CNORMAL}" >&2;
49 else echo "${CFAIL}FAIL${CNORMAL}" >&2; fi
50 EXIT_CODE
=$((EXIT_CODE+1));
53 # enable / disable Debugging
54 MSGLEVEL
=${MSGLEVEL:-3}
55 if [ $MSGLEVEL -le 0 ]; then
58 if [ $MSGLEVEL -le 1 ]; then
62 if [ $MSGLEVEL -le 2 ]; then
66 msgpass
() { echo -n " ${CPASS}P${CNORMAL}"; }
67 msgskip
() { echo -n " ${CWARNING}S${CNORMAL}" >&2; }
68 if [ -n "$CFAIL" ]; then
69 msgfail
() { echo -n " ${CFAIL}FAIL${CNORMAL}" >&2; EXIT_CODE
=$((EXIT_CODE+1)); }
71 msgfail
() { echo -n " ###FAILED###" >&2; EXIT_CODE
=$((EXIT_CODE+1)); }
74 if [ $MSGLEVEL -le 3 ]; then
78 if [ $MSGLEVEL -le 4 ]; then
83 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
84 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
85 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
86 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
87 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
90 echo "${CDONE}DONE${CNORMAL}";
95 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
98 if [ -f .
/aptconfig.conf
]; then
99 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
100 elif [ -f ..
/aptconfig.conf
]; then
101 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
=..
/aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
103 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
106 aptconfig
() { runapt apt
-config "$@"; }
107 aptcache
() { runapt apt
-cache "$@"; }
108 aptcdrom
() { runapt apt
-cdrom "$@"; }
109 aptget
() { runapt apt
-get "$@"; }
110 aptftparchive
() { runapt apt
-ftparchive "$@"; }
111 aptkey
() { runapt apt
-key "$@"; }
112 aptmark
() { runapt apt
-mark "$@"; }
113 apt
() { runapt apt
"$@"; }
115 LD_LIBRARY_PATH
=${APTWEBSERVERBINDIR} ${APTWEBSERVERBINDIR}/aptwebserver
"$@";
118 command dpkg
--root=${TMPWORKINGDIRECTORY}/rootdir
--force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir
/var
/log
/dpkg.log
"$@"
121 if [ -f .
/aptconfig.conf
]; then
122 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} command aptitude
"$@"
123 elif [ -f ..
/aptconfig.conf
]; then
124 APT_CONFIG
=..
/aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} command aptitude
"$@"
126 LD_LIBRARY_PATH
=${BUILDDIRECTORY} command aptitude
"$@"
131 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} command gdb
${BUILDDIRECTORY}/$1 --args "$@"
134 LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods
/http
137 # see apt-key for the whole trickery. Setup is done in setupenvironment
138 command gpg
--ignore-time-conflict --no-options --no-default-keyring \
139 --homedir "${TMPWORKINGDIRECTORY}/gnupghome" \
140 --no-auto-check-trustdb --trust-model always \
145 # error if we about to overflow, but ...
146 # "255 failures ought to be enough for everybody"
147 if [ $EXIT_CODE -gt 255 ]; then
148 msgdie
"Total failure count $EXIT_CODE too big"
150 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
153 shellsetedetector
() {
155 if [ "$exit_status" != '0' ]; then
156 echo >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}"
157 if [ "$EXIT_CODE" = '0' ]; then
158 EXIT_CODE
="$exit_status"
164 if [ "$1" = 'prefix' ]; then
165 CURRENTTRAP
="$2 $CURRENTTRAP"
167 CURRENTTRAP
="$CURRENTTRAP $1"
169 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
173 TMPWORKINGDIRECTORY
=$(mktemp -d)
174 TESTDIRECTORY
=$(readlink -f $(dirname $0))
175 msgninfo
"Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
177 # allow overriding the default BUILDDIR location
178 BUILDDIRECTORY
=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
179 METHODSDIR
=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
180 APTWEBSERVERBINDIR
=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
181 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
184 addtrap
"cd /; rm -rf $TMPWORKINGDIRECTORY;"
185 cd $TMPWORKINGDIRECTORY
186 mkdir rootdir aptarchive keys
188 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
189 mkdir -p var
/cache var
/lib var
/log tmp
190 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
191 touch var
/lib
/dpkg
/available
193 ln -s ${METHODSDIR} usr
/lib
/apt
/methods
195 local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
196 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
197 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
199 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
200 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
201 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
203 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/
204 ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
205 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
206 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
207 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
208 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
209 echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
210 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
211 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
212 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
213 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
214 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
215 if ! command dpkg
--assert-multi-arch >/dev
/null
2>&1; then
216 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf
# Added to test multiarch before dpkg is ready for it…
218 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
219 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
220 echo "Acquire::https::CaInfo \"${TESTDIR}/apt.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
221 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary
222 export LC_ALL
=C.UTF
-8
223 export PATH
="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
224 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
226 # gpg needs a trustdb to function, but it can't be invalid (not even empty)
227 # see also apt-key where this trickery comes from:
228 local TRUSTDBDIR
="${TMPWORKINGDIRECTORY}/gnupghome"
230 chmod 700 "$TRUSTDBDIR"
231 # We also don't use a secret keyring, of course, but gpg panics and
232 # implodes if there isn't one available - and writeable for imports
233 local SECRETKEYRING
="${TRUSTDBDIR}/secring.gpg"
235 # now create the trustdb with an (empty) dummy keyring
236 # newer gpg versions are fine without it, but play it safe for now
237 gpg
--quiet --check-trustdb --secret-keyring $SECRETKEYRING --keyring $SECRETKEYRING >/dev
/null
2>&1
243 if [ "$1" = "native" -o -z "$1" ]; then
244 eval `aptconfig shell ARCH APT::Architecture`
245 if [ -n "$ARCH" ]; then
248 dpkg
--print-architecture
256 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
259 configarchitecture
() {
261 echo "APT::Architecture \"$(getarchitecture $1)\";"
262 while [ -n "$1" ]; do
263 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
266 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
271 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
272 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
273 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
274 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
276 echo -n > rootdir/var/lib/dpkg/status
279 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
280 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
281 local ARCHS="$(getarchitectures)"
282 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
283 DPKGARCH="$(dpkg --print-architecture)"
284 for ARCH in ${ARCHS}; do
285 if [ "${ARCH}" != "${DPKGARCH}" ]; then
286 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
287 # old-style used e.g. in Ubuntu-P – and as it seems travis
288 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
289 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
293 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
294 # dpkg doesn't really check the version as long as it is fully installed,
295 # but just to be sure we choose one above the required version
296 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
302 configcompression() {
303 while [ -n "$1" ]; do
305 '.') echo ".
\t.
\tcat
";;
306 'gz') echo "gzip\tgz
\tgzip
";;
307 'bz2') echo "bzip2\tbz
2\tbzip
2";;
308 'lzma') echo "lzma
\tlzma
\txz
--format=lzma
";;
309 'xz') echo "xz
\txz
\txz
";;
310 *) echo "$1\t$1\t$1";;
313 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
316 setupsimplenativepackage() {
320 local RELEASE="${4:-unstable}"
321 local DEPENDENCIES="$5"
322 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
323 If you
find such a package installed on your system
,
324 something went horribly wrong
! They are autogenerated
325 und used only by testcases and surf no other propose…
"}"
327 local SECTION
="${7:-others}"
329 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
332 DISTSECTION
="$(echo "$SECTION" | cut -d'/' -f 1)"
334 local BUILDDIR
=incoming
/${NAME}-${VERSION}
335 mkdir -p ${BUILDDIR}/debian
/source
337 echo "* most suckless software product ever" > FEATURES
338 test -e debian
/copyright
|| echo "Copyleft by Joe Sixpack $(date +%Y)" > debian
/copyright
339 test -e debian
/changelog
|| echo "$NAME ($VERSION) $RELEASE; urgency=low
343 -- Joe Sixpack <joe@example.org> $(date -R)" > debian
/changelog
344 test -e debian
/control
|| echo "Source: $NAME
347 Maintainer: Joe Sixpack <joe@example.org>
348 Build-Depends: debhelper (>= 7)
349 Standards-Version: 3.9.1
351 Package: $NAME" > debian
/control
352 if [ "$ARCH" = 'all' ]; then
353 echo "Architecture: all" >> debian
/control
355 echo "Architecture: any" >> debian
/control
357 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian
/control
358 echo "Description: $DESCRIPTION" >> debian
/control
360 test -e debian
/compat
|| echo "7" > debian
/compat
361 test -e debian
/source
/format
|| echo "3.0 (native)" > debian
/source
/format
362 test -e debian
/rules
|| cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny debian
/rules
366 buildsimplenativepackage
() {
370 local RELEASE
="${4:-unstable}"
371 local DEPENDENCIES
="$5"
372 local DESCRIPTION
="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
373 If you find such a package installed on your system,
374 something went horribly wrong! They are autogenerated
375 und used only by testcases and surf no other propose…"}"
377 local SECTION="${7:-others}"
378 local PRIORITY="${8:-optional}"
381 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
384 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
386 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
388 msgninfo "Build package
${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}…
"
389 mkdir -p $BUILDDIR/debian/source
390 echo "* most suckless software product ever
" > ${BUILDDIR}/FEATURES
392 echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
394 echo "Copyleft by Joe Sixpack
$(date +%Y)" > ${BUILDDIR}/debian/copyright
395 echo "$NAME ($VERSION) $RELEASE; urgency
=low
399 -- Joe Sixpack
<joe@example.org
> $(date -R)" > ${BUILDDIR}/debian/changelog
403 Maintainer
: Joe Sixpack
<joe@example.org
>
404 Standards
-Version: 3.9.3" > ${BUILDDIR}/debian/control
405 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
406 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
408 Package
: $NAME" >> ${BUILDDIR}/debian/control
410 if [ "$ARCH" = 'all' ]; then
411 echo "Architecture
: all
" >> ${BUILDDIR}/debian/control
413 echo "Architecture
: any
" >> ${BUILDDIR}/debian/control
415 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
416 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
417 echo "Description
: $DESCRIPTION" >> ${BUILDDIR}/debian/control
419 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
420 (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' \
422 echo "pool
/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
423 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
424 # gpg --yes --secret-keyring ./keys/joesixpack.sec \
425 # --keyring ./keys/joesixpack.pub --default-key 'Joe Sixpack' \
426 # --clearsign -o "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
427 # mv "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
431 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
432 rm -rf ${BUILDDIR}/debian
/tmp
433 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
434 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
435 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
436 if [ -n "$FILE_TREE" ]; then
437 cp -ar "$FILE_TREE" ${BUILDDIR}/debian
/tmp
440 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
441 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
442 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
443 # ensure the right permissions as dpkg-deb ensists
444 chmod 755 ${BUILDDIR}/debian
/tmp
/DEBIAN
445 if ! dpkg
-deb --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
>$LOG 2>&1; then
450 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
453 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
454 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
455 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
464 local ARCH
=$(getarchitecture $4)
465 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
466 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
467 msgninfo
"Build package ${PKGNAME} for ${RELEASE} in ${SECTION}… "
469 if [ "$ARCH" = "all" ]; then
470 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
472 if ! dpkg
-buildpackage -uc -us -a$ARCH >$BUILDLOG 2>&1 ; then
476 local PKGS
="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
477 local SRCS
="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
480 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
483 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
489 if [ -d incoming
]; then
490 buildaptarchivefromincoming
"$@"
492 buildaptarchivefromfiles
"$@"
496 createaptftparchiveconfig
() {
497 local COMPRESSORS
="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
498 COMPRESSORS
="${COMPRESSORS%* }"
499 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' ' ')"
500 if [ -z "$ARCHS" ]; then
501 # the pool is empty, so we will operate on faked packages - let us use the configured archs
502 ARCHS
="$(getarchitectures)"
505 ArchiveDir "' >> ftparchive.conf
506 echo -n $(readlink -f .) >> ftparchive.conf
508 CacheDir "' >> ftparchive.conf
509 echo -n $(readlink -f ..) >> ftparchive.conf
511 FileListDir "' >> ftparchive.conf
512 echo -n $(readlink -f pool/) >> ftparchive.conf
516 Packages::Compress "'"$COMPRESSORS"'";
517 Sources::Compress "'"$COMPRESSORS"'";
518 Contents::Compress "'"$COMPRESSORS"'";
519 Translation::Compress "'"$COMPRESSORS"'";
520 LongDescription "false";
524 SrcDirectory "pool/";
530 Label "apttestcases";
532 Description "repository with dummy packages";
533 Architectures "' >> ftparchive.conf
534 echo -n "$ARCHS" >> ftparchive.conf
538 };' >> ftparchive.conf
539 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
540 echo -n 'tree "dists/' >> ftparchive.conf
541 echo -n "$DIST" >> ftparchive.conf
543 Architectures "' >> ftparchive.conf
544 echo -n "$ARCHS" >> ftparchive.conf
546 FileList "' >> ftparchive.conf
547 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
549 SourceFileList "' >> ftparchive.conf
550 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
552 Sections "' >> ftparchive.conf
553 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
555 };' >> ftparchive.conf
559 buildaptftparchivedirectorystructure
() {
560 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
561 for DIST
in $DISTS; do
562 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
563 for SECTION
in $SECTIONS; do
564 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
565 for ARCH
in $ARCHS; do
566 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
568 mkdir -p dists
/${DIST}/${SECTION}/source
569 mkdir -p dists
/${DIST}/${SECTION}/i18n
579 local DEPENDENCIES
="$5"
580 local PRIORITY
="${6:-optional}"
581 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
582 If you find such a package installed on your system,
583 something went horribly wrong! They are autogenerated
584 und used only by testcases and surf no other propose…"}"
586 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
587 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
588 ARCHS
="$(getarchitectures)"
592 for BUILDARCH
in $ARCHS; do
593 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
594 mkdir -p $PPATH aptarchive
/dists
/${RELEASE}/main
/source
595 touch aptarchive
/dists
/${RELEASE}/main
/source
/Sources
596 local FILE
="${PPATH}/Packages"
601 Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
602 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
603 echo "Version: $VERSION
604 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
605 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
606 echo "Description: $DESCRIPTION" >> $FILE
617 local DEPENDENCIES
="$5"
619 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
621 local FILE
="${SPATH}/Sources"
625 Maintainer: Joe Sixpack <joe@example.org>
626 Architecture: $ARCH" >> $FILE
627 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
629 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
630 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
634 insertinstalledpackage
() {
638 local DEPENDENCIES
="$4"
639 local PRIORITY
="${5:-optional}"
640 local STATUS
="${6:-install ok installed}"
641 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
642 If you find such a package installed on your system,
643 something went horribly wrong! They are autogenerated
644 und used only by testcases and surf no other propose…"}"
646 local FILE='rootdir/var/lib/dpkg/status'
647 local INFO='rootdir/var/lib/dpkg/info'
648 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
654 Maintainer: Joe Sixpack <joe@example.org>
655 Version: $VERSION" >> $FILE
656 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
657 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
658 echo "Description: $DESCRIPTION" >> $FILE
660 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
661 echo -n > ${INFO}/${NAME}:${arch}.list
663 echo -n > ${INFO}/${NAME}.list
669 buildaptarchivefromincoming
() {
670 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
672 [ -e pool
] || ln -s ..
/incoming pool
673 [ -e ftparchive.conf
] || createaptftparchiveconfig
674 [ -e dists
] || buildaptftparchivedirectorystructure
675 msgninfo
"\tGenerate Packages, Sources and Contents files… "
676 aptftparchive
-qq generate ftparchive.conf
682 buildaptarchivefromfiles
() {
683 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
684 find aptarchive
-name 'Packages' -o -name 'Sources' | while read line
; do
685 msgninfo
"\t${line} file… "
686 compressfile
"$line" "$1"
689 generatereleasefiles
"$@"
693 cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
| while read compressor extension
command; do
694 if [ "$compressor" = '.' ]; then
700 cat "$1" | $command > "${1}.${extension}"
702 touch -d "$2" "${1}.${extension}"
707 # can be overridden by testcases for their pleasure
708 getcodenamefromsuite
() {
710 unstable
) echo 'sid';;
714 getreleaseversionfromsuite
() { true
; }
715 getlabelfromsuite
() { true
; }
717 generatereleasefiles
() {
718 # $1 is the Date header and $2 is the ValidUntil header to be set
719 # both should be given in notation date/touch can understand
720 msgninfo
"\tGenerate Release files… "
721 if [ -e aptarchive
/dists
]; then
722 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
723 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
724 local CODENAME
="$(getcodenamefromsuite $SUITE)"
725 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
726 local LABEL
="$(getlabelfromsuite $SUITE)"
727 if [ -n "$VERSION" ]; then
728 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
730 if [ -n "$LABEL" ]; then
731 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
733 aptftparchive
-qq release
$dir \
734 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
735 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
738 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
739 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
741 NotAutomatic: yes' $dir/Release
743 if [ -n "$1" -a "$1" != "now" ]; then
744 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
748 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
752 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
754 if [ -n "$1" -a "$1" != "now" ]; then
755 for release
in $(find ./aptarchive -name 'Release'); do
756 touch -d "$1" $release
762 setupdistsaptarchive
() {
763 local APTARCHIVE
=$(readlink -f ./aptarchive)
764 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
765 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
766 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
767 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
768 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
769 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
770 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
775 setupflataptarchive
() {
776 local APTARCHIVE
=$(readlink -f ./aptarchive)
777 if [ -f ${APTARCHIVE}/Packages
]; then
778 msgninfo
"\tadd deb sources.list line… "
779 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
782 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
784 if [ -f ${APTARCHIVE}/Sources
]; then
785 msgninfo
"\tadd deb-src sources.list line… "
786 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
789 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
795 if [ -e aptarchive
/dists
]; then
801 if [ "$1" != '--no-update' ]; then
802 msgninfo
"\tSync APT's cache with the archive… "
809 local SIGNER
="${1:-Joe Sixpack}"
810 local GPG
="gpg --batch --yes"
811 msgninfo
"\tSign archive with $SIGNER key… "
812 local REXKEY
='keys/rexexpired'
813 local SECEXPIREBAK
="${REXKEY}.sec.bak"
814 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
815 if [ "${SIGNER}" = 'Rex Expired' ]; then
816 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
817 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
818 # therefore we 'temporary' make the key not expired and restore a backup after signing
819 cp ${REXKEY}.sec
$SECEXPIREBAK
820 cp ${REXKEY}.pub
$PUBEXPIREBAK
821 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
822 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
823 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
824 cp $SECUNEXPIRED ${REXKEY}.sec
825 cp $PUBUNEXPIRED ${REXKEY}.pub
827 printf "expire\n1w\nsave\n" | $GPG --keyring ${REXKEY}.pub
--secret-keyring ${REXKEY}.sec
--command-fd 0 --edit-key "${SIGNER}" >/dev
/null
2>&1 || true
828 cp ${REXKEY}.sec
$SECUNEXPIRED
829 cp ${REXKEY}.pub
$PUBUNEXPIRED
832 for KEY
in $(find keys/ -name '*.sec'); do
833 GPG
="$GPG --secret-keyring $KEY"
835 for KEY
in $(find keys/ -name '*.pub'); do
836 GPG
="$GPG --keyring $KEY"
838 for RELEASE
in $(find aptarchive/ -name Release); do
839 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
840 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
841 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
842 # we might have set a specific date for the Release file, so copy it
843 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
845 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
846 mv -f $SECEXPIREBAK ${REXKEY}.sec
847 mv -f $PUBEXPIREBAK ${REXKEY}.pub
853 msgtest
"Set webserver config option '${1}' to" "$2"
854 downloadfile
"http://localhost:8080/_config/set/${1}/${2}" '/dev/null' >/dev
/null
855 local DOWNLOG
='download-testfile.log'
857 local STATUS
="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.status"
858 downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
859 if [ "$(cat "$STATUS")" = '200' ]; then
863 msgfail
"Statuscode was $(cat "$STATUS")"
868 rewritesourceslist
() {
869 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
870 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
871 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#http://localhost:4433/#${1}#"
875 changetowebserver
() {
876 if [ "$1" != '--no-rewrite' ]; then
877 rewritesourceslist
'http://localhost:8080/'
881 if test -x ${APTWEBSERVERBINDIR}/aptwebserver
; then
883 local LOG
="webserver.log"
884 if ! aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1 ; then
888 local PID
="$(cat aptwebserver.pid)"
889 if [ -z "$PID" ]; then
890 msgdie
'Could not fork aptwebserver successfully'
895 msgdie
'You have to build aptwerbserver or install a webserver'
899 changetohttpswebserver
() {
900 if ! which stunnel4
>/dev
/null
; then
901 msgdie
'You need to install stunnel4 for https testcases'
903 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
904 changetowebserver
--no-rewrite "$@"
906 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
907 cert = ${TESTDIRECTORY}/apt.pem
913 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
914 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
915 local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
916 addtrap
'prefix' "kill ${PID};"
917 rewritesourceslist
'https://localhost:4433/'
921 mkdir -p rootdir
/media
/cdrom
/.disk
922 local CD
="$(readlink -f rootdir/media/cdrom)"
923 echo "acquire::cdrom::mount \"${CD}\";" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
924 echo 'acquire::cdrom::autodetect 0;' >> rootdir
/etc
/apt
/apt.conf.d
/00cdrom
925 echo -n "$1" > ${CD}/.disk
/info
926 if [ ! -d aptarchive
/dists
]; then
927 msgdie
'Flat file archive cdroms can not be created currently'
930 mv aptarchive
/dists
$CD
931 ln -s "$(readlink -f ./incoming)" $CD/pool
932 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
936 PROTO
="$(echo "$1" | cut -d':' -f 1)"
937 local DOWNLOG
="${TMPWORKINGDIRECTORY}/download.log"
941 echo "601 Configuration
942 Config-Item: Acquire::https::CaInfo=${TESTDIR}/apt.pem
943 Config-Item: Debug::Acquire::${PROTO}=1
949 # simple worker keeping stdin open until we are done (201) or error (400)
950 # and requesting new URIs on try-agains/redirects inbetween
951 { tail -n 999 -f "$DOWNLOG" & echo "TAILPID: $!"; } | while read f1 f2
; do
952 if [ "$f1" = 'TAILPID:' ]; then
954 elif [ "$f1" = 'New-URI:' ]; then
955 echo "600 Acquire URI
959 elif [ "$f1" = '201' ] || [ "$f1" = '400' ]; then
960 # tail would only die on next read – which never happens
961 test -z "$TAILPID" || kill -s HUP
"$TAILPID"
965 } | LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods
/${PROTO} 2>&1 | tee "$DOWNLOG"
967 # only if the file exists the download was successful
976 local DIFFTEXT
="$(command diff -u "$@" | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
977 if [ -n "$DIFFTEXT" ]; then
989 msgtest
"Test for correctness of file" "$FILE"
991 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
993 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
998 msgtest
"Test for no output of" "$*"
999 test -z "$($* 2>&1)" && msgpass
|| msgfail
1003 local MSG
='Test of equality of'
1004 if [ "$1" = '--nomsg' ]; then
1009 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
1010 echo "$1" > $COMPAREFILE
1013 if [ -n "$MSG" ]; then
1016 $
* 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1020 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1021 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1022 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1023 echo "$1" > $COMPAREFILE1
1024 echo "$2" > $COMPAREFILE2
1026 msgtest
"Test for equality OR of" "$*"
1027 $
* >$COMPAREAGAINST 2>&1 || true
1028 (checkdiff
$COMPAREFILE1 $COMPAREAGAINST 1> /dev
/null
||
1029 checkdiff
$COMPAREFILE2 $COMPAREAGAINST 1> /dev
/null
) && msgpass
||
1030 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
1031 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
1036 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1039 while [ -n "$1" ]; do
1041 N: Can't select versions from package '$1' as it is purely virtual"
1042 PACKAGE
="${PACKAGE} $1"
1045 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1047 N: No packages found"
1048 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1049 local ARCH
="$(getarchitecture 'native')"
1050 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1051 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1055 msgtest
"Test for non-existent packages" "apt-cache show $*"
1056 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1057 if [ -n "$SHOWPKG" ]; then
1066 testdpkginstalled
() {
1067 msgtest
"Test for correctly installed package(s) with" "dpkg -l $*"
1068 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep '^i' | wc -l)"
1069 if [ "$PKGS" != $# ]; then
1071 dpkg
-l "$@" | grep '^[a-z]'
1078 testdpkgnotinstalled
() {
1079 msgtest
"Test for correctly not-installed package(s) with" "dpkg -l $*"
1080 local PKGS
="$(dpkg -l "$@" 2> /dev/null | grep '^i' | wc -l)"
1081 if [ "$PKGS" != 0 ]; then
1083 dpkg
-l "$@" | grep '^[a-z]'
1091 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1092 if [ -n "$1" ]; then
1093 msgtest
'Test for correctly marked as auto-installed' "$*"
1094 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1096 msgtest
'Test for correctly marked as auto-installed' 'no package'
1097 echo -n > $COMPAREFILE
1099 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1103 if [ "$1" = '--nomsg' ]; then
1106 msgtest
'Test for successful execution of' "$*"
1108 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1109 if $@
>${OUTPUT} 2>&1; then
1119 if [ "$1" = '--nomsg' ]; then
1122 msgtest
'Test for failure in execution of' "$*"
1124 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1125 if $@
>${OUTPUT} 2>&1; then
1135 echo "STOPPED execution. Press enter to continue"