]>
Commit | Line | Data |
---|---|---|
8d876415 DK |
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 | msginfo() { true; } | |
32 | msgdebug() { true; } | |
33 | msgninfo() { true; } | |
34 | msgndebug() { true; } | |
35 | msgdone() { if [ "$1" = "debug" -o "$1" = "info" ]; then true; else echo "${CDONE}DONE${CNORMAL}" >&2; fi } | |
36 | ||
37 | runapt() { | |
38 | msgdebug "Executing: ${CCMD}$*${CDEBUG} " | |
7d0627b6 DK |
39 | if [ -f ./aptconfig.conf ]; then |
40 | APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$* | |
41 | else | |
42 | LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$* | |
43 | fi | |
8d876415 DK |
44 | } |
45 | aptconfig() { runapt apt-config $*; } | |
46 | aptcache() { runapt apt-cache $*; } | |
47 | aptget() { runapt apt-get $*; } | |
48 | aptftparchive() { runapt apt-ftparchive $*; } | |
49 | ||
50 | setupenvironment() { | |
51 | local TMPWORKINGDIRECTORY=$(mktemp -d) | |
8f8169ac | 52 | local TESTDIR=$(readlink -f $(dirname $0)) |
8d876415 | 53 | msgninfo "Preparing environment for ${CCMD}$0${CINFO} in ${TMPWORKINGDIRECTORY}… " |
8f8169ac | 54 | BUILDDIRECTORY="${TESTDIR}/../../build/bin" |
8d876415 DK |
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 | |
60 | cd rootdir | |
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 | |
8f8169ac DK |
63 | local STATUSFILE=$(echo "$(basename $0)" | sed 's/^test-/status-/') |
64 | if [ -f "${TESTDIR}/${STATUSFILE}" ]; then | |
65 | cp "${TESTDIR}/${STATUSFILE}" var/lib/dpkg/status | |
66 | else | |
67 | touch var/lib/dpkg/status | |
68 | fi | |
8d876415 DK |
69 | mkdir -p usr/lib/apt |
70 | ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods | |
71 | cd .. | |
8f8169ac DK |
72 | local PACKAGESFILE=$(echo "$(basename $0)" | sed 's/^test-/Packages-/') |
73 | if [ -f "${TESTDIR}/${PACKAGESFILE}" ]; then | |
74 | cp "${TESTDIR}/${PACKAGESFILE}" aptarchive/Packages | |
75 | else | |
4bec02c2 | 76 | touch aptarchive/Packages |
8f8169ac | 77 | fi |
8d876415 DK |
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 | |
81 | export LC_ALL=C | |
82 | msgdone "info" | |
83 | } | |
84 | ||
85 | configarchitecture() { | |
86 | local CONFFILE=rootdir/etc/apt/apt.conf.d/01multiarch.conf | |
87 | echo "APT::Architecture \"$1\";" > $CONFFILE | |
88 | shift | |
89 | while [ -n "$1" ]; do | |
90 | echo "APT::Architectures:: \"$1\";" >> $CONFFILE | |
91 | shift | |
92 | done | |
93 | } | |
94 | ||
ce9864a8 DK |
95 | buildsimplenativepackage() { |
96 | local NAME="$1" | |
97 | local ARCH="$2" | |
98 | local VERSION="$3" | |
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 | |
105 | cd ${BUILDDIR} | |
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 | |
109 | ||
110 | * Initial release | |
111 | ||
112 | -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog) | |
113 | test -e debian/control || (echo "Source: $NAME | |
114 | Section: admin | |
115 | Priority: optional | |
116 | Maintainer: Joe Sixpack <joe@example.org> | |
117 | Build-Depends: debhelper (>= 7) | |
118 | Standards-Version: 3.9.1 | |
119 | ||
120 | Package: $NAME | |
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 | |
128 | else | |
129 | echo "Description: $DESCRIPTION" >> debian/control | |
130 | fi | |
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 | |
135 | cd - > /dev/null | |
136 | rm -rf $BUILDDIR | |
137 | msgdone "debug" | |
138 | } | |
139 | ||
140 | buildaptarchive() { | |
141 | msgninfo "Build APT archive for ${CCMD}$0${CINFO} based on " | |
142 | if [ -d incoming ]; then | |
143 | buildaptarchivefromincoming $* | |
144 | else | |
145 | buildaptarchivefromfiles $* | |
146 | fi | |
147 | } | |
148 | ||
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' ' ')" | |
151 | echo -n 'Dir { | |
152 | ArchiveDir "' >> ftparchive.conf | |
153 | echo -n $(readlink -f .) >> ftparchive.conf | |
154 | echo -n '"; | |
155 | CacheDir "' >> ftparchive.conf | |
156 | echo -n $(readlink -f ..) >> ftparchive.conf | |
157 | echo -n '"; | |
158 | }; | |
159 | TreeDefault { | |
160 | Directory "pool/"; | |
161 | SrcDirectory "pool/"; | |
162 | }; | |
163 | APT { | |
164 | FTPArchive { | |
165 | Release { | |
166 | Origin "joesixpack"; | |
167 | Label "apttestcases"; | |
168 | Suite "unstable"; | |
169 | Description "repository with dummy packages"; | |
170 | Architectures "' >> ftparchive.conf | |
171 | echo -n "$ARCHS" >> ftparchive.conf | |
172 | echo 'source"; | |
173 | }; | |
174 | }; | |
175 | };' >> ftparchive.conf | |
176 | if [ -z "$1" ]; then | |
177 | echo -n 'tree "dists/unstable" { | |
178 | Architectures "' >> ftparchive.conf | |
179 | echo -n "$ARCHS" >> ftparchive.conf | |
180 | echo 'source"; | |
181 | Sections "main"; | |
182 | };' >> ftparchive.conf | |
183 | fi | |
184 | } | |
185 | ||
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} | |
190 | done | |
191 | mkdir -p dists/unstable/main/source | |
192 | mkdir -p dists/unstable/main/i18n | |
193 | } | |
194 | ||
195 | buildaptarchivefromincoming() { | |
196 | msginfo "incoming packages…" | |
197 | cd aptarchive | |
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 | |
205 | done | |
206 | cd - > /dev/null | |
207 | msgdone "info" | |
208 | } | |
209 | ||
210 | buildaptarchivefromfiles() { | |
211 | msginfo "prebuild files…" | |
8d876415 | 212 | cd aptarchive |
8d876415 DK |
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 | |
218 | msgdone "info" | |
219 | fi | |
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 | |
225 | msgdone "info" | |
226 | fi | |
ce9864a8 DK |
227 | aptftparchive -qq release . > Release |
228 | sed -i -e '/0 Release$/ d' Release # remove the self reference | |
8d876415 | 229 | cd .. |
8d876415 DK |
230 | } |
231 | ||
ce9864a8 DK |
232 | setupaptarchive() { |
233 | buildaptarchive | |
234 | local APTARCHIVE=$(readlink -f ./aptarchive) | |
8d876415 DK |
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 | |
238 | msgdone "info" | |
239 | else | |
240 | rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list | |
241 | fi | |
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 | |
245 | msgdone "info" | |
246 | else | |
247 | rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list | |
248 | fi | |
249 | aptget update -qq | |
250 | } | |
251 | ||
252 | diff() { | |
253 | local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')" | |
254 | if [ -n "$DIFFTEXT" ]; then | |
255 | echo | |
256 | echo "$DIFFTEXT" | |
257 | return 1 | |
258 | else | |
259 | return 0 | |
260 | fi | |
261 | } | |
262 | ||
263 | testequal() { | |
264 | local COMPAREFILE=$(mktemp) | |
265 | echo "$1" > $COMPAREFILE | |
266 | shift | |
267 | msgtest "Test for equality of" "$*" | |
268 | $* 2>&1 | diff $COMPAREFILE - && msgpass || msgfail | |
8e86786b | 269 | rm $COMPAREFILE |
8d876415 DK |
270 | } |
271 | ||
685625bd DK |
272 | testequalor2() { |
273 | local COMPAREFILE1=$(mktemp) | |
274 | local COMPAREFILE2=$(mktemp) | |
275 | local COMPAREAGAINST=$(mktemp) | |
276 | echo "$1" > $COMPAREFILE1 | |
277 | echo "$2" > $COMPAREFILE2 | |
278 | shift 2 | |
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)" && | |
285 | msgfail ) | |
8e86786b | 286 | rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST |
685625bd DK |
287 | } |
288 | ||
8d876415 | 289 | testshowvirtual() { |
4bec02c2 | 290 | local VIRTUAL="N: Can't select versions from package '$1' as it purely virtual" |
8d876415 DK |
291 | local PACKAGE="$1" |
292 | shift | |
293 | while [ -n "$1" ]; do | |
294 | VIRTUAL="${VIRTUAL} | |
4bec02c2 | 295 | N: Can't select versions from package '$1' as it purely virtual" |
8d876415 DK |
296 | PACKAGE="${PACKAGE} $1" |
297 | shift | |
298 | done | |
299 | msgtest "Test for virtual packages" "apt-cache show $PACKAGE" | |
300 | VIRTUAL="${VIRTUAL} | |
4bec02c2 | 301 | N: No packages found" |
8d876415 DK |
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 | |
8e86786b | 307 | rm $COMPAREFILE |
8d876415 DK |
308 | } |
309 | ||
310 | testnopackage() { | |
311 | msgtest "Test for non-existent packages" "apt-cache show $*" | |
312 | local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')" | |
313 | if [ -n "$SHOWPKG" ]; then | |
314 | echo | |
315 | echo "$SHOWPKG" | |
316 | msgfail | |
317 | return 1 | |
318 | fi | |
319 | msgpass | |
320 | } |