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}";
94 if [ -f .
/aptconfig.conf
]; then
95 echo "./aptconfig.conf"
96 elif [ -f ..
/aptconfig.conf
]; then
97 echo "../aptconfig.conf"
101 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
104 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
="$(getaptconfig)" 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 APT_CONFIG
="$(getaptconfig)" 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
"$@"
124 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
=${BUILDDIRECTORY} command aptitude
"$@"
128 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
=${BUILDDIRECTORY} command gdb
${BUILDDIRECTORY}/$1 --args "$@"
131 LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods
/http
134 # see apt-key for the whole trickery. Setup is done in setupenvironment
135 command gpg
--ignore-time-conflict --no-options --no-default-keyring \
136 --homedir "${TMPWORKINGDIRECTORY}/gnupghome" \
137 --no-auto-check-trustdb --trust-model always \
142 # error if we about to overflow, but ...
143 # "255 failures ought to be enough for everybody"
144 if [ $EXIT_CODE -gt 255 ]; then
145 msgdie
"Total failure count $EXIT_CODE too big"
147 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
150 shellsetedetector
() {
152 if [ "$exit_status" != '0' ]; then
153 echo >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}"
154 if [ "$EXIT_CODE" = '0' ]; then
155 EXIT_CODE
="$exit_status"
161 if [ "$1" = 'prefix' ]; then
162 CURRENTTRAP
="$2 $CURRENTTRAP"
164 CURRENTTRAP
="$CURRENTTRAP $1"
166 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
170 TMPWORKINGDIRECTORY
=$(mktemp -d)
171 TESTDIRECTORY
=$(readlink -f $(dirname $0))
172 msgninfo
"Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
174 # allow overriding the default BUILDDIR location
175 BUILDDIRECTORY
=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
176 METHODSDIR
=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
177 APTHELPERBINDIR
=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}
178 APTWEBSERVERBINDIR
=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
179 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
182 addtrap
"cd /; rm -rf $TMPWORKINGDIRECTORY;"
183 cd $TMPWORKINGDIRECTORY
184 mkdir rootdir aptarchive keys
186 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
187 mkdir -p var
/cache var
/lib var
/log tmp
188 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
189 touch var
/lib
/dpkg
/available
191 ln -s ${METHODSDIR} usr
/lib
/apt
/methods
193 local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
194 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
195 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
197 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
198 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
199 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
201 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/
202 ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
203 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
204 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
205 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
206 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
207 echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
208 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
209 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
210 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
211 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
212 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
213 if ! command dpkg
--assert-multi-arch >/dev
/null
2>&1; then
214 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf
# Added to test multiarch before dpkg is ready for it…
216 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
217 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
218 echo "Acquire::https::CaInfo \"${TESTDIR}/apt.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
219 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary
220 export LC_ALL
=C.UTF
-8
221 export PATH
="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
222 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
224 # gpg needs a trustdb to function, but it can't be invalid (not even empty)
225 # see also apt-key where this trickery comes from:
226 local TRUSTDBDIR
="${TMPWORKINGDIRECTORY}/gnupghome"
228 chmod 700 "$TRUSTDBDIR"
229 # We also don't use a secret keyring, of course, but gpg panics and
230 # implodes if there isn't one available - and writeable for imports
231 local SECRETKEYRING
="${TRUSTDBDIR}/secring.gpg"
233 # now create the trustdb with an (empty) dummy keyring
234 # newer gpg versions are fine without it, but play it safe for now
235 gpg
--quiet --check-trustdb --secret-keyring $SECRETKEYRING --keyring $SECRETKEYRING >/dev
/null
2>&1
241 if [ "$1" = "native" -o -z "$1" ]; then
242 eval `aptconfig shell ARCH APT::Architecture`
243 if [ -n "$ARCH" ]; then
246 dpkg
--print-architecture
254 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
257 configarchitecture
() {
259 echo "APT::Architecture \"$(getarchitecture $1)\";"
260 while [ -n "$1" ]; do
261 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
264 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
269 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
270 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
271 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
272 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
274 echo -n > rootdir/var/lib/dpkg/status
277 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
278 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
279 local ARCHS="$(getarchitectures)"
280 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
281 DPKGARCH="$(dpkg --print-architecture)"
282 for ARCH in ${ARCHS}; do
283 if [ "${ARCH}" != "${DPKGARCH}" ]; then
284 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
285 # old-style used e.g. in Ubuntu-P – and as it seems travis
286 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
287 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
291 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
292 # dpkg doesn't really check the version as long as it is fully installed,
293 # but just to be sure we choose one above the required version
294 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
300 configcompression() {
301 while [ -n "$1" ]; do
303 '.') echo ".
\t.
\tcat
";;
304 'gz') echo "gzip\tgz
\tgzip
";;
305 'bz2') echo "bzip2\tbz
2\tbzip
2";;
306 'lzma') echo "lzma
\tlzma
\txz
--format=lzma
";;
307 'xz') echo "xz
\txz
\txz
";;
308 *) echo "$1\t$1\t$1";;
311 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
314 setupsimplenativepackage() {
318 local RELEASE="${4:-unstable}"
319 local DEPENDENCIES="$5"
320 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
321 If you
find such a package installed on your system
,
322 something went horribly wrong
! They are autogenerated
323 und used only by testcases and surf no other propose…
"}"
325 local SECTION
="${7:-others}"
327 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
330 DISTSECTION
="$(echo "$SECTION" | cut -d'/' -f 1)"
332 local BUILDDIR
=incoming
/${NAME}-${VERSION}
333 mkdir -p ${BUILDDIR}/debian
/source
335 echo "* most suckless software product ever" > FEATURES
336 test -e debian
/copyright
|| echo "Copyleft by Joe Sixpack $(date +%Y)" > debian
/copyright
337 test -e debian
/changelog
|| echo "$NAME ($VERSION) $RELEASE; urgency=low
341 -- Joe Sixpack <joe@example.org> $(date -R)" > debian
/changelog
342 test -e debian
/control
|| echo "Source: $NAME
345 Maintainer: Joe Sixpack <joe@example.org>
346 Build-Depends: debhelper (>= 7)
347 Standards-Version: 3.9.1
349 Package: $NAME" > debian
/control
350 if [ "$ARCH" = 'all' ]; then
351 echo "Architecture: all" >> debian
/control
353 echo "Architecture: any" >> debian
/control
355 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian
/control
356 echo "Description: $DESCRIPTION" >> debian
/control
358 test -e debian
/compat
|| echo "7" > debian
/compat
359 test -e debian
/source
/format
|| echo "3.0 (native)" > debian
/source
/format
360 test -e debian
/rules
|| cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny debian
/rules
364 buildsimplenativepackage
() {
368 local RELEASE
="${4:-unstable}"
369 local DEPENDENCIES
="$5"
370 local DESCRIPTION
="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
371 If you find such a package installed on your system,
372 something went horribly wrong! They are autogenerated
373 und used only by testcases and surf no other propose…"}"
375 local SECTION="${7:-others}"
376 local PRIORITY="${8:-optional}"
378 local COMPRESS_TYPE="${10:-gzip}"
380 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
383 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
385 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
387 msgninfo "Build package
${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}…
"
388 mkdir -p $BUILDDIR/debian/source
389 echo "* most suckless software product ever
" > ${BUILDDIR}/FEATURES
391 echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
393 echo "Copyleft by Joe Sixpack
$(date +%Y)" > ${BUILDDIR}/debian/copyright
394 echo "$NAME ($VERSION) $RELEASE; urgency
=low
398 -- Joe Sixpack
<joe@example.org
> $(date -R)" > ${BUILDDIR}/debian/changelog
402 Maintainer
: Joe Sixpack
<joe@example.org
>
403 Standards
-Version: 3.9.3" > ${BUILDDIR}/debian/control
404 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
405 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
407 Package
: $NAME" >> ${BUILDDIR}/debian/control
409 if [ "$ARCH" = 'all' ]; then
410 echo "Architecture
: all
" >> ${BUILDDIR}/debian/control
412 echo "Architecture
: any
" >> ${BUILDDIR}/debian/control
414 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
415 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
416 echo "Description
: $DESCRIPTION" >> ${BUILDDIR}/debian/control
418 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
419 (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' \
421 echo "pool
/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
422 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
423 # gpg --yes --secret-keyring ./keys/joesixpack.sec \
424 # --keyring ./keys/joesixpack.pub --default-key 'Joe Sixpack' \
425 # --clearsign -o "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
426 # mv "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
430 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
431 rm -rf ${BUILDDIR}/debian
/tmp
432 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
433 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
434 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
435 if [ -n "$FILE_TREE" ]; then
436 cp -ar "$FILE_TREE" ${BUILDDIR}/debian
/tmp
439 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
440 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
441 local LOG
="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
442 # ensure the right permissions as dpkg-deb ensists
443 chmod 755 ${BUILDDIR}/debian
/tmp
/DEBIAN
444 if ! dpkg
-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
>$LOG 2>&1; then
449 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
452 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
453 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
454 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
463 local ARCH
=$(getarchitecture $4)
464 local PKGNAME
="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
465 local BUILDLOG
="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
466 msgninfo
"Build package ${PKGNAME} for ${RELEASE} in ${SECTION}… "
468 if [ "$ARCH" = "all" ]; then
469 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
471 if ! dpkg
-buildpackage -uc -us -a$ARCH >$BUILDLOG 2>&1 ; then
475 local PKGS
="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
476 local SRCS
="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
479 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
482 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
488 if [ -d incoming
]; then
489 buildaptarchivefromincoming
"$@"
491 buildaptarchivefromfiles
"$@"
495 createaptftparchiveconfig
() {
496 local COMPRESSORS
="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
497 COMPRESSORS
="${COMPRESSORS%* }"
498 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' ' ')"
499 if [ -z "$ARCHS" ]; then
500 # the pool is empty, so we will operate on faked packages - let us use the configured archs
501 ARCHS
="$(getarchitectures)"
504 ArchiveDir "' >> ftparchive.conf
505 echo -n $(readlink -f .) >> ftparchive.conf
507 CacheDir "' >> ftparchive.conf
508 echo -n $(readlink -f ..) >> ftparchive.conf
510 FileListDir "' >> ftparchive.conf
511 echo -n $(readlink -f pool/) >> ftparchive.conf
515 Packages::Compress "'"$COMPRESSORS"'";
516 Sources::Compress "'"$COMPRESSORS"'";
517 Contents::Compress "'"$COMPRESSORS"'";
518 Translation::Compress "'"$COMPRESSORS"'";
519 LongDescription "false";
523 SrcDirectory "pool/";
529 Label "apttestcases";
531 Description "repository with dummy packages";
532 Architectures "' >> ftparchive.conf
533 echo -n "$ARCHS" >> ftparchive.conf
537 };' >> ftparchive.conf
538 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
539 echo -n 'tree "dists/' >> ftparchive.conf
540 echo -n "$DIST" >> ftparchive.conf
542 Architectures "' >> ftparchive.conf
543 echo -n "$ARCHS" >> ftparchive.conf
545 FileList "' >> ftparchive.conf
546 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
548 SourceFileList "' >> ftparchive.conf
549 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
551 Sections "' >> ftparchive.conf
552 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
554 };' >> ftparchive.conf
558 buildaptftparchivedirectorystructure
() {
559 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
560 for DIST
in $DISTS; do
561 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
562 for SECTION
in $SECTIONS; do
563 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
564 for ARCH
in $ARCHS; do
565 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
567 mkdir -p dists
/${DIST}/${SECTION}/source
568 mkdir -p dists
/${DIST}/${SECTION}/i18n
578 local DEPENDENCIES
="$5"
579 local PRIORITY
="${6:-optional}"
580 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
581 If you find such a package installed on your system,
582 something went horribly wrong! They are autogenerated
583 und used only by testcases and surf no other propose…"}"
585 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
586 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
587 ARCHS
="$(getarchitectures)"
591 for BUILDARCH
in $ARCHS; do
592 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
593 mkdir -p $PPATH aptarchive
/dists
/${RELEASE}/main
/source
594 touch aptarchive
/dists
/${RELEASE}/main
/source
/Sources
595 local FILE
="${PPATH}/Packages"
600 Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
601 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
602 echo "Version: $VERSION
603 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
604 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
605 echo "Description: $DESCRIPTION" >> $FILE
616 local DEPENDENCIES
="$5"
618 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
620 local FILE
="${SPATH}/Sources"
624 Maintainer: Joe Sixpack <joe@example.org>
625 Architecture: $ARCH" >> $FILE
626 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
628 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
629 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
633 insertinstalledpackage
() {
637 local DEPENDENCIES
="$4"
638 local PRIORITY
="${5:-optional}"
639 local STATUS
="${6:-install ok installed}"
640 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
641 If you find such a package installed on your system,
642 something went horribly wrong! They are autogenerated
643 und used only by testcases and surf no other propose…"}"
645 local FILE='rootdir/var/lib/dpkg/status'
646 local INFO='rootdir/var/lib/dpkg/info'
647 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
653 Maintainer: Joe Sixpack <joe@example.org>
654 Version: $VERSION" >> $FILE
655 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
656 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
657 echo "Description: $DESCRIPTION" >> $FILE
659 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
660 echo -n > ${INFO}/${NAME}:${arch}.list
662 echo -n > ${INFO}/${NAME}.list
668 buildaptarchivefromincoming
() {
669 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
671 [ -e pool
] || ln -s ..
/incoming pool
672 [ -e ftparchive.conf
] || createaptftparchiveconfig
673 [ -e dists
] || buildaptftparchivedirectorystructure
674 msgninfo
"\tGenerate Packages, Sources and Contents files… "
675 aptftparchive
-qq generate ftparchive.conf
681 buildaptarchivefromfiles
() {
682 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
683 find aptarchive
-name 'Packages' -o -name 'Sources' | while read line
; do
684 msgninfo
"\t${line} file… "
685 compressfile
"$line" "$1"
688 generatereleasefiles
"$@"
692 cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
| while read compressor extension
command; do
693 if [ "$compressor" = '.' ]; then
699 cat "$1" | $command > "${1}.${extension}"
701 touch -d "$2" "${1}.${extension}"
706 # can be overridden by testcases for their pleasure
707 getcodenamefromsuite
() {
709 unstable
) echo 'sid';;
713 getreleaseversionfromsuite
() { true
; }
714 getlabelfromsuite
() { true
; }
716 generatereleasefiles
() {
717 # $1 is the Date header and $2 is the ValidUntil header to be set
718 # both should be given in notation date/touch can understand
719 msgninfo
"\tGenerate Release files… "
720 if [ -e aptarchive
/dists
]; then
721 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
722 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
723 local CODENAME
="$(getcodenamefromsuite $SUITE)"
724 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
725 local LABEL
="$(getlabelfromsuite $SUITE)"
726 if [ -n "$VERSION" ]; then
727 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
729 if [ -n "$LABEL" ]; then
730 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
732 aptftparchive
-qq release
$dir \
733 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
734 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
737 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
738 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
740 NotAutomatic: yes' $dir/Release
742 if [ -n "$1" -a "$1" != "now" ]; then
743 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
747 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
751 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
753 if [ -n "$1" -a "$1" != "now" ]; then
754 for release
in $(find ./aptarchive -name 'Release'); do
755 touch -d "$1" $release
761 setupdistsaptarchive
() {
762 local APTARCHIVE
=$(readlink -f ./aptarchive)
763 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
764 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
765 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
766 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
767 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
768 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
769 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
774 setupflataptarchive
() {
775 local APTARCHIVE
=$(readlink -f ./aptarchive)
776 if [ -f ${APTARCHIVE}/Packages
]; then
777 msgninfo
"\tadd deb sources.list line… "
778 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
781 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
783 if [ -f ${APTARCHIVE}/Sources
]; then
784 msgninfo
"\tadd deb-src sources.list line… "
785 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
788 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
794 if [ -e aptarchive
/dists
]; then
800 if [ "$1" != '--no-update' ]; then
801 msgninfo
"\tSync APT's cache with the archive… "
808 local SIGNER
="${1:-Joe Sixpack}"
809 local GPG
="gpg --batch --yes"
810 msgninfo
"\tSign archive with $SIGNER key… "
811 local REXKEY
='keys/rexexpired'
812 local SECEXPIREBAK
="${REXKEY}.sec.bak"
813 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
814 if [ "${SIGNER}" = 'Rex Expired' ]; then
815 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
816 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
817 # therefore we 'temporary' make the key not expired and restore a backup after signing
818 cp ${REXKEY}.sec
$SECEXPIREBAK
819 cp ${REXKEY}.pub
$PUBEXPIREBAK
820 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
821 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
822 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
823 cp $SECUNEXPIRED ${REXKEY}.sec
824 cp $PUBUNEXPIRED ${REXKEY}.pub
826 printf "expire\n1w\nsave\n" | $GPG --keyring ${REXKEY}.pub
--secret-keyring ${REXKEY}.sec
--command-fd 0 --edit-key "${SIGNER}" >/dev
/null
2>&1 || true
827 cp ${REXKEY}.sec
$SECUNEXPIRED
828 cp ${REXKEY}.pub
$PUBUNEXPIRED
831 for KEY
in $(find keys/ -name '*.sec'); do
832 GPG
="$GPG --secret-keyring $KEY"
834 for KEY
in $(find keys/ -name '*.pub'); do
835 GPG
="$GPG --keyring $KEY"
837 for RELEASE
in $(find aptarchive/ -name Release); do
838 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
839 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
840 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
841 # we might have set a specific date for the Release file, so copy it
842 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
844 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
845 mv -f $SECEXPIREBAK ${REXKEY}.sec
846 mv -f $PUBEXPIREBAK ${REXKEY}.pub
852 msgtest
"Set webserver config option '${1}' to" "$2"
853 downloadfile
"http://localhost:8080/_config/set/${1}/${2}" '/dev/null' >/dev
/null
854 local DOWNLOG
='download-testfile.log'
856 local STATUS
="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.status"
857 downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
858 if [ "$(cat "$STATUS")" = '200' ]; then
862 msgfail
"Statuscode was $(cat "$STATUS")"
867 rewritesourceslist
() {
868 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
869 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
870 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#http://localhost:4433/#${1}#"
874 changetowebserver
() {
875 if [ "$1" != '--no-rewrite' ]; then
876 rewritesourceslist
'http://localhost:8080/'
880 if test -x ${APTWEBSERVERBINDIR}/aptwebserver
; then
882 local LOG
="webserver.log"
883 if ! aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1 ; then
887 local PID
="$(cat aptwebserver.pid)"
888 if [ -z "$PID" ]; then
889 msgdie
'Could not fork aptwebserver successfully'
894 msgdie
'You have to build aptwerbserver or install a webserver'
898 changetohttpswebserver
() {
899 if ! which stunnel4
>/dev
/null
; then
900 msgdie
'You need to install stunnel4 for https testcases'
902 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
903 changetowebserver
--no-rewrite "$@"
905 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
906 cert = ${TESTDIRECTORY}/apt.pem
912 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
913 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
914 local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
915 addtrap
'prefix' "kill ${PID};"
916 rewritesourceslist
'https://localhost:4433/'
920 mkdir -p rootdir
/media
/cdrom
/.disk
921 local CD
="$(readlink -f rootdir/media/cdrom)"
922 echo "acquire::cdrom::mount \"${CD}\";" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
923 echo 'acquire::cdrom::autodetect 0;' >> rootdir
/etc
/apt
/apt.conf.d
/00cdrom
924 echo -n "$1" > ${CD}/.disk
/info
925 if [ ! -d aptarchive
/dists
]; then
926 msgdie
'Flat file archive cdroms can not be created currently'
929 mv aptarchive
/dists
$CD
930 ln -s "$(readlink -f ./incoming)" $CD/pool
931 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
935 PROTO
="$(echo "$1" | cut -d':' -f 1)"
936 apthelper
-o Acquire
::https
::CaInfo
=${TESTDIR}/apt.pem \
937 -o Debug
::Acquire
::${PROTO}=1 \
938 download
-file "$1" "$2" 2>&1
939 # only if the file exists the download was successful
948 local DIFFTEXT
="$(command diff -u "$@" | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
949 if [ -n "$DIFFTEXT" ]; then
961 msgtest
"Test for correctness of file" "$FILE"
963 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
965 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
970 msgtest
"Test for no output of" "$*"
971 test -z "$($* 2>&1)" && msgpass
|| msgfail
975 local MSG
='Test of equality of'
976 if [ "$1" = '--nomsg' ]; then
981 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
982 echo "$1" > $COMPAREFILE
985 if [ -n "$MSG" ]; then
988 $
* 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
992 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
993 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
994 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.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
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1021 local ARCH
="$(getarchitecture 'native')"
1022 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1023 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1027 msgtest
"Test for non-existent packages" "apt-cache show $*"
1028 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1029 if [ -n "$SHOWPKG" ]; then
1038 testdpkginstalled
() {
1039 msgtest
"Test for correctly installed package(s) with" "dpkg -l $*"
1040 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep '^i' | wc -l)"
1041 if [ "$PKGS" != $# ]; then
1043 dpkg
-l "$@" | grep '^[a-z]'
1050 testdpkgnotinstalled
() {
1051 msgtest
"Test for correctly not-installed package(s) with" "dpkg -l $*"
1052 local PKGS
="$(dpkg -l "$@" 2> /dev/null | grep '^i' | wc -l)"
1053 if [ "$PKGS" != 0 ]; then
1055 dpkg
-l "$@" | grep '^[a-z]'
1063 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1064 if [ -n "$1" ]; then
1065 msgtest
'Test for correctly marked as auto-installed' "$*"
1066 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1068 msgtest
'Test for correctly marked as auto-installed' 'no package'
1069 echo -n > $COMPAREFILE
1071 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1075 if [ "$1" = '--nomsg' ]; then
1078 msgtest
'Test for successful execution of' "$*"
1080 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1081 if $@
>${OUTPUT} 2>&1; then
1091 if [ "$1" = '--nomsg' ]; then
1094 msgtest
'Test for failure in execution of' "$*"
1096 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1097 if $@
>${OUTPUT} 2>&1; then
1107 echo "STOPPED execution. Press enter to continue"