]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh -- # no runable script, just for vi | |
2 | ||
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 | |
14 | ||
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; } | |
29 | ||
30 | # enable / disable Debugging | |
31 | MSGLEVEL=${MSGLEVEL:-3} | |
32 | if [ $MSGLEVEL -le 0 ]; then | |
33 | msgdie() { true; } | |
34 | fi | |
35 | if [ $MSGLEVEL -le 1 ]; then | |
36 | msgwarn() { true; } | |
37 | msgnwarn() { true; } | |
38 | fi | |
39 | if [ $MSGLEVEL -le 2 ]; then | |
40 | msgmsg() { true; } | |
41 | msgnmsg() { true; } | |
42 | fi | |
43 | if [ $MSGLEVEL -le 3 ]; then | |
44 | msginfo() { true; } | |
45 | msgninfo() { true; } | |
46 | fi | |
47 | if [ $MSGLEVEL -le 4 ]; then | |
48 | msgdebug() { true; } | |
49 | msgndebug() { true; } | |
50 | fi | |
51 | msgdone() { | |
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 | |
57 | true; | |
58 | else | |
59 | echo "${CDONE}DONE${CNORMAL}" >&2; | |
60 | fi | |
61 | } | |
62 | ||
63 | runapt() { | |
64 | msgdebug "Executing: ${CCMD}$*${CDEBUG} " | |
65 | if [ -f ./aptconfig.conf ]; then | |
66 | APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$* | |
67 | else | |
68 | LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$* | |
69 | fi | |
70 | } | |
71 | aptconfig() { runapt apt-config $*; } | |
72 | aptcache() { runapt apt-cache $*; } | |
73 | aptget() { runapt apt-get $*; } | |
74 | aptftparchive() { runapt apt-ftparchive $*; } | |
75 | ||
76 | setupenvironment() { | |
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 | |
86 | cd rootdir | |
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 | |
92 | else | |
93 | touch var/lib/dpkg/status | |
94 | fi | |
95 | mkdir -p usr/lib/apt | |
96 | ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods | |
97 | cd .. | |
98 | local PACKAGESFILE=$(echo "$(basename $0)" | sed 's/^test-/Packages-/') | |
99 | if [ -f "${TESTDIR}/${PACKAGESFILE}" ]; then | |
100 | cp "${TESTDIR}/${PACKAGESFILE}" aptarchive/Packages | |
101 | else | |
102 | touch aptarchive/Packages | |
103 | fi | |
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 | |
107 | export LC_ALL=C | |
108 | msgdone "info" | |
109 | } | |
110 | ||
111 | configarchitecture() { | |
112 | local CONFFILE=rootdir/etc/apt/apt.conf.d/01multiarch.conf | |
113 | echo "APT::Architecture \"$1\";" > $CONFFILE | |
114 | shift | |
115 | while [ -n "$1" ]; do | |
116 | echo "APT::Architectures:: \"$1\";" >> $CONFFILE | |
117 | shift | |
118 | done | |
119 | } | |
120 | ||
121 | buildsimplenativepackage() { | |
122 | local NAME="$1" | |
123 | local ARCH="$2" | |
124 | local VERSION="$3" | |
125 | local RELEASE="${4:-unstable}" | |
126 | local DEPENDENCIES="$5" | |
127 | local DESCRIPTION="$6" | |
128 | local SECTION="${7:-others}" | |
129 | local DISTSECTION | |
130 | if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then | |
131 | DISTSECTION="main" | |
132 | else | |
133 | DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)" | |
134 | fi | |
135 | msgndebug "Build package ${CCMD}${NAME}=${VERSION}/${RELEASE}${CDEBUG}… " | |
136 | local BUILDDIR=incoming/${NAME}-${VERSION} | |
137 | mkdir -p ${BUILDDIR}/debian/source | |
138 | cd ${BUILDDIR} | |
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 | |
142 | ||
143 | * Initial release | |
144 | ||
145 | -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog | |
146 | test -e debian/control || echo "Source: $NAME | |
147 | Section: $SECTION | |
148 | Priority: optional | |
149 | Maintainer: Joe Sixpack <joe@example.org> | |
150 | Build-Depends: debhelper (>= 7) | |
151 | Standards-Version: 3.9.1 | |
152 | ||
153 | Package: $NAME | |
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 | |
161 | else | |
162 | echo "Description: $DESCRIPTION" >> debian/control | |
163 | fi | |
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._-]*$')" | |
170 | cd - > /dev/null | |
171 | for PKG in $PKGS; do | |
172 | echo "pool/${PKG}" >> ./incoming/${RELEASE}.${DISTSECTION}.pkglist | |
173 | done | |
174 | for SRC in $SRCS; do | |
175 | echo "pool/${SRC}" >> ./incoming/${RELEASE}.${DISTSECTION}.srclist | |
176 | done | |
177 | rm -rf $BUILDDIR | |
178 | msgdone "debug" | |
179 | } | |
180 | ||
181 | buildaptarchive() { | |
182 | if [ -d incoming ]; then | |
183 | buildaptarchivefromincoming $* | |
184 | else | |
185 | buildaptarchivefromfiles $* | |
186 | fi | |
187 | } | |
188 | ||
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' ' ')" | |
191 | echo -n 'Dir { | |
192 | ArchiveDir "' >> ftparchive.conf | |
193 | echo -n $(readlink -f .) >> ftparchive.conf | |
194 | echo -n '"; | |
195 | CacheDir "' >> ftparchive.conf | |
196 | echo -n $(readlink -f ..) >> ftparchive.conf | |
197 | echo -n '"; | |
198 | FileListDir "' >> ftparchive.conf | |
199 | echo -n $(readlink -f pool/) >> ftparchive.conf | |
200 | echo -n '"; | |
201 | }; | |
202 | Default { | |
203 | Packages::Compress ". gzip bzip2 lzma"; | |
204 | Sources::Compress ". gzip bzip2 lzma"; | |
205 | Contents::Compress ". gzip bzip2 lzma"; | |
206 | }; | |
207 | TreeDefault { | |
208 | Directory "pool/"; | |
209 | SrcDirectory "pool/"; | |
210 | }; | |
211 | APT { | |
212 | FTPArchive { | |
213 | Release { | |
214 | Origin "joesixpack"; | |
215 | Label "apttestcases"; | |
216 | Suite "unstable"; | |
217 | Description "repository with dummy packages"; | |
218 | Architectures "' >> ftparchive.conf | |
219 | echo -n "$ARCHS" >> ftparchive.conf | |
220 | echo 'source"; | |
221 | }; | |
222 | }; | |
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 | |
227 | echo -n '" { | |
228 | Architectures "' >> ftparchive.conf | |
229 | echo -n "$ARCHS" >> ftparchive.conf | |
230 | echo -n 'source"; | |
231 | FileList "' >> ftparchive.conf | |
232 | echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf | |
233 | echo -n '"; | |
234 | SourceFileList "' >> ftparchive.conf | |
235 | echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf | |
236 | echo -n '"; | |
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 | |
239 | echo '"; | |
240 | };' >> ftparchive.conf | |
241 | done | |
242 | less ftparchive.conf | |
243 | } | |
244 | ||
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} | |
253 | done | |
254 | mkdir -p dists/${DIST}/${SECTION}/source | |
255 | mkdir -p dists/${DIST}/${SECTION}/i18n | |
256 | done | |
257 | done | |
258 | } | |
259 | ||
260 | buildaptarchivefromincoming() { | |
261 | msginfo "Build APT archive for ${CCMD}$0${CINFO} based on incoming packages…" | |
262 | cd aptarchive | |
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 | |
268 | msgdone "info" | |
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 | |
272 | done | |
273 | cd - > /dev/null | |
274 | msgdone "info" | |
275 | } | |
276 | ||
277 | buildaptarchivefromfiles() { | |
278 | msginfo "Build APT archive for ${CCMD}$0${CINFO} based on prebuild files…" | |
279 | cd aptarchive | |
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 | |
285 | msgdone "info" | |
286 | fi | |
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 | |
292 | msgdone "info" | |
293 | fi | |
294 | msgninfo "\tRelease file… " | |
295 | aptftparchive -qq release . | sed -e '/0 Release$/ d' > Release # remove the self reference | |
296 | msgdone "info" | |
297 | cd .. | |
298 | } | |
299 | ||
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 | |
309 | msgdone "info" | |
310 | done | |
311 | } | |
312 | ||
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 | |
318 | msgdone "info" | |
319 | else | |
320 | rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list | |
321 | fi | |
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 | |
325 | msgdone "info" | |
326 | else | |
327 | rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list | |
328 | fi | |
329 | } | |
330 | ||
331 | setupaptarchive() { | |
332 | buildaptarchive | |
333 | if [ -e aptarchive/dists ]; then | |
334 | setupdistsaptarchive | |
335 | else | |
336 | setupflataptarchive | |
337 | fi | |
338 | aptget update -qq | |
339 | } | |
340 | ||
341 | diff() { | |
342 | local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')" | |
343 | if [ -n "$DIFFTEXT" ]; then | |
344 | echo | |
345 | echo "$DIFFTEXT" | |
346 | return 1 | |
347 | else | |
348 | return 0 | |
349 | fi | |
350 | } | |
351 | ||
352 | testequal() { | |
353 | local COMPAREFILE=$(mktemp) | |
354 | echo "$1" > $COMPAREFILE | |
355 | shift | |
356 | msgtest "Test for equality of" "$*" | |
357 | $* 2>&1 | diff $COMPAREFILE - && msgpass || msgfail | |
358 | rm $COMPAREFILE | |
359 | } | |
360 | ||
361 | testequalor2() { | |
362 | local COMPAREFILE1=$(mktemp) | |
363 | local COMPAREFILE2=$(mktemp) | |
364 | local COMPAREAGAINST=$(mktemp) | |
365 | echo "$1" > $COMPAREFILE1 | |
366 | echo "$2" > $COMPAREFILE2 | |
367 | shift 2 | |
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)" && | |
374 | msgfail ) | |
375 | rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST | |
376 | } | |
377 | ||
378 | testshowvirtual() { | |
379 | local VIRTUAL="N: Can't select versions from package '$1' as it purely virtual" | |
380 | local PACKAGE="$1" | |
381 | shift | |
382 | while [ -n "$1" ]; do | |
383 | VIRTUAL="${VIRTUAL} | |
384 | N: Can't select versions from package '$1' as it purely virtual" | |
385 | PACKAGE="${PACKAGE} $1" | |
386 | shift | |
387 | done | |
388 | msgtest "Test for virtual packages" "apt-cache show $PACKAGE" | |
389 | VIRTUAL="${VIRTUAL} | |
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 | |
396 | rm $COMPAREFILE | |
397 | } | |
398 | ||
399 | testnopackage() { | |
400 | msgtest "Test for non-existent packages" "apt-cache show $*" | |
401 | local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')" | |
402 | if [ -n "$SHOWPKG" ]; then | |
403 | echo | |
404 | echo "$SHOWPKG" | |
405 | msgfail | |
406 | return 1 | |
407 | fi | |
408 | msgpass | |
409 | } |