1 #!/bin/sh -- # no runable script, just for vi
3 # we all like colorful messages
4 CERROR
="\e[1;31m" # red
5 CWARNING
="\e[1;33m" # yellow
6 CMSG
="\e[1;32m" # green
7 CINFO
="\e[1;96m" # light blue
8 CDEBUG
="\e[1;94m" # blue
9 CNORMAL
="\e[0;39m" # default system console color
10 CDONE
="\e[1;32m" # green
11 CPASS
="\e[1;32m" # green
12 CFAIL
="\e[1;31m" # red
13 CCMD
="\e[1;35m" # pink
15 msgdie
() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; }
16 msgwarn
() { echo "${CWARNING}W: $1${CNORMAL}" >&2; }
17 msgmsg
() { echo "${CMSG}$1${CNORMAL}" >&2; }
18 msginfo
() { echo "${CINFO}I: $1${CNORMAL}" >&2; }
19 msgdebug
() { echo "${CDEBUG}D: $1${CNORMAL}" >&2; }
20 msgdone
() { echo "${CDONE}DONE${CNORMAL}" >&2; }
21 msgnwarn
() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; }
22 msgnmsg
() { echo -n "${CMSG}$1${CNORMAL}" >&2; }
23 msgninfo
() { echo -n "${CINFO}I: $1${CNORMAL}" >&2; }
24 msgndebug
() { echo -n "${CDEBUG}D: $1${CNORMAL}" >&2; }
25 msgtest
() { echo -n "${CINFO}$1 ${CCMD}$(echo "$2" | sed -e 's/^aptc/apt-c/' -e 's/^aptg/apt-g/' -e 's/^aptf/apt-f/')${CINFO} …${CNORMAL} " >&2; }
26 msgpass
() { echo "${CPASS}PASS${CNORMAL}" >&2; }
27 msgskip
() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
28 msgfail
() { echo "${CFAIL}FAIL${CNORMAL}" >&2; }
30 # enable / disable Debugging
31 MSGLEVEL
=${MSGLEVEL:-3}
32 if [ $MSGLEVEL -le 0 ]; then
35 if [ $MSGLEVEL -le 1 ]; then
39 if [ $MSGLEVEL -le 2 ]; then
43 if [ $MSGLEVEL -le 3 ]; then
47 if [ $MSGLEVEL -le 4 ]; then
52 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
53 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
54 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
55 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
56 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
59 echo "${CDONE}DONE${CNORMAL}" >&2;
64 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
65 if [ -f .
/aptconfig.conf
]; then
66 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
68 LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
71 aptconfig
() { runapt apt
-config $
*; }
72 aptcache
() { runapt apt
-cache $
*; }
73 aptget
() { runapt apt
-get $
*; }
74 aptftparchive
() { runapt apt
-ftparchive $
*; }
77 local TMPWORKINGDIRECTORY
=$(mktemp -d)
78 local TESTDIR
=$(readlink -f $(dirname $0))
79 msgninfo
"Preparing environment for ${CCMD}$0${CINFO} in ${TMPWORKINGDIRECTORY}… "
80 BUILDDIRECTORY
="${TESTDIR}/../../build/bin"
81 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
82 local OLDWORKINGDIRECTORY
=$(pwd)
83 trap "cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
84 cd $TMPWORKINGDIRECTORY
85 mkdir rootdir aptarchive
87 mkdir -p etc
/apt
/apt.conf.d etc
/apt
/sources.list.d etc
/apt
/trusted.gpg.d etc
/apt
/preferences.d var
/cache var
/lib
/dpkg
88 mkdir -p var
/cache
/apt
/archives
/partial var
/lib
/apt
/lists
/partial
89 local STATUSFILE
=$(echo "$(basename $0)" | sed 's/^test-/status-/')
90 if [ -f "${TESTDIR}/${STATUSFILE}" ]; then
91 cp "${TESTDIR}/${STATUSFILE}" var/lib/dpkg/status
93 touch var/lib/dpkg/status
96 ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods
98 local PACKAGESFILE=$(echo "$(basename $0)" | sed 's/^test-/Packages-/')
99 if [ -f "${TESTDIR}/${PACKAGESFILE}" ]; then
100 cp "${TESTDIR}/${PACKAGESFILE}" aptarchive
/Packages
102 touch aptarchive
/Packages
104 echo "RootDir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
105 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
106 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
111 configarchitecture
() {
112 local CONFFILE
=rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
113 echo "APT::Architecture \"$1\";" > $CONFFILE
115 while [ -n "$1" ]; do
116 echo "APT::Architectures:: \"$1\";" >> $CONFFILE
121 buildsimplenativepackage
() {
125 local RELEASE
="${4:-unstable}"
126 local DEPENDENCIES
="$5"
127 local DESCRIPTION
="$6"
128 local SECTION
="${7:-others}"
130 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
133 DISTSECTION
="$(echo "$SECTION" | cut -d'/' -f 1)"
135 msgndebug
"Build package ${CCMD}${NAME}=${VERSION}/${RELEASE}${CDEBUG}… "
136 local BUILDDIR
=incoming
/${NAME}-${VERSION}
137 mkdir -p ${BUILDDIR}/debian
/source
139 echo "* most suckless software product ever" > FEATURES
140 test -e debian
/copyright
|| echo "Copyleft by Joe Sixpack $(date +%Y)" > debian
/copyright
141 test -e debian
/changelog
|| echo "$NAME ($VERSION) $RELEASE; urgency=low
145 -- Joe Sixpack <joe@example.org> $(date -R)" > debian
/changelog
146 test -e debian
/control
|| echo "Source: $NAME
149 Maintainer: Joe Sixpack <joe@example.org>
150 Build-Depends: debhelper (>= 7)
151 Standards-Version: 3.9.1
154 Architecture: $ARCH" > debian
/control
155 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian
/control
156 if [ -z "$DESCRIPTION" ]; then
157 echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
158 If you find such a package installed on your system,
159 YOU did something horribly wrong! They are autogenerated
160 und used only by testcases for APT and surf no other propose…" >> debian
/control
162 echo "Description: $DESCRIPTION" >> debian
/control
164 test -e debian
/compat
|| echo "7" > debian
/compat
165 test -e debian
/source
/format
|| echo "3.0 (native)" > debian
/source
/format
166 test -e debian
/rules
|| cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny debian
/rules
167 local BUILT
="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
168 local PKGS
="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
169 local SRCS
="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._-]*$')"
172 echo "pool/${PKG}" >> .
/incoming
/${RELEASE}.
${DISTSECTION}.pkglist
175 echo "pool/${SRC}" >> .
/incoming
/${RELEASE}.
${DISTSECTION}.srclist
182 if [ -d incoming
]; then
183 buildaptarchivefromincoming $
*
185 buildaptarchivefromfiles $
*
189 createaptftparchiveconfig
() {
190 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' ' ')"
192 ArchiveDir "' >> ftparchive.conf
193 echo -n $(readlink -f .) >> ftparchive.conf
195 CacheDir "' >> ftparchive.conf
196 echo -n $(readlink -f ..) >> ftparchive.conf
198 FileListDir "' >> ftparchive.conf
199 echo -n $(readlink -f pool/) >> ftparchive.conf
203 Packages::Compress ". gzip bzip2 lzma";
204 Sources::Compress ". gzip bzip2 lzma";
205 Contents::Compress ". gzip bzip2 lzma";
209 SrcDirectory "pool/";
215 Label "apttestcases";
217 Description "repository with dummy packages";
218 Architectures "' >> ftparchive.conf
219 echo -n "$ARCHS" >> ftparchive.conf
223 };' >> ftparchive.conf
224 for DIST
in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
225 echo -n 'tree "dists/' >> ftparchive.conf
226 echo -n "$DIST" >> ftparchive.conf
228 Architectures "' >> ftparchive.conf
229 echo -n "$ARCHS" >> ftparchive.conf
231 FileList "' >> ftparchive.conf
232 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
234 SourceFileList "' >> ftparchive.conf
235 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
237 Sections "' >> ftparchive.conf
238 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
240 };' >> ftparchive.conf
245 buildaptftparchivedirectorystructure
() {
246 local DISTS
="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
247 for DIST
in $DISTS; do
248 local SECTIONS
="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
249 for SECTION
in $SECTIONS; do
250 local ARCHS
="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
251 for ARCH
in $ARCHS; do
252 mkdir -p dists
/${DIST}/${SECTION}/binary
-${ARCH}
254 mkdir -p dists
/${DIST}/${SECTION}/source
255 mkdir -p dists
/${DIST}/${SECTION}/i18n
260 buildaptarchivefromincoming
() {
261 msginfo
"Build APT archive for ${CCMD}$0${CINFO} based on incoming packages…"
263 [ -e pool
] || ln -s ..
/incoming pool
264 [ -e ftparchive.conf
] || createaptftparchiveconfig
265 [ -e dists
] || buildaptftparchivedirectorystructure
266 msgninfo
"\tGenerate Packages, Sources and Contents files… "
267 aptftparchive
-qq generate ftparchive.conf
269 msgninfo
"\tGenerate Release files… "
270 for dir
in $(find ./dists -mindepth 1 -maxdepth 1 -type d); do
271 aptftparchive
-qq release
$dir | sed -e '/0 Release$/ d' > $dir/Release
# remove the self reference
277 buildaptarchivefromfiles
() {
278 msginfo
"Build APT archive for ${CCMD}$0${CINFO} based on prebuild files…"
280 if [ -f Packages
]; then
281 msgninfo
"\tPackages file… "
282 cat Packages
| gzip > Packages.gz
283 cat Packages
| bzip2 > Packages.bz2
284 cat Packages
| lzma
> Packages.lzma
287 if [ -f Sources
]; then
288 msgninfo
"\tSources file… "
289 cat Sources
| gzip > Sources.gz
290 cat Sources
| bzip2 > Sources.bz2
291 cat Sources
| lzma
> Sources.lzma
294 msgninfo
"\tRelease file… "
295 aptftparchive
-qq release .
| sed -e '/0 Release$/ d' > Release
# remove the self reference
300 setupdistsaptarchive
() {
301 local APTARCHIVE
=$(readlink -f ./aptarchive)
302 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb.list
303 rm -f root
/etc
/apt
/sources.list.d
/apt
-test-*-deb-src.list
304 for DISTS
in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
305 SECTIONS
=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
306 msgninfo
"\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
307 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb.list
308 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-${DISTS}-deb-src.list
313 setupflataptarchive
() {
314 local APTARCHIVE
=$(readlink -f ./aptarchive)
315 if [ -f ${APTARCHIVE}/Packages
]; then
316 msgninfo
"\tadd deb sources.list line… "
317 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
320 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
322 if [ -f ${APTARCHIVE}/Sources
]; then
323 msgninfo
"\tadd deb-src sources.list line… "
324 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
327 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
333 if [ -e aptarchive
/dists
]; then
342 local DIFFTEXT
="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
343 if [ -n "$DIFFTEXT" ]; then
353 local COMPAREFILE
=$(mktemp)
354 echo "$1" > $COMPAREFILE
356 msgtest
"Test for equality of" "$*"
357 $
* 2>&1 | diff $COMPAREFILE - && msgpass
|| msgfail
362 local COMPAREFILE1
=$(mktemp)
363 local COMPAREFILE2
=$(mktemp)
364 local COMPAREAGAINST
=$(mktemp)
365 echo "$1" > $COMPAREFILE1
366 echo "$2" > $COMPAREFILE2
368 msgtest
"Test for equality OR of" "$*"
369 $
* 2>&1 1> $COMPAREAGAINST
370 (diff $COMPAREFILE1 $COMPAREAGAINST 1> /dev
/null
||
371 diff $COMPAREFILE2 $COMPAREAGAINST 1> /dev
/null
) && msgpass
||
372 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(diff $COMPAREFILE1 $COMPAREAGAINST)" \
373 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(diff $COMPAREFILE2 $COMPAREAGAINST)" &&
375 rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST
379 local VIRTUAL
="N: Can't select versions from package '$1' as it purely virtual"
382 while [ -n "$1" ]; do
384 N: Can't select versions from package '$1' as it purely virtual"
385 PACKAGE
="${PACKAGE} $1"
388 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
390 N: No packages found"
391 local COMPAREFILE
=$(mktemp)
392 local ARCH
=$(dpkg-architecture -qDEB_HOST_ARCH_CPU)
393 eval `apt-config shell ARCH APT::Architecture`
394 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
395 aptcache show
$PACKAGE 2>&1 | diff $COMPAREFILE - && msgpass
|| msgfail
400 msgtest
"Test for non-existent packages" "apt-cache show $*"
401 local SHOWPKG
="$(aptcache show $* 2>&1 | grep '^Package: ')"
402 if [ -n "$SHOWPKG" ]; then