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
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
196 export PATH
="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
201 if [ "$1" = "native" -o -z "$1" ]; then
202 eval `aptconfig shell ARCH APT::Architecture`
203 if [ -n "$ARCH" ]; then
206 dpkg
--print-architecture
214 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
217 configarchitecture
() {
218 local CONFFILE
=rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
220 echo "APT::Architecture \"$(getarchitecture $1)\";" > $CONFFILE
222 while [ -n "$1" ]; do
223 echo "APT::Architectures:: \"$(getarchitecture $1)\";" >> $CONFFILE
230 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
231 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
232 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
233 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
235 echo -n > rootdir/var/lib/dpkg/status
238 if $(which dpkg) --assert-multi-arch >/dev/null 2>&1; then
239 local ARCHS="$(getarchitectures)"
240 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
241 DPKGARCH="$(dpkg --print-architecture)"
242 for ARCH in ${ARCHS}; do
243 if [ "${ARCH}" != "${DPKGARCH}" ]; then
244 if ! dpkg --add-architecture ${ARCH}; then
245 # old-style used e.g. in Ubuntu-P – and as it seems travis
246 echo "DPKG
::options
:: \"--foreign-architecture\";" >> aptconfig.conf
247 echo "DPKG
::options
:: \"${ARCH}\";" >> aptconfig.conf
251 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
252 # dpkg doesn't really check the version as long as it is fully installed,
253 # but just to be sure we choose one above the required version
254 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
260 setupsimplenativepackage() {
264 local RELEASE="${4:-unstable}"
265 local DEPENDENCIES="$5"
266 local DESCRIPTION="$6"
267 local SECTION="${7:-others}"
269 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
272 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
274 local BUILDDIR=incoming/${NAME}-${VERSION}
275 mkdir -p ${BUILDDIR}/debian/source
277 echo "* most suckless software product ever
" > FEATURES
278 test -e debian/copyright || echo "Copyleft by Joe Sixpack
$(date +%Y)" > debian/copyright
279 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency
=low
283 -- Joe Sixpack
<joe@example.org
> $(date -R)" > debian/changelog
284 test -e debian/control || echo "Source
: $NAME
287 Maintainer
: Joe Sixpack
<joe@example.org
>
288 Build
-Depends: debhelper
(>= 7)
289 Standards
-Version: 3.9.1
291 Package
: $NAME" > debian/control
292 if [ "$ARCH" = 'all' ]; then
293 echo "Architecture
: all
" >> debian/control
295 echo "Architecture
: any
" >> debian/control
297 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
298 if [ -z "$DESCRIPTION" ]; then
299 echo "Description
: an autogenerated dummy
${NAME}=${VERSION}/${RELEASE}
300 If you
find such a package installed on your system
,
301 YOU did something horribly wrong
! They are autogenerated
302 und used only by testcases
for APT and surf no other propose…
" >> debian/control
304 echo "Description
: $DESCRIPTION" >> debian/control
306 test -e debian/compat || echo "7" > debian/compat
307 test -e debian/source/format || echo "3.0 (native
)" > debian/source/format
308 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
312 buildsimplenativepackage() {
316 local RELEASE="${4:-unstable}"
317 local DEPENDENCIES="$5"
318 local DESCRIPTION="$6"
319 local SECTION="${7:-others}"
320 local PRIORITY="${8:-optional}"
322 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
325 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
327 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
329 msgninfo "Build package
${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}…
"
330 mkdir -p $BUILDDIR/debian/source
331 echo "* most suckless software product ever
" > ${BUILDDIR}/FEATURES
333 echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
335 echo "Copyleft by Joe Sixpack
$(date +%Y)" > ${BUILDDIR}/debian/copyright
336 echo "$NAME ($VERSION) $RELEASE; urgency
=low
340 -- Joe Sixpack
<joe@example.org
> $(date -R)" > ${BUILDDIR}/debian/changelog
344 Maintainer
: Joe Sixpack
<joe@example.org
>
345 Standards
-Version: 3.9.3" > ${BUILDDIR}/debian/control
346 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
347 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
349 Package
: $NAME" >> ${BUILDDIR}/debian/control
351 if [ "$ARCH" = 'all' ]; then
352 echo "Architecture
: all
" >> ${BUILDDIR}/debian/control
354 echo "Architecture
: any
" >> ${BUILDDIR}/debian/control
356 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
357 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
358 if [ -z "$DESCRIPTION" ]; then
359 echo "Description
: an autogenerated dummy
${NAME}=${VERSION}/${RELEASE}
360 If you
find such a package installed on your system
,
361 YOU did something horribly wrong
! They are autogenerated
362 und used only by testcases
for APT and surf no other propose…
" >> ${BUILDDIR}/debian/control
364 echo "Description
: $DESCRIPTION" >> ${BUILDDIR}/debian/control
367 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
368 (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' \
370 echo "pool
/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
371 # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
372 # gpg --yes --no-default-keyring --secret-keyring ./keys/joesixpack.sec \
373 # --keyring ./keys/joesixpack.pub --default-key 'Joe Sixpack' \
374 # --clearsign -o "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
375 # mv "${BUILDDIR}/..
/${SRC}.sign
" "${BUILDDIR}/..
/$SRC"
379 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
380 rm -rf ${BUILDDIR}/debian
/tmp
381 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
382 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
383 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
384 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
385 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
387 dpkg
-deb --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
2> /dev
/null
> /dev
/null
388 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
391 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
392 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
393 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
402 local ARCH
=$(getarchitecture $4)
403 msgninfo
"Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… "
405 if [ "$ARCH" = "all" ]; then
406 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
408 local BUILT
="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
409 local PKGS
="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
410 local SRCS
="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
413 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
416 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
422 if [ -d incoming
]; then
423 buildaptarchivefromincoming $
*
425 buildaptarchivefromfiles $
*
429 createaptftparchiveconfig
() {
430 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' ' ')"
431 if [ -z "$ARCHS" ]; then
432 # the pool is empty, so we will operate on faked packages - let us use the configured archs
433 ARCHS
="$(getarchitectures)"
436 ArchiveDir "' >> ftparchive.conf
437 echo -n $(readlink -f .) >> ftparchive.conf
439 CacheDir "' >> ftparchive.conf
440 echo -n $(readlink -f ..) >> ftparchive.conf
442 FileListDir "' >> ftparchive.conf
443 echo -n $(readlink -f pool/) >> ftparchive.conf
447 Packages::Compress ". gzip bzip2 lzma xz";
448 Sources::Compress ". gzip bzip2 lzma xz";
449 Contents::Compress ". gzip bzip2 lzma xz";
450 Translation::Compress ". gzip bzip2 lzma xz";
451 LongDescription "false";
455 SrcDirectory "pool/";
461 Label "apttestcases";
463 Description "repository with dummy packages";
464 Architectures "' >> ftparchive.conf
465 echo -n "$ARCHS" >> ftparchive.conf
469 };' >> ftparchive.conf
470 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
471 echo -n 'tree "dists/' >> ftparchive.conf
472 echo -n "$DIST" >> ftparchive.conf
474 Architectures "' >> ftparchive.conf
475 echo -n "$ARCHS" >> ftparchive.conf
477 FileList "' >> ftparchive.conf
478 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
480 SourceFileList "' >> ftparchive.conf
481 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
483 Sections "' >> ftparchive.conf
484 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
486 };' >> ftparchive.conf
490 buildaptftparchivedirectorystructure
() {
491 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
492 for DIST
in $DISTS; do
493 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
494 for SECTION
in $SECTIONS; do
495 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
496 for ARCH
in $ARCHS; do
497 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
499 mkdir -p dists
/${DIST}/${SECTION}/source
500 mkdir -p dists
/${DIST}/${SECTION}/i18n
510 local DEPENDENCIES
="$5"
511 local PRIORITY
="${6:-optional}"
512 local DESCRIPTION
="${7}"
514 for arch
in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
515 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
516 ARCHS
="$(getarchitectures)"
520 for BUILDARCH
in $ARCHS; do
521 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
522 mkdir -p $PPATH aptarchive
/dists
/${RELEASE}/main
/source
523 touch aptarchive
/dists
/${RELEASE}/main
/source
/Sources
524 local FILE
="${PPATH}/Packages"
529 Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
530 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
531 echo "Version: $VERSION
532 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
533 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
534 echo -n 'Description: ' >> $FILE
535 if [ -z "$DESCRIPTION" ]; then
536 echo "an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
537 If you find such a package installed on your system,
538 YOU did something horribly wrong! They are autogenerated
539 und used only by testcases for APT and surf no other propose…" >> $FILE
541 echo "$DESCRIPTION" >> $FILE
553 local DEPENDENCIES
="$5"
555 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
557 local FILE
="${SPATH}/Sources"
561 Maintainer: Joe Sixpack <joe@example.org>
562 Architecture: $ARCH" >> $FILE
563 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
565 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
566 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
570 insertinstalledpackage
() {
574 local DEPENDENCIES
="$4"
575 local PRIORITY
="${5:-optional}"
576 local STATUS
="${6:-install ok installed}"
577 local FILE
='rootdir/var/lib/dpkg/status'
578 local INFO
='rootdir/var/lib/dpkg/info'
579 for arch
in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
585 Maintainer: Joe Sixpack <joe@example.org>
586 Version: $VERSION" >> $FILE
587 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
588 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
589 echo "Description: an autogenerated dummy ${NAME}=${VERSION}/installed
590 If you find such a package installed on your system,
591 YOU did something horribly wrong! They are autogenerated
592 und used only by testcases for APT and surf no other propose…
594 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
595 echo -n > ${INFO}/${NAME}:${arch}.list
597 echo -n > ${INFO}/${NAME}.list
603 buildaptarchivefromincoming
() {
604 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
606 [ -e pool
] || ln -s ..
/incoming pool
607 [ -e ftparchive.conf
] || createaptftparchiveconfig
608 [ -e dists
] || buildaptftparchivedirectorystructure
609 msgninfo
"\tGenerate Packages, Sources and Contents files… "
610 aptftparchive
-qq generate ftparchive.conf
616 buildaptarchivefromfiles
() {
617 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
618 find aptarchive
-name 'Packages' -o -name 'Sources' | while read line
; do
619 msgninfo
"\t${line} file… "
620 cat ${line} | gzip > ${line}.gz
621 cat ${line} | bzip2 > ${line}.bz2
622 cat ${line} | xz
--format=lzma
> ${line}.lzma
623 cat ${line} | xz
> ${line}.xz
625 touch -d "$1" ${line}.gz
${line}.bz2
${line}.lzma
${line}.xz
629 generatereleasefiles
"$@"
632 # can be overridden by testcases for their pleasure
633 getcodenamefromsuite
() { echo -n "$1"; }
634 getreleaseversionfromsuite
() { true
; }
635 getlabelfromsuite
() { true
; }
637 generatereleasefiles
() {
638 # $1 is the Date header and $2 is the ValidUntil header to be set
639 # both should be given in notation date/touch can understand
640 msgninfo
"\tGenerate Release files… "
641 if [ -e aptarchive
/dists
]; then
642 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
643 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
644 local CODENAME
="$(getcodenamefromsuite $SUITE)"
645 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
646 local LABEL
="$(getlabelfromsuite $SUITE)"
647 if [ -n "$VERSION" ]; then
648 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
650 if [ -n "$LABEL" ]; then
651 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
653 aptftparchive
-qq release
$dir \
654 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
655 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
658 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
659 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
661 NotAutomatic: yes' $dir/Release
663 if [ -n "$1" -a "$1" != "now" ]; then
664 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
668 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
672 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
674 if [ -n "$1" -a "$1" != "now" ]; then
675 for release
in $(find ./aptarchive -name 'Release'); do
676 touch -d "$1" $release
682 setupdistsaptarchive
() {
683 local APTARCHIVE
=$(readlink -f ./aptarchive)
684 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
685 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
686 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
687 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
688 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
689 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
690 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
695 setupflataptarchive
() {
696 local APTARCHIVE
=$(readlink -f ./aptarchive)
697 if [ -f ${APTARCHIVE}/Packages
]; then
698 msgninfo
"\tadd deb sources.list line… "
699 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
702 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
704 if [ -f ${APTARCHIVE}/Sources
]; then
705 msgninfo
"\tadd deb-src sources.list line… "
706 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
709 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
715 if [ -e aptarchive
/dists
]; then
721 if [ "$1" != '--no-update' ]; then
722 msgninfo
"\tSync APT's cache with the archive… "
729 local SIGNER
="${1:-Joe Sixpack}"
730 local GPG
="gpg --batch --yes --no-default-keyring --trustdb-name rootdir/etc/apt/trustdb.gpg"
731 msgninfo
"\tSign archive with $SIGNER key… "
732 local REXKEY
='keys/rexexpired'
733 local SECEXPIREBAK
="${REXKEY}.sec.bak"
734 local PUBEXPIREBAK
="${REXKEY}.pub.bak"
735 if [ "${SIGNER}" = 'Rex Expired' ]; then
736 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
737 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
738 # therefore we 'temporary' make the key not expired and restore a backup after signing
739 cp ${REXKEY}.sec
$SECEXPIREBAK
740 cp ${REXKEY}.pub
$PUBEXPIREBAK
741 local SECUNEXPIRED
="${REXKEY}.sec.unexpired"
742 local PUBUNEXPIRED
="${REXKEY}.pub.unexpired"
743 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
744 cp $SECUNEXPIRED ${REXKEY}.sec
745 cp $PUBUNEXPIRED ${REXKEY}.pub
747 printf "expire\n1w\nsave\n" | $GPG --keyring ${REXKEY}.pub
--secret-keyring ${REXKEY}.sec
--command-fd 0 --edit-key "${SIGNER}" >/dev
/null
2>&1 || true
748 cp ${REXKEY}.sec
$SECUNEXPIRED
749 cp ${REXKEY}.pub
$PUBUNEXPIRED
752 for KEY
in $(find keys/ -name '*.sec'); do
753 GPG
="$GPG --secret-keyring $KEY"
755 for KEY
in $(find keys/ -name '*.pub'); do
756 GPG
="$GPG --keyring $KEY"
758 for RELEASE
in $(find aptarchive/ -name Release); do
759 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg
${RELEASE}
760 local INRELEASE
="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
761 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
762 # we might have set a specific date for the Release file, so copy it
763 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg
${INRELEASE}
765 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
766 mv -f $SECEXPIREBAK ${REXKEY}.sec
767 mv -f $PUBEXPIREBAK ${REXKEY}.pub
772 changetowebserver
() {
773 local LOG
='/dev/null'
774 if test -x ${BUILDDIRECTORY}/aptwebserver
; then
776 LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/aptwebserver
-o aptwebserver
::fork
=1 "$@" >$LOG 2>&1
777 local PID
="$(cat aptwebserver.pid)"
778 if [ -z "$PID" ]; then
779 msgdie
'Could not fork aptwebserver successfully'
783 elif [ $# -gt 0 ]; then
784 msgdie
'Need the aptwebserver when passing arguments for the webserver'
785 elif which weborf
> /dev
/null
; then
786 weborf
-xb aptarchive
/ >$LOG 2>&1 &
788 elif which gatling
> /dev
/null
; then
790 gatling
-p 8080 -F -S >$LOG 2>&1 &
793 elif which lighttpd
> /dev
/null
; then
794 echo "server.document-root = \"$(readlink -f ./aptarchive)\"
796 server.stat-cache-engine = \"disable\"" > lighttpd.conf
797 lighttpd
-t -f lighttpd.conf
>/dev
/null
|| msgdie
'Can not change to webserver: our lighttpd config is invalid'
798 lighttpd
-D -f lighttpd.conf
>$LOG 2>&1 &
801 msgdie
'You have to build aptwerbserver or install a webserver'
803 local APTARCHIVE
="file://$(readlink -f ./aptarchive)"
804 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
805 sed -i $LIST -e "s#$APTARCHIVE#http://localhost:8080/#"
811 mkdir -p rootdir
/media
/cdrom
/.disk
812 local CD
="$(readlink -f rootdir/media/cdrom)"
813 echo "acquire::cdrom::mount \"${CD}\";" > rootdir
/etc
/apt
/apt.conf.d
/00cdrom
814 echo 'acquire::cdrom::autodetect 0;' >> rootdir
/etc
/apt
/apt.conf.d
/00cdrom
815 echo -n "$1" > ${CD}/.disk
/info
816 if [ ! -d aptarchive
/dists
]; then
817 msgdie
'Flat file archive cdroms can not be created currently'
820 mv aptarchive
/dists
$CD
821 ln -s "$(readlink -f ./incoming)" $CD/pool
822 find rootdir
/etc
/apt
/sources.list.d
/ -name 'apt-test-*.list' -delete
826 local DIFFTEXT
="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
827 if [ -n "$DIFFTEXT" ]; then
839 msgtest
"Test for correctness of file" "$FILE"
841 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
843 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
848 msgtest
"Test for no output of" "$*"
849 test -z "$($* 2>&1)" && msgpass
|| msgfail
853 local COMPAREFILE
=$(mktemp)
854 addtrap
"rm $COMPAREFILE;"
855 echo "$1" > $COMPAREFILE
857 msgtest
"Test for equality of" "$*"
858 $
* 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
862 local COMPAREFILE1
=$(mktemp)
863 local COMPAREFILE2
=$(mktemp)
864 local COMPAREAGAINST
=$(mktemp)
865 addtrap
"rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
866 echo "$1" > $COMPAREFILE1
867 echo "$2" > $COMPAREFILE2
869 msgtest
"Test for equality OR of" "$*"
870 $
* >$COMPAREAGAINST 2>&1
871 (checkdiff
$COMPAREFILE1 $COMPAREAGAINST 1> /dev
/null
||
872 checkdiff
$COMPAREFILE2 $COMPAREAGAINST 1> /dev
/null
) && msgpass
||
873 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
874 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
879 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
882 while [ -n "$1" ]; do
884 N: Can't select versions from package '$1' as it is purely virtual"
885 PACKAGE
="${PACKAGE} $1"
888 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
890 N: No packages found"
891 local COMPAREFILE
=$(mktemp)
892 addtrap
"rm $COMPAREFILE;"
893 local ARCH
="$(getarchitecture 'native')"
894 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
895 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
899 msgtest
"Test for non-existent packages" "apt-cache show $*"
900 local SHOWPKG
="$(aptcache show $* 2>&1 | grep '^Package: ')"
901 if [ -n "$SHOWPKG" ]; then
910 testdpkginstalled
() {
911 msgtest
"Test for correctly installed package(s) with" "dpkg -l $*"
912 local PKGS
="$(dpkg -l $* 2>/dev/null | grep '^i' | wc -l)"
913 if [ "$PKGS" != $# ]; then
915 dpkg
-l $
* | grep '^[a-z]'
922 testdpkgnotinstalled
() {
923 msgtest
"Test for correctly not-installed package(s) with" "dpkg -l $*"
924 local PKGS
="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)"
925 if [ "$PKGS" != 0 ]; then
927 dpkg
-l $
* | grep '^[a-z]'
935 local COMPAREFILE
=$(mktemp)
936 addtrap
"rm $COMPAREFILE;"
938 msgtest
'Test for correctly marked as auto-installed' "$*"
939 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
941 msgtest
'Test for correctly marked as auto-installed' 'no package'
942 echo -n > $COMPAREFILE
944 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
948 if [ "$1" = '--nomsg' ]; then
951 msgtest
'Test for successful execution of' "$*"
953 local OUTPUT
=$(mktemp)
954 addtrap
"rm $OUTPUT;"
955 if $@
>${OUTPUT} 2>&1; then
965 if [ "$1" = '--nomsg' ]; then
968 msgtest
'Test for failure in execution of' "$*"
970 local OUTPUT
=$(mktemp)
971 addtrap
"rm $OUTPUT;"
972 if $@
>${OUTPUT} 2>&1; then
982 echo "STOPPED execution. Press enter to continue"