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;
34 echo -n "…${CNORMAL} " >&2;
36 msgpass
() { echo "${CPASS}PASS${CNORMAL}" >&2; }
37 msgskip
() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
38 msgfail
() { echo "${CFAIL}FAIL${CNORMAL}" >&2; }
40 # enable / disable Debugging
41 MSGLEVEL
=${MSGLEVEL:-3}
42 if [ $MSGLEVEL -le 0 ]; then
45 if [ $MSGLEVEL -le 1 ]; then
49 if [ $MSGLEVEL -le 2 ]; then
53 msgpass
() { echo -n " ${CPASS}P${CNORMAL}" >&2; }
54 msgskip
() { echo -n " ${CWARNING}S${CNORMAL}" >&2; }
55 if [ -n "$CFAIL" ]; then
56 msgfail
() { echo -n " ${CFAIL}FAIL${CNORMAL}" >&2; }
58 msgfail
() { echo -n " ###FAILED###" >&2; }
61 if [ $MSGLEVEL -le 3 ]; then
65 if [ $MSGLEVEL -le 4 ]; then
70 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
71 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
72 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
73 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
74 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
77 echo "${CDONE}DONE${CNORMAL}" >&2;
82 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
83 if [ -f .
/aptconfig.conf
]; then
84 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
85 elif [ -f ..
/aptconfig.conf
]; then
86 APT_CONFIG
=..
/aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
88 LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
91 aptconfig
() { runapt apt
-config $
*; }
92 aptcache
() { runapt apt
-cache $
*; }
93 aptget
() { runapt apt
-get $
*; }
94 aptftparchive
() { runapt apt
-ftparchive $
*; }
95 aptkey
() { runapt apt
-key $
*; }
96 aptmark
() { runapt apt
-mark $
*; }
98 $(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir
--force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir
/var
/log
/dpkg.log $
*
101 if [ -f .
/aptconfig.conf
]; then
102 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which aptitude) $
*
103 elif [ -f ..
/aptconfig.conf
]; then
104 APT_CONFIG
=..
/aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which aptitude) $
*
106 LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which aptitude) $
*
111 CURRENTTRAP
="$CURRENTTRAP $1"
112 trap "$CURRENTTRAP exit;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
116 TMPWORKINGDIRECTORY
=$(mktemp -d)
117 TESTDIRECTORY
=$(readlink -f $(dirname $0))
118 msgninfo
"Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
119 BUILDDIRECTORY
="${TESTDIRECTORY}/../../build/bin"
120 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
121 local OLDWORKINGDIRECTORY
=$(pwd)
122 addtrap
"cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY;"
123 cd $TMPWORKINGDIRECTORY
124 mkdir rootdir aptarchive keys
126 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
127 mkdir -p var
/cache var
/lib var
/log
128 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
129 touch var
/lib
/dpkg
/available
131 ln -s ${BUILDDIRECTORY}/methods usr
/lib
/apt
/methods
133 local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
134 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
135 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
137 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
138 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
139 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
141 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/
142 ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
143 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
144 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
145 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
146 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
147 echo "Dir::Bin::Methods \"${BUILDDIRECTORY}/methods\";" >> aptconfig.conf
148 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
149 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
150 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
151 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
152 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
153 if ! $(which dpkg) --assert-multi-arch; then
154 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf
# Added to test multiarch before dpkg is ready for it…
156 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
157 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
159 export PATH
="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
164 if [ "$1" = "native" -o -z "$1" ]; then
165 eval `aptconfig shell ARCH APT::Architecture`
166 if [ -n "$ARCH" ]; then
169 dpkg
-architecture -qDEB_BUILD_ARCH
177 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
180 configarchitecture
() {
181 local CONFFILE
=rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
183 echo "APT::Architecture \"$(getarchitecture $1)\";" > $CONFFILE
185 while [ -n "$1" ]; do
186 echo "APT::Architectures:: \"$(getarchitecture $1)\";" >> $CONFFILE
193 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
194 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
195 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
196 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
198 echo -n > rootdir/var/lib/dpkg/status
201 if $(which dpkg) --assert-multi-arch; then
202 local ARCHS="$(getarchitectures)"
203 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
204 DPKGARCH="$(dpkg --print-architecture)"
205 for ARCH in ${ARCHS}; do
206 if [ "${ARCH}" != "${DPKGARCH}" ]; then dpkg --add-architecture ${ARCH}; fi
208 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
209 insertinstalledpackage 'dpkg' "all
" '1.16.2~wipmultiarch~fake'
215 setupsimplenativepackage() {
219 local RELEASE="${4:-unstable}"
220 local DEPENDENCIES="$5"
221 local DESCRIPTION="$6"
222 local SECTION="${7:-others}"
224 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
227 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
229 local BUILDDIR=incoming/${NAME}-${VERSION}
230 mkdir -p ${BUILDDIR}/debian/source
232 echo "* most suckless software product ever
" > FEATURES
233 test -e debian/copyright || echo "Copyleft by Joe Sixpack
$(date +%Y)" > debian/copyright
234 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency
=low
238 -- Joe Sixpack
<joe@example.org
> $(date -R)" > debian/changelog
239 test -e debian/control || echo "Source
: $NAME
242 Maintainer
: Joe Sixpack
<joe@example.org
>
243 Build
-Depends: debhelper
(>= 7)
244 Standards
-Version: 3.9.1
246 Package
: $NAME" > debian/control
247 if [ "$ARCH" = 'all' ]; then
248 echo "Architecture
: all
" >> debian/control
250 echo "Architecture
: any
" >> debian/control
252 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
253 if [ -z "$DESCRIPTION" ]; then
254 echo "Description
: an autogenerated dummy
${NAME}=${VERSION}/${RELEASE}
255 If you
find such a package installed on your system
,
256 YOU did something horribly wrong
! They are autogenerated
257 und used only by testcases
for APT and surf no other propose…
" >> debian/control
259 echo "Description
: $DESCRIPTION" >> debian/control
261 test -e debian/compat || echo "7" > debian/compat
262 test -e debian/source/format || echo "3.0 (native
)" > debian/source/format
263 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
267 buildsimplenativepackage() {
271 local RELEASE="${4:-unstable}"
272 local DEPENDENCIES="$5"
273 local DESCRIPTION="$6"
274 local SECTION="${7:-others}"
275 local PRIORITY="${8:-optional}"
277 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
280 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
282 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
284 msgninfo "Build package
${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}…
"
285 mkdir -p $BUILDDIR/debian/source
286 echo "* most suckless software product ever
" > ${BUILDDIR}/FEATURES
288 echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
290 echo "Copyleft by Joe Sixpack
$(date +%Y)" > ${BUILDDIR}/debian/copyright
291 echo "$NAME ($VERSION) $RELEASE; urgency
=low
295 -- Joe Sixpack
<joe@example.org
> $(date -R)" > ${BUILDDIR}/debian/changelog
299 Maintainer
: Joe Sixpack
<joe@example.org
>
300 Standards
-Version: 3.9.1
302 Package
: $NAME" > ${BUILDDIR}/debian/control
303 if [ "$ARCH" = 'all' ]; then
304 echo "Architecture
: all
" >> ${BUILDDIR}/debian/control
306 echo "Architecture
: any
" >> ${BUILDDIR}/debian/control
308 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> ${BUILDDIR}/debian/control
309 if [ -z "$DESCRIPTION" ]; then
310 echo "Description
: an autogenerated dummy
${NAME}=${VERSION}/${RELEASE}
311 If you
find such a package installed on your system
,
312 YOU did something horribly wrong
! They are autogenerated
313 und used only by testcases
for APT and surf no other propose…
" >> ${BUILDDIR}/debian/control
315 echo "Description
: $DESCRIPTION" >> ${BUILDIR}/debian/control
317 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
318 local SRCS="$( (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
320 echo "pool
/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
323 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
324 rm -rf ${BUILDDIR}/debian
/tmp
325 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
326 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
327 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
328 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
329 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
331 dpkg
-deb --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
2> /dev
/null
> /dev
/null
332 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
335 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
336 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
337 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
346 local ARCH
=$(getarchitecture $4)
347 msgninfo
"Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… "
349 if [ "$ARCH" = "all" ]; then
350 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
352 local BUILT
="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
353 local PKGS
="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
354 local SRCS
="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
357 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
360 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
366 if [ -d incoming
]; then
367 buildaptarchivefromincoming $
*
369 buildaptarchivefromfiles $
*
373 createaptftparchiveconfig
() {
374 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' ' ')"
375 if [ -z "$ARCHS" ]; then
376 # the pool is empty, so we will operate on faked packages - let us use the configured archs
377 ARCHS
="$(getarchitectures)"
380 ArchiveDir "' >> ftparchive.conf
381 echo -n $(readlink -f .) >> ftparchive.conf
383 CacheDir "' >> ftparchive.conf
384 echo -n $(readlink -f ..) >> ftparchive.conf
386 FileListDir "' >> ftparchive.conf
387 echo -n $(readlink -f pool/) >> ftparchive.conf
391 Packages::Compress ". gzip bzip2 lzma xz";
392 Sources::Compress ". gzip bzip2 lzma xz";
393 Contents::Compress ". gzip bzip2 lzma xz";
394 Translation::Compress ". gzip bzip2 lzma xz";
395 LongDescription "false";
399 SrcDirectory "pool/";
405 Label "apttestcases";
407 Description "repository with dummy packages";
408 Architectures "' >> ftparchive.conf
409 echo -n "$ARCHS" >> ftparchive.conf
413 };' >> ftparchive.conf
414 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
415 echo -n 'tree "dists/' >> ftparchive.conf
416 echo -n "$DIST" >> ftparchive.conf
418 Architectures "' >> ftparchive.conf
419 echo -n "$ARCHS" >> ftparchive.conf
421 FileList "' >> ftparchive.conf
422 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
424 SourceFileList "' >> ftparchive.conf
425 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
427 Sections "' >> ftparchive.conf
428 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
430 };' >> ftparchive.conf
434 buildaptftparchivedirectorystructure
() {
435 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
436 for DIST
in $DISTS; do
437 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
438 for SECTION
in $SECTIONS; do
439 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
440 for ARCH
in $ARCHS; do
441 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
443 mkdir -p dists
/${DIST}/${SECTION}/source
444 mkdir -p dists
/${DIST}/${SECTION}/i18n
454 local DEPENDENCIES
="$5"
455 local PRIORITY
="${6:-optional}"
457 for arch
in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
458 if [ "$arch" = "all" ]; then
459 ARCHS
="$(getarchitectures)"
463 for BUILDARCH
in $ARCHS; do
464 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
465 mkdir -p $PPATH aptarchive
/dists
/${RELEASE}/main
/source
466 touch aptarchive
/dists
/${RELEASE}/main
/source
/Sources
467 local FILE
="${PPATH}/Packages"
472 Maintainer: Joe Sixpack <joe@example.org>
475 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
476 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
477 echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
478 If you find such a package installed on your system,
479 YOU did something horribly wrong! They are autogenerated
480 und used only by testcases for APT and surf no other propose…
491 local DEPENDENCIES
="$5"
493 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
495 local FILE
="${SPATH}/Sources"
499 Maintainer: Joe Sixpack <joe@example.org>
500 Architecture: $ARCH" >> $FILE
501 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
503 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
504 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz" >> $FILE
507 insertinstalledpackage
() {
511 local DEPENDENCIES
="$4"
512 local PRIORITY
="${5:-optional}"
513 local FILE
='rootdir/var/lib/dpkg/status'
514 local INFO
='rootdir/var/lib/dpkg/info'
515 for arch
in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
517 Status: install ok installed
521 Maintainer: Joe Sixpack <joe@example.org>
523 Version: $VERSION" >> $FILE
524 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
525 echo "Description: an autogenerated dummy ${NAME}=${VERSION}/installed
526 If you find such a package installed on your system,
527 YOU did something horribly wrong! They are autogenerated
528 und used only by testcases for APT and surf no other propose…
530 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
531 echo -n > ${INFO}/${NAME}:${arch}.list
533 echo -n > ${INFO}/${NAME}.list
539 buildaptarchivefromincoming
() {
540 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
542 [ -e pool
] || ln -s ..
/incoming pool
543 [ -e ftparchive.conf
] || createaptftparchiveconfig
544 [ -e dists
] || buildaptftparchivedirectorystructure
545 msgninfo
"\tGenerate Packages, Sources and Contents files… "
546 aptftparchive
-qq generate ftparchive.conf
552 buildaptarchivefromfiles
() {
553 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
554 find aptarchive
-name 'Packages' -o -name 'Sources' | while read line
; do
555 msgninfo
"\t${line} file… "
556 cat ${line} | gzip > ${line}.gz
557 cat ${line} | bzip2 > ${line}.bz2
558 cat ${line} | lzma
> ${line}.lzma
559 cat ${line} | xz
> ${line}.xz
565 # can be overridden by testcases for their pleasure
566 getcodenamefromsuite
() { echo -n "$1"; }
567 getreleaseversionfromsuite
() { true
; }
568 getlabelfromsuite
() { true
; }
570 generatereleasefiles
() {
571 # $1 is the Date header and $2 is the ValidUntil header to be set
572 # both should be given in notation date/touch can understand
573 msgninfo
"\tGenerate Release files… "
574 if [ -e aptarchive
/dists
]; then
575 for dir
in $(find ./aptarchive/dists -mindepth 3 -maxdepth 3 -type d -name 'i18n'); do
576 aptftparchive
-qq release
$dir -o APT
::FTPArchive
::Release
::Patterns
::='Translation-*' > $dir/Index
578 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
579 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
580 local CODENAME
="$(getcodenamefromsuite $SUITE)"
581 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
582 local LABEL
="$(getlabelfromsuite $SUITE)"
583 if [ -n "$VERSION" ]; then
584 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
586 if [ -n "$LABEL" ]; then
587 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
589 aptftparchive
-qq release
$dir \
590 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
591 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
594 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
595 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
597 NotAutomatic: yes' $dir/Release
599 if [ -n "$1" -a "$1" != "now" ]; then
600 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
604 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
608 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
610 if [ -n "$1" -a "$1" != "now" ]; then
611 for release
in $(find ./aptarchive -name 'Release'); do
612 touch -d "$1" $release
618 setupdistsaptarchive
() {
619 local APTARCHIVE
=$(readlink -f ./aptarchive)
620 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
621 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
622 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
623 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
624 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
625 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
626 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
631 setupflataptarchive
() {
632 local APTARCHIVE
=$(readlink -f ./aptarchive)
633 if [ -f ${APTARCHIVE}/Packages
]; then
634 msgninfo
"\tadd deb sources.list line… "
635 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
638 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
640 if [ -f ${APTARCHIVE}/Sources
]; then
641 msgninfo
"\tadd deb-src sources.list line… "
642 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
645 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
651 if [ -e aptarchive
/dists
]; then
657 msgninfo
"\tSync APT's cache with the archive… "
663 local SIGNER
="${1:-Joe Sixpack}"
664 msgninfo
"\tSign archive with $SIGNER key… "
666 for KEY
in $(find keys/ -name '*.sec'); do
667 SECKEYS
="$SECKEYS --secret-keyring $KEY"
670 for KEY
in $(find keys/ -name '*.pub'); do
671 PUBKEYS
="$PUBKEYS --keyring $KEY"
673 for RELEASE
in $(find aptarchive/ -name Release); do
674 gpg
--yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" -abs -o ${RELEASE}.gpg
${RELEASE}
675 gpg
--yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" --clearsign -o "$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')" $RELEASE
680 changetowebserver
() {
681 if which weborf
> /dev
/null
; then
682 weborf
-xb aptarchive
/ 2>&1 > /dev
/null
&
684 elif which gatling
> /dev
/null
; then
686 gatling
-p 8080 -F -S 2>&1 > /dev
/null
&
689 elif which lighttpd
> /dev
/null
; then
690 echo "server.document-root = \"$(readlink -f ./aptarchive)\"
692 server.stat-cache-engine = \"disable\"" > lighttpd.conf
693 lighttpd
-t -f lighttpd.conf
>/dev
/null
|| msgdie
'Can not change to webserver: our lighttpd config is invalid'
694 lighttpd
-D -f lighttpd.conf
2>/dev
/null
>/dev
/null
&
697 msgdie
'You have to install weborf or lighttpd first'
700 local APTARCHIVE
="file://$(readlink -f ./aptarchive)"
701 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
702 sed -i $LIST -e "s#$APTARCHIVE#http://localhost:8080/#"
708 local DIFFTEXT
="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
709 if [ -n "$DIFFTEXT" ]; then
721 msgtest
"Test for correctness of file" "$FILE"
723 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
725 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
730 local COMPAREFILE
=$(mktemp)
731 addtrap
"rm $COMPAREFILE;"
732 echo "$1" > $COMPAREFILE
734 msgtest
"Test for equality of" "$*"
735 $
* 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
739 local COMPAREFILE1
=$(mktemp)
740 local COMPAREFILE2
=$(mktemp)
741 local COMPAREAGAINST
=$(mktemp)
742 addtrap
"rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
743 echo "$1" > $COMPAREFILE1
744 echo "$2" > $COMPAREFILE2
746 msgtest
"Test for equality OR of" "$*"
747 $
* 2>&1 1> $COMPAREAGAINST
748 (checkdiff
$COMPAREFILE1 $COMPAREAGAINST 1> /dev
/null
||
749 checkdiff
$COMPAREFILE2 $COMPAREAGAINST 1> /dev
/null
) && msgpass
||
750 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
751 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
756 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
759 while [ -n "$1" ]; do
761 N: Can't select versions from package '$1' as it is purely virtual"
762 PACKAGE
="${PACKAGE} $1"
765 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
767 N: No packages found"
768 local COMPAREFILE
=$(mktemp)
769 addtrap
"rm $COMPAREFILE;"
770 local ARCH
="$(getarchitecture 'native')"
771 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
772 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
776 msgtest
"Test for non-existent packages" "apt-cache show $*"
777 local SHOWPKG
="$(aptcache show $* 2>&1 | grep '^Package: ')"
778 if [ -n "$SHOWPKG" ]; then
787 testdpkginstalled
() {
788 msgtest
"Test for correctly installed package(s) with" "dpkg -l $*"
789 local PKGS
="$(dpkg -l $* | grep '^i' | wc -l)"
790 if [ "$PKGS" != $# ]; then
792 dpkg
-l $
* | grep '^[a-z]'
799 testdpkgnotinstalled
() {
800 msgtest
"Test for correctly not-installed package(s) with" "dpkg -l $*"
801 local PKGS
="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)"
802 if [ "$PKGS" != 0 ]; then
804 dpkg
-l $
* | grep '^[a-z]'
812 local COMPAREFILE
=$(mktemp)
813 addtrap
"rm $COMPAREFILE;"
815 msgtest
'Test for correctly marked as auto-installed' "$*"
816 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
818 msgtest
'Test for correctly marked as auto-installed' 'no package'
819 echo -n > $COMPAREFILE
821 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
825 echo "STOPPED execution. Press enter to continue"