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
=${APTHELPERBINDIR} ${APTHELPERBINDIR}/apt
-helper "$@";
118 LD_LIBRARY_PATH
=${APTWEBSERVERBINDIR} ${APTWEBSERVERBINDIR}/aptwebserver
"$@";
121 command dpkg
--root=${TMPWORKINGDIRECTORY}/rootdir
--force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir
/var
/log
/dpkg.log
"$@"
123 dpkgcheckbuilddeps
() {
124 command dpkg
-checkbuilddeps --admindir=${TMPWORKINGDIRECTORY}/rootdir
/var
/lib
/dpkg
"$@"
127 if [ -f .
/aptconfig.conf
]; then
128 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} command aptitude
"$@"
129 elif [ -f ..
/aptconfig.conf
]; then
130 APT_CONFIG
=..
/aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} command aptitude
"$@"
132 LD_LIBRARY_PATH
=${BUILDDIRECTORY} command aptitude
"$@"
137 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} command gdb
${BUILDDIRECTORY}/$1 --args "$@"
140 LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods
/http
143 # see apt-key for the whole trickery. Setup is done in setupenvironment
144 command gpg
--ignore-time-conflict --no-options --no-default-keyring \
145 --homedir "${TMPWORKINGDIRECTORY}/gnupghome" \
146 --no-auto-check-trustdb --trust-model always \
151 # error if we about to overflow, but ...
152 # "255 failures ought to be enough for everybody"
153 if [ $EXIT_CODE -gt 255 ]; then
154 msgdie
"Total failure count $EXIT_CODE too big"
156 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
159 shellsetedetector
() {
161 if [ "$exit_status" != '0' ]; then
162 echo >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}"
163 if [ "$EXIT_CODE" = '0' ]; then
164 EXIT_CODE
="$exit_status"
170 if [ "$1" = 'prefix' ]; then
171 CURRENTTRAP
="$2 $CURRENTTRAP"
173 CURRENTTRAP
="$CURRENTTRAP $1"
175 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
179 TMPWORKINGDIRECTORY
=$(mktemp -d)
180 TESTDIRECTORY
=$(readlink -f $(dirname $0))
181 msgninfo
"Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
183 # allow overriding the default BUILDDIR location
184 BUILDDIRECTORY
=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
185 METHODSDIR
=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
186 APTHELPERBINDIR
=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}
187 APTWEBSERVERBINDIR
=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
188 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
191 addtrap
"cd /; rm -rf $TMPWORKINGDIRECTORY;"
192 cd $TMPWORKINGDIRECTORY
193 mkdir rootdir aptarchive keys
195 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
196 mkdir -p var
/cache var
/lib var
/log tmp
197 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
198 touch var
/lib
/dpkg
/available
200 ln -s ${METHODSDIR} usr
/lib
/apt
/methods
202 local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
203 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
204 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
206 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
207 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
208 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
210 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/
211 ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
212 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
213 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
214 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
215 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
216 echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
217 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
218 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
219 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
220 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
221 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
222 if ! command dpkg
--assert-multi-arch >/dev
/null
2>&1; then
223 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf
# Added to test multiarch before dpkg is ready for it…
225 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
226 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
227 echo "Acquire::https::CaInfo \"${TESTDIR}/apt.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
228 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary
229 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
231 # gpg needs a trustdb to function, but it can't be invalid (not even empty)
232 # see also apt-key where this trickery comes from:
233 local TRUSTDBDIR
="${TMPWORKINGDIRECTORY}/gnupghome"
235 chmod 700 "$TRUSTDBDIR"
236 # We also don't use a secret keyring, of course, but gpg panics and
237 # implodes if there isn't one available - and writeable for imports
238 local SECRETKEYRING
="${TRUSTDBDIR}/secring.gpg"
240 # now create the trustdb with an (empty) dummy keyring
241 # newer gpg versions are fine without it, but play it safe for now
242 gpg
--quiet --check-trustdb --secret-keyring $SECRETKEYRING --keyring $SECRETKEYRING >/dev
/null
2>&1
244 # cleanup the environment a bit
245 export PATH
="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
246 export LC_ALL
=C.UTF
-8
248 unset GREP_OPTIONS DEB_BUILD_PROFILES
254 if [ "$1" = "native" -o -z "$1" ]; then
255 eval `aptconfig shell ARCH APT::Architecture`
256 if [ -n "$ARCH" ]; then
259 dpkg
--print-architecture
267 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
270 configarchitecture
() {
272 echo "APT::Architecture \"$(getarchitecture $1)\";"
273 while [ -n "$1" ]; do
274 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
277 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
282 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
283 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
284 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
285 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
287 echo -n > rootdir/var/lib/dpkg/status
290 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
291 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
292 local ARCHS="$(getarchitectures)"
293 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
294 DPKGARCH="$(dpkg --print-architecture)"
295 for ARCH in ${ARCHS}; do
296 if [ "${ARCH}" != "${DPKGARCH}" ]; then
297 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
298 # old-style used e.g. in Ubuntu-P – and as it seems travis
299 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
300 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
304 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
305 # dpkg doesn't really check the version as long as it is fully installed,
306 # but just to be sure we choose one above the required version
307 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
313 configcompression() {
314 while [ -n "$1" ]; do
316 '.') echo ".
\t.
\tcat
";;
317 'gz') echo "gzip\tgz
\tgzip
";;
318 'bz2') echo "bzip2\tbz
2\tbzip
2";;
319 'lzma') echo "lzma
\tlzma
\txz
--format=lzma
";;
320 'xz') echo "xz
\txz
\txz
";;
321 *) echo "$1\t$1\t$1";;
324 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
327 setupsimplenativepackage() {
331 local RELEASE="${4:-unstable}"
332 local DEPENDENCIES="$5"
333 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
334 If you
find such a package installed on your system
,
335 something went horribly wrong
! They are autogenerated
336 und used only by testcases and surf no other propose…
"}"
338 local SECTION
="${7:-others}"
340 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
343 DISTSECTION
="$(echo "$SECTION" | cut -d'/' -f 1)"
345 local BUILDDIR
=incoming
/${NAME}-${VERSION}
346 mkdir -p ${BUILDDIR}/debian
/source
348 echo "* most suckless software product ever" > FEATURES
349 test -e debian
/copyright
|| echo "Copyleft by Joe Sixpack $(date +%Y)" > debian
/copyright
350 test -e debian
/changelog
|| echo "$NAME ($VERSION) $RELEASE; urgency=low
354 -- Joe Sixpack <joe@example.org> $(date -R)" > debian
/changelog
355 test -e debian
/control
|| echo "Source: $NAME
358 Maintainer: Joe Sixpack <joe@example.org>
359 Build-Depends: debhelper (>= 7)
360 Standards-Version: 3.9.1
362 Package: $NAME" > debian
/control
363 if [ "$ARCH" = 'all' ]; then
364 echo "Architecture: all" >> debian
/control
366 echo "Architecture: any" >> debian
/control
368 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian
/control
369 echo "Description: $DESCRIPTION" >> debian
/control
371 test -e debian
/compat
|| echo "7" > debian
/compat
372 test -e debian
/source
/format
|| echo "3.0 (native)" > debian
/source
/format
373 test -e debian
/rules
|| cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny debian
/rules
377 buildsimplenativepackage
() {
381 local RELEASE
="${4:-unstable}"
382 local DEPENDENCIES
="$5"
383 local DESCRIPTION
="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
384 If you find such a package installed on your system,
385 something went horribly wrong! They are autogenerated
386 und used only by testcases and surf no other propose…"}"
388 local SECTION="${7:-others}"
389 local PRIORITY="${8:-optional}"
391 local COMPRESS_TYPE="${10:-gzip}"
393 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
396 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
398 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
400 msgninfo "Build package
${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}…
"
401 mkdir -p $BUILDDIR/debian/source
402 echo "* most suckless software product ever
" > ${BUILDDIR}/FEATURES
404 echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
406 echo "Copyleft by Joe Sixpack
$(date +%Y)" > ${BUILDDIR}/debian/copyright
407 echo "$NAME ($VERSION) $RELEASE; urgency
=low
411 -- Joe Sixpack
<joe@example.org
> $(date -R)" > ${BUILDDIR}/debian/changelog
415 Maintainer
: Joe Sixpack
<joe@example.org
>
416 Standards
-Version: 3.9.3" > ${BUILDDIR}/debian/control
417 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
418 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
420 Package
: $NAME" >> ${BUILDDIR}/debian/control
422 if [ "$ARCH" = 'all' ]; then
423 echo "Architecture
: all
" >> ${BUILDDIR}/debian/control
425 echo "Architecture
: any
" >> ${BUILDDIR}/debian/control
427 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
428 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
429 echo "Description
: $DESCRIPTION" >> ${BUILDDIR}/debian/control
431 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
432 (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' \
434 echo "pool
/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
435 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
436 # gpg --yes --secret-keyring ./keys/joesixpack.sec \
437 # --keyring ./keys/joesixpack.pub --default-key 'Joe Sixpack' \
438 # --clearsign -o "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
439 # mv "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
443 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
444 rm -rf ${BUILDDIR}/debian
/tmp
445 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
446 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
447 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
448 if [ -n "$FILE_TREE" ]; then
449 cp -ar "$FILE_TREE" ${BUILDDIR}/debian
/tmp
452 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
453 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
454 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
455 # ensure the right permissions as dpkg-deb ensists
456 chmod 755 ${BUILDDIR}/debian
/tmp
/DEBIAN
457 if ! dpkg
-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
>$LOG 2>&1; then
462 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
465 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
466 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
467 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
476 local ARCH
=$(getarchitecture $4)
477 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
478 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
479 msgninfo
"Build package ${PKGNAME} for ${RELEASE} in ${SECTION}… "
481 if [ "$ARCH" = "all" ]; then
482 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
484 if ! dpkg
-buildpackage -uc -us -a$ARCH >$BUILDLOG 2>&1 ; then
488 local PKGS
="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
489 local SRCS
="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
492 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
495 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
501 if [ -d incoming
]; then
502 buildaptarchivefromincoming
"$@"
504 buildaptarchivefromfiles
"$@"
508 createaptftparchiveconfig
() {
509 local COMPRESSORS
="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
510 COMPRESSORS
="${COMPRESSORS%* }"
511 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' ' ')"
512 if [ -z "$ARCHS" ]; then
513 # the pool is empty, so we will operate on faked packages - let us use the configured archs
514 ARCHS
="$(getarchitectures)"
517 ArchiveDir "' >> ftparchive.conf
518 echo -n $(readlink -f .) >> ftparchive.conf
520 CacheDir "' >> ftparchive.conf
521 echo -n $(readlink -f ..) >> ftparchive.conf
523 FileListDir "' >> ftparchive.conf
524 echo -n $(readlink -f pool/) >> ftparchive.conf
528 Packages::Compress "'"$COMPRESSORS"'";
529 Sources::Compress "'"$COMPRESSORS"'";
530 Contents::Compress "'"$COMPRESSORS"'";
531 Translation::Compress "'"$COMPRESSORS"'";
532 LongDescription "false";
536 SrcDirectory "pool/";
542 Label "apttestcases";
544 Description "repository with dummy packages";
545 Architectures "' >> ftparchive.conf
546 echo -n "$ARCHS" >> ftparchive.conf
550 };' >> ftparchive.conf
551 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
552 echo -n 'tree "dists/' >> ftparchive.conf
553 echo -n "$DIST" >> ftparchive.conf
555 Architectures "' >> ftparchive.conf
556 echo -n "$ARCHS" >> ftparchive.conf
558 FileList "' >> ftparchive.conf
559 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
561 SourceFileList "' >> ftparchive.conf
562 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
564 Sections "' >> ftparchive.conf
565 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
567 };' >> ftparchive.conf
571 buildaptftparchivedirectorystructure
() {
572 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
573 for DIST
in $DISTS; do
574 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
575 for SECTION
in $SECTIONS; do
576 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
577 for ARCH
in $ARCHS; do
578 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
580 mkdir -p dists
/${DIST}/${SECTION}/source
581 mkdir -p dists
/${DIST}/${SECTION}/i18n
591 local DEPENDENCIES
="$5"
592 local PRIORITY
="${6:-optional}"
593 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
594 If you find such a package installed on your system,
595 something went horribly wrong! They are autogenerated
596 und used only by testcases and surf no other propose…"}"
598 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
599 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
600 ARCHS
="$(getarchitectures)"
604 for BUILDARCH
in $ARCHS; do
605 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
606 mkdir -p $PPATH aptarchive
/dists
/${RELEASE}/main
/source
607 touch aptarchive
/dists
/${RELEASE}/main
/source
/Sources
608 local FILE
="${PPATH}/Packages"
613 Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
614 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
615 echo "Version: $VERSION
616 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
617 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
618 echo "Description: $DESCRIPTION" >> $FILE
629 local DEPENDENCIES
="$5"
631 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
633 local FILE
="${SPATH}/Sources"
637 Maintainer: Joe Sixpack <joe@example.org>
638 Architecture: $ARCH" >> $FILE
639 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
641 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
642 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
646 insertinstalledpackage
() {
650 local DEPENDENCIES
="$4"
651 local PRIORITY
="${5:-optional}"
652 local STATUS
="${6:-install ok installed}"
653 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
654 If you find such a package installed on your system,
655 something went horribly wrong! They are autogenerated
656 und used only by testcases and surf no other propose…"}"
658 local FILE='rootdir/var/lib/dpkg/status'
659 local INFO='rootdir/var/lib/dpkg/info'
660 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
666 Maintainer: Joe Sixpack <joe@example.org>
667 Version: $VERSION" >> $FILE
668 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
669 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
670 echo "Description: $DESCRIPTION" >> $FILE
672 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
673 echo -n > ${INFO}/${NAME}:${arch}.list
675 echo -n > ${INFO}/${NAME}.list
681 buildaptarchivefromincoming
() {
682 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
684 [ -e pool
] || ln -s ..
/incoming pool
685 [ -e ftparchive.conf
] || createaptftparchiveconfig
686 [ -e dists
] || buildaptftparchivedirectorystructure
687 msgninfo
"\tGenerate Packages, Sources and Contents files… "
688 aptftparchive
-qq generate ftparchive.conf
694 buildaptarchivefromfiles
() {
695 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
696 find aptarchive
-name 'Packages' -o -name 'Sources' | while read line
; do
697 msgninfo
"\t${line} file… "
698 compressfile
"$line" "$1"
701 generatereleasefiles
"$@"
705 cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
| while read compressor extension
command; do
706 if [ "$compressor" = '.' ]; then
712 cat "$1" | $command > "${1}.${extension}"
714 touch -d "$2" "${1}.${extension}"
719 # can be overridden by testcases for their pleasure
720 getcodenamefromsuite
() {
722 unstable
) echo 'sid';;
726 getreleaseversionfromsuite
() { true
; }
727 getlabelfromsuite
() { true
; }
729 generatereleasefiles
() {
730 # $1 is the Date header and $2 is the ValidUntil header to be set
731 # both should be given in notation date/touch can understand
732 msgninfo
"\tGenerate Release files… "
733 if [ -e aptarchive
/dists
]; then
734 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
735 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
736 local CODENAME
="$(getcodenamefromsuite $SUITE)"
737 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
738 local LABEL
="$(getlabelfromsuite $SUITE)"
739 if [ -n "$VERSION" ]; then
740 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
742 if [ -n "$LABEL" ]; then
743 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
745 aptftparchive
-qq release
$dir \
746 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
747 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
750 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
751 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
753 NotAutomatic: yes' $dir/Release
755 if [ -n "$1" -a "$1" != "now" ]; then
756 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
760 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
764 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
766 if [ -n "$1" -a "$1" != "now" ]; then
767 for release
in $(find ./aptarchive -name 'Release'); do
768 touch -d "$1" $release
774 setupdistsaptarchive
() {
775 local APTARCHIVE
=$(readlink -f ./aptarchive)
776 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
777 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
778 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
779 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
780 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
781 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
782 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
787 setupflataptarchive
() {
788 local APTARCHIVE
=$(readlink -f ./aptarchive)
789 if [ -f ${APTARCHIVE}/Packages
]; then
790 msgninfo
"\tadd deb sources.list line… "
791 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
794 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
796 if [ -f ${APTARCHIVE}/Sources
]; then
797 msgninfo
"\tadd deb-src sources.list line… "
798 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
801 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
807 if [ -e aptarchive
/dists
]; then
813 if [ "$1" != '--no-update' ]; then
814 msgninfo
"\tSync APT's cache with the archive… "
821 local SIGNER
="${1:-Joe Sixpack}"
822 local GPG
="gpg --batch --yes"
823 msgninfo
"\tSign archive with $SIGNER key… "
824 local REXKEY
='keys/rexexpired'
825 local SECEXPIREBAK
="${REXKEY}.sec.bak"
826 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
827 if [ "${SIGNER}" = 'Rex Expired' ]; then
828 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
829 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
830 # therefore we 'temporary' make the key not expired and restore a backup after signing
831 cp ${REXKEY}.sec
$SECEXPIREBAK
832 cp ${REXKEY}.pub
$PUBEXPIREBAK
833 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
834 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
835 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
836 cp $SECUNEXPIRED ${REXKEY}.sec
837 cp $PUBUNEXPIRED ${REXKEY}.pub
839 printf "expire\n1w\nsave\n" | $GPG --keyring ${REXKEY}.pub
--secret-keyring ${REXKEY}.sec
--command-fd 0 --edit-key "${SIGNER}" >/dev
/null
2>&1 || true
840 cp ${REXKEY}.sec
$SECUNEXPIRED
841 cp ${REXKEY}.pub
$PUBUNEXPIRED
844 for KEY
in $(find keys/ -name '*.sec'); do
845 GPG
="$GPG --secret-keyring $KEY"
847 for KEY
in $(find keys/ -name '*.pub'); do
848 GPG
="$GPG --keyring $KEY"
850 for RELEASE
in $(find aptarchive/ -name Release); do
851 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
852 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
853 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
854 # we might have set a specific date for the Release file, so copy it
855 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
857 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
858 mv -f $SECEXPIREBAK ${REXKEY}.sec
859 mv -f $PUBEXPIREBAK ${REXKEY}.pub
865 msgtest
"Set webserver config option '${1}' to" "$2"
866 downloadfile
"http://localhost:8080/_config/set/${1}/${2}" '/dev/null' >/dev
/null
867 local DOWNLOG
='download-testfile.log'
869 local STATUS
="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.status"
870 downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
871 if [ "$(cat "$STATUS")" = '200' ]; then
875 msgfail
"Statuscode was $(cat "$STATUS")"
880 rewritesourceslist
() {
881 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
882 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
883 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#http://localhost:4433/#${1}#"
887 changetowebserver
() {
888 if [ "$1" != '--no-rewrite' ]; then
889 rewritesourceslist
'http://localhost:8080/'
893 if test -x ${APTWEBSERVERBINDIR}/aptwebserver
; then
895 local LOG
="webserver.log"
896 if ! aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1 ; then
900 local PID
="$(cat aptwebserver.pid)"
901 if [ -z "$PID" ]; then
902 msgdie
'Could not fork aptwebserver successfully'
907 msgdie
'You have to build aptwerbserver or install a webserver'
911 changetohttpswebserver
() {
912 if ! which stunnel4
>/dev
/null
; then
913 msgdie
'You need to install stunnel4 for https testcases'
915 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
916 changetowebserver
--no-rewrite "$@"
918 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
919 cert = ${TESTDIRECTORY}/apt.pem
925 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
926 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
927 local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
928 addtrap
'prefix' "kill ${PID};"
929 rewritesourceslist
'https://localhost:4433/'
933 mkdir -p rootdir
/media
/cdrom
/.disk
934 local CD
="$(readlink -f rootdir/media/cdrom)"
935 echo "acquire::cdrom::mount \"${CD}\";" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
936 echo 'acquire::cdrom::autodetect 0;' >> rootdir
/etc
/apt
/apt.conf.d
/00cdrom
937 echo -n "$1" > ${CD}/.disk
/info
938 if [ ! -d aptarchive
/dists
]; then
939 msgdie
'Flat file archive cdroms can not be created currently'
942 mv aptarchive
/dists
$CD
943 ln -s "$(readlink -f ./incoming)" $CD/pool
944 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
948 PROTO
="$(echo "$1" | cut -d':' -f 1)"
949 apthelper
-o Acquire
::https
::CaInfo
=${TESTDIR}/apt.pem \
950 -o Debug
::Acquire
::${PROTO}=1 \
951 download
-file "$1" "$2" 2>&1
952 # only if the file exists the download was successful
961 local DIFFTEXT
="$(command diff -u "$@" | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
962 if [ -n "$DIFFTEXT" ]; then
974 msgtest
"Test for correctness of file" "$FILE"
976 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
978 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
983 msgtest
"Test for no output of" "$*"
984 test -z "$($* 2>&1)" && msgpass
|| msgfail
988 local MSG
='Test of equality of'
989 if [ "$1" = '--nomsg' ]; then
994 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
995 echo "$1" > $COMPAREFILE
998 if [ -n "$MSG" ]; then
1001 $
* 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1005 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1006 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1007 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1008 echo "$1" > $COMPAREFILE1
1009 echo "$2" > $COMPAREFILE2
1011 msgtest
"Test for equality OR of" "$*"
1012 $
* >$COMPAREAGAINST 2>&1 || true
1013 (checkdiff
$COMPAREFILE1 $COMPAREAGAINST 1> /dev
/null
||
1014 checkdiff
$COMPAREFILE2 $COMPAREAGAINST 1> /dev
/null
) && msgpass
||
1015 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
1016 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
1021 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1024 while [ -n "$1" ]; do
1026 N: Can't select versions from package '$1' as it is purely virtual"
1027 PACKAGE
="${PACKAGE} $1"
1030 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1032 N: No packages found"
1033 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1034 local ARCH
="$(getarchitecture 'native')"
1035 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1036 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1040 msgtest
"Test for non-existent packages" "apt-cache show $*"
1041 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1042 if [ -n "$SHOWPKG" ]; then
1051 testdpkginstalled
() {
1052 msgtest
"Test for correctly installed package(s) with" "dpkg -l $*"
1053 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep '^i' | wc -l)"
1054 if [ "$PKGS" != $# ]; then
1056 dpkg
-l "$@" | grep '^[a-z]'
1063 testdpkgnotinstalled
() {
1064 msgtest
"Test for correctly not-installed package(s) with" "dpkg -l $*"
1065 local PKGS
="$(dpkg -l "$@" 2> /dev/null | grep '^i' | wc -l)"
1066 if [ "$PKGS" != 0 ]; then
1068 dpkg
-l "$@" | grep '^[a-z]'
1076 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1077 if [ -n "$1" ]; then
1078 msgtest
'Test for correctly marked as auto-installed' "$*"
1079 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1081 msgtest
'Test for correctly marked as auto-installed' 'no package'
1082 echo -n > $COMPAREFILE
1084 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1088 if [ "$1" = '--nomsg' ]; then
1091 msgtest
'Test for successful execution of' "$*"
1093 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1094 if $@
>${OUTPUT} 2>&1; then
1104 if [ "$1" = '--nomsg' ]; then
1107 msgtest
'Test for failure in execution of' "$*"
1109 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1110 if $@
>${OUTPUT} 2>&1; then
1120 echo "STOPPED execution. Press enter to continue"