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 aptftparchive
() { runapt apt
-ftparchive $
*; }
103 aptkey
() { runapt apt
-key $
*; }
104 aptmark
() { runapt apt
-mark $
*; }
106 LD_LIBRARY_PATH
=${APTWEBSERVERBINDIR} ${APTWEBSERVERBINDIR}/aptwebserver $
*;
109 $(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir
--force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir
/var
/log
/dpkg.log $
*
112 if [ -f .
/aptconfig.conf
]; then
113 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which aptitude) $
*
114 elif [ -f ..
/aptconfig.conf
]; then
115 APT_CONFIG
=..
/aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which aptitude) $
*
117 LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which aptitude) $
*
122 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which gdb) ${BUILDDIRECTORY}/$1 --args $
*
125 LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods
/http
129 # error if we about to overflow, but ...
130 # "255 failures ought to be enough for everybody"
131 if [ $EXIT_CODE -gt 255 ]; then
132 msgdie
"Total failure count $EXIT_CODE too big"
134 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
137 shellsetedetector
() {
139 if [ "$exit_status" != '0' ]; then
140 echo >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}"
141 if [ "$EXIT_CODE" = '0' ]; then
142 EXIT_CODE
="$exit_status"
148 if [ "$1" = 'prefix' ]; then
149 CURRENTTRAP
="$2 $CURRENTTRAP"
151 CURRENTTRAP
="$CURRENTTRAP $1"
153 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
157 TMPWORKINGDIRECTORY
=$(mktemp -d)
158 TESTDIRECTORY
=$(readlink -f $(dirname $0))
159 msgninfo
"Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
161 # allow overriding the default BUILDDIR location
162 BUILDDIRECTORY
=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
163 METHODSDIR
=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
164 APTWEBSERVERBINDIR
=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
165 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
168 addtrap
"cd /; rm -rf $TMPWORKINGDIRECTORY;"
169 cd $TMPWORKINGDIRECTORY
170 mkdir rootdir aptarchive keys
172 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
173 mkdir -p var
/cache var
/lib var
/log
174 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
175 touch var
/lib
/dpkg
/available
177 ln -s ${BUILDDIRECTORY}/methods usr
/lib
/apt
/methods
179 local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
180 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
181 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
183 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
184 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
185 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
187 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/
188 ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
189 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
190 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
191 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
192 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
193 echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
194 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
195 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
196 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
197 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
198 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
199 if ! $(which dpkg) --assert-multi-arch >/dev
/null
2>&1; then
200 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf
# Added to test multiarch before dpkg is ready for it…
202 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
203 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
204 echo "Acquire::https::CaInfo \"${TESTDIR}/apt.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
205 export LC_ALL
=C.UTF
-8
206 export PATH
="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
207 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
212 if [ "$1" = "native" -o -z "$1" ]; then
213 eval `aptconfig shell ARCH APT::Architecture`
214 if [ -n "$ARCH" ]; then
217 dpkg
--print-architecture
225 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
228 configarchitecture
() {
230 echo "APT::Architecture \"$(getarchitecture $1)\";"
231 while [ -n "$1" ]; do
232 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
235 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
240 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
241 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
242 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
243 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
245 echo -n > rootdir/var/lib/dpkg/status
248 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
249 if $(which dpkg) --assert-multi-arch >/dev/null 2>&1; then
250 local ARCHS="$(getarchitectures)"
251 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
252 DPKGARCH="$(dpkg --print-architecture)"
253 for ARCH in ${ARCHS}; do
254 if [ "${ARCH}" != "${DPKGARCH}" ]; then
255 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
256 # old-style used e.g. in Ubuntu-P – and as it seems travis
257 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
258 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
262 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
263 # dpkg doesn't really check the version as long as it is fully installed,
264 # but just to be sure we choose one above the required version
265 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
271 configcompression() {
272 while [ -n "$1" ]; do
274 '.') echo ".
\t.
\tcat
";;
275 'gz') echo "gzip\tgz
\tgzip
";;
276 'bz2') echo "bzip2\tbz
2\tbzip
2";;
277 'lzma') echo "lzma
\tlzma
\txz
--format=lzma
";;
278 'xz') echo "xz
\txz
\txz
";;
279 *) echo "$1\t$1\t$1";;
282 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
285 setupsimplenativepackage() {
289 local RELEASE="${4:-unstable}"
290 local DEPENDENCIES="$5"
291 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
292 If you
find such a package installed on your system
,
293 something went horribly wrong
! They are autogenerated
294 und used only by testcases and surf no other propose…
"}"
296 local SECTION
="${7:-others}"
298 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
301 DISTSECTION
="$(echo "$SECTION" | cut -d'/' -f 1)"
303 local BUILDDIR
=incoming
/${NAME}-${VERSION}
304 mkdir -p ${BUILDDIR}/debian
/source
306 echo "* most suckless software product ever" > FEATURES
307 test -e debian
/copyright
|| echo "Copyleft by Joe Sixpack $(date +%Y)" > debian
/copyright
308 test -e debian
/changelog
|| echo "$NAME ($VERSION) $RELEASE; urgency=low
312 -- Joe Sixpack <joe@example.org> $(date -R)" > debian
/changelog
313 test -e debian
/control
|| echo "Source: $NAME
316 Maintainer: Joe Sixpack <joe@example.org>
317 Build-Depends: debhelper (>= 7)
318 Standards-Version: 3.9.1
320 Package: $NAME" > debian
/control
321 if [ "$ARCH" = 'all' ]; then
322 echo "Architecture: all" >> debian
/control
324 echo "Architecture: any" >> debian
/control
326 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian
/control
327 echo "Description: $DESCRIPTION" >> debian
/control
329 test -e debian
/compat
|| echo "7" > debian
/compat
330 test -e debian
/source
/format
|| echo "3.0 (native)" > debian
/source
/format
331 test -e debian
/rules
|| cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny debian
/rules
335 buildsimplenativepackage
() {
339 local RELEASE
="${4:-unstable}"
340 local DEPENDENCIES
="$5"
341 local DESCRIPTION
="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
342 If you find such a package installed on your system,
343 something went horribly wrong! They are autogenerated
344 und used only by testcases and surf no other propose…"}"
346 local SECTION="${7:-others}"
347 local PRIORITY="${8:-optional}"
350 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
353 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
355 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
357 msgninfo "Build package
${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}…
"
358 mkdir -p $BUILDDIR/debian/source
359 echo "* most suckless software product ever
" > ${BUILDDIR}/FEATURES
361 echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
363 echo "Copyleft by Joe Sixpack
$(date +%Y)" > ${BUILDDIR}/debian/copyright
364 echo "$NAME ($VERSION) $RELEASE; urgency
=low
368 -- Joe Sixpack
<joe@example.org
> $(date -R)" > ${BUILDDIR}/debian/changelog
372 Maintainer
: Joe Sixpack
<joe@example.org
>
373 Standards
-Version: 3.9.3" > ${BUILDDIR}/debian/control
374 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
375 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
377 Package
: $NAME" >> ${BUILDDIR}/debian/control
379 if [ "$ARCH" = 'all' ]; then
380 echo "Architecture
: all
" >> ${BUILDDIR}/debian/control
382 echo "Architecture
: any
" >> ${BUILDDIR}/debian/control
384 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
385 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
386 echo "Description
: $DESCRIPTION" >> ${BUILDDIR}/debian/control
388 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
389 (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' \
391 echo "pool
/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
392 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
393 # gpg --yes --no-default-keyring --secret-keyring ./keys/joesixpack.sec \
394 # --keyring ./keys/joesixpack.pub --default-key 'Joe Sixpack' \
395 # --clearsign -o "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
396 # mv "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
400 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
401 rm -rf ${BUILDDIR}/debian
/tmp
402 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
403 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
404 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
405 if [ -n "$FILE_TREE" ]; then
406 cp -ar "$FILE_TREE" ${BUILDDIR}/debian
/tmp
409 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
410 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
411 dpkg
-deb --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
2> /dev
/null
> /dev
/null
412 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
415 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
416 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
417 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
426 local ARCH
=$(getarchitecture $4)
427 msgninfo
"Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… "
429 if [ "$ARCH" = "all" ]; then
430 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
432 local BUILT
="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
433 local PKGS
="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
434 local SRCS
="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
437 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
440 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
446 if [ -d incoming
]; then
447 buildaptarchivefromincoming $
*
449 buildaptarchivefromfiles $
*
453 createaptftparchiveconfig
() {
454 local COMPRESSORS
="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
455 COMPRESSORS
="${COMPRESSORS%* }"
456 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' ' ')"
457 if [ -z "$ARCHS" ]; then
458 # the pool is empty, so we will operate on faked packages - let us use the configured archs
459 ARCHS
="$(getarchitectures)"
462 ArchiveDir "' >> ftparchive.conf
463 echo -n $(readlink -f .) >> ftparchive.conf
465 CacheDir "' >> ftparchive.conf
466 echo -n $(readlink -f ..) >> ftparchive.conf
468 FileListDir "' >> ftparchive.conf
469 echo -n $(readlink -f pool/) >> ftparchive.conf
473 Packages::Compress "'"$COMPRESSORS"'";
474 Sources::Compress "'"$COMPRESSORS"'";
475 Contents::Compress "'"$COMPRESSORS"'";
476 Translation::Compress "'"$COMPRESSORS"'";
477 LongDescription "false";
481 SrcDirectory "pool/";
487 Label "apttestcases";
489 Description "repository with dummy packages";
490 Architectures "' >> ftparchive.conf
491 echo -n "$ARCHS" >> ftparchive.conf
495 };' >> ftparchive.conf
496 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
497 echo -n 'tree "dists/' >> ftparchive.conf
498 echo -n "$DIST" >> ftparchive.conf
500 Architectures "' >> ftparchive.conf
501 echo -n "$ARCHS" >> ftparchive.conf
503 FileList "' >> ftparchive.conf
504 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
506 SourceFileList "' >> ftparchive.conf
507 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
509 Sections "' >> ftparchive.conf
510 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
512 };' >> ftparchive.conf
516 buildaptftparchivedirectorystructure
() {
517 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
518 for DIST
in $DISTS; do
519 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
520 for SECTION
in $SECTIONS; do
521 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
522 for ARCH
in $ARCHS; do
523 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
525 mkdir -p dists
/${DIST}/${SECTION}/source
526 mkdir -p dists
/${DIST}/${SECTION}/i18n
536 local DEPENDENCIES
="$5"
537 local PRIORITY
="${6:-optional}"
538 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
539 If you find such a package installed on your system,
540 something went horribly wrong! They are autogenerated
541 und used only by testcases and surf no other propose…"}"
543 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
544 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
545 ARCHS
="$(getarchitectures)"
549 for BUILDARCH
in $ARCHS; do
550 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
551 mkdir -p $PPATH aptarchive
/dists
/${RELEASE}/main
/source
552 touch aptarchive
/dists
/${RELEASE}/main
/source
/Sources
553 local FILE
="${PPATH}/Packages"
558 Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
559 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
560 echo "Version: $VERSION
561 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
562 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
563 echo "Description: $DESCRIPTION" >> $FILE
574 local DEPENDENCIES
="$5"
576 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
578 local FILE
="${SPATH}/Sources"
582 Maintainer: Joe Sixpack <joe@example.org>
583 Architecture: $ARCH" >> $FILE
584 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
586 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
587 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
591 insertinstalledpackage
() {
595 local DEPENDENCIES
="$4"
596 local PRIORITY
="${5:-optional}"
597 local STATUS
="${6:-install ok installed}"
598 local DESCRIPTION
="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
599 If you find such a package installed on your system,
600 something went horribly wrong! They are autogenerated
601 und used only by testcases and surf no other propose…"}"
603 local FILE='rootdir/var/lib/dpkg/status'
604 local INFO='rootdir/var/lib/dpkg/info'
605 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
611 Maintainer: Joe Sixpack <joe@example.org>
612 Version: $VERSION" >> $FILE
613 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
614 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
615 echo "Description: $DESCRIPTION" >> $FILE
617 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
618 echo -n > ${INFO}/${NAME}:${arch}.list
620 echo -n > ${INFO}/${NAME}.list
626 buildaptarchivefromincoming
() {
627 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
629 [ -e pool
] || ln -s ..
/incoming pool
630 [ -e ftparchive.conf
] || createaptftparchiveconfig
631 [ -e dists
] || buildaptftparchivedirectorystructure
632 msgninfo
"\tGenerate Packages, Sources and Contents files… "
633 aptftparchive
-qq generate ftparchive.conf
639 buildaptarchivefromfiles
() {
640 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
641 find aptarchive
-name 'Packages' -o -name 'Sources' | while read line
; do
642 msgninfo
"\t${line} file… "
643 compressfile
"$line" "$1"
646 generatereleasefiles
"$@"
650 cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
| while read compressor extension
command; do
651 if [ "$compressor" = '.' ]; then
657 cat "$1" | $command > "${1}.${extension}"
659 touch -d "$2" "${1}.${extension}"
664 # can be overridden by testcases for their pleasure
665 getcodenamefromsuite
() {
667 unstable
) echo 'sid';;
671 getreleaseversionfromsuite
() { true
; }
672 getlabelfromsuite
() { true
; }
674 generatereleasefiles
() {
675 # $1 is the Date header and $2 is the ValidUntil header to be set
676 # both should be given in notation date/touch can understand
677 msgninfo
"\tGenerate Release files… "
678 if [ -e aptarchive
/dists
]; then
679 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
680 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
681 local CODENAME
="$(getcodenamefromsuite $SUITE)"
682 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
683 local LABEL
="$(getlabelfromsuite $SUITE)"
684 if [ -n "$VERSION" ]; then
685 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
687 if [ -n "$LABEL" ]; then
688 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
690 aptftparchive
-qq release
$dir \
691 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
692 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
695 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
696 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
698 NotAutomatic: yes' $dir/Release
700 if [ -n "$1" -a "$1" != "now" ]; then
701 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
705 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
709 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
711 if [ -n "$1" -a "$1" != "now" ]; then
712 for release
in $(find ./aptarchive -name 'Release'); do
713 touch -d "$1" $release
719 setupdistsaptarchive
() {
720 local APTARCHIVE
=$(readlink -f ./aptarchive)
721 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
722 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
723 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
724 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
725 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
726 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
727 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
732 setupflataptarchive
() {
733 local APTARCHIVE
=$(readlink -f ./aptarchive)
734 if [ -f ${APTARCHIVE}/Packages
]; then
735 msgninfo
"\tadd deb sources.list line… "
736 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
739 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
741 if [ -f ${APTARCHIVE}/Sources
]; then
742 msgninfo
"\tadd deb-src sources.list line… "
743 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
746 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
752 if [ -e aptarchive
/dists
]; then
758 if [ "$1" != '--no-update' ]; then
759 msgninfo
"\tSync APT's cache with the archive… "
766 local SIGNER
="${1:-Joe Sixpack}"
767 local GPG
="gpg --batch --yes --no-default-keyring --trustdb-name rootdir/etc/apt/trustdb.gpg"
768 msgninfo
"\tSign archive with $SIGNER key… "
769 local REXKEY
='keys/rexexpired'
770 local SECEXPIREBAK
="${REXKEY}.sec.bak"
771 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
772 if [ "${SIGNER}" = 'Rex Expired' ]; then
773 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
774 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
775 # therefore we 'temporary' make the key not expired and restore a backup after signing
776 cp ${REXKEY}.sec
$SECEXPIREBAK
777 cp ${REXKEY}.pub
$PUBEXPIREBAK
778 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
779 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
780 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
781 cp $SECUNEXPIRED ${REXKEY}.sec
782 cp $PUBUNEXPIRED ${REXKEY}.pub
784 printf "expire\n1w\nsave\n" | $GPG --keyring ${REXKEY}.pub
--secret-keyring ${REXKEY}.sec
--command-fd 0 --edit-key "${SIGNER}" >/dev
/null
2>&1 || true
785 cp ${REXKEY}.sec
$SECUNEXPIRED
786 cp ${REXKEY}.pub
$PUBUNEXPIRED
789 for KEY
in $(find keys/ -name '*.sec'); do
790 GPG
="$GPG --secret-keyring $KEY"
792 for KEY
in $(find keys/ -name '*.pub'); do
793 GPG
="$GPG --keyring $KEY"
795 for RELEASE
in $(find aptarchive/ -name Release); do
796 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
797 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
798 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
799 # we might have set a specific date for the Release file, so copy it
800 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
802 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
803 mv -f $SECEXPIREBAK ${REXKEY}.sec
804 mv -f $PUBEXPIREBAK ${REXKEY}.pub
810 msgtest
"Set webserver config option '${1}' to" "$2"
811 downloadfile
"http://localhost:8080/_config/set/${1}/${2}" '/dev/null' >/dev
/null
812 local DOWNLOG
='download-testfile.log'
814 local STATUS
="$(mktemp)"
815 addtrap
"rm $STATUS;"
816 downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
817 if [ "$(cat "$STATUS")" = '200' ]; then
821 msgfail
"Statuscode was $(cat "$STATUS")"
825 rewritesourceslist
() {
826 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
827 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
828 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#http://localhost:4433/#${1}#"
832 changetowebserver
() {
833 if [ "$1" != '--no-rewrite' ]; then
834 rewritesourceslist
'http://localhost:8080/'
838 if test -x ${APTWEBSERVERBINDIR}/aptwebserver
; then
840 local LOG
="$(mktemp)"
842 if ! aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1 ; then
846 local PID
="$(cat aptwebserver.pid)"
847 if [ -z "$PID" ]; then
848 msgdie
'Could not fork aptwebserver successfully'
853 msgdie
'You have to build aptwerbserver or install a webserver'
857 changetohttpswebserver
() {
858 if ! which stunnel4
>/dev
/null
; then
859 msgdie
'You need to install stunnel4 for https testcases'
861 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
862 changetowebserver
--no-rewrite
864 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
865 cert = ${TESTDIRECTORY}/apt.pem
871 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
872 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
873 local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
874 addtrap
'prefix' "kill ${PID};"
875 rewritesourceslist
'https://localhost:4433/'
879 mkdir -p rootdir
/media
/cdrom
/.disk
880 local CD
="$(readlink -f rootdir/media/cdrom)"
881 echo "acquire::cdrom::mount \"${CD}\";" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
882 echo 'acquire::cdrom::autodetect 0;' >> rootdir
/etc
/apt
/apt.conf.d
/00cdrom
883 echo -n "$1" > ${CD}/.disk
/info
884 if [ ! -d aptarchive
/dists
]; then
885 msgdie
'Flat file archive cdroms can not be created currently'
888 mv aptarchive
/dists
$CD
889 ln -s "$(readlink -f ./incoming)" $CD/pool
890 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
894 PROTO
="$(echo "$1" | cut -d':' -f 1)"
895 local DOWNLOG
="${TMPWORKINGDIRECTORY}/download.log"
899 echo "601 Configuration
900 Config-Item: Acquire::https::CaInfo=${TESTDIR}/apt.pem
901 Config-Item: Debug::Acquire::${PROTO}=1
907 # simple worker keeping stdin open until we are done (201) or error (400)
908 # and requesting new URIs on try-agains/redirects inbetween
909 { tail -n 999 -f "$DOWNLOG" & echo "TAILPID: $!"; } | while read f1 f2
; do
910 if [ "$f1" = 'TAILPID:' ]; then
912 elif [ "$f1" = 'New-URI:' ]; then
913 echo "600 Acquire URI
917 elif [ "$f1" = '201' ] || [ "$f1" = '400' ]; then
918 # tail would only die on next read – which never happens
919 test -z "$TAILPID" || kill -s HUP
"$TAILPID"
923 } | LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods
/${PROTO} 2>&1 | tee "$DOWNLOG"
925 # only if the file exists the download was successful
934 local DIFFTEXT
="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
935 if [ -n "$DIFFTEXT" ]; then
947 msgtest
"Test for correctness of file" "$FILE"
949 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
951 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
956 msgtest
"Test for no output of" "$*"
957 test -z "$($* 2>&1)" && msgpass
|| msgfail
961 local COMPAREFILE
=$(mktemp)
962 addtrap
"rm $COMPAREFILE;"
963 echo "$1" > $COMPAREFILE
965 msgtest
"Test for equality of" "$*"
966 $
* 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
970 local COMPAREFILE1
=$(mktemp)
971 local COMPAREFILE2
=$(mktemp)
972 local COMPAREAGAINST
=$(mktemp)
973 addtrap
"rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
974 echo "$1" > $COMPAREFILE1
975 echo "$2" > $COMPAREFILE2
977 msgtest
"Test for equality OR of" "$*"
978 $
* >$COMPAREAGAINST 2>&1 || true
979 (checkdiff
$COMPAREFILE1 $COMPAREAGAINST 1> /dev
/null
||
980 checkdiff
$COMPAREFILE2 $COMPAREAGAINST 1> /dev
/null
) && msgpass
||
981 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
982 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
987 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
990 while [ -n "$1" ]; do
992 N: Can't select versions from package '$1' as it is purely virtual"
993 PACKAGE
="${PACKAGE} $1"
996 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
998 N: No packages found"
999 local COMPAREFILE
=$(mktemp)
1000 addtrap
"rm $COMPAREFILE;"
1001 local ARCH
="$(getarchitecture 'native')"
1002 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
1003 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1007 msgtest
"Test for non-existent packages" "apt-cache show $*"
1008 local SHOWPKG
="$(aptcache show $* 2>&1 | grep '^Package: ')"
1009 if [ -n "$SHOWPKG" ]; then
1018 testdpkginstalled
() {
1019 msgtest
"Test for correctly installed package(s) with" "dpkg -l $*"
1020 local PKGS
="$(dpkg -l $* 2>/dev/null | grep '^i' | wc -l)"
1021 if [ "$PKGS" != $# ]; then
1023 dpkg
-l $
* | grep '^[a-z]'
1030 testdpkgnotinstalled
() {
1031 msgtest
"Test for correctly not-installed package(s) with" "dpkg -l $*"
1032 local PKGS
="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)"
1033 if [ "$PKGS" != 0 ]; then
1035 dpkg
-l $
* | grep '^[a-z]'
1043 local COMPAREFILE
=$(mktemp)
1044 addtrap
"rm $COMPAREFILE;"
1045 if [ -n "$1" ]; then
1046 msgtest
'Test for correctly marked as auto-installed' "$*"
1047 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1049 msgtest
'Test for correctly marked as auto-installed' 'no package'
1050 echo -n > $COMPAREFILE
1052 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1056 if [ "$1" = '--nomsg' ]; then
1059 msgtest
'Test for successful execution of' "$*"
1061 local OUTPUT
=$(mktemp)
1062 addtrap
"rm $OUTPUT;"
1063 if $@
>${OUTPUT} 2>&1; then
1073 if [ "$1" = '--nomsg' ]; then
1076 msgtest
'Test for failure in execution of' "$*"
1078 local OUTPUT
=$(mktemp)
1079 addtrap
"rm $OUTPUT;"
1080 if $@
>${OUTPUT} 2>&1; then
1090 echo "STOPPED execution. Press enter to continue"