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} "
106 *) CMD
="${BUILDDIRECTORY}/$CMD";;
108 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
="$(getaptconfig)" LD_LIBRARY_PATH
=${BUILDDIRECTORY} $CMD "$@"
110 aptconfig
() { runapt apt
-config "$@"; }
111 aptcache
() { runapt apt
-cache "$@"; }
112 aptcdrom
() { runapt apt
-cdrom "$@"; }
113 aptget
() { runapt apt
-get "$@"; }
114 aptftparchive
() { runapt apt
-ftparchive "$@"; }
115 aptkey
() { runapt apt
-key "$@"; }
116 aptmark
() { runapt apt
-mark "$@"; }
117 apt
() { runapt apt
"$@"; }
118 apthelper
() { runapt
"${APTHELPERBINDIR}/apt-helper" "$@"; }
119 aptwebserver
() { runapt
"${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
120 aptitude
() { runapt aptitude
"$@"; }
121 aptextracttemplates
() { runapt apt
-extracttemplates "$@"; }
124 command dpkg
--root=${TMPWORKINGDIRECTORY}/rootdir
--force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir
/var
/log
/dpkg.log
"$@"
126 dpkgcheckbuilddeps
() {
127 command dpkg
-checkbuilddeps --admindir=${TMPWORKINGDIRECTORY}/rootdir
/var
/lib
/dpkg
"$@"
131 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${LIBRARYPATH} command gdb
${BUILDDIRECTORY}/$1 --args "$@"
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 LIBRARYPATH
=${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}
177 METHODSDIR
=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
178 APTHELPERBINDIR
=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}
179 APTWEBSERVERBINDIR
=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
180 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
183 addtrap
"cd /; rm -rf $TMPWORKINGDIRECTORY;"
184 cd $TMPWORKINGDIRECTORY
185 mkdir rootdir aptarchive keys
187 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
188 mkdir -p var
/cache var
/lib
/apt var
/log tmp
189 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
190 touch var
/lib
/dpkg
/available
192 ln -s ${METHODSDIR} usr
/lib
/apt
/methods
193 ln -s ${BUILDDIRECTORY}/..
/..
/debian
/apt.conf.autoremove etc
/apt
/apt.conf.d
/01autoremove
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 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
237 # cleanup the environment a bit
238 export PATH
="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
239 export LC_ALL
=C.UTF
-8
240 unset LANGUAGE APT_CONFIG
241 unset GREP_OPTIONS DEB_BUILD_PROFILES
247 if [ "$1" = "native" -o -z "$1" ]; then
248 eval `aptconfig shell ARCH APT::Architecture`
249 if [ -n "$ARCH" ]; then
252 dpkg
--print-architecture
260 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
263 getarchitecturesfromcommalist
() {
264 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
267 configarchitecture
() {
269 echo "APT::Architecture \"$(getarchitecture $1)\";"
270 while [ -n "$1" ]; do
271 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
274 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
279 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
280 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
281 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
282 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
284 echo -n > rootdir/var/lib/dpkg/status
287 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
288 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
289 local ARCHS="$(getarchitectures)"
290 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
291 DPKGARCH="$(dpkg --print-architecture)"
292 for ARCH in ${ARCHS}; do
293 if [ "${ARCH}" != "${DPKGARCH}" ]; then
294 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
295 # old-style used e.g. in Ubuntu-P – and as it seems travis
296 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
297 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
301 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
302 # dpkg doesn't really check the version as long as it is fully installed,
303 # but just to be sure we choose one above the required version
304 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
310 configcompression() {
311 while [ -n "$1" ]; do
313 '.') echo ".
\t.
\tcat
";;
314 'gz') echo "gzip\tgz
\tgzip
";;
315 'bz2') echo "bzip2\tbz
2\tbzip
2";;
316 'lzma') echo "lzma
\tlzma
\txz
--format=lzma
";;
317 'xz') echo "xz
\txz
\txz
";;
318 *) echo "$1\t$1\t$1";;
321 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
324 setupsimplenativepackage() {
328 local RELEASE="${4:-unstable}"
329 local DEPENDENCIES="$5"
330 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
331 If you
find such a package installed on your system
,
332 something went horribly wrong
! They are autogenerated
333 und used only by testcases and surf no other propose…
"}"
335 local SECTION
="${7:-others}"
337 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
340 DISTSECTION
="$(echo "$SECTION" | cut -d'/' -f 1)"
342 local BUILDDIR
=incoming
/${NAME}-${VERSION}
343 mkdir -p ${BUILDDIR}/debian
/source
345 echo "* most suckless software product ever" > FEATURES
346 test -e debian
/copyright
|| echo "Copyleft by Joe Sixpack $(date +%Y)" > debian
/copyright
347 test -e debian
/changelog
|| echo "$NAME ($VERSION) $RELEASE; urgency=low
351 -- Joe Sixpack <joe@example.org> $(date -R)" > debian
/changelog
352 test -e debian
/control
|| echo "Source: $NAME
355 Maintainer: Joe Sixpack <joe@example.org>
356 Build-Depends: debhelper (>= 7)
357 Standards-Version: 3.9.1
359 Package: $NAME" > debian
/control
360 if [ "$ARCH" = 'all' ]; then
361 echo "Architecture: all" >> debian
/control
363 echo "Architecture: any" >> debian
/control
365 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian
/control
366 echo "Description: $DESCRIPTION" >> debian
/control
368 test -e debian
/compat
|| echo "7" > debian
/compat
369 test -e debian
/source
/format
|| echo "3.0 (native)" > debian
/source
/format
370 test -e debian
/rules
|| cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny debian
/rules
374 buildsimplenativepackage
() {
378 local RELEASE
="${4:-unstable}"
379 local DEPENDENCIES
="$5"
380 local DESCRIPTION
="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
381 If you find such a package installed on your system,
382 something went horribly wrong! They are autogenerated
383 und used only by testcases and surf no other propose…"}"
385 local SECTION="${7:-others}"
386 local PRIORITY="${8:-optional}"
388 local COMPRESS_TYPE="${10:-gzip}"
390 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
393 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
395 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
397 msgninfo "Build package
${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}…
"
398 mkdir -p $BUILDDIR/debian/source
399 echo "* most suckless software product ever
" > ${BUILDDIR}/FEATURES
401 echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
403 echo "Copyleft by Joe Sixpack
$(date +%Y)" > ${BUILDDIR}/debian/copyright
404 echo "$NAME ($VERSION) $RELEASE; urgency
=low
408 -- Joe Sixpack
<joe@example.org
> $(date -R)" > ${BUILDDIR}/debian/changelog
412 Maintainer
: Joe Sixpack
<joe@example.org
>
413 Standards
-Version: 3.9.3" > ${BUILDDIR}/debian/control
414 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
415 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
417 Package
: $NAME" >> ${BUILDDIR}/debian/control
419 if [ "$ARCH" = 'all' ]; then
420 echo "Architecture
: all
" >> ${BUILDDIR}/debian/control
422 echo "Architecture
: any
" >> ${BUILDDIR}/debian/control
424 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
425 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
426 echo "Description
: $DESCRIPTION" >> ${BUILDDIR}/debian/control
428 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
429 (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' \
431 echo "pool
/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
432 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
433 # gpg --yes --secret-keyring ./keys/joesixpack.sec \
434 # --keyring ./keys/joesixpack.pub --default-key 'Joe Sixpack' \
435 # --clearsign -o "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
436 # mv "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
440 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
441 rm -rf ${BUILDDIR}/debian/tmp
442 mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
443 cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}
444 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}
445 if [ -n "$FILE_TREE" ]; then
446 cp -ar "$FILE_TREE" ${BUILDDIR}/debian/tmp
449 (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch)
450 (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
451 local LOG="${BUILDDIR}/..
/${NAME}_
${VERSION}_
${arch}.dpkg
-deb.log
"
452 # ensure the right permissions as dpkg-deb ensists
453 chmod 755 ${BUILDDIR}/debian/tmp/DEBIAN
454 if ! dpkg-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/.. >$LOG 2>&1; then
459 echo "pool
/${NAME}_
${VERSION}_
${arch}.deb
" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist
462 mkdir -p ${BUILDDIR}/../${NAME}_${VERSION}
463 cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}/
464 cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}.changelog
473 local ARCH=$(getarchitecture $4)
474 local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
475 local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
476 msgninfo "Build package
${PKGNAME} for ${RELEASE} in ${SECTION}…
"
478 if [ "$ARCH" = "all
" ]; then
479 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
481 if ! dpkg-buildpackage -uc -us -a$ARCH >$BUILDLOG 2>&1 ; then
485 local PKGS="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
486 local SRCS="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
489 echo "pool
/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist
492 echo "pool
/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist
498 if [ -d incoming ]; then
499 buildaptarchivefromincoming "$@
"
501 buildaptarchivefromfiles "$@
"
505 createaptftparchiveconfig() {
506 local COMPRESSORS="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
507 COMPRESSORS="${COMPRESSORS%* }"
508 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' ' ')"
509 if [ -z "$ARCHS" ]; then
510 # the pool is empty, so we will operate on faked packages - let us use the configured archs
511 ARCHS
="$(getarchitectures)"
514 ArchiveDir "' >> ftparchive.conf
515 echo -n $(readlink -f .) >> ftparchive.conf
517 CacheDir "' >> ftparchive.conf
518 echo -n $(readlink -f ..) >> ftparchive.conf
520 FileListDir "' >> ftparchive.conf
521 echo -n $(readlink -f pool/) >> ftparchive.conf
525 Packages::Compress "'"$COMPRESSORS"'";
526 Sources::Compress "'"$COMPRESSORS"'";
527 Contents::Compress "'"$COMPRESSORS"'";
528 Translation::Compress "'"$COMPRESSORS"'";
529 LongDescription "false";
533 SrcDirectory "pool/";
539 Label "apttestcases";
541 Description "repository with dummy packages";
542 Architectures "' >> ftparchive.conf
543 echo -n "$ARCHS" >> ftparchive.conf
547 };' >> ftparchive.conf
548 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
549 echo -n 'tree "dists/' >> ftparchive.conf
550 echo -n "$DIST" >> ftparchive.conf
552 Architectures "' >> ftparchive.conf
553 echo -n "$ARCHS" >> ftparchive.conf
555 FileList "' >> ftparchive.conf
556 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
558 SourceFileList "' >> ftparchive.conf
559 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
561 Sections "' >> ftparchive.conf
562 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
564 };' >> ftparchive.conf
568 buildaptftparchivedirectorystructure
() {
569 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
570 for DIST
in $DISTS; do
571 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
572 for SECTION
in $SECTIONS; do
573 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
574 for ARCH
in $ARCHS; do
575 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
577 mkdir -p dists
/${DIST}/${SECTION}/source
578 mkdir -p dists
/${DIST}/${SECTION}/i18n
588 local DEPENDENCIES
="$5"
589 local PRIORITY
="${6:-optional}"
590 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
591 If you find such a package installed on your system,
592 something went horribly wrong! They are autogenerated
593 und used only by testcases and surf no other propose…"}"
595 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
596 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
597 ARCHS="$(getarchitectures)"
601 for BUILDARCH in $ARCHS; do
602 local PPATH="aptarchive
/dists
/${RELEASE}/main
/binary
-${BUILDARCH}"
603 mkdir -p $PPATH aptarchive/dists/${RELEASE}/main/source
604 touch aptarchive/dists/${RELEASE}/main/source/Sources
605 local FILE="${PPATH}/Packages
"
610 Maintainer
: Joe Sixpack
<joe@example.org
>" >> $FILE
611 test "$arch" = 'none' || echo "Architecture
: $arch" >> $FILE
612 echo "Version
: $VERSION
613 Filename
: pool
/main
/${NAME}/${NAME}_
${VERSION}_
${arch}.deb
" >> $FILE
614 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
615 echo "Description
: $DESCRIPTION" >> $FILE
626 local DEPENDENCIES="$5"
628 local SPATH="aptarchive
/dists
/${RELEASE}/main
/source"
630 local FILE="${SPATH}/Sources
"
634 Maintainer
: Joe Sixpack
<joe@example.org
>
635 Architecture
: $ARCH" >> $FILE
636 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
638 d41d8cd98f00b204e9800998ecf8427e
0 ${NAME}_
${VERSION}.dsc
639 d41d8cd98f00b204e9800998ecf8427e
0 ${NAME}_
${VERSION}.
tar.gz
643 insertinstalledpackage() {
647 local DEPENDENCIES="$4"
648 local PRIORITY="${5:-optional}"
649 local STATUS="${6:-install ok installed}"
650 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
651 If you
find such a package installed on your system
,
652 something went horribly wrong
! They are autogenerated
653 und used only by testcases and surf no other propose…
"}"
655 local FILE
='rootdir/var/lib/dpkg/status'
656 local INFO
='rootdir/var/lib/dpkg/info'
657 for arch
in $(getarchitecturesfromcommalist "$ARCH"); do
663 Maintainer: Joe Sixpack <joe@example.org>
664 Version: $VERSION" >> $FILE
665 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
666 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
667 echo "Description: $DESCRIPTION" >> $FILE
669 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
670 echo -n > ${INFO}/${NAME}:${arch}.list
672 echo -n > ${INFO}/${NAME}.list
678 buildaptarchivefromincoming
() {
679 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
681 [ -e pool
] || ln -s ..
/incoming pool
682 [ -e ftparchive.conf
] || createaptftparchiveconfig
683 [ -e dists
] || buildaptftparchivedirectorystructure
684 msgninfo
"\tGenerate Packages, Sources and Contents files… "
685 aptftparchive
-qq generate ftparchive.conf
691 buildaptarchivefromfiles
() {
692 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
693 find aptarchive
-name 'Packages' -o -name 'Sources' | while read line
; do
694 msgninfo
"\t${line} file… "
695 compressfile
"$line" "$1"
698 generatereleasefiles
"$@"
702 cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
| while read compressor extension
command; do
703 if [ "$compressor" = '.' ]; then
709 cat "$1" | $command > "${1}.${extension}"
711 touch -d "$2" "${1}.${extension}"
716 # can be overridden by testcases for their pleasure
717 getcodenamefromsuite
() {
719 unstable
) echo 'sid';;
723 getreleaseversionfromsuite
() { true
; }
724 getlabelfromsuite
() { true
; }
726 generatereleasefiles
() {
727 # $1 is the Date header and $2 is the ValidUntil header to be set
728 # both should be given in notation date/touch can understand
729 msgninfo
"\tGenerate Release files… "
730 if [ -e aptarchive
/dists
]; then
731 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
732 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
733 local CODENAME
="$(getcodenamefromsuite $SUITE)"
734 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
735 local LABEL
="$(getlabelfromsuite $SUITE)"
736 if [ -n "$VERSION" ]; then
737 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
739 if [ -n "$LABEL" ]; then
740 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
742 aptftparchive
-qq release
$dir \
743 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
744 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
747 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
748 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
750 NotAutomatic: yes' $dir/Release
752 if [ -n "$1" -a "$1" != "now" ]; then
753 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
757 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
761 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
763 if [ -n "$1" -a "$1" != "now" ]; then
764 for release
in $(find ./aptarchive -name 'Release'); do
765 touch -d "$1" $release
771 setupdistsaptarchive
() {
772 local APTARCHIVE
=$(readlink -f ./aptarchive)
773 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
774 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
775 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
776 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
777 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
778 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
779 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
784 setupflataptarchive
() {
785 local APTARCHIVE
=$(readlink -f ./aptarchive)
786 if [ -f ${APTARCHIVE}/Packages
]; then
787 msgninfo
"\tadd deb sources.list line… "
788 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
791 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
793 if [ -f ${APTARCHIVE}/Sources
]; then
794 msgninfo
"\tadd deb-src sources.list line… "
795 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
798 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
804 if [ -e aptarchive
/dists
]; then
810 if [ "$1" != '--no-update' ]; then
811 msgninfo
"\tSync APT's cache with the archive… "
818 local SIGNER
="${1:-Joe Sixpack}"
819 local GPG
="gpg --batch --yes"
820 msgninfo
"\tSign archive with $SIGNER key… "
821 local REXKEY
='keys/rexexpired'
822 local SECEXPIREBAK
="${REXKEY}.sec.bak"
823 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
824 if [ "${SIGNER}" = 'Rex Expired' ]; then
825 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
826 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
827 # therefore we 'temporary' make the key not expired and restore a backup after signing
828 cp ${REXKEY}.sec
$SECEXPIREBAK
829 cp ${REXKEY}.pub
$PUBEXPIREBAK
830 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
831 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
832 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
833 cp $SECUNEXPIRED ${REXKEY}.sec
834 cp $PUBUNEXPIRED ${REXKEY}.pub
836 printf "expire\n1w\nsave\n" | $GPG --keyring ${REXKEY}.pub
--secret-keyring ${REXKEY}.sec
--command-fd 0 --edit-key "${SIGNER}" >/dev
/null
2>&1 || true
837 cp ${REXKEY}.sec
$SECUNEXPIRED
838 cp ${REXKEY}.pub
$PUBUNEXPIRED
841 for KEY
in $(find keys/ -name '*.sec'); do
842 GPG
="$GPG --secret-keyring $KEY"
844 for KEY
in $(find keys/ -name '*.pub'); do
845 GPG
="$GPG --keyring $KEY"
847 for RELEASE
in $(find aptarchive/ -name Release); do
848 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
849 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
850 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
851 # we might have set a specific date for the Release file, so copy it
852 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
854 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
855 mv -f $SECEXPIREBAK ${REXKEY}.sec
856 mv -f $PUBEXPIREBAK ${REXKEY}.pub
862 msgtest
"Set webserver config option '${1}' to" "$2"
863 local DOWNLOG
='rootdir/tmp/download-testfile.log'
864 local STATUS
='rootdir/tmp/webserverconfig.status'
865 rm -f "$STATUS" "$DOWNLOG"
866 if downloadfile
"http://localhost:8080/_config/set/${1}/${2}" "$STATUS" > "$DOWNLOG"; then
869 cat "$DOWNLOG" "$STATUS"
872 testwebserverlaststatuscode
'200'
875 rewritesourceslist
() {
876 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
877 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
878 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#http://localhost:4433/#${1}#"
882 changetowebserver
() {
883 if [ "$1" != '--no-rewrite' ]; then
884 rewritesourceslist
'http://localhost:8080/'
888 if test -x ${APTWEBSERVERBINDIR}/aptwebserver
; then
890 local LOG
="webserver.log"
891 if ! aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1 ; then
895 local PID
="$(cat aptwebserver.pid)"
896 if [ -z "$PID" ]; then
897 msgdie
'Could not fork aptwebserver successfully'
902 msgdie
'You have to build aptwerbserver or install a webserver'
906 changetohttpswebserver
() {
907 if ! which stunnel4
>/dev
/null
; then
908 msgdie
'You need to install stunnel4 for https testcases'
910 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
911 changetowebserver
--no-rewrite "$@"
913 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
914 cert = ${TESTDIRECTORY}/apt.pem
920 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
921 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
922 local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
923 addtrap
'prefix' "kill ${PID};"
924 rewritesourceslist
'https://localhost:4433/'
928 mkdir -p rootdir
/media
/cdrom
/.disk
929 local CD
="$(readlink -f rootdir/media/cdrom)"
930 echo "acquire::cdrom::mount \"${CD}\";
931 acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
932 acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
933 acquire::cdrom::autodetect 0;" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
934 echo -n "$1" > ${CD}/.disk
/info
935 if [ ! -d aptarchive
/dists
]; then
936 msgdie
'Flat file archive cdroms can not be created currently'
939 mv aptarchive
/dists
"$CD"
940 ln -s "$(readlink -f ./incoming)" $CD/pool
941 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
942 # start with an unmounted disk
943 mv "${CD}" "${CD}-unmounted"
944 # we don't want the disk to be modifiable
945 addtrap
'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
946 chmod -R -w rootdir
/media
/cdrom
-unmounted/dists
950 local PROTO
="$(echo "$1" | cut -d':' -f 1 )"
951 apthelper
-o Debug
::Acquire
::${PROTO}=1 \
952 download
-file "$1" "$2" 2>&1 || true
953 # only if the file exists the download was successful
962 local DIFFTEXT
="$(command diff -u "$@" | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
963 if [ -n "$DIFFTEXT" ]; then
975 msgtest
"Test for correctness of file" "$FILE"
977 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
979 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
984 msgtest
"Test for no output of" "$*"
985 test -z "$($* 2>&1)" && msgpass
|| msgfail
989 local MSG
='Test of equality of'
990 if [ "$1" = '--nomsg' ]; then
995 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
996 echo "$1" > $COMPAREFILE
999 if [ -n "$MSG" ]; then
1002 $
* 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1006 local COMPAREFILE1
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1007 local COMPAREFILE2
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1008 local COMPAREAGAINST
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
1009 echo "$1" > $COMPAREFILE1
1010 echo "$2" > $COMPAREFILE2
1012 msgtest
"Test for equality OR of" "$*"
1013 $
* >$COMPAREAGAINST 2>&1 || true
1014 if checkdiff
$COMPAREFILE1 $COMPAREAGAINST >/dev
/null
2>&1 || \
1015 checkdiff
$COMPAREFILE2 $COMPAREAGAINST >/dev
/null
2>&1
1019 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
1020 checkdiff
$COMPAREFILE1 $COMPAREAGAINST || true
1021 echo -n "${CINFO}Diff against OR 2${CNORMAL}"
1022 checkdiff
$COMPAREFILE2 $COMPAREAGAINST || true
1028 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
1031 while [ -n "$1" ]; do
1033 N: Can't select versions from package '$1' as it is purely virtual"
1034 PACKAGE
="${PACKAGE} $1"
1037 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1039 N: No packages found"
1040 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
1041 local ARCH
="$(getarchitecture 'native')"
1042 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1043 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1047 msgtest
"Test for non-existent packages" "apt-cache show $*"
1048 local SHOWPKG
="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
1049 if [ -n "$SHOWPKG" ]; then
1058 testdpkginstalled
() {
1059 msgtest
"Test for correctly installed package(s) with" "dpkg -l $*"
1060 local PKGS
="$(dpkg -l "$@" 2>/dev/null | grep '^i' | wc -l)"
1061 if [ "$PKGS" != $# ]; then
1063 dpkg
-l "$@" | grep '^[a-z]' >&2
1070 testdpkgnotinstalled
() {
1071 msgtest
"Test for correctly not-installed package(s) with" "dpkg -l $*"
1072 local PKGS
="$(dpkg -l "$@" 2> /dev/null | grep '^i' | wc -l)"
1073 if [ "$PKGS" != 0 ]; then
1075 dpkg
-l "$@" | grep '^[a-z]' >&2
1083 local COMPAREFILE
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
1084 if [ -n "$1" ]; then
1085 msgtest
'Test for correctly marked as auto-installed' "$*"
1086 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1088 msgtest
'Test for correctly marked as auto-installed' 'no package'
1089 echo -n > $COMPAREFILE
1091 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1095 if [ "$1" = '--nomsg' ]; then
1098 msgtest
'Test for successful execution of' "$*"
1100 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
1101 if $@
>${OUTPUT} 2>&1; then
1111 if [ "$1" = '--nomsg' ]; then
1114 msgtest
'Test for failure in execution of' "$*"
1116 local OUTPUT
="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
1117 if $@
>${OUTPUT} 2>&1; then
1126 testwebserverlaststatuscode
() {
1127 local DOWNLOG
='rootdir/tmp/webserverstatus-testfile.log'
1128 local STATUS
='rootdir/tmp/webserverstatus-statusfile.log'
1129 rm -f "$DOWNLOG" "$STATUS"
1130 msgtest
'Test last status code from the webserver was' "$1"
1131 downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
1132 if [ "$(cat "$STATUS")" = "$1" ]; then
1136 if [ -n "$2" ]; then
1138 echo >&2 '#### Additionally provided output files contain:'
1141 echo >&2 '#### Download log of the status code:'
1143 msgfail
"Status was $(cat "$STATUS")"
1148 echo "STOPPED execution. Press enter to continue"