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
35 msgdone
() { if [ "$1" = "debug" -o "$1" = "info" ]; then true
; else echo "${CDONE}DONE${CNORMAL}" >&2; fi }
38 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
39 if [ -f .
/aptconfig.conf
]; then
40 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
42 LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
45 aptconfig
() { runapt apt
-config $
*; }
46 aptcache
() { runapt apt
-cache $
*; }
47 aptget
() { runapt apt
-get $
*; }
48 aptftparchive
() { runapt apt
-ftparchive $
*; }
51 local TMPWORKINGDIRECTORY
=$(mktemp -d)
52 local TESTDIR
=$(readlink -f $(dirname $0))
53 msgninfo
"Preparing environment for ${CCMD}$0${CINFO} in ${TMPWORKINGDIRECTORY}… "
54 BUILDDIRECTORY
="${TESTDIR}/../../build/bin"
55 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
56 local OLDWORKINGDIRECTORY
=$(pwd)
57 trap "cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
58 cd $TMPWORKINGDIRECTORY
59 mkdir rootdir aptarchive
61 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
62 mkdir -p var
/cache
/apt
/archives
/partial var
/lib
/apt
/lists
/partial
63 local STATUSFILE
=$(echo "$(basename $0)" | sed 's/^test-/status-/')
64 if [ -f "${TESTDIR}/${STATUSFILE}" ]; then
65 cp "${TESTDIR}/${STATUSFILE}" var/lib/dpkg/status
67 touch var/lib/dpkg/status
70 ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods
72 local PACKAGESFILE=$(echo "$(basename $0)" | sed 's/^test-/Packages-/')
73 if [ -f "${TESTDIR}/${PACKAGESFILE}" ]; then
74 cp "${TESTDIR}/${PACKAGESFILE}" aptarchive
/Packages
76 touch aptarchive
/Packages
78 echo "RootDir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
79 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
80 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
85 configarchitecture
() {
86 local CONFFILE
=rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
87 echo "APT::Architecture \"$1\";" > $CONFFILE
90 echo "APT::Architectures:: \"$1\";" >> $CONFFILE
95 buildsimplenativepackage
() {
99 local RELEASE
="${4:-unstable}"
100 local DEPENDENCIES
="$5"
101 local DESCRIPTION
="$6"
102 msgndebug
"Build package ${CCMD}${NAME}=${VERSION}/${RELEASE}${CDEBUG}… "
103 local BUILDDIR
=incoming
/${NAME}-${VERSION}
104 mkdir -p ${BUILDDIR}/debian
/source
106 echo "* most suckless software product ever" > FEATURES
107 test -e debian
/copyright
|| (echo "Copyleft by Joe Sixpack $(date +%Y)" > debian
/copyright
)
108 test -e debian
/changelog
|| (echo "$NAME ($VERSION) $RELEASE; urgency=low
112 -- Joe Sixpack <joe@example.org> $(date -R)" > debian
/changelog
)
113 test -e debian
/control
|| (echo "Source: $NAME
116 Maintainer: Joe Sixpack <joe@example.org>
117 Build-Depends: debhelper (>= 7)
118 Standards-Version: 3.9.1
121 Architecture: $ARCH" > debian
/control
)
122 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian
/control
123 if [ -z "$DESCRIPTION" ]; then
124 echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
125 If you find such a package installed on your system,
126 YOU did something horribly wrong! They are autogenerated
127 und used only by testcases for APT and surf no other propose…" >> debian
/control
129 echo "Description: $DESCRIPTION" >> debian
/control
131 test -e debian
/compat
|| (echo "7" > debian
/compat
)
132 test -e debian
/source
/format
|| (echo "3.0 (native)" > debian
/source
/format
)
133 test -e debian
/rules
|| cp /usr
/share
/doc
/debhelper
/examples
/rules.tiny debian
/rules
134 dpkg
-buildpackage -uc -us -a$ARCH > /dev
/null
2> /dev
/null
141 msgninfo
"Build APT archive for ${CCMD}$0${CINFO} based on "
142 if [ -d incoming
]; then
143 buildaptarchivefromincoming $
*
145 buildaptarchivefromfiles $
*
149 createaptftparchiveconfig
() {
150 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' ' ')"
152 ArchiveDir "' >> ftparchive.conf
153 echo -n $(readlink -f .) >> ftparchive.conf
155 CacheDir "' >> ftparchive.conf
156 echo -n $(readlink -f ..) >> ftparchive.conf
161 SrcDirectory "pool/";
167 Label "apttestcases";
169 Description "repository with dummy packages";
170 Architectures "' >> ftparchive.conf
171 echo -n "$ARCHS" >> ftparchive.conf
175 };' >> ftparchive.conf
177 echo -n 'tree "dists/unstable" {
178 Architectures "' >> ftparchive.conf
179 echo -n "$ARCHS" >> ftparchive.conf
182 };' >> ftparchive.conf
186 buildaptftparchivedirectorystructure
() {
187 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#')"
188 for arch
in $ARCHS; do
189 mkdir -p dists
/unstable
/main
/binary
-${arch}
191 mkdir -p dists
/unstable
/main
/source
192 mkdir -p dists
/unstable
/main
/i18n
195 buildaptarchivefromincoming
() {
196 msginfo
"incoming packages…"
198 [ -e pool
] || ln -s ..
/incoming pool
199 [ -e ftparchive.conf
] || createaptftparchiveconfig
200 [ -e dists
] || buildaptftparchivedirectorystructure
201 aptftparchive
-qq generate ftparchive.conf
202 for dir
in $(find ./dists -mindepth 1 -maxdepth 1 -type d); do
203 aptftparchive
-qq release
$dir > $dir/Release
204 sed -i -e '/0 Release$/ d' $dir/Release
# remove the self reference
210 buildaptarchivefromfiles
() {
211 msginfo
"prebuild files…"
213 if [ -f Packages
]; then
214 msgninfo
"\tPackages file… "
215 cat Packages
| gzip > Packages.gz
216 cat Packages
| bzip2 > Packages.bz2
217 cat Packages
| lzma
> Packages.lzma
220 if [ -f Sources
]; then
221 msgninfo
"\tSources file… "
222 cat Sources
| gzip > Sources.gz
223 cat Sources
| bzip2 > Sources.bz2
224 cat Sources
| lzma
> Sources.lzma
227 aptftparchive
-qq release .
> Release
228 sed -i -e '/0 Release$/ d' Release
# remove the self reference
234 local APTARCHIVE
=$(readlink -f ./aptarchive)
235 if [ -f ${APTARCHIVE}/Packages
]; then
236 msgninfo
"\tadd deb sources.list line… "
237 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
240 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
242 if [ -f ${APTARCHIVE}/Sources
]; then
243 msgninfo
"\tadd deb-src sources.list line… "
244 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
247 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
253 local DIFFTEXT
="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
254 if [ -n "$DIFFTEXT" ]; then
264 local COMPAREFILE
=$(mktemp)
265 echo "$1" > $COMPAREFILE
267 msgtest
"Test for equality of" "$*"
268 $
* 2>&1 | diff $COMPAREFILE - && msgpass
|| msgfail
273 local COMPAREFILE1
=$(mktemp)
274 local COMPAREFILE2
=$(mktemp)
275 local COMPAREAGAINST
=$(mktemp)
276 echo "$1" > $COMPAREFILE1
277 echo "$2" > $COMPAREFILE2
279 msgtest
"Test for equality OR of" "$*"
280 $
* 2>&1 1> $COMPAREAGAINST
281 (diff $COMPAREFILE1 $COMPAREAGAINST 1> /dev
/null
||
282 diff $COMPAREFILE2 $COMPAREAGAINST 1> /dev
/null
) && msgpass
||
283 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(diff $COMPAREFILE1 $COMPAREAGAINST)" \
284 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(diff $COMPAREFILE2 $COMPAREAGAINST)" &&
286 rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST
290 local VIRTUAL
="N: Can't select versions from package '$1' as it purely virtual"
293 while [ -n "$1" ]; do
295 N: Can't select versions from package '$1' as it purely virtual"
296 PACKAGE
="${PACKAGE} $1"
299 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
301 N: No packages found"
302 local COMPAREFILE
=$(mktemp)
303 local ARCH
=$(dpkg-architecture -qDEB_HOST_ARCH_CPU)
304 eval `apt-config shell ARCH APT::Architecture`
305 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
306 aptcache show
$PACKAGE 2>&1 | diff $COMPAREFILE - && msgpass
|| msgfail
311 msgtest
"Test for non-existent packages" "apt-cache show $*"
312 local SHOWPKG
="$(aptcache show $* 2>&1 | grep '^Package: ')"
313 if [ -n "$SHOWPKG" ]; then