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 $(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir
--force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir
/var
/log
/dpkg.log $
*
109 if [ -f .
/aptconfig.conf
]; then
110 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which aptitude) $
*
111 elif [ -f ..
/aptconfig.conf
]; then
112 APT_CONFIG
=..
/aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which aptitude) $
*
114 LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which aptitude) $
*
119 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which gdb) ${BUILDDIRECTORY}/$1 --args $
*
122 LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods
/http
126 # error if we about to overflow, but ...
127 # "255 failures ought to be enough for everybody"
128 if [ $EXIT_CODE -gt 255 ]; then
129 msgdie
"Total failure count $EXIT_CODE too big"
131 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
134 shellsetedetector
() {
136 if [ "$exit_status" != '0' ]; then
137 echo >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}"
138 if [ "$EXIT_CODE" = '0' ]; then
139 EXIT_CODE
="$exit_status"
145 if [ "$1" = 'prefix' ]; then
146 CURRENTTRAP
="$2 $CURRENTTRAP"
148 CURRENTTRAP
="$CURRENTTRAP $1"
150 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
154 TMPWORKINGDIRECTORY
=$(mktemp -d)
155 TESTDIRECTORY
=$(readlink -f $(dirname $0))
156 msgninfo
"Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
157 BUILDDIRECTORY
="${TESTDIRECTORY}/../../build/bin"
158 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
159 addtrap
"cd /; rm -rf $TMPWORKINGDIRECTORY;"
160 cd $TMPWORKINGDIRECTORY
161 mkdir rootdir aptarchive keys
163 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
164 mkdir -p var
/cache var
/lib var
/log
165 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
166 touch var
/lib
/dpkg
/available
168 ln -s ${BUILDDIRECTORY}/methods usr
/lib
/apt
/methods
170 local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
171 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
172 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
174 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
175 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
176 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
178 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/
179 ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
180 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
181 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
182 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
183 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
184 echo "Dir::Bin::Methods \"${BUILDDIRECTORY}/methods\";" >> aptconfig.conf
185 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
186 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
187 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
188 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
189 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
190 if ! $(which dpkg) --assert-multi-arch >/dev
/null
2>&1; then
191 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf
# Added to test multiarch before dpkg is ready for it…
193 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
194 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
195 echo "Acquire::https::CaInfo \"${TESTDIR}/apt.pem\";" > rootdir
/etc
/apt
/apt.conf.d
/99https
197 export PATH
="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
198 configcompression
'.' 'gz' #'bz2' 'lzma' 'xz'
203 if [ "$1" = "native" -o -z "$1" ]; then
204 eval `aptconfig shell ARCH APT::Architecture`
205 if [ -n "$ARCH" ]; then
208 dpkg
--print-architecture
216 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
219 configarchitecture
() {
221 echo "APT::Architecture \"$(getarchitecture $1)\";"
222 while [ -n "$1" ]; do
223 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
226 } >rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
231 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
232 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
233 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
234 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
236 echo -n > rootdir/var/lib/dpkg/status
239 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
240 if $(which dpkg) --assert-multi-arch >/dev/null 2>&1; then
241 local ARCHS="$(getarchitectures)"
242 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
243 DPKGARCH="$(dpkg --print-architecture)"
244 for ARCH in ${ARCHS}; do
245 if [ "${ARCH}" != "${DPKGARCH}" ]; then
246 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
247 # old-style used e.g. in Ubuntu-P – and as it seems travis
248 echo "DPKG
::options
:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
249 echo "DPKG
::options
:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
253 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
254 # dpkg doesn't really check the version as long as it is fully installed,
255 # but just to be sure we choose one above the required version
256 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
262 configcompression() {
263 while [ -n "$1" ]; do
265 '.') echo ".
\t.
\tcat
";;
266 'gz') echo "gzip\tgz
\tgzip
";;
267 'bz2') echo "bzip2\tbz
2\tbzip
2";;
268 'lzma') echo "lzma
\tlzma
\txz
--format=lzma
";;
269 'xz') echo "xz
\txz
\txz
";;
270 *) echo "$1\t$1\t$1";;
273 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
276 setupsimplenativepackage() {
280 local RELEASE="${4:-unstable}"
281 local DEPENDENCIES="$5"
282 local DESCRIPTION="${6:-"Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
283 If you
find such a package installed on your system
,
284 something went horribly wrong
! They are autogenerated
285 und used only by testcases and surf no other propose…
"}"
287 local SECTION
="${7:-others}"
289 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
292 DISTSECTION
="$(echo "$SECTION" | cut -d'/' -f 1)"
294 local BUILDDIR
=incoming
/${NAME}-${VERSION}
295 mkdir -p ${BUILDDIR}/debian
/source
297 echo "* most suckless software product ever" > FEATURES
298 test -e debian
/copyright
|| echo "Copyleft by Joe Sixpack $(date +%Y)" > debian
/copyright
299 test -e debian
/changelog
|| echo "$NAME ($VERSION) $RELEASE; urgency=low
303 -- Joe Sixpack <joe@example.org> $(date -R)" > debian
/changelog
304 test -e debian
/control
|| echo "Source: $NAME
307 Maintainer: Joe Sixpack <joe@example.org>
308 Build-Depends: debhelper (>= 7)
309 Standards-Version: 3.9.1
311 Package: $NAME" > debian
/control
312 if [ "$ARCH" = 'all' ]; then
313 echo "Architecture: all" >> debian
/control
315 echo "Architecture: any" >> debian
/control
317 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian
/control
318 echo "Description: $DESCRIPTION" >> debian
/control
320 test -e debian
/compat
|| echo "7" > debian
/compat
321 test -e debian
/source
/format
|| echo "3.0 (native)" > debian
/source
/format
322 test -e debian
/rules
|| cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny debian
/rules
326 buildsimplenativepackage
() {
330 local RELEASE
="${4:-unstable}"
331 local DEPENDENCIES
="$5"
332 local DESCRIPTION
="${6:-"Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
333 If you find such a package installed on your system,
334 something went horribly wrong! They are autogenerated
335 und used only by testcases and surf no other propose…"}"
337 local SECTION="${7:-others}"
338 local PRIORITY="${8:-optional}"
341 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
344 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
346 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
348 msgninfo "Build package
${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}…
"
349 mkdir -p $BUILDDIR/debian/source
350 echo "* most suckless software product ever
" > ${BUILDDIR}/FEATURES
352 echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
354 echo "Copyleft by Joe Sixpack
$(date +%Y)" > ${BUILDDIR}/debian/copyright
355 echo "$NAME ($VERSION) $RELEASE; urgency
=low
359 -- Joe Sixpack
<joe@example.org
> $(date -R)" > ${BUILDDIR}/debian/changelog
363 Maintainer
: Joe Sixpack
<joe@example.org
>
364 Standards
-Version: 3.9.3" > ${BUILDDIR}/debian/control
365 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
366 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
368 Package
: $NAME" >> ${BUILDDIR}/debian/control
370 if [ "$ARCH" = 'all' ]; then
371 echo "Architecture
: all
" >> ${BUILDDIR}/debian/control
373 echo "Architecture
: any
" >> ${BUILDDIR}/debian/control
375 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
376 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
377 echo "Description
: $DESCRIPTION" >> ${BUILDDIR}/debian/control
379 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
380 (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' \
382 echo "pool
/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
383 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
384 # gpg --yes --no-default-keyring --secret-keyring ./keys/joesixpack.sec \
385 # --keyring ./keys/joesixpack.pub --default-key 'Joe Sixpack' \
386 # --clearsign -o "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
387 # mv "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
391 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
392 rm -rf ${BUILDDIR}/debian
/tmp
393 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
394 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
395 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
396 if [ -n "$FILE_TREE" ]; then
397 cp -ar "$FILE_TREE" ${BUILDDIR}/debian
/tmp
400 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
401 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
402 dpkg
-deb --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
2> /dev
/null
> /dev
/null
403 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
406 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
407 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
408 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
417 local ARCH
=$(getarchitecture $4)
418 msgninfo
"Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… "
420 if [ "$ARCH" = "all" ]; then
421 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
423 local BUILT
="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
424 local PKGS
="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
425 local SRCS
="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
428 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
431 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
437 if [ -d incoming
]; then
438 buildaptarchivefromincoming $
*
440 buildaptarchivefromfiles $
*
444 createaptftparchiveconfig
() {
445 local COMPRESSORS
="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
446 COMPRESSORS
="${COMPRESSORS%* }"
447 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' ' ')"
448 if [ -z "$ARCHS" ]; then
449 # the pool is empty, so we will operate on faked packages - let us use the configured archs
450 ARCHS
="$(getarchitectures)"
453 ArchiveDir "' >> ftparchive.conf
454 echo -n $(readlink -f .) >> ftparchive.conf
456 CacheDir "' >> ftparchive.conf
457 echo -n $(readlink -f ..) >> ftparchive.conf
459 FileListDir "' >> ftparchive.conf
460 echo -n $(readlink -f pool/) >> ftparchive.conf
464 Packages::Compress "'"$COMPRESSORS"'";
465 Sources::Compress "'"$COMPRESSORS"'";
466 Contents::Compress "'"$COMPRESSORS"'";
467 Translation::Compress "'"$COMPRESSORS"'";
468 LongDescription "false";
472 SrcDirectory "pool/";
478 Label "apttestcases";
480 Description "repository with dummy packages";
481 Architectures "' >> ftparchive.conf
482 echo -n "$ARCHS" >> ftparchive.conf
486 };' >> ftparchive.conf
487 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
488 echo -n 'tree "dists/' >> ftparchive.conf
489 echo -n "$DIST" >> ftparchive.conf
491 Architectures "' >> ftparchive.conf
492 echo -n "$ARCHS" >> ftparchive.conf
494 FileList "' >> ftparchive.conf
495 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
497 SourceFileList "' >> ftparchive.conf
498 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
500 Sections "' >> ftparchive.conf
501 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
503 };' >> ftparchive.conf
507 buildaptftparchivedirectorystructure
() {
508 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
509 for DIST
in $DISTS; do
510 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
511 for SECTION
in $SECTIONS; do
512 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
513 for ARCH
in $ARCHS; do
514 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
516 mkdir -p dists
/${DIST}/${SECTION}/source
517 mkdir -p dists
/${DIST}/${SECTION}/i18n
527 local DEPENDENCIES
="$5"
528 local PRIORITY
="${6:-optional}"
529 local DESCRIPTION
="${7:-"Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
530 If you find such a package installed on your system,
531 something went horribly wrong! They are autogenerated
532 und used only by testcases and surf no other propose…"}"
534 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
535 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
536 ARCHS
="$(getarchitectures)"
540 for BUILDARCH
in $ARCHS; do
541 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
542 mkdir -p $PPATH aptarchive
/dists
/${RELEASE}/main
/source
543 touch aptarchive
/dists
/${RELEASE}/main
/source
/Sources
544 local FILE
="${PPATH}/Packages"
549 Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
550 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
551 echo "Version: $VERSION
552 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
553 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
554 echo "Description: $DESCRIPTION" >> $FILE
565 local DEPENDENCIES
="$5"
567 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
569 local FILE
="${SPATH}/Sources"
573 Maintainer: Joe Sixpack <joe@example.org>
574 Architecture: $ARCH" >> $FILE
575 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
577 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
578 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
582 insertinstalledpackage
() {
586 local DEPENDENCIES
="$4"
587 local PRIORITY
="${5:-optional}"
588 local STATUS
="${6:-install ok installed}"
589 local DESCRIPTION
="${7:-"Description: an autogenerated dummy ${NAME}=${VERSION}/installed
590 If you find such a package installed on your system,
591 something went horribly wrong! They are autogenerated
592 und used only by testcases and surf no other propose…"}"
594 local FILE='rootdir/var/lib/dpkg/status'
595 local INFO='rootdir/var/lib/dpkg/info'
596 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
602 Maintainer: Joe Sixpack <joe@example.org>
603 Version: $VERSION" >> $FILE
604 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
605 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
606 echo "Description: $DESCRIPTION" >> $FILE
608 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
609 echo -n > ${INFO}/${NAME}:${arch}.list
611 echo -n > ${INFO}/${NAME}.list
617 buildaptarchivefromincoming
() {
618 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
620 [ -e pool
] || ln -s ..
/incoming pool
621 [ -e ftparchive.conf
] || createaptftparchiveconfig
622 [ -e dists
] || buildaptftparchivedirectorystructure
623 msgninfo
"\tGenerate Packages, Sources and Contents files… "
624 aptftparchive
-qq generate ftparchive.conf
630 buildaptarchivefromfiles
() {
631 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
632 find aptarchive
-name 'Packages' -o -name 'Sources' | while read line
; do
633 msgninfo
"\t${line} file… "
634 compressfile
"$line" "$1"
637 generatereleasefiles
"$@"
641 cat ${TMPWORKINGDIRECTORY}/rootdir
/etc
/testcase
-compressor.conf
| while read compressor extension
command; do
642 if [ "$compressor" = '.' ]; then
648 cat "$1" | $command > "${1}.${extension}"
650 touch -d "$2" "${1}.${extension}"
655 # can be overridden by testcases for their pleasure
656 getcodenamefromsuite
() { echo -n "$1"; }
657 getreleaseversionfromsuite
() { true
; }
658 getlabelfromsuite
() { true
; }
660 generatereleasefiles
() {
661 # $1 is the Date header and $2 is the ValidUntil header to be set
662 # both should be given in notation date/touch can understand
663 msgninfo
"\tGenerate Release files… "
664 if [ -e aptarchive
/dists
]; then
665 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
666 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
667 local CODENAME
="$(getcodenamefromsuite $SUITE)"
668 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
669 local LABEL
="$(getlabelfromsuite $SUITE)"
670 if [ -n "$VERSION" ]; then
671 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
673 if [ -n "$LABEL" ]; then
674 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
676 aptftparchive
-qq release
$dir \
677 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
678 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
681 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
682 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
684 NotAutomatic: yes' $dir/Release
686 if [ -n "$1" -a "$1" != "now" ]; then
687 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
691 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
695 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
697 if [ -n "$1" -a "$1" != "now" ]; then
698 for release
in $(find ./aptarchive -name 'Release'); do
699 touch -d "$1" $release
705 setupdistsaptarchive
() {
706 local APTARCHIVE
=$(readlink -f ./aptarchive)
707 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
708 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
709 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
710 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
711 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
712 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
713 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
718 setupflataptarchive
() {
719 local APTARCHIVE
=$(readlink -f ./aptarchive)
720 if [ -f ${APTARCHIVE}/Packages
]; then
721 msgninfo
"\tadd deb sources.list line… "
722 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
725 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
727 if [ -f ${APTARCHIVE}/Sources
]; then
728 msgninfo
"\tadd deb-src sources.list line… "
729 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
732 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
738 if [ -e aptarchive
/dists
]; then
744 if [ "$1" != '--no-update' ]; then
745 msgninfo
"\tSync APT's cache with the archive… "
752 local SIGNER
="${1:-Joe Sixpack}"
753 local GPG
="gpg --batch --yes --no-default-keyring --trustdb-name rootdir/etc/apt/trustdb.gpg"
754 msgninfo
"\tSign archive with $SIGNER key… "
755 local REXKEY
='keys/rexexpired'
756 local SECEXPIREBAK
="${REXKEY}.sec.bak"
757 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
758 if [ "${SIGNER}" = 'Rex Expired' ]; then
759 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
760 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
761 # therefore we 'temporary' make the key not expired and restore a backup after signing
762 cp ${REXKEY}.sec
$SECEXPIREBAK
763 cp ${REXKEY}.pub
$PUBEXPIREBAK
764 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
765 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
766 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
767 cp $SECUNEXPIRED ${REXKEY}.sec
768 cp $PUBUNEXPIRED ${REXKEY}.pub
770 printf "expire\n1w\nsave\n" | $GPG --keyring ${REXKEY}.pub
--secret-keyring ${REXKEY}.sec
--command-fd 0 --edit-key "${SIGNER}" >/dev
/null
2>&1 || true
771 cp ${REXKEY}.sec
$SECUNEXPIRED
772 cp ${REXKEY}.pub
$PUBUNEXPIRED
775 for KEY
in $(find keys/ -name '*.sec'); do
776 GPG
="$GPG --secret-keyring $KEY"
778 for KEY
in $(find keys/ -name '*.pub'); do
779 GPG
="$GPG --keyring $KEY"
781 for RELEASE
in $(find aptarchive/ -name Release); do
782 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
783 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
784 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
785 # we might have set a specific date for the Release file, so copy it
786 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
788 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
789 mv -f $SECEXPIREBAK ${REXKEY}.sec
790 mv -f $PUBEXPIREBAK ${REXKEY}.pub
796 msgtest
"Set webserver config option '${1}' to" "$2"
797 downloadfile
"http://localhost:8080/_config/set/${1}/${2}" '/dev/null' >/dev
/null
798 local DOWNLOG
='download-testfile.log'
800 local STATUS
="$(mktemp)"
801 addtrap
"rm $STATUS;"
802 downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
803 if [ "$(cat "$STATUS")" = '200' ]; then
807 msgfail
"Statuscode was $(cat "$STATUS")"
811 rewritesourceslist
() {
812 local APTARCHIVE
="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
813 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
814 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#http://localhost:4433/#${1}#"
818 changetowebserver
() {
819 if [ "$1" != '--no-rewrite' ]; then
820 rewritesourceslist
'http://localhost:8080/'
824 local LOG
='/dev/null'
825 if test -x ${BUILDDIRECTORY}/aptwebserver
; then
827 LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1
828 local PID
="$(cat aptwebserver.pid)"
829 if [ -z "$PID" ]; then
830 msgdie
'Could not fork aptwebserver successfully'
835 msgdie
'You have to build aptwerbserver or install a webserver'
839 changetohttpswebserver
() {
840 if ! which stunnel4
>/dev
/null
; then
841 msgdie
'You need to install stunnel4 for https testcases'
843 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
844 changetowebserver
--no-rewrite
846 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
847 cert = ${TESTDIRECTORY}/apt.pem
853 " > ${TMPWORKINGDIRECTORY}/stunnel.conf
854 stunnel4
"${TMPWORKINGDIRECTORY}/stunnel.conf"
855 local PID
="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
856 addtrap
'prefix' "kill ${PID};"
857 rewritesourceslist
'https://localhost:4433/'
861 mkdir -p rootdir
/media
/cdrom
/.disk
862 local CD
="$(readlink -f rootdir/media/cdrom)"
863 echo "acquire::cdrom::mount \"${CD}\";" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
864 echo 'acquire::cdrom::autodetect 0;' >> rootdir
/etc
/apt
/apt.conf.d
/00cdrom
865 echo -n "$1" > ${CD}/.disk
/info
866 if [ ! -d aptarchive
/dists
]; then
867 msgdie
'Flat file archive cdroms can not be created currently'
870 mv aptarchive
/dists
$CD
871 ln -s "$(readlink -f ./incoming)" $CD/pool
872 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
876 PROTO
="$(echo "$1" | cut -d':' -f 1)"
877 local DOWNLOG
="${TMPWORKINGDIRECTORY}/download.log"
881 echo "601 Configuration
882 Config-Item: Acquire::https::CaInfo=${TESTDIR}/apt.pem
883 Config-Item: Debug::Acquire::${PROTO}=1
889 # simple worker keeping stdin open until we are done (201) or error (400)
890 # and requesting new URIs on try-agains/redirects inbetween
891 { tail -n 999 -f "$DOWNLOG" & echo "TAILPID: $!"; } | while read f1 f2
; do
892 if [ "$f1" = 'TAILPID:' ]; then
894 elif [ "$f1" = 'New-URI:' ]; then
895 echo "600 Acquire URI
899 elif [ "$f1" = '201' ] || [ "$f1" = '400' ]; then
900 # tail would only die on next read – which never happens
901 test -z "$TAILPID" || kill -s HUP
"$TAILPID"
905 } | LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods
/${PROTO} 2>&1 | tee "$DOWNLOG"
907 # only if the file exists the download was successful
916 local DIFFTEXT
="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
917 if [ -n "$DIFFTEXT" ]; then
929 msgtest
"Test for correctness of file" "$FILE"
931 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
933 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
938 msgtest
"Test for no output of" "$*"
939 test -z "$($* 2>&1)" && msgpass
|| msgfail
943 local COMPAREFILE
=$(mktemp)
944 addtrap
"rm $COMPAREFILE;"
945 echo "$1" > $COMPAREFILE
947 msgtest
"Test for equality of" "$*"
948 $
* 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
952 local COMPAREFILE1
=$(mktemp)
953 local COMPAREFILE2
=$(mktemp)
954 local COMPAREAGAINST
=$(mktemp)
955 addtrap
"rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
956 echo "$1" > $COMPAREFILE1
957 echo "$2" > $COMPAREFILE2
959 msgtest
"Test for equality OR of" "$*"
960 $
* >$COMPAREAGAINST 2>&1 || true
961 (checkdiff
$COMPAREFILE1 $COMPAREAGAINST 1> /dev
/null
||
962 checkdiff
$COMPAREFILE2 $COMPAREAGAINST 1> /dev
/null
) && msgpass
||
963 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
964 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
969 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
972 while [ -n "$1" ]; do
974 N: Can't select versions from package '$1' as it is purely virtual"
975 PACKAGE
="${PACKAGE} $1"
978 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
980 N: No packages found"
981 local COMPAREFILE
=$(mktemp)
982 addtrap
"rm $COMPAREFILE;"
983 local ARCH
="$(getarchitecture 'native')"
984 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
985 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
989 msgtest
"Test for non-existent packages" "apt-cache show $*"
990 local SHOWPKG
="$(aptcache show $* 2>&1 | grep '^Package: ')"
991 if [ -n "$SHOWPKG" ]; then
1000 testdpkginstalled
() {
1001 msgtest
"Test for correctly installed package(s) with" "dpkg -l $*"
1002 local PKGS
="$(dpkg -l $* 2>/dev/null | grep '^i' | wc -l)"
1003 if [ "$PKGS" != $# ]; then
1005 dpkg
-l $
* | grep '^[a-z]'
1012 testdpkgnotinstalled
() {
1013 msgtest
"Test for correctly not-installed package(s) with" "dpkg -l $*"
1014 local PKGS
="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)"
1015 if [ "$PKGS" != 0 ]; then
1017 dpkg
-l $
* | grep '^[a-z]'
1025 local COMPAREFILE
=$(mktemp)
1026 addtrap
"rm $COMPAREFILE;"
1027 if [ -n "$1" ]; then
1028 msgtest
'Test for correctly marked as auto-installed' "$*"
1029 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1031 msgtest
'Test for correctly marked as auto-installed' 'no package'
1032 echo -n > $COMPAREFILE
1034 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
1038 if [ "$1" = '--nomsg' ]; then
1041 msgtest
'Test for successful execution of' "$*"
1043 local OUTPUT
=$(mktemp)
1044 addtrap
"rm $OUTPUT;"
1045 if $@
>${OUTPUT} 2>&1; then
1055 if [ "$1" = '--nomsg' ]; then
1058 msgtest
'Test for failure in execution of' "$*"
1060 local OUTPUT
=$(mktemp)
1061 addtrap
"rm $OUTPUT;"
1062 if $@
>${OUTPUT} 2>&1; then
1072 echo "STOPPED execution. Press enter to continue"