1 #!/bin/sh -- # no runable script, just for vi
5 # we all like colorful messages
6 if expr match
"$(readlink -f /proc/$$/fd/1)" '/dev/pts/[0-9]\+' > /dev
/null
&& \
7 expr match
"$(readlink -f /proc/$$/fd/2)" '/dev/pts/[0-9]\+' > /dev
/null
; then
8 CERROR
="\e[1;31m" # red
9 CWARNING
="\e[1;33m" # yellow
10 CMSG
="\e[1;32m" # green
11 CINFO
="\e[1;96m" # light blue
12 CDEBUG
="\e[1;94m" # blue
13 CNORMAL
="\e[0;39m" # default system console color
14 CDONE
="\e[1;32m" # green
15 CPASS
="\e[1;32m" # green
16 CFAIL
="\e[1;31m" # red
17 CCMD
="\e[1;35m" # pink
20 msgdie
() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; }
21 msgwarn
() { echo "${CWARNING}W: $1${CNORMAL}" >&2; }
22 msgmsg
() { echo "${CMSG}$1${CNORMAL}" >&2; }
23 msginfo
() { echo "${CINFO}I: $1${CNORMAL}" >&2; }
24 msgdebug
() { echo "${CDEBUG}D: $1${CNORMAL}" >&2; }
25 msgdone
() { echo "${CDONE}DONE${CNORMAL}" >&2; }
26 msgnwarn
() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; }
27 msgnmsg
() { echo -n "${CMSG}$1${CNORMAL}" >&2; }
28 msgninfo
() { echo -n "${CINFO}I: $1${CNORMAL}" >&2; }
29 msgndebug
() { echo -n "${CDEBUG}D: $1${CNORMAL}" >&2; }
32 echo -n "${CINFO}$1${CCMD} " >&2;
33 echo -n "$(echo "$2" | sed -e 's/^aptc/apt-c/' -e 's/^aptg/apt-g/' -e 's/^aptf/apt-f/')${CINFO} " >&2;
35 if [ -n "$1" ]; then shift; else break; fi
37 echo -n "…${CNORMAL} " >&2;
39 msgpass
() { echo "${CPASS}PASS${CNORMAL}" >&2; }
40 msgskip
() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
42 if [ $# -gt 0 ]; then echo "${CFAIL}FAIL: $*${CNORMAL}" >&2;
43 else echo "${CFAIL}FAIL${CNORMAL}" >&2; fi
44 EXIT_CODE
=$((EXIT_CODE+1));
47 # enable / disable Debugging
48 MSGLEVEL
=${MSGLEVEL:-3}
49 if [ $MSGLEVEL -le 0 ]; then
52 if [ $MSGLEVEL -le 1 ]; then
56 if [ $MSGLEVEL -le 2 ]; then
60 msgpass
() { echo -n " ${CPASS}P${CNORMAL}" >&2; }
61 msgskip
() { echo -n " ${CWARNING}S${CNORMAL}" >&2; }
62 if [ -n "$CFAIL" ]; then
63 msgfail
() { echo -n " ${CFAIL}FAIL${CNORMAL}" >&2; EXIT_CODE
=$((EXIT_CODE+1)); }
65 msgfail
() { echo -n " ###FAILED###" >&2; EXIT_CODE
=$((EXIT_CODE+1)); }
68 if [ $MSGLEVEL -le 3 ]; then
72 if [ $MSGLEVEL -le 4 ]; then
77 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
78 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
79 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
80 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
81 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
84 echo "${CDONE}DONE${CNORMAL}" >&2;
89 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
90 if [ -f .
/aptconfig.conf
]; then
91 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
92 elif [ -f ..
/aptconfig.conf
]; then
93 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 APT_CONFIG
=..
/aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
95 MALLOC_PERTURB_
=21 MALLOC_CHECK_
=2 LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
98 aptconfig
() { runapt apt
-config $
*; }
99 aptcache
() { runapt apt
-cache $
*; }
100 aptcdrom
() { runapt apt
-cdrom $
*; }
101 aptget
() { runapt apt
-get $
*; }
102 apt
() { runapt apt $
*; }
103 aptftparchive
() { runapt apt
-ftparchive $
*; }
104 aptkey
() { runapt apt
-key $
*; }
105 aptmark
() { runapt apt
-mark $
*; }
107 LD_LIBRARY_PATH
=${APTWEBSERVERBINDIR} ${APTWEBSERVERBINDIR}/aptwebserver $
*;
110 $(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir
--force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir
/var
/log
/dpkg.log $
*
113 if [ -f .
/aptconfig.conf
]; then
114 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which aptitude) $
*
115 elif [ -f ..
/aptconfig.conf
]; then
116 APT_CONFIG
=..
/aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which aptitude) $
*
118 LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which aptitude) $
*
123 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which gdb) ${BUILDDIRECTORY}/$1 --args $
*
126 LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods
/http
130 # error if we about to overflow, but ...
131 # "255 failures ought to be enough for everybody"
132 if [ $EXIT_CODE -gt 255 ]; then
133 msgdie
"Total failure count $EXIT_CODE too big"
135 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
138 shellsetedetector
() {
140 if [ "$exit_status" != '0' ]; then
141 echo >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}"
142 if [ "$EXIT_CODE" = '0' ]; then
143 EXIT_CODE
="$exit_status"
149 if [ "$1" = 'prefix' ]; then
150 CURRENTTRAP
="$2 $CURRENTTRAP"
152 CURRENTTRAP
="$CURRENTTRAP $1"
154 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
158 TMPWORKINGDIRECTORY
=$(mktemp -d)
159 TESTDIRECTORY
=$(readlink -f $(dirname $0))
160 msgninfo
"Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
162 # allow overriding the default BUILDDIR location
163 BUILDDIRECTORY
=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
164 METHODSDIR
=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
165 APTWEBSERVERBINDIR
=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
166 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
169 addtrap
"cd /; rm -rf $TMPWORKINGDIRECTORY;"
170 cd $TMPWORKINGDIRECTORY
171 mkdir rootdir aptarchive keys
173 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
174 mkdir -p var
/cache var
/lib var
/log
175 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
176 touch var
/lib
/dpkg
/available
178 ln -s ${BUILDDIRECTORY}/methods usr
/lib
/apt
/methods
180 local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
181 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
182 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
184 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
185 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
186 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
188 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/
189 ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
190 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
191 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
192 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
193 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
194 echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
195 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
196 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
197 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
198 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
199 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
200 if ! $(which dpkg) --assert-multi-arch >/dev
/null
2>&1; then
201 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf
# Added to test multiarch before dpkg is ready for it…
203 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
204 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
205 echo "Acquire::https::CaInfo \"${TESTDIR}/apt.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
206 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir
/etc
/apt
/apt.conf.d
/apt
-binary
208 export PATH
="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
209 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
214 if [ "$1" = "native" -o -z "$1" ]; then
215 eval `aptconfig shell ARCH APT::Architecture`
216 if [ -n "$ARCH" ]; then
219 dpkg
--print-architecture
227 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
230 configarchitecture
() {
232 echo "APT::Architecture \"$(getarchitecture $1)\";"
233 while [ -n "$1" ]; do
234 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
237 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
242 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
243 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
244 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
245 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
247 echo -n > rootdir/var/lib/dpkg/status
250 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
251 if $(which dpkg) --assert-multi-arch >/dev/null 2>&1; then
252 local ARCHS="$(getarchitectures)"
253 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
254 DPKGARCH="$(dpkg --print-architecture)"
255 for ARCH in ${ARCHS}; do
256 if [ "${ARCH}" != "${DPKGARCH}" ]; then
257 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
258 # old-style used e.g. in Ubuntu-P – and as it seems travis
259 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
260 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
264 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
265 # dpkg doesn't really check the version as long as it is fully installed,
266 # but just to be sure we choose one above the required version
267 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
273 configcompression() {
274 while [ -n "$1" ]; do
276 '.') echo ".
\t.
\tcat
";;
277 'gz') echo "gzip\tgz
\tgzip
";;
278 'bz2') echo "bzip2\tbz
2\tbzip
2";;
279 'lzma') echo "lzma
\tlzma
\txz
--format=lzma
";;
280 'xz') echo "xz
\txz
\txz
";;
281 *) echo "$1\t$1\t$1";;
284 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
287 setupsimplenativepackage() {
291 local RELEASE="${4:-unstable}"
292 local DEPENDENCIES="$5"
293 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
294 If you
find such a package installed on your system
,
295 something went horribly wrong
! They are autogenerated
296 und used only by testcases and surf no other propose…
"}"
298 local SECTION
="${7:-others}"
300 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
303 DISTSECTION
="$(echo "$SECTION" | cut -d'/' -f 1)"
305 local BUILDDIR
=incoming
/${NAME}-${VERSION}
306 mkdir -p ${BUILDDIR}/debian
/source
308 echo "* most suckless software product ever" > FEATURES
309 test -e debian
/copyright
|| echo "Copyleft by Joe Sixpack $(date +%Y)" > debian
/copyright
310 test -e debian
/changelog
|| echo "$NAME ($VERSION) $RELEASE; urgency=low
314 -- Joe Sixpack <joe@example.org> $(date -R)" > debian
/changelog
315 test -e debian
/control
|| echo "Source: $NAME
318 Maintainer: Joe Sixpack <joe@example.org>
319 Build-Depends: debhelper (>= 7)
320 Standards-Version: 3.9.1
322 Package: $NAME" > debian
/control
323 if [ "$ARCH" = 'all' ]; then
324 echo "Architecture: all" >> debian
/control
326 echo "Architecture: any" >> debian
/control
328 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian
/control
329 echo "Description: $DESCRIPTION" >> debian
/control
331 test -e debian
/compat
|| echo "7" > debian
/compat
332 test -e debian
/source
/format
|| echo "3.0 (native)" > debian
/source
/format
333 test -e debian
/rules
|| cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny debian
/rules
337 buildsimplenativepackage
() {
341 local RELEASE
="${4:-unstable}"
342 local DEPENDENCIES
="$5"
343 local DESCRIPTION
="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
344 If you find such a package installed on your system,
345 something went horribly wrong! They are autogenerated
346 und used only by testcases and surf no other propose…"}"
348 local SECTION="${7:-others}"
349 local PRIORITY="${8:-optional}"
352 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
355 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
357 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
359 msgninfo "Build package
${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}…
"
360 mkdir -p $BUILDDIR/debian/source
361 echo "* most suckless software product ever
" > ${BUILDDIR}/FEATURES
363 echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
365 echo "Copyleft by Joe Sixpack
$(date +%Y)" > ${BUILDDIR}/debian/copyright
366 echo "$NAME ($VERSION) $RELEASE; urgency
=low
370 -- Joe Sixpack
<joe@example.org
> $(date -R)" > ${BUILDDIR}/debian/changelog
374 Maintainer
: Joe Sixpack
<joe@example.org
>
375 Standards
-Version: 3.9.3" > ${BUILDDIR}/debian/control
376 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
377 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
379 Package
: $NAME" >> ${BUILDDIR}/debian/control
381 if [ "$ARCH" = 'all' ]; then
382 echo "Architecture
: all
" >> ${BUILDDIR}/debian/control
384 echo "Architecture
: any
" >> ${BUILDDIR}/debian/control
386 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
387 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
388 echo "Description
: $DESCRIPTION" >> ${BUILDDIR}/debian/control
390 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
391 (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' \
393 echo "pool
/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
394 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
395 # gpg --yes --no-default-keyring --secret-keyring ./keys/joesixpack.sec \
396 # --keyring ./keys/joesixpack.pub --default-key 'Joe Sixpack' \
397 # --clearsign -o "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
398 # mv "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
402 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
403 rm -rf ${BUILDDIR}/debian
/tmp
404 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
405 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
406 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
407 if [ -n "$FILE_TREE" ]; then
408 cp -ar "$FILE_TREE" ${BUILDDIR}/debian
/tmp
411 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
412 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
413 dpkg
-deb --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
2> /dev
/null
> /dev
/null
414 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
417 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
418 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
419 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
428 local ARCH
=$(getarchitecture $4)
429 msgninfo
"Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… "
431 if [ "$ARCH" = "all" ]; then
432 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
434 local BUILT
="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
435 local PKGS
="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
436 local SRCS
="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
439 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
442 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
448 if [ -d incoming
]; then
449 buildaptarchivefromincoming $
*
451 buildaptarchivefromfiles $
*
455 createaptftparchiveconfig
() {
456 local COMPRESSORS
="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
457 COMPRESSORS
="${COMPRESSORS%* }"
458 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' ' ')"
459 if [ -z "$ARCHS" ]; then
460 # the pool is empty, so we will operate on faked packages - let us use the configured archs
461 ARCHS
="$(getarchitectures)"
464 ArchiveDir "' >> ftparchive.conf
465 echo -n $(readlink -f .) >> ftparchive.conf
467 CacheDir "' >> ftparchive.conf
468 echo -n $(readlink -f ..) >> ftparchive.conf
470 FileListDir "' >> ftparchive.conf
471 echo -n $(readlink -f pool/) >> ftparchive.conf
475 Packages::Compress "'"$COMPRESSORS"'";
476 Sources::Compress "'"$COMPRESSORS"'";
477 Contents::Compress "'"$COMPRESSORS"'";
478 Translation::Compress "'"$COMPRESSORS"'";
479 LongDescription "false";
483 SrcDirectory "pool/";
489 Label "apttestcases";
491 Description "repository with dummy packages";
492 Architectures "' >> ftparchive.conf
493 echo -n "$ARCHS" >> ftparchive.conf
497 };' >> ftparchive.conf
498 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
499 echo -n 'tree "dists/' >> ftparchive.conf
500 echo -n "$DIST" >> ftparchive.conf
502 Architectures "' >> ftparchive.conf
503 echo -n "$ARCHS" >> ftparchive.conf
505 FileList "' >> ftparchive.conf
506 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
508 SourceFileList "' >> ftparchive.conf
509 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
511 Sections "' >> ftparchive.conf
512 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
514 };' >> ftparchive.conf
518 buildaptftparchivedirectorystructure
() {
519 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
520 for DIST
in $DISTS; do
521 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
522 for SECTION
in $SECTIONS; do
523 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
524 for ARCH
in $ARCHS; do
525 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
527 mkdir -p dists
/${DIST}/${SECTION}/source
528 mkdir -p dists
/${DIST}/${SECTION}/i18n
538 local DEPENDENCIES
="$5"
539 local PRIORITY
="${6:-optional}"
540 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
541 If you find such a package installed on your system,
542 something went horribly wrong! They are autogenerated
543 und used only by testcases and surf no other propose…"}"
545 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
546 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
547 ARCHS
="$(getarchitectures)"
551 for BUILDARCH
in $ARCHS; do
552 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
553 mkdir -p $PPATH aptarchive
/dists
/${RELEASE}/main
/source
554 touch aptarchive
/dists
/${RELEASE}/main
/source
/Sources
555 local FILE
="${PPATH}/Packages"
560 Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
561 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
562 echo "Version: $VERSION
563 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
564 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
565 echo "Description: $DESCRIPTION" >> $FILE
576 local DEPENDENCIES
="$5"
578 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
580 local FILE
="${SPATH}/Sources"
584 Maintainer: Joe Sixpack <joe@example.org>
585 Architecture: $ARCH" >> $FILE
586 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
588 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
589 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
593 insertinstalledpackage
() {
597 local DEPENDENCIES
="$4"
598 local PRIORITY
="${5:-optional}"
599 local STATUS
="${6:-install ok installed}"
600 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
601 If you find such a package installed on your system,
602 something went horribly wrong! They are autogenerated
603 und used only by testcases and surf no other propose…"}"
605 local FILE='rootdir/var/lib/dpkg/status'
606 local INFO='rootdir/var/lib/dpkg/info'
607 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
613 Maintainer: Joe Sixpack <joe@example.org>
614 Version: $VERSION" >> $FILE
615 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
616 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
617 echo "Description: $DESCRIPTION" >> $FILE
619 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
620 echo -n > ${INFO}/${NAME}:${arch}.list
622 echo -n > ${INFO}/${NAME}.list
628 buildaptarchivefromincoming
() {
629 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
631 [ -e pool
] || ln -s ..
/incoming pool
632 [ -e ftparchive.conf
] || createaptftparchiveconfig
633 [ -e dists
] || buildaptftparchivedirectorystructure
634 msgninfo
"\tGenerate Packages, Sources and Contents files… "
635 aptftparchive
-qq generate ftparchive.conf
641 buildaptarchivefromfiles
() {
642 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
643 find aptarchive
-name 'Packages' -o -name 'Sources' | while read line
; do
644 msgninfo
"\t${line} file… "
645 compressfile
"$line" "$1"
648 generatereleasefiles
"$@"
652 cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
| while read compressor extension
command; do
653 if [ "$compressor" = '.' ]; then
659 cat "$1" | $command > "${1}.${extension}"
661 touch -d "$2" "${1}.${extension}"
666 # can be overridden by testcases for their pleasure
667 getcodenamefromsuite
() { echo -n "$1"; }
668 getreleaseversionfromsuite
() { true
; }
669 getlabelfromsuite
() { true
; }
671 generatereleasefiles
() {
672 # $1 is the Date header and $2 is the ValidUntil header to be set
673 # both should be given in notation date/touch can understand
674 msgninfo
"\tGenerate Release files… "
675 if [ -e aptarchive
/dists
]; then
676 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
677 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
678 local CODENAME
="$(getcodenamefromsuite $SUITE)"
679 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
680 local LABEL
="$(getlabelfromsuite $SUITE)"
681 if [ -n "$VERSION" ]; then
682 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
684 if [ -n "$LABEL" ]; then
685 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
687 aptftparchive
-qq release
$dir \
688 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
689 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
692 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
693 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
695 NotAutomatic: yes' $dir/Release
697 if [ -n "$1" -a "$1" != "now" ]; then
698 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
702 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
706 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
708 if [ -n "$1" -a "$1" != "now" ]; then
709 for release
in $(find ./aptarchive -name 'Release'); do
710 touch -d "$1" $release
716 setupdistsaptarchive
() {
717 local APTARCHIVE
=$(readlink -f ./aptarchive)
718 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
719 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
720 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
721 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
722 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
723 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
724 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
729 setupflataptarchive
() {
730 local APTARCHIVE
=$(readlink -f ./aptarchive)
731 if [ -f ${APTARCHIVE}/Packages
]; then
732 msgninfo
"\tadd deb sources.list line… "
733 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
736 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
738 if [ -f ${APTARCHIVE}/Sources
]; then
739 msgninfo
"\tadd deb-src sources.list line… "
740 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
743 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
749 if [ -e aptarchive
/dists
]; then
755 if [ "$1" != '--no-update' ]; then
756 msgninfo
"\tSync APT's cache with the archive… "
763 local SIGNER
="${1:-Joe Sixpack}"
764 local GPG
="gpg --batch --yes --no-default-keyring --trustdb-name rootdir/etc/apt/trustdb.gpg"
765 msgninfo
"\tSign archive with $SIGNER key… "
766 local REXKEY
='keys/rexexpired'
767 local SECEXPIREBAK
="${REXKEY}.sec.bak"
768 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
769 if [ "${SIGNER}" = 'Rex Expired' ]; then
770 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
771 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
772 # therefore we 'temporary' make the key not expired and restore a backup after signing
773 cp ${REXKEY}.sec
$SECEXPIREBAK
774 cp ${REXKEY}.pub
$PUBEXPIREBAK
775 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
776 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
777 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
778 cp $SECUNEXPIRED ${REXKEY}.sec
779 cp $PUBUNEXPIRED ${REXKEY}.pub
781 printf "expire\n1w\nsave\n" | $GPG --keyring ${REXKEY}.pub
--secret-keyring ${REXKEY}.sec
--command-fd 0 --edit-key "${SIGNER}" >/dev
/null
2>&1 || true
782 cp ${REXKEY}.sec
$SECUNEXPIRED
783 cp ${REXKEY}.pub
$PUBUNEXPIRED
786 for KEY
in $(find keys/ -name '*.sec'); do
787 GPG
="$GPG --secret-keyring $KEY"
789 for KEY
in $(find keys/ -name '*.pub'); do
790 GPG
="$GPG --keyring $KEY"
792 for RELEASE
in $(find aptarchive/ -name Release); do
793 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
794 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
795 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
796 # we might have set a specific date for the Release file, so copy it
797 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
799 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
800 mv -f $SECEXPIREBAK ${REXKEY}.sec
801 mv -f $PUBEXPIREBAK ${REXKEY}.pub
807 msgtest
"Set webserver config option '${1}' to" "$2"
808 downloadfile
"http://localhost:8080/_config/set/${1}/${2}" '/dev/null' >/dev
/null
809 local DOWNLOG
='download-testfile.log'
811 local STATUS
="$(mktemp)"
812 addtrap
"rm $STATUS;"
813 downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
814 if [ "$(cat "$STATUS")" = '200' ]; then
818 msgfail
"Statuscode was $(cat "$STATUS")"
822 rewritesourceslist
() {
823 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
824 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
825 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#http://localhost:4433/#${1}#"
829 changetowebserver
() {
830 if [ "$1" != '--no-rewrite' ]; then
831 rewritesourceslist
'http://localhost:8080/'
835 local LOG
='/dev/null'
836 if test -x ${APTWEBSERVERBINDIR}/aptwebserver
; then
838 aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1
839 local PID
="$(cat aptwebserver.pid)"
840 if [ -z "$PID" ]; then
841 msgdie
'Could not fork aptwebserver successfully'
846 msgdie
'You have to build aptwerbserver or install a webserver'
850 changetohttpswebserver
() {
851 if ! which stunnel4
>/dev
/null
; then
852 msgdie
'You need to install stunnel4 for https testcases'
854 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
855 changetowebserver
--no-rewrite
857 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
858 cert = ${TESTDIRECTORY}/apt.pem
864 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
865 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
866 local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
867 addtrap
'prefix' "kill ${PID};"
868 rewritesourceslist
'https://localhost:4433/'
872 mkdir -p rootdir
/media
/cdrom
/.disk
873 local CD
="$(readlink -f rootdir/media/cdrom)"
874 echo "acquire::cdrom::mount \"${CD}\";" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
875 echo 'acquire::cdrom::autodetect 0;' >> rootdir
/etc
/apt
/apt.conf.d
/00cdrom
876 echo -n "$1" > ${CD}/.disk
/info
877 if [ ! -d aptarchive
/dists
]; then
878 msgdie
'Flat file archive cdroms can not be created currently'
881 mv aptarchive
/dists
$CD
882 ln -s "$(readlink -f ./incoming)" $CD/pool
883 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
887 PROTO
="$(echo "$1" | cut -d':' -f 1)"
888 local DOWNLOG
="${TMPWORKINGDIRECTORY}/download.log"
892 echo "601 Configuration
893 Config-Item: Acquire::https::CaInfo=${TESTDIR}/apt.pem
894 Config-Item: Debug::Acquire::${PROTO}=1
900 # simple worker keeping stdin open until we are done (201) or error (400)
901 # and requesting new URIs on try-agains/redirects inbetween
902 { tail -n 999 -f "$DOWNLOG" & echo "TAILPID: $!"; } | while read f1 f2
; do
903 if [ "$f1" = 'TAILPID:' ]; then
905 elif [ "$f1" = 'New-URI:' ]; then
906 echo "600 Acquire URI
910 elif [ "$f1" = '201' ] || [ "$f1" = '400' ]; then
911 # tail would only die on next read – which never happens
912 test -z "$TAILPID" || kill -s HUP
"$TAILPID"
916 } | LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods
/${PROTO} 2>&1 | tee "$DOWNLOG"
918 # only if the file exists the download was successful
927 local DIFFTEXT
="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
928 if [ -n "$DIFFTEXT" ]; then
940 msgtest
"Test for correctness of file" "$FILE"
942 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
944 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
949 msgtest
"Test for no output of" "$*"
950 test -z "$($* 2>&1)" && msgpass
|| msgfail
954 local MSG
='Test of equality of'
955 if [ "$1" = '--nomsg' ]; then
960 local COMPAREFILE
=$(mktemp)
961 addtrap
"rm $COMPAREFILE;"
962 echo "$1" > $COMPAREFILE
965 if [ -n "$MSG" ]; then
968 $
* 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
972 local COMPAREFILE1
=$(mktemp)
973 local COMPAREFILE2
=$(mktemp)
974 local COMPAREAGAINST
=$(mktemp)
975 addtrap
"rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
976 echo "$1" > $COMPAREFILE1
977 echo "$2" > $COMPAREFILE2
979 msgtest
"Test for equality OR of" "$*"
980 $
* >$COMPAREAGAINST 2>&1 || true
981 (checkdiff
$COMPAREFILE1 $COMPAREAGAINST 1> /dev
/null
||
982 checkdiff
$COMPAREFILE2 $COMPAREAGAINST 1> /dev
/null
) && msgpass
||
983 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
984 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
989 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
992 while [ -n "$1" ]; do
994 N: Can't select versions from package '$1' as it is purely virtual"
995 PACKAGE
="${PACKAGE} $1"
998 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
1000 N: No packages found"
1001 local COMPAREFILE
=$(mktemp)
1002 addtrap
"rm $COMPAREFILE;"
1003 local ARCH
="$(getarchitecture 'native')"
1004 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1005 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1009 msgtest
"Test for non-existent packages" "apt-cache show $*"
1010 local SHOWPKG
="$(aptcache show $* 2>&1 | grep '^Package: ')"
1011 if [ -n "$SHOWPKG" ]; then
1020 testdpkginstalled
() {
1021 msgtest
"Test for correctly installed package(s) with" "dpkg -l $*"
1022 local PKGS
="$(dpkg -l $* 2>/dev/null | grep '^i' | wc -l)"
1023 if [ "$PKGS" != $# ]; then
1025 dpkg
-l $
* | grep '^[a-z]'
1032 testdpkgnotinstalled
() {
1033 msgtest
"Test for correctly not-installed package(s) with" "dpkg -l $*"
1034 local PKGS
="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)"
1035 if [ "$PKGS" != 0 ]; then
1037 dpkg
-l $
* | grep '^[a-z]'
1045 local COMPAREFILE
=$(mktemp)
1046 addtrap
"rm $COMPAREFILE;"
1047 if [ -n "$1" ]; then
1048 msgtest
'Test for correctly marked as auto-installed' "$*"
1049 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1051 msgtest
'Test for correctly marked as auto-installed' 'no package'
1052 echo -n > $COMPAREFILE
1054 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1058 if [ "$1" = '--nomsg' ]; then
1061 msgtest
'Test for successful execution of' "$*"
1063 local OUTPUT
=$(mktemp)
1064 addtrap
"rm $OUTPUT;"
1065 if $@
>${OUTPUT} 2>&1; then
1075 if [ "$1" = '--nomsg' ]; then
1078 msgtest
'Test for failure in execution of' "$*"
1080 local OUTPUT
=$(mktemp)
1081 addtrap
"rm $OUTPUT;"
1082 if $@
>${OUTPUT} 2>&1; then
1092 echo "STOPPED execution. Press enter to continue"