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 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} $(which gdb) ${BUILDDIRECTORY}/$1
116 CURRENTTRAP
="$CURRENTTRAP $1"
117 trap "$CURRENTTRAP exit;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
121 TMPWORKINGDIRECTORY
=$(mktemp -d)
122 TESTDIRECTORY
=$(readlink -f $(dirname $0))
123 msgninfo
"Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
124 BUILDDIRECTORY
="${TESTDIRECTORY}/../../build/bin"
125 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
126 local OLDWORKINGDIRECTORY
=$(pwd)
127 addtrap
"cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY;"
128 cd $TMPWORKINGDIRECTORY
129 mkdir rootdir aptarchive keys
131 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d
132 mkdir -p var
/cache var
/lib var
/log
133 mkdir -p var
/lib
/dpkg
/info var
/lib
/dpkg
/updates var
/lib
/dpkg
/triggers
134 touch var
/lib
/dpkg
/available
136 ln -s ${BUILDDIRECTORY}/methods usr
/lib
/apt
/methods
138 local PACKAGESFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
139 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
140 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
142 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
143 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
144 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive
/Sources
146 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys
/
147 ln -s ${TMPWORKINGDIRECTORY}/keys
/joesixpack.pub rootdir
/etc
/apt
/trusted.gpg.d
/joesixpack.gpg
148 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
149 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
150 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
151 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
152 echo "Dir::Bin::Methods \"${BUILDDIRECTORY}/methods\";" >> aptconfig.conf
153 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
154 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
155 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
156 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
157 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
158 if ! $(which dpkg) --assert-multi-arch 2>&1 > /dev
/null
; then
159 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf
# Added to test multiarch before dpkg is ready for it…
161 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
162 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
164 export PATH
="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
169 if [ "$1" = "native" -o -z "$1" ]; then
170 eval `aptconfig shell ARCH APT::Architecture`
171 if [ -n "$ARCH" ]; then
174 dpkg
--print-architecture
182 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
185 configarchitecture
() {
186 local CONFFILE
=rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
188 echo "APT::Architecture \"$(getarchitecture $1)\";" > $CONFFILE
190 while [ -n "$1" ]; do
191 echo "APT::Architectures:: \"$(getarchitecture $1)\";" >> $CONFFILE
198 if [ ! -e rootdir
/var
/lib
/dpkg
/status
]; then
199 local STATUSFILE
=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
200 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
201 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
203 echo -n > rootdir/var/lib/dpkg/status
206 if $(which dpkg) --assert-multi-arch 2>&1 > /dev/null; then
207 local ARCHS="$(getarchitectures)"
208 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
209 DPKGARCH="$(dpkg --print-architecture)"
210 for ARCH in ${ARCHS}; do
211 if [ "${ARCH}" != "${DPKGARCH}" ]; then dpkg --add-architecture ${ARCH}; fi
213 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
214 # dpkg doesn't really check the version as long as it is fully installed,
215 # but just to be sure we choose one above the required version
216 insertinstalledpackage 'dpkg' "all
" '1.16.2+fake'
222 setupsimplenativepackage() {
226 local RELEASE="${4:-unstable}"
227 local DEPENDENCIES="$5"
228 local DESCRIPTION="$6"
229 local SECTION="${7:-others}"
231 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
234 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
236 local BUILDDIR=incoming/${NAME}-${VERSION}
237 mkdir -p ${BUILDDIR}/debian/source
239 echo "* most suckless software product ever
" > FEATURES
240 test -e debian/copyright || echo "Copyleft by Joe Sixpack
$(date +%Y)" > debian/copyright
241 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency
=low
245 -- Joe Sixpack
<joe@example.org
> $(date -R)" > debian/changelog
246 test -e debian/control || echo "Source
: $NAME
249 Maintainer
: Joe Sixpack
<joe@example.org
>
250 Build
-Depends: debhelper
(>= 7)
251 Standards
-Version: 3.9.1
253 Package
: $NAME" > debian/control
254 if [ "$ARCH" = 'all' ]; then
255 echo "Architecture
: all
" >> debian/control
257 echo "Architecture
: any
" >> debian/control
259 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
260 if [ -z "$DESCRIPTION" ]; then
261 echo "Description
: an autogenerated dummy
${NAME}=${VERSION}/${RELEASE}
262 If you
find such a package installed on your system
,
263 YOU did something horribly wrong
! They are autogenerated
264 und used only by testcases
for APT and surf no other propose…
" >> debian/control
266 echo "Description
: $DESCRIPTION" >> debian/control
268 test -e debian/compat || echo "7" > debian/compat
269 test -e debian/source/format || echo "3.0 (native
)" > debian/source/format
270 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
274 buildsimplenativepackage() {
278 local RELEASE="${4:-unstable}"
279 local DEPENDENCIES="$5"
280 local DESCRIPTION="$6"
281 local SECTION="${7:-others}"
282 local PRIORITY="${8:-optional}"
284 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
287 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
289 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
291 msgninfo "Build package
${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}…
"
292 mkdir -p $BUILDDIR/debian/source
293 echo "* most suckless software product ever
" > ${BUILDDIR}/FEATURES
295 echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
297 echo "Copyleft by Joe Sixpack
$(date +%Y)" > ${BUILDDIR}/debian/copyright
298 echo "$NAME ($VERSION) $RELEASE; urgency
=low
302 -- Joe Sixpack
<joe@example.org
> $(date -R)" > ${BUILDDIR}/debian/changelog
306 Maintainer
: Joe Sixpack
<joe@example.org
>
307 Standards
-Version: 3.9.3" > ${BUILDDIR}/debian/control
308 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
309 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
311 Package
: $NAME" >> ${BUILDDIR}/debian/control
313 if [ "$ARCH" = 'all' ]; then
314 echo "Architecture
: all
" >> ${BUILDDIR}/debian/control
316 echo "Architecture
: any
" >> ${BUILDDIR}/debian/control
318 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
319 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
320 if [ -z "$DESCRIPTION" ]; then
321 echo "Description
: an autogenerated dummy
${NAME}=${VERSION}/${RELEASE}
322 If you
find such a package installed on your system
,
323 YOU did something horribly wrong
! They are autogenerated
324 und used only by testcases
for APT and surf no other propose…
" >> ${BUILDDIR}/debian/control
326 echo "Description
: $DESCRIPTION" >> ${BUILDDIR}/debian/control
329 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
330 local SRCS="$( (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
332 echo "pool
/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
335 for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
336 rm -rf ${BUILDDIR}/debian
/tmp
337 mkdir -p ${BUILDDIR}/debian
/tmp
/DEBIAN
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
338 cp ${BUILDDIR}/debian
/copyright
${BUILDDIR}/debian
/changelog
${BUILDDIR}/FEATURES
${BUILDDIR}/debian
/tmp
/usr
/share
/doc
/${NAME}
339 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian
/tmp
/usr
/bin
/${NAME}-${arch}
340 (cd ${BUILDDIR}; dpkg
-gencontrol -DArchitecture=$arch)
341 (cd ${BUILDDIR}/debian
/tmp
; md5sum $(find usr/ -type f) > DEBIAN
/md5sums
)
343 dpkg
-deb --build ${BUILDDIR}/debian
/tmp
${BUILDDIR}/..
2> /dev
/null
> /dev
/null
344 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/..
/${RELEASE}.
${DISTSECTION}.pkglist
347 mkdir -p ${BUILDDIR}/..
/${NAME}_
${VERSION}
348 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}/
349 cp ${BUILDDIR}/debian
/changelog
${BUILDDIR}/..
/${NAME}_
${VERSION}.changelog
358 local ARCH
=$(getarchitecture $4)
359 msgninfo
"Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… "
361 if [ "$ARCH" = "all" ]; then
362 ARCH
="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
364 local BUILT
="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
365 local PKGS
="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
366 local SRCS
="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
369 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.pkglist
372 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming
/${RELEASE}.
${SECTION}.srclist
378 if [ -d incoming
]; then
379 buildaptarchivefromincoming $
*
381 buildaptarchivefromfiles $
*
385 createaptftparchiveconfig
() {
386 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' ' ')"
387 if [ -z "$ARCHS" ]; then
388 # the pool is empty, so we will operate on faked packages - let us use the configured archs
389 ARCHS
="$(getarchitectures)"
392 ArchiveDir "' >> ftparchive.conf
393 echo -n $(readlink -f .) >> ftparchive.conf
395 CacheDir "' >> ftparchive.conf
396 echo -n $(readlink -f ..) >> ftparchive.conf
398 FileListDir "' >> ftparchive.conf
399 echo -n $(readlink -f pool/) >> ftparchive.conf
403 Packages::Compress ". gzip bzip2 lzma xz";
404 Sources::Compress ". gzip bzip2 lzma xz";
405 Contents::Compress ". gzip bzip2 lzma xz";
406 Translation::Compress ". gzip bzip2 lzma xz";
407 LongDescription "false";
411 SrcDirectory "pool/";
417 Label "apttestcases";
419 Description "repository with dummy packages";
420 Architectures "' >> ftparchive.conf
421 echo -n "$ARCHS" >> ftparchive.conf
425 };' >> ftparchive.conf
426 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
427 echo -n 'tree "dists/' >> ftparchive.conf
428 echo -n "$DIST" >> ftparchive.conf
430 Architectures "' >> ftparchive.conf
431 echo -n "$ARCHS" >> ftparchive.conf
433 FileList "' >> ftparchive.conf
434 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
436 SourceFileList "' >> ftparchive.conf
437 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
439 Sections "' >> ftparchive.conf
440 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
442 };' >> ftparchive.conf
446 buildaptftparchivedirectorystructure
() {
447 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
448 for DIST
in $DISTS; do
449 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
450 for SECTION
in $SECTIONS; do
451 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
452 for ARCH
in $ARCHS; do
453 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
455 mkdir -p dists
/${DIST}/${SECTION}/source
456 mkdir -p dists
/${DIST}/${SECTION}/i18n
466 local DEPENDENCIES
="$5"
467 local PRIORITY
="${6:-optional}"
469 for arch
in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
470 if [ "$arch" = "all" ]; then
471 ARCHS
="$(getarchitectures)"
475 for BUILDARCH
in $ARCHS; do
476 local PPATH
="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
477 mkdir -p $PPATH aptarchive
/dists
/${RELEASE}/main
/source
478 touch aptarchive
/dists
/${RELEASE}/main
/source
/Sources
479 local FILE
="${PPATH}/Packages"
484 Maintainer: Joe Sixpack <joe@example.org>
487 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
488 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
489 echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
490 If you find such a package installed on your system,
491 YOU did something horribly wrong! They are autogenerated
492 und used only by testcases for APT and surf no other propose…
503 local DEPENDENCIES
="$5"
505 local SPATH
="aptarchive/dists/${RELEASE}/main/source"
507 local FILE
="${SPATH}/Sources"
511 Maintainer: Joe Sixpack <joe@example.org>
512 Architecture: $ARCH" >> $FILE
513 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
515 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
516 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
520 insertinstalledpackage
() {
524 local DEPENDENCIES
="$4"
525 local PRIORITY
="${5:-optional}"
526 local FILE
='rootdir/var/lib/dpkg/status'
527 local INFO
='rootdir/var/lib/dpkg/info'
528 for arch
in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
530 Status: install ok installed
534 Maintainer: Joe Sixpack <joe@example.org>
536 Version: $VERSION" >> $FILE
537 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
538 echo "Description: an autogenerated dummy ${NAME}=${VERSION}/installed
539 If you find such a package installed on your system,
540 YOU did something horribly wrong! They are autogenerated
541 und used only by testcases for APT and surf no other propose…
543 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
544 echo -n > ${INFO}/${NAME}:${arch}.list
546 echo -n > ${INFO}/${NAME}.list
552 buildaptarchivefromincoming
() {
553 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
555 [ -e pool
] || ln -s ..
/incoming pool
556 [ -e ftparchive.conf
] || createaptftparchiveconfig
557 [ -e dists
] || buildaptftparchivedirectorystructure
558 msgninfo
"\tGenerate Packages, Sources and Contents files… "
559 aptftparchive
-qq generate ftparchive.conf
565 buildaptarchivefromfiles
() {
566 msginfo
"Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
567 find aptarchive
-name 'Packages' -o -name 'Sources' | while read line
; do
568 msgninfo
"\t${line} file… "
569 cat ${line} | gzip > ${line}.gz
570 cat ${line} | bzip2 > ${line}.bz2
571 cat ${line} | xz
--format=lzma
> ${line}.lzma
572 cat ${line} | xz
> ${line}.xz
578 # can be overridden by testcases for their pleasure
579 getcodenamefromsuite
() { echo -n "$1"; }
580 getreleaseversionfromsuite
() { true
; }
581 getlabelfromsuite
() { true
; }
583 generatereleasefiles
() {
584 # $1 is the Date header and $2 is the ValidUntil header to be set
585 # both should be given in notation date/touch can understand
586 msgninfo
"\tGenerate Release files… "
587 if [ -e aptarchive
/dists
]; then
588 for dir
in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
589 local SUITE
="$(echo "$dir" | cut -d'/' -f 4)"
590 local CODENAME
="$(getcodenamefromsuite $SUITE)"
591 local VERSION
="$(getreleaseversionfromsuite $SUITE)"
592 local LABEL
="$(getlabelfromsuite $SUITE)"
593 if [ -n "$VERSION" ]; then
594 VERSION
="-o APT::FTPArchive::Release::Version=${VERSION}"
596 if [ -n "$LABEL" ]; then
597 LABEL
="-o APT::FTPArchive::Release::Label=${LABEL}"
599 aptftparchive
-qq release
$dir \
600 -o APT
::FTPArchive
::Release
::Suite
="${SUITE}" \
601 -o APT
::FTPArchive
::Release
::Codename
="${CODENAME}" \
604 | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
605 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
607 NotAutomatic: yes' $dir/Release
609 if [ -n "$1" -a "$1" != "now" ]; then
610 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
614 Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
618 aptftparchive
-qq release .
/aptarchive
| sed -e '/0 Release$/ d' > aptarchive
/Release
# remove the self reference
620 if [ -n "$1" -a "$1" != "now" ]; then
621 for release
in $(find ./aptarchive -name 'Release'); do
622 touch -d "$1" $release
628 setupdistsaptarchive
() {
629 local APTARCHIVE
=$(readlink -f ./aptarchive)
630 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
631 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
632 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
633 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
634 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
635 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
636 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
641 setupflataptarchive
() {
642 local APTARCHIVE
=$(readlink -f ./aptarchive)
643 if [ -f ${APTARCHIVE}/Packages
]; then
644 msgninfo
"\tadd deb sources.list line… "
645 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
648 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
650 if [ -f ${APTARCHIVE}/Sources
]; then
651 msgninfo
"\tadd deb-src sources.list line… "
652 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
655 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
661 if [ -e aptarchive
/dists
]; then
667 msgninfo
"\tSync APT's cache with the archive… "
673 local SIGNER
="${1:-Joe Sixpack}"
674 msgninfo
"\tSign archive with $SIGNER key… "
676 for KEY
in $(find keys/ -name '*.sec'); do
677 SECKEYS
="$SECKEYS --secret-keyring $KEY"
680 for KEY
in $(find keys/ -name '*.pub'); do
681 PUBKEYS
="$PUBKEYS --keyring $KEY"
683 for RELEASE
in $(find aptarchive/ -name Release); do
684 gpg
--yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" -abs -o ${RELEASE}.gpg
${RELEASE}
685 gpg
--yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" --clearsign -o "$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')" $RELEASE
690 changetowebserver
() {
691 if [ -n "$1" ] && ! test -x ${BUILDDIRECTORY}/aptwebserver
; then
692 msgdie
'Need the aptwebserver when passing arguments'
695 local LOG
='/dev/null'
696 if test -x ${BUILDDIRECTORY}/aptwebserver
; then
698 LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/aptwebserver $@
2> $LOG > $LOG &
701 elif which weborf
> /dev
/null
; then
702 weborf
-xb aptarchive
/ 2> $LOG > $LOG &
704 elif which gatling
> /dev
/null
; then
706 gatling
-p 8080 -F -S 2> $LOG > $LOG &
709 elif which lighttpd
> /dev
/null
; then
710 echo "server.document-root = \"$(readlink -f ./aptarchive)\"
712 server.stat-cache-engine = \"disable\"" > lighttpd.conf
713 lighttpd
-t -f lighttpd.conf
2> $LOG > $LOG || msgdie
'Can not change to webserver: our lighttpd config is invalid'
714 lighttpd
-D -f lighttpd.conf
2> $LOG > $LOG &
717 msgdie
'You have to install weborf or lighttpd first'
720 local APTARCHIVE
="file://$(readlink -f ./aptarchive)"
721 for LIST
in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
722 sed -i $LIST -e "s#$APTARCHIVE#http://localhost:8080/#"
728 local DIFFTEXT
="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
729 if [ -n "$DIFFTEXT" ]; then
741 msgtest
"Test for correctness of file" "$FILE"
743 echo -n "" | checkdiff
$FILE - && msgpass
|| msgfail
745 echo "$*" | checkdiff
$FILE - && msgpass
|| msgfail
750 local COMPAREFILE
=$(mktemp)
751 addtrap
"rm $COMPAREFILE;"
752 echo "$1" > $COMPAREFILE
754 msgtest
"Test for equality of" "$*"
755 $
* 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
759 local COMPAREFILE1
=$(mktemp)
760 local COMPAREFILE2
=$(mktemp)
761 local COMPAREAGAINST
=$(mktemp)
762 addtrap
"rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
763 echo "$1" > $COMPAREFILE1
764 echo "$2" > $COMPAREFILE2
766 msgtest
"Test for equality OR of" "$*"
767 $
* 2>&1 1> $COMPAREAGAINST
768 (checkdiff
$COMPAREFILE1 $COMPAREAGAINST 1> /dev
/null
||
769 checkdiff
$COMPAREFILE2 $COMPAREAGAINST 1> /dev
/null
) && msgpass
||
770 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
771 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
776 local VIRTUAL
="N: Can't select versions from package '$1' as it is purely virtual"
779 while [ -n "$1" ]; do
781 N: Can't select versions from package '$1' as it is purely virtual"
782 PACKAGE
="${PACKAGE} $1"
785 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
787 N: No packages found"
788 local COMPAREFILE
=$(mktemp)
789 addtrap
"rm $COMPAREFILE;"
790 local ARCH
="$(getarchitecture 'native')"
791 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
792 aptcache show
-q=0 $PACKAGE 2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
796 msgtest
"Test for non-existent packages" "apt-cache show $*"
797 local SHOWPKG
="$(aptcache show $* 2>&1 | grep '^Package: ')"
798 if [ -n "$SHOWPKG" ]; then
807 testdpkginstalled
() {
808 msgtest
"Test for correctly installed package(s) with" "dpkg -l $*"
809 local PKGS
="$(dpkg -l $* | grep '^i' | wc -l)"
810 if [ "$PKGS" != $# ]; then
812 dpkg
-l $
* | grep '^[a-z]'
819 testdpkgnotinstalled
() {
820 msgtest
"Test for correctly not-installed package(s) with" "dpkg -l $*"
821 local PKGS
="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)"
822 if [ "$PKGS" != 0 ]; then
824 dpkg
-l $
* | grep '^[a-z]'
832 local COMPAREFILE
=$(mktemp)
833 addtrap
"rm $COMPAREFILE;"
835 msgtest
'Test for correctly marked as auto-installed' "$*"
836 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
838 msgtest
'Test for correctly marked as auto-installed' 'no package'
839 echo -n > $COMPAREFILE
841 aptmark showauto
2>&1 | checkdiff
$COMPAREFILE - && msgpass
|| msgfail
845 echo "STOPPED execution. Press enter to continue"