]>
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 | |
fc89263e DK |
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 | } | |
8d876415 DK |
62 | |
63 | runapt() { | |
64 | msgdebug "Executing: ${CCMD}$*${CDEBUG} " | |
7d0627b6 DK |
65 | if [ -f ./aptconfig.conf ]; then |
66 | APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$* | |
4b2a4ab8 MV |
67 | elif [ -f ../aptconfig.conf ]; then |
68 | APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$* | |
7d0627b6 DK |
69 | else |
70 | LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$* | |
71 | fi | |
8d876415 DK |
72 | } |
73 | aptconfig() { runapt apt-config $*; } | |
74 | aptcache() { runapt apt-cache $*; } | |
75 | aptget() { runapt apt-get $*; } | |
76 | aptftparchive() { runapt apt-ftparchive $*; } | |
158fda31 DK |
77 | dpkg() { |
78 | $(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log $* | |
79 | } | |
8d876415 DK |
80 | |
81 | setupenvironment() { | |
75954ae2 | 82 | TMPWORKINGDIRECTORY=$(mktemp -d) |
8f8169ac | 83 | local TESTDIR=$(readlink -f $(dirname $0)) |
3cbbda3c | 84 | msgninfo "Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… " |
8f8169ac | 85 | BUILDDIRECTORY="${TESTDIR}/../../build/bin" |
8d876415 DK |
86 | test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first" |
87 | local OLDWORKINGDIRECTORY=$(pwd) | |
f213b6ea DK |
88 | CURRENTTRAP="cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY" |
89 | trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM | |
8d876415 | 90 | cd $TMPWORKINGDIRECTORY |
cd725954 | 91 | mkdir rootdir aptarchive keys |
8d876415 | 92 | cd rootdir |
b29c3712 DK |
93 | mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d |
94 | mkdir -p var/cache var/lib var/log | |
cffea9af | 95 | mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers |
2c6baa5a | 96 | local STATUSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/') |
8f8169ac DK |
97 | if [ -f "${TESTDIR}/${STATUSFILE}" ]; then |
98 | cp "${TESTDIR}/${STATUSFILE}" var/lib/dpkg/status | |
99 | else | |
100 | touch var/lib/dpkg/status | |
101 | fi | |
cd725954 | 102 | touch var/lib/dpkg/available |
8d876415 DK |
103 | mkdir -p usr/lib/apt |
104 | ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods | |
105 | cd .. | |
2c6baa5a | 106 | local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/') |
8f8169ac DK |
107 | if [ -f "${TESTDIR}/${PACKAGESFILE}" ]; then |
108 | cp "${TESTDIR}/${PACKAGESFILE}" aptarchive/Packages | |
109 | else | |
4bec02c2 | 110 | touch aptarchive/Packages |
8f8169ac | 111 | fi |
cd725954 DK |
112 | cp $(find $TESTDIR -name '*.pub' -o -name '*.sec') keys/ |
113 | ln -s ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg | |
cffea9af | 114 | echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf |
8d876415 DK |
115 | echo "Debug::NoLocking \"true\";" >> aptconfig.conf |
116 | echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf | |
cffea9af DK |
117 | echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf |
118 | echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf | |
119 | echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf | |
120 | echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf | |
121 | echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf | |
122 | echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf | |
8d876415 DK |
123 | export LC_ALL=C |
124 | msgdone "info" | |
125 | } | |
126 | ||
127 | configarchitecture() { | |
128 | local CONFFILE=rootdir/etc/apt/apt.conf.d/01multiarch.conf | |
129 | echo "APT::Architecture \"$1\";" > $CONFFILE | |
130 | shift | |
131 | while [ -n "$1" ]; do | |
132 | echo "APT::Architectures:: \"$1\";" >> $CONFFILE | |
133 | shift | |
134 | done | |
135 | } | |
136 | ||
75954ae2 | 137 | setupsimplenativepackage() { |
ce9864a8 DK |
138 | local NAME="$1" |
139 | local ARCH="$2" | |
140 | local VERSION="$3" | |
141 | local RELEASE="${4:-unstable}" | |
142 | local DEPENDENCIES="$5" | |
143 | local DESCRIPTION="$6" | |
b7899b00 DK |
144 | local SECTION="${7:-others}" |
145 | local DISTSECTION | |
146 | if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then | |
147 | DISTSECTION="main" | |
148 | else | |
149 | DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)" | |
150 | fi | |
ce9864a8 DK |
151 | local BUILDDIR=incoming/${NAME}-${VERSION} |
152 | mkdir -p ${BUILDDIR}/debian/source | |
153 | cd ${BUILDDIR} | |
154 | echo "* most suckless software product ever" > FEATURES | |
b7899b00 DK |
155 | test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright |
156 | test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low | |
ce9864a8 DK |
157 | |
158 | * Initial release | |
159 | ||
b7899b00 DK |
160 | -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog |
161 | test -e debian/control || echo "Source: $NAME | |
162 | Section: $SECTION | |
ce9864a8 DK |
163 | Priority: optional |
164 | Maintainer: Joe Sixpack <joe@example.org> | |
165 | Build-Depends: debhelper (>= 7) | |
166 | Standards-Version: 3.9.1 | |
167 | ||
168 | Package: $NAME | |
b7899b00 | 169 | Architecture: $ARCH" > debian/control |
ce9864a8 DK |
170 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control |
171 | if [ -z "$DESCRIPTION" ]; then | |
172 | echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} | |
173 | If you find such a package installed on your system, | |
174 | YOU did something horribly wrong! They are autogenerated | |
175 | und used only by testcases for APT and surf no other propose…" >> debian/control | |
176 | else | |
177 | echo "Description: $DESCRIPTION" >> debian/control | |
178 | fi | |
b7899b00 DK |
179 | test -e debian/compat || echo "7" > debian/compat |
180 | test -e debian/source/format || echo "3.0 (native)" > debian/source/format | |
ce9864a8 | 181 | test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules |
75954ae2 DK |
182 | cd - > /dev/null |
183 | } | |
184 | ||
185 | buildsimplenativepackage() { | |
186 | local NAME="$1" | |
187 | local ARCH="$2" | |
188 | local VERSION="$3" | |
189 | local RELEASE="${4:-unstable}" | |
190 | local DEPENDENCIES="$5" | |
191 | local DESCRIPTION="$6" | |
192 | local SECTION="${7:-others}" | |
193 | local DISTSECTION | |
194 | if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then | |
195 | DISTSECTION="main" | |
196 | else | |
197 | DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)" | |
198 | fi | |
199 | setupsimplenativepackage "$NAME" "$ARCH" "$VERSION" "$RELEASE" "$DEPENDENCIES" "$DESCRIPTION" "$SECTION" | |
200 | buildpackage "incoming/${NAME}-${VERSION}" "$RELEASE" "$DISTSECTION" | |
201 | rm -rf "incoming/${NAME}-${VERSION}" | |
202 | } | |
203 | ||
204 | buildpackage() { | |
205 | local BUILDDIR=$1 | |
206 | local RELEASE=$2 | |
207 | local SECTION=$3 | |
208 | msgninfo "Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… " | |
209 | cd $BUILDDIR | |
210 | if [ "$ARCH" = "all" ]; then | |
211 | ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)" | |
212 | fi | |
b7899b00 DK |
213 | local BUILT="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)" |
214 | local PKGS="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")" | |
215 | local SRCS="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._-]*$')" | |
ce9864a8 | 216 | cd - > /dev/null |
b7899b00 | 217 | for PKG in $PKGS; do |
75954ae2 | 218 | echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist |
b7899b00 DK |
219 | done |
220 | for SRC in $SRCS; do | |
75954ae2 | 221 | echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist |
b7899b00 | 222 | done |
cffea9af | 223 | msgdone "info" |
ce9864a8 DK |
224 | } |
225 | ||
226 | buildaptarchive() { | |
ce9864a8 DK |
227 | if [ -d incoming ]; then |
228 | buildaptarchivefromincoming $* | |
229 | else | |
230 | buildaptarchivefromfiles $* | |
231 | fi | |
232 | } | |
233 | ||
234 | createaptftparchiveconfig() { | |
235 | 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' ' ')" | |
158fda31 DK |
236 | if [ -z "$ARCHS" ]; then |
237 | # the pool is empty, so we will operate on faked packages - let us use the configured archs | |
238 | ARCHS="$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')" | |
239 | fi | |
ce9864a8 DK |
240 | echo -n 'Dir { |
241 | ArchiveDir "' >> ftparchive.conf | |
242 | echo -n $(readlink -f .) >> ftparchive.conf | |
243 | echo -n '"; | |
244 | CacheDir "' >> ftparchive.conf | |
245 | echo -n $(readlink -f ..) >> ftparchive.conf | |
246 | echo -n '"; | |
b7899b00 DK |
247 | FileListDir "' >> ftparchive.conf |
248 | echo -n $(readlink -f pool/) >> ftparchive.conf | |
249 | echo -n '"; | |
250 | }; | |
251 | Default { | |
252 | Packages::Compress ". gzip bzip2 lzma"; | |
253 | Sources::Compress ". gzip bzip2 lzma"; | |
254 | Contents::Compress ". gzip bzip2 lzma"; | |
ce9864a8 DK |
255 | }; |
256 | TreeDefault { | |
257 | Directory "pool/"; | |
258 | SrcDirectory "pool/"; | |
259 | }; | |
260 | APT { | |
261 | FTPArchive { | |
262 | Release { | |
263 | Origin "joesixpack"; | |
264 | Label "apttestcases"; | |
265 | Suite "unstable"; | |
266 | Description "repository with dummy packages"; | |
267 | Architectures "' >> ftparchive.conf | |
268 | echo -n "$ARCHS" >> ftparchive.conf | |
269 | echo 'source"; | |
270 | }; | |
271 | }; | |
272 | };' >> ftparchive.conf | |
b7899b00 DK |
273 | for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do |
274 | echo -n 'tree "dists/' >> ftparchive.conf | |
275 | echo -n "$DIST" >> ftparchive.conf | |
276 | echo -n '" { | |
ce9864a8 DK |
277 | Architectures "' >> ftparchive.conf |
278 | echo -n "$ARCHS" >> ftparchive.conf | |
b7899b00 DK |
279 | echo -n 'source"; |
280 | FileList "' >> ftparchive.conf | |
281 | echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf | |
282 | echo -n '"; | |
283 | SourceFileList "' >> ftparchive.conf | |
284 | echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf | |
285 | echo -n '"; | |
286 | Sections "' >> ftparchive.conf | |
287 | 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 | |
288 | echo '"; | |
ce9864a8 | 289 | };' >> ftparchive.conf |
b7899b00 | 290 | done |
ce9864a8 DK |
291 | } |
292 | ||
293 | buildaptftparchivedirectorystructure() { | |
b7899b00 DK |
294 | local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')" |
295 | for DIST in $DISTS; do | |
296 | local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)" | |
297 | for SECTION in $SECTIONS; do | |
298 | local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')" | |
299 | for ARCH in $ARCHS; do | |
300 | mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH} | |
301 | done | |
302 | mkdir -p dists/${DIST}/${SECTION}/source | |
303 | mkdir -p dists/${DIST}/${SECTION}/i18n | |
304 | done | |
ce9864a8 | 305 | done |
ce9864a8 DK |
306 | } |
307 | ||
308 | buildaptarchivefromincoming() { | |
3cbbda3c | 309 | msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…" |
ce9864a8 DK |
310 | cd aptarchive |
311 | [ -e pool ] || ln -s ../incoming pool | |
312 | [ -e ftparchive.conf ] || createaptftparchiveconfig | |
313 | [ -e dists ] || buildaptftparchivedirectorystructure | |
b7899b00 | 314 | msgninfo "\tGenerate Packages, Sources and Contents files… " |
ce9864a8 | 315 | aptftparchive -qq generate ftparchive.conf |
b7899b00 DK |
316 | msgdone "info" |
317 | msgninfo "\tGenerate Release files… " | |
ce9864a8 | 318 | for dir in $(find ./dists -mindepth 1 -maxdepth 1 -type d); do |
cd725954 | 319 | aptftparchive -qq release $dir -o APT::FTPArchive::Release::Codename="$(echo "$dir" | cut -d'/' -f 3)" | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference |
ce9864a8 DK |
320 | done |
321 | cd - > /dev/null | |
322 | msgdone "info" | |
323 | } | |
324 | ||
325 | buildaptarchivefromfiles() { | |
3cbbda3c | 326 | msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…" |
8d876415 | 327 | cd aptarchive |
8d876415 DK |
328 | if [ -f Packages ]; then |
329 | msgninfo "\tPackages file… " | |
330 | cat Packages | gzip > Packages.gz | |
331 | cat Packages | bzip2 > Packages.bz2 | |
332 | cat Packages | lzma > Packages.lzma | |
333 | msgdone "info" | |
334 | fi | |
335 | if [ -f Sources ]; then | |
336 | msgninfo "\tSources file… " | |
337 | cat Sources | gzip > Sources.gz | |
338 | cat Sources | bzip2 > Sources.bz2 | |
339 | cat Sources | lzma > Sources.lzma | |
340 | msgdone "info" | |
341 | fi | |
b7899b00 DK |
342 | msgninfo "\tRelease file… " |
343 | aptftparchive -qq release . | sed -e '/0 Release$/ d' > Release # remove the self reference | |
344 | msgdone "info" | |
8d876415 | 345 | cd .. |
8d876415 DK |
346 | } |
347 | ||
b7899b00 DK |
348 | setupdistsaptarchive() { |
349 | local APTARCHIVE=$(readlink -f ./aptarchive) | |
350 | rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list | |
351 | rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list | |
352 | for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do | |
353 | SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ') | |
354 | msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… " | |
355 | echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list | |
356 | echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list | |
357 | msgdone "info" | |
358 | done | |
359 | } | |
360 | ||
361 | setupflataptarchive() { | |
ce9864a8 | 362 | local APTARCHIVE=$(readlink -f ./aptarchive) |
8d876415 DK |
363 | if [ -f ${APTARCHIVE}/Packages ]; then |
364 | msgninfo "\tadd deb sources.list line… " | |
365 | echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list | |
366 | msgdone "info" | |
367 | else | |
368 | rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list | |
369 | fi | |
370 | if [ -f ${APTARCHIVE}/Sources ]; then | |
371 | msgninfo "\tadd deb-src sources.list line… " | |
372 | echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list | |
373 | msgdone "info" | |
374 | else | |
375 | rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list | |
376 | fi | |
b7899b00 DK |
377 | } |
378 | ||
379 | setupaptarchive() { | |
380 | buildaptarchive | |
381 | if [ -e aptarchive/dists ]; then | |
382 | setupdistsaptarchive | |
383 | else | |
384 | setupflataptarchive | |
385 | fi | |
f213b6ea | 386 | signreleasefiles |
cd725954 | 387 | msgninfo "\tSync APT's cache with the archive… " |
8d876415 | 388 | aptget update -qq |
cd725954 | 389 | msgdone "info" |
8d876415 DK |
390 | } |
391 | ||
f213b6ea DK |
392 | signreleasefiles() { |
393 | local SIGNER="${1:-Joe Sixpack}" | |
394 | msgninfo "\tSign archive with $SIGNER key… " | |
395 | local SECKEYS="" | |
396 | for KEY in $(find keys/ -name '*.sec'); do | |
397 | SECKEYS="$SECKEYS --secret-keyring $KEY" | |
398 | done | |
399 | local PUBKEYS="" | |
400 | for KEY in $(find keys/ -name '*.pub'); do | |
401 | PUBKEYS="$PUBKEYS --keyring $KEY" | |
402 | done | |
403 | for RELEASE in $(find aptarchive/ -name Release); do | |
404 | gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" -abs -o ${RELEASE}.gpg ${RELEASE} | |
405 | done | |
406 | msgdone "info" | |
407 | } | |
408 | ||
409 | changetowebserver() { | |
410 | if which weborf > /dev/null; then | |
411 | weborf -xb aptarchive/ 2>&1 > /dev/null & | |
412 | CURRENTTRAP="kill $(ps | grep weborf | sed -e 's#^[ ]*##' | cut -d' ' -f 1); $CURRENTTRAP" | |
413 | trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM | |
414 | local APTARCHIVE="file://$(readlink -f ./aptarchive)" | |
415 | for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do | |
416 | sed -i $LIST -e "s#$APTARCHIVE#http://localhost:8080/#" | |
417 | done | |
418 | return 0 | |
419 | fi | |
420 | return 1 | |
421 | } | |
422 | ||
423 | checkdiff() { | |
8d876415 DK |
424 | local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')" |
425 | if [ -n "$DIFFTEXT" ]; then | |
426 | echo | |
427 | echo "$DIFFTEXT" | |
428 | return 1 | |
429 | else | |
430 | return 0 | |
431 | fi | |
432 | } | |
433 | ||
75954ae2 DK |
434 | testfileequal() { |
435 | local FILE="$1" | |
436 | shift | |
437 | msgtest "Test for correctness of file" "$FILE" | |
438 | if [ -z "$*" ]; then | |
f213b6ea | 439 | echo -n "" | checkdiff $FILE - && msgpass || msgfail |
75954ae2 | 440 | else |
f213b6ea | 441 | echo "$*" | checkdiff $FILE - && msgpass || msgfail |
75954ae2 DK |
442 | fi |
443 | } | |
444 | ||
8d876415 DK |
445 | testequal() { |
446 | local COMPAREFILE=$(mktemp) | |
447 | echo "$1" > $COMPAREFILE | |
448 | shift | |
449 | msgtest "Test for equality of" "$*" | |
f213b6ea | 450 | $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail |
8e86786b | 451 | rm $COMPAREFILE |
8d876415 DK |
452 | } |
453 | ||
685625bd DK |
454 | testequalor2() { |
455 | local COMPAREFILE1=$(mktemp) | |
456 | local COMPAREFILE2=$(mktemp) | |
457 | local COMPAREAGAINST=$(mktemp) | |
458 | echo "$1" > $COMPAREFILE1 | |
459 | echo "$2" > $COMPAREFILE2 | |
460 | shift 2 | |
461 | msgtest "Test for equality OR of" "$*" | |
462 | $* 2>&1 1> $COMPAREAGAINST | |
f213b6ea DK |
463 | (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null || |
464 | checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass || | |
465 | ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \ | |
466 | "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" && | |
685625bd | 467 | msgfail ) |
8e86786b | 468 | rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST |
685625bd DK |
469 | } |
470 | ||
8d876415 | 471 | testshowvirtual() { |
4bec02c2 | 472 | local VIRTUAL="N: Can't select versions from package '$1' as it purely virtual" |
8d876415 DK |
473 | local PACKAGE="$1" |
474 | shift | |
475 | while [ -n "$1" ]; do | |
476 | VIRTUAL="${VIRTUAL} | |
4bec02c2 | 477 | N: Can't select versions from package '$1' as it purely virtual" |
8d876415 DK |
478 | PACKAGE="${PACKAGE} $1" |
479 | shift | |
480 | done | |
481 | msgtest "Test for virtual packages" "apt-cache show $PACKAGE" | |
482 | VIRTUAL="${VIRTUAL} | |
4bec02c2 | 483 | N: No packages found" |
8d876415 DK |
484 | local COMPAREFILE=$(mktemp) |
485 | local ARCH=$(dpkg-architecture -qDEB_HOST_ARCH_CPU) | |
486 | eval `apt-config shell ARCH APT::Architecture` | |
487 | echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE | |
e8379ba3 | 488 | aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail |
8e86786b | 489 | rm $COMPAREFILE |
8d876415 DK |
490 | } |
491 | ||
492 | testnopackage() { | |
493 | msgtest "Test for non-existent packages" "apt-cache show $*" | |
494 | local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')" | |
495 | if [ -n "$SHOWPKG" ]; then | |
496 | echo | |
497 | echo "$SHOWPKG" | |
498 | msgfail | |
499 | return 1 | |
500 | fi | |
501 | msgpass | |
502 | } |