1 #!/bin/sh -- # no runable script, just for vi
3 # we all like colorful messages
4 if expr match
"$(readlink -f /proc/$$/fd/1)" '/dev/pts/[0-9]\+' > /dev
/null
&& \
5 expr match
"$(readlink -f /proc/$$/fd/2)" '/dev/pts/[0-9]\+' > /dev
/null
; then
6 CERROR
="\e[1;31m" # red
7 CWARNING
="\e[1;33m" # yellow
8 CMSG
="\e[1;32m" # green
9 CINFO
="\e[1;96m" # light blue
10 CDEBUG
="\e[1;94m" # blue
11 CNORMAL
="\e[0;39m" # default system console color
12 CDONE
="\e[1;32m" # green
13 CPASS
="\e[1;32m" # green
14 CFAIL
="\e[1;31m" # red
15 CCMD
="\e[1;35m" # pink
18 msgdie
() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; }
19 msgwarn
() { echo "${CWARNING}W: $1${CNORMAL}" >&2; }
20 msgmsg
() { echo "${CMSG}$1${CNORMAL}" >&2; }
21 msginfo
() { echo "${CINFO}I: $1${CNORMAL}" >&2; }
22 msgdebug
() { echo "${CDEBUG}D: $1${CNORMAL}" >&2; }
23 msgdone
() { echo "${CDONE}DONE${CNORMAL}" >&2; }
24 msgnwarn
() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; }
25 msgnmsg
() { echo -n "${CMSG}$1${CNORMAL}" >&2; }
26 msgninfo
() { echo -n "${CINFO}I: $1${CNORMAL}" >&2; }
27 msgndebug
() { echo -n "${CDEBUG}D: $1${CNORMAL}" >&2; }
30 echo -n "${CINFO}$1${CCMD} " >&2;
31 echo -n "$(echo "$2" | sed -e 's/^aptc/apt-c/' -e 's/^aptg/apt-g/' -e 's/^aptf/apt-f/')${CINFO} " >&2;
33 if [ -n "$1" ]; then shift; else break; fi
35 echo -n "…${CNORMAL} " >&2;
37 msgpass
() { echo "${CPASS}PASS${CNORMAL}" >&2; }
38 msgskip
() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
39 msgfail
() { echo "${CFAIL}FAIL${CNORMAL}" >&2; }
41 # enable / disable Debugging
42 MSGLEVEL
=${MSGLEVEL:-3}
43 if [ $MSGLEVEL -le 0 ]; then
46 if [ $MSGLEVEL -le 1 ]; then
50 if [ $MSGLEVEL -le 2 ]; then
54 msgpass
() { echo -n " ${CPASS}P${CNORMAL}" >&2; }
55 msgskip
() { echo -n " ${CWARNING}S${CNORMAL}" >&2; }
56 if [ -n "$CFAIL" ]; then
57 msgfail
() { echo -n " ${CFAIL}FAIL${CNORMAL}" >&2; }
59 msgfail
() { echo -n " ###FAILED###" >&2; }
62 if [ $MSGLEVEL -le 3 ]; then
66 if [ $MSGLEVEL -le 4 ]; then
71 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
72 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
73 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
74 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
75 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
78 echo "${CDONE}DONE${CNORMAL}" >&2;
83 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
84 if [ -f .
/aptconfig.conf
]; then
85 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
86 elif [ -f ..
/aptconfig.conf
]; then
87 APT_CONFIG
=..
/aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
89 LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
92 aptconfig
() { runapt apt
-config $
*; }
93 aptcache
() { runapt apt
-cache $
*; }
94 aptget
() { runapt apt
-get $
*; }
95 aptftparchive
() { runapt apt
-ftparchive $
*; }
96 aptkey
() { runapt apt
-key $
*; }
97 aptmark
() { runapt apt
-mark $
*; }
99 $(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir
--force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir
/var
/log
/dpkg.log $
*
102 if [ -f .
/aptconfig.conf
]; then
103 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which aptitude) $
*
104 elif [ -f ..
/aptconfig.conf
]; then
105 APT_CONFIG
=..
/aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which aptitude) $
*
107 LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which aptitude) $
*
112 CURRENTTRAP
="$CURRENTTRAP $1"
113 trap "$CURRENTTRAP exit;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
117 TMPWORKINGDIRECTORY
=$(mktemp -d)
118 TESTDIRECTORY
=$(readlink -f $(dirname $0))
119 msgninfo
"Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
120 BUILDDIRECTORY
="${TESTDIRECTORY}/../../build/bin"
121 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
122 local OLDWORKINGDIRECTORY
=$(pwd)
123 addtrap
"cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY;"
124 cd $TMPWORKINGDIRECTORY
125 mkdir rootdir aptarchive keys
127 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
128 mkdir -p var
/cache var
/lib var
/log
129 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
130 touch var
/lib
/dpkg
/available
132 ln -s ${BUILDDIRECTORY}/methods usr
/lib
/apt
/methods
134 local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
135 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
136 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
138 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
139 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
140 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
142 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/
143 ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
144 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
145 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
146 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
147 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
148 echo "Dir::Bin::Methods \"${BUILDDIRECTORY}/methods\";" >> aptconfig.conf
149 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
150 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
151 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
152 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
153 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
154 if ! $(which dpkg) --assert-multi-arch; then
155 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf
# Added to test multiarch before dpkg is ready for it…
157 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
158 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
160 export PATH
="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
165 if [ "$1" = "native" -o -z "$1" ]; then
166 eval `aptconfig shell ARCH APT::Architecture`
167 if [ -n "$ARCH" ]; then
170 dpkg
--print-architecture
178 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
181 configarchitecture
() {
182 local CONFFILE
=rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
184 echo "APT::Architecture \"$(getarchitecture $1)\";" > $CONFFILE
186 while [ -n "$1" ]; do
187 echo "APT::Architectures:: \"$(getarchitecture $1)\";" >> $CONFFILE
194 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
195 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
196 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
197 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
199 echo -n > rootdir/var/lib/dpkg/status
202 if $(which dpkg) --assert-multi-arch; then
203 local ARCHS="$(getarchitectures)"
204 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
205 DPKGARCH="$(dpkg --print-architecture)"
206 for ARCH in ${ARCHS}; do
207 if [ "${ARCH}" != "${DPKGARCH}" ]; then dpkg --add-architecture ${ARCH}; fi
209 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
210 insertinstalledpackage 'dpkg' "all
" '1.16.2~wipmultiarch~fake'
216 setupsimplenativepackage() {
220 local RELEASE="${4:-unstable}"
221 local DEPENDENCIES="$5"
222 local DESCRIPTION="$6"
223 local SECTION="${7:-others}"
225 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
228 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
230 local BUILDDIR=incoming/${NAME}-${VERSION}
231 mkdir -p ${BUILDDIR}/debian/source
233 echo "* most suckless software product ever
" > FEATURES
234 test -e debian/copyright || echo "Copyleft by Joe Sixpack
$(date +%Y)" > debian/copyright
235 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency
=low
239 -- Joe Sixpack
<joe@example.org
> $(date -R)" > debian/changelog
240 test -e debian/control || echo "Source
: $NAME
243 Maintainer
: Joe Sixpack
<joe@example.org
>
244 Build
-Depends: debhelper
(>= 7)
245 Standards
-Version: 3.9.1
247 Package
: $NAME" > debian/control
248 if [ "$ARCH" = 'all' ]; then
249 echo "Architecture
: all
" >> debian/control
251 echo "Architecture
: any
" >> debian/control
253 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
254 if [ -z "$DESCRIPTION" ]; then
255 echo "Description
: an autogenerated dummy
${NAME}=${VERSION}/${RELEASE}
256 If you
find such a package installed on your system
,
257 YOU did something horribly wrong
! They are autogenerated
258 und used only by testcases
for APT and surf no other propose…
" >> debian/control
260 echo "Description
: $DESCRIPTION" >> debian/control
262 test -e debian/compat || echo "7" > debian/compat
263 test -e debian/source/format || echo "3.0 (native
)" > debian/source/format
264 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
268 buildsimplenativepackage() {
272 local RELEASE="${4:-unstable}"
273 local DEPENDENCIES="$5"
274 local DESCRIPTION="$6"
275 local SECTION="${7:-others}"
276 local PRIORITY="${8:-optional}"
278 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
281 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
283 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
285 msgninfo "Build package
${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}…
"
286 mkdir -p $BUILDDIR/debian/source
287 echo "* most suckless software product ever
" > ${BUILDDIR}/FEATURES
289 echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
291 echo "Copyleft by Joe Sixpack
$(date +%Y)" > ${BUILDDIR}/debian/copyright
292 echo "$NAME ($VERSION) $RELEASE; urgency
=low
296 -- Joe Sixpack
<joe@example.org
> $(date -R)" > ${BUILDDIR}/debian/changelog
300 Maintainer
: Joe Sixpack
<joe@example.org
>
301 Standards
-Version: 3.9.1
303 Package
: $NAME" > ${BUILDDIR}/debian/control
304 if [ "$ARCH" = 'all' ]; then
305 echo "Architecture
: all
" >> ${BUILDDIR}/debian/control
307 echo "Architecture
: any
" >> ${BUILDDIR}/debian/control
309 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> ${BUILDDIR}/debian/control
310 if [ -z "$DESCRIPTION" ]; then
311 echo "Description
: an autogenerated dummy
${NAME}=${VERSION}/${RELEASE}
312 If you
find such a package installed on your system
,
313 YOU did something horribly wrong
! They are autogenerated
314 und used only by testcases
for APT and surf no other propose…
" >> ${BUILDDIR}/debian/control
316 echo "Description
: $DESCRIPTION" >> ${BUILDIR}/debian/control
318 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
319 local SRCS="$( (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
321 echo "pool
/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
324 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
325 rm -rf ${BUILDDIR}/debian
/tmp
326 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
327 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
328 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
329 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
330 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
332 dpkg
-deb --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
2> /dev
/null
> /dev
/null
333 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
336 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
337 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
338 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
347 local ARCH
=$(getarchitecture $4)
348 msgninfo
"Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… "
350 if [ "$ARCH" = "all" ]; then
351 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
353 local BUILT
="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
354 local PKGS
="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
355 local SRCS
="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
358 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
361 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
367 if [ -d incoming
]; then
368 buildaptarchivefromincoming $
*
370 buildaptarchivefromfiles $
*
374 createaptftparchiveconfig
() {
375 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' ' ')"
376 if [ -z "$ARCHS" ]; then
377 # the pool is empty, so we will operate on faked packages - let us use the configured archs
378 ARCHS
="$(getarchitectures)"
381 ArchiveDir "' >> ftparchive.conf
382 echo -n $(readlink -f .) >> ftparchive.conf
384 CacheDir "' >> ftparchive.conf
385 echo -n $(readlink -f ..) >> ftparchive.conf
387 FileListDir "' >> ftparchive.conf
388 echo -n $(readlink -f pool/) >> ftparchive.conf
392 Packages::Compress ". gzip bzip2 lzma xz";
393 Sources::Compress ". gzip bzip2 lzma xz";
394 Contents::Compress ". gzip bzip2 lzma xz";
395 Translation::Compress ". gzip bzip2 lzma xz";
396 LongDescription "false";
400 SrcDirectory "pool/";
406 Label "apttestcases";
408 Description "repository with dummy packages";
409 Architectures "' >> ftparchive.conf
410 echo -n "$ARCHS" >> ftparchive.conf
414 };' >> ftparchive.conf
415 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
416 echo -n 'tree "dists/' >> ftparchive.conf
417 echo -n "$DIST" >> ftparchive.conf
419 Architectures "' >> ftparchive.conf
420 echo -n "$ARCHS" >> ftparchive.conf
422 FileList "' >> ftparchive.conf
423 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
425 SourceFileList "' >> ftparchive.conf
426 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
428 Sections "' >> ftparchive.conf
429 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
431 };' >> ftparchive.conf
435 buildaptftparchivedirectorystructure
() {
436 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
437 for DIST
in $DISTS; do
438 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
439 for SECTION
in $SECTIONS; do
440 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
441 for ARCH
in $ARCHS; do
442 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
444 mkdir -p dists
/${DIST}/${SECTION}/source
445 mkdir -p dists
/${DIST}/${SECTION}/i18n
455 local DEPENDENCIES
="$5"
456 local PRIORITY
="${6:-optional}"
458 for arch
in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
459 if [ "$arch" = "all" ]; then
460 ARCHS
="$(getarchitectures)"
464 for BUILDARCH
in $ARCHS; do
465 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
466 mkdir -p $PPATH aptarchive
/dists
/${RELEASE}/main
/source
467 touch aptarchive
/dists
/${RELEASE}/main
/source
/Sources
468 local FILE
="${PPATH}/Packages"
473 Maintainer: Joe Sixpack <joe@example.org>
476 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
477 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
478 echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
479 If you find such a package installed on your system,
480 YOU did something horribly wrong! They are autogenerated
481 und used only by testcases for APT and surf no other propose…
492 local DEPENDENCIES
="$5"
494 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
496 local FILE
="${SPATH}/Sources"
500 Maintainer: Joe Sixpack <joe@example.org>
501 Architecture: $ARCH" >> $FILE
502 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
504 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
505 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz" >> $FILE
508 insertinstalledpackage
() {
512 local DEPENDENCIES
="$4"
513 local PRIORITY
="${5:-optional}"
514 local FILE
='rootdir/var/lib/dpkg/status'
515 local INFO
='rootdir/var/lib/dpkg/info'
516 for arch
in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
518 Status: install ok installed
522 Maintainer: Joe Sixpack <joe@example.org>
524 Version: $VERSION" >> $FILE
525 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
526 echo "Description: an autogenerated dummy ${NAME}=${VERSION}/installed
527 If you find such a package installed on your system,
528 YOU did something horribly wrong! They are autogenerated
529 und used only by testcases for APT and surf no other propose…
531 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
532 echo -n > ${INFO}/${NAME}:${arch}.list
534 echo -n > ${INFO}/${NAME}.list
540 buildaptarchivefromincoming
() {
541 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
543 [ -e pool
] || ln -s ..
/incoming pool
544 [ -e ftparchive.conf
] || createaptftparchiveconfig
545 [ -e dists
] || buildaptftparchivedirectorystructure
546 msgninfo
"\tGenerate Packages, Sources and Contents files… "
547 aptftparchive
-qq generate ftparchive.conf
553 buildaptarchivefromfiles
() {
554 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
555 find aptarchive
-name 'Packages' -o -name 'Sources' | while read line
; do
556 msgninfo
"\t${line} file… "
557 cat ${line} | gzip > ${line}.gz
558 cat ${line} | bzip2 > ${line}.bz2
559 cat ${line} | lzma
> ${line}.lzma
560 cat ${line} | xz
> ${line}.xz
566 # can be overridden by testcases for their pleasure
567 getcodenamefromsuite
() { echo -n "$1"; }
568 getreleaseversionfromsuite
() { true
; }
569 getlabelfromsuite
() { true
; }
571 generatereleasefiles
() {
572 # $1 is the Date header and $2 is the ValidUntil header to be set
573 # both should be given in notation date/touch can understand
574 msgninfo
"\tGenerate Release files… "
575 if [ -e aptarchive
/dists
]; then
576 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
577 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
578 local CODENAME
="$(getcodenamefromsuite $SUITE)"
579 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
580 local LABEL
="$(getlabelfromsuite $SUITE)"
581 if [ -n "$VERSION" ]; then
582 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
584 if [ -n "$LABEL" ]; then
585 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
587 aptftparchive
-qq release
$dir \
588 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
589 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
592 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
593 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
595 NotAutomatic: yes' $dir/Release
597 if [ -n "$1" -a "$1" != "now" ]; then
598 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
602 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
606 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
608 if [ -n "$1" -a "$1" != "now" ]; then
609 for release
in $(find ./aptarchive -name 'Release'); do
610 touch -d "$1" $release
616 setupdistsaptarchive
() {
617 local APTARCHIVE
=$(readlink -f ./aptarchive)
618 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
619 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
620 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
621 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
622 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
623 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
624 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
629 setupflataptarchive
() {
630 local APTARCHIVE
=$(readlink -f ./aptarchive)
631 if [ -f ${APTARCHIVE}/Packages
]; then
632 msgninfo
"\tadd deb sources.list line… "
633 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
636 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
638 if [ -f ${APTARCHIVE}/Sources
]; then
639 msgninfo
"\tadd deb-src sources.list line… "
640 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
643 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
649 if [ -e aptarchive
/dists
]; then
655 msgninfo
"\tSync APT's cache with the archive… "
661 local SIGNER
="${1:-Joe Sixpack}"
662 msgninfo
"\tSign archive with $SIGNER key… "
664 for KEY
in $(find keys/ -name '*.sec'); do
665 SECKEYS
="$SECKEYS --secret-keyring $KEY"
668 for KEY
in $(find keys/ -name '*.pub'); do
669 PUBKEYS
="$PUBKEYS --keyring $KEY"
671 for RELEASE
in $(find aptarchive/ -name Release); do
672 gpg
--yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" -abs -o ${RELEASE}.gpg
${RELEASE}
673 gpg
--yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" --clearsign -o "$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')" $RELEASE
678 changetowebserver
() {
679 if which weborf
> /dev
/null
; then
680 weborf
-xb aptarchive
/ 2>&1 > /dev
/null
&
682 elif which gatling
> /dev
/null
; then
684 gatling
-p 8080 -F -S 2>&1 > /dev
/null
&
687 elif which lighttpd
> /dev
/null
; then
688 echo "server.document-root = \"$(readlink -f ./aptarchive)\"
690 server.stat-cache-engine = \"disable\"" > lighttpd.conf
691 lighttpd
-t -f lighttpd.conf
>/dev
/null
|| msgdie
'Can not change to webserver: our lighttpd config is invalid'
692 lighttpd
-D -f lighttpd.conf
2>/dev
/null
>/dev
/null
&
695 msgdie
'You have to install weborf or lighttpd first'
698 local APTARCHIVE
="file://$(readlink -f ./aptarchive)"
699 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
700 sed -i $LIST -e "s#$APTARCHIVE#http://localhost:8080/#"
706 local DIFFTEXT
="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
707 if [ -n "$DIFFTEXT" ]; then
719 msgtest
"Test for correctness of file" "$FILE"
721 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
723 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
728 local COMPAREFILE
=$(mktemp)
729 addtrap
"rm $COMPAREFILE;"
730 echo "$1" > $COMPAREFILE
732 msgtest
"Test for equality of" "$*"
733 $
* 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
737 local COMPAREFILE1
=$(mktemp)
738 local COMPAREFILE2
=$(mktemp)
739 local COMPAREAGAINST
=$(mktemp)
740 addtrap
"rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
741 echo "$1" > $COMPAREFILE1
742 echo "$2" > $COMPAREFILE2
744 msgtest
"Test for equality OR of" "$*"
745 $
* 2>&1 1> $COMPAREAGAINST
746 (checkdiff
$COMPAREFILE1 $COMPAREAGAINST 1> /dev
/null
||
747 checkdiff
$COMPAREFILE2 $COMPAREAGAINST 1> /dev
/null
) && msgpass
||
748 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
749 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
754 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
757 while [ -n "$1" ]; do
759 N: Can't select versions from package '$1' as it is purely virtual"
760 PACKAGE
="${PACKAGE} $1"
763 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
765 N: No packages found"
766 local COMPAREFILE
=$(mktemp)
767 addtrap
"rm $COMPAREFILE;"
768 local ARCH
="$(getarchitecture 'native')"
769 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
770 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
774 msgtest
"Test for non-existent packages" "apt-cache show $*"
775 local SHOWPKG
="$(aptcache show $* 2>&1 | grep '^Package: ')"
776 if [ -n "$SHOWPKG" ]; then
785 testdpkginstalled
() {
786 msgtest
"Test for correctly installed package(s) with" "dpkg -l $*"
787 local PKGS
="$(dpkg -l $* | grep '^i' | wc -l)"
788 if [ "$PKGS" != $# ]; then
790 dpkg
-l $
* | grep '^[a-z]'
797 testdpkgnotinstalled
() {
798 msgtest
"Test for correctly not-installed package(s) with" "dpkg -l $*"
799 local PKGS
="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)"
800 if [ "$PKGS" != 0 ]; then
802 dpkg
-l $
* | grep '^[a-z]'
810 local COMPAREFILE
=$(mktemp)
811 addtrap
"rm $COMPAREFILE;"
813 msgtest
'Test for correctly marked as auto-installed' "$*"
814 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
816 msgtest
'Test for correctly marked as auto-installed' 'no package'
817 echo -n > $COMPAREFILE
819 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
823 echo "STOPPED execution. Press enter to continue"