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