]>
Commit | Line | Data |
---|---|---|
8d876415 DK |
1 | #!/bin/sh -- # no runable script, just for vi |
2 | ||
3 | # we all like colorful messages | |
682a3bf7 DK |
4 | if expr match "$(readlink -f /proc/$$/fd/1)" '/dev/pts/[0-9]\+' > /dev/null && \ |
5 | expr match "$(readlink -f /proc/$$/fd/2)" '/dev/pts/[0-9]\+' > /dev/null; then | |
6 | CERROR="\e[1;31m" # red | |
7 | CWARNING="\e[1;33m" # yellow | |
8 | CMSG="\e[1;32m" # green | |
9 | CINFO="\e[1;96m" # light blue | |
10 | CDEBUG="\e[1;94m" # blue | |
11 | CNORMAL="\e[0;39m" # default system console color | |
12 | CDONE="\e[1;32m" # green | |
13 | CPASS="\e[1;32m" # green | |
14 | CFAIL="\e[1;31m" # red | |
15 | CCMD="\e[1;35m" # pink | |
16 | fi | |
8d876415 DK |
17 | |
18 | msgdie() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; } | |
19 | msgwarn() { echo "${CWARNING}W: $1${CNORMAL}" >&2; } | |
20 | msgmsg() { echo "${CMSG}$1${CNORMAL}" >&2; } | |
21 | msginfo() { echo "${CINFO}I: $1${CNORMAL}" >&2; } | |
22 | msgdebug() { echo "${CDEBUG}D: $1${CNORMAL}" >&2; } | |
23 | msgdone() { echo "${CDONE}DONE${CNORMAL}" >&2; } | |
24 | msgnwarn() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; } | |
25 | msgnmsg() { echo -n "${CMSG}$1${CNORMAL}" >&2; } | |
26 | msgninfo() { echo -n "${CINFO}I: $1${CNORMAL}" >&2; } | |
27 | msgndebug() { echo -n "${CDEBUG}D: $1${CNORMAL}" >&2; } | |
2a2a7ef4 DK |
28 | msgtest() { |
29 | while [ -n "$1" ]; do | |
30 | echo -n "${CINFO}$1${CCMD} " >&2; | |
31 | echo -n "$(echo "$2" | sed -e 's/^aptc/apt-c/' -e 's/^aptg/apt-g/' -e 's/^aptf/apt-f/')${CINFO} " >&2; | |
d73840dc DK |
32 | shift |
33 | if [ -n "$1" ]; then shift; else break; fi | |
2a2a7ef4 DK |
34 | done |
35 | echo -n "…${CNORMAL} " >&2; | |
36 | } | |
8d876415 DK |
37 | msgpass() { echo "${CPASS}PASS${CNORMAL}" >&2; } |
38 | msgskip() { echo "${CWARNING}SKIP${CNORMAL}" >&2; } | |
39 | msgfail() { echo "${CFAIL}FAIL${CNORMAL}" >&2; } | |
40 | ||
41 | # enable / disable Debugging | |
fc89263e DK |
42 | MSGLEVEL=${MSGLEVEL:-3} |
43 | if [ $MSGLEVEL -le 0 ]; then | |
44 | msgdie() { true; } | |
45 | fi | |
46 | if [ $MSGLEVEL -le 1 ]; then | |
47 | msgwarn() { true; } | |
48 | msgnwarn() { true; } | |
49 | fi | |
50 | if [ $MSGLEVEL -le 2 ]; then | |
51 | msgmsg() { true; } | |
52 | msgnmsg() { true; } | |
39cc8228 DK |
53 | msgtest() { true; } |
54 | msgpass() { echo -n " ${CPASS}P${CNORMAL}" >&2; } | |
55 | msgskip() { echo -n " ${CWARNING}S${CNORMAL}" >&2; } | |
682a3bf7 DK |
56 | if [ -n "$CFAIL" ]; then |
57 | msgfail() { echo -n " ${CFAIL}FAIL${CNORMAL}" >&2; } | |
58 | else | |
59 | msgfail() { echo -n " ###FAILED###" >&2; } | |
60 | fi | |
fc89263e DK |
61 | fi |
62 | if [ $MSGLEVEL -le 3 ]; then | |
63 | msginfo() { true; } | |
64 | msgninfo() { true; } | |
65 | fi | |
66 | if [ $MSGLEVEL -le 4 ]; then | |
67 | msgdebug() { true; } | |
68 | msgndebug() { true; } | |
69 | fi | |
70 | msgdone() { | |
71 | if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] || | |
72 | [ "$1" = "info" -a $MSGLEVEL -le 3 ] || | |
73 | [ "$1" = "msg" -a $MSGLEVEL -le 2 ] || | |
74 | [ "$1" = "warn" -a $MSGLEVEL -le 1 ] || | |
75 | [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then | |
76 | true; | |
77 | else | |
78 | echo "${CDONE}DONE${CNORMAL}" >&2; | |
79 | fi | |
80 | } | |
8d876415 DK |
81 | |
82 | runapt() { | |
83 | msgdebug "Executing: ${CCMD}$*${CDEBUG} " | |
7d0627b6 DK |
84 | if [ -f ./aptconfig.conf ]; then |
85 | APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$* | |
4b2a4ab8 MV |
86 | elif [ -f ../aptconfig.conf ]; then |
87 | APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$* | |
7d0627b6 DK |
88 | else |
89 | LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$* | |
90 | fi | |
8d876415 DK |
91 | } |
92 | aptconfig() { runapt apt-config $*; } | |
93 | aptcache() { runapt apt-cache $*; } | |
94 | aptget() { runapt apt-get $*; } | |
95 | aptftparchive() { runapt apt-ftparchive $*; } | |
1f8b2599 | 96 | aptkey() { runapt apt-key $*; } |
ec7f904e | 97 | aptmark() { runapt apt-mark $*; } |
158fda31 DK |
98 | dpkg() { |
99 | $(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log $* | |
100 | } | |
b6b5a542 DK |
101 | aptitude() { |
102 | if [ -f ./aptconfig.conf ]; then | |
103 | APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $* | |
104 | elif [ -f ../aptconfig.conf ]; then | |
105 | APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $* | |
106 | else | |
107 | LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $* | |
108 | fi | |
109 | } | |
3fa950f1 DK |
110 | gdb() { |
111 | echo "gdb: run »$*«" | |
112 | APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which gdb) ${BUILDDIRECTORY}/$1 | |
113 | } | |
8d876415 | 114 | |
b720d0bd DK |
115 | addtrap() { |
116 | CURRENTTRAP="$CURRENTTRAP $1" | |
a7e052ea | 117 | trap "$CURRENTTRAP exit;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM |
b720d0bd | 118 | } |
8d876415 DK |
119 | |
120 | setupenvironment() { | |
75954ae2 | 121 | TMPWORKINGDIRECTORY=$(mktemp -d) |
53ea1b56 | 122 | TESTDIRECTORY=$(readlink -f $(dirname $0)) |
3cbbda3c | 123 | msgninfo "Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… " |
53ea1b56 | 124 | BUILDDIRECTORY="${TESTDIRECTORY}/../../build/bin" |
8d876415 DK |
125 | test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first" |
126 | local OLDWORKINGDIRECTORY=$(pwd) | |
b720d0bd | 127 | addtrap "cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY;" |
8d876415 | 128 | cd $TMPWORKINGDIRECTORY |
cd725954 | 129 | mkdir rootdir aptarchive keys |
8d876415 | 130 | cd rootdir |
b29c3712 DK |
131 | mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d |
132 | mkdir -p var/cache var/lib var/log | |
cffea9af | 133 | mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers |
cd725954 | 134 | touch var/lib/dpkg/available |
8d876415 DK |
135 | mkdir -p usr/lib/apt |
136 | ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods | |
137 | cd .. | |
2c6baa5a | 138 | local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/') |
53ea1b56 DK |
139 | if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then |
140 | cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages | |
8f8169ac | 141 | fi |
4a4ea26c | 142 | local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/') |
53ea1b56 DK |
143 | if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then |
144 | cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources | |
8f8169ac | 145 | fi |
53ea1b56 | 146 | cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys/ |
cd725954 | 147 | ln -s ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg |
cffea9af | 148 | echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf |
94eb3bee | 149 | echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf |
8d876415 DK |
150 | echo "Debug::NoLocking \"true\";" >> aptconfig.conf |
151 | echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf | |
f425d4d5 | 152 | echo "Dir::Bin::Methods \"${BUILDDIRECTORY}/methods\";" >> aptconfig.conf |
cffea9af DK |
153 | echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf |
154 | echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf | |
155 | echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf | |
156 | echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf | |
157 | echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf | |
c204d148 | 158 | if ! $(which dpkg) --assert-multi-arch 2>&1 > /dev/null; then |
53ea1b56 DK |
159 | echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf # Added to test multiarch before dpkg is ready for it… |
160 | fi | |
cffea9af | 161 | echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf |
2c085486 | 162 | echo 'quiet::NoUpdate "true";' >> aptconfig.conf |
8d876415 | 163 | export LC_ALL=C |
7f52cf7b | 164 | export PATH="${PATH}:/usr/local/sbin:/usr/sbin:/sbin" |
8d876415 DK |
165 | msgdone "info" |
166 | } | |
167 | ||
ea65d079 DK |
168 | getarchitecture() { |
169 | if [ "$1" = "native" -o -z "$1" ]; then | |
170 | eval `aptconfig shell ARCH APT::Architecture` | |
171 | if [ -n "$ARCH" ]; then | |
172 | echo $ARCH | |
173 | else | |
5834d7a1 | 174 | dpkg --print-architecture |
ea65d079 DK |
175 | fi |
176 | else | |
177 | echo $1 | |
178 | fi | |
179 | } | |
180 | ||
53ea1b56 DK |
181 | getarchitectures() { |
182 | echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')" | |
183 | } | |
184 | ||
8d876415 DK |
185 | configarchitecture() { |
186 | local CONFFILE=rootdir/etc/apt/apt.conf.d/01multiarch.conf | |
234675b7 | 187 | rm -f $CONFFILE |
ea65d079 | 188 | echo "APT::Architecture \"$(getarchitecture $1)\";" > $CONFFILE |
8d876415 DK |
189 | shift |
190 | while [ -n "$1" ]; do | |
ea65d079 | 191 | echo "APT::Architectures:: \"$(getarchitecture $1)\";" >> $CONFFILE |
8d876415 DK |
192 | shift |
193 | done | |
53ea1b56 DK |
194 | configdpkg |
195 | } | |
196 | ||
197 | configdpkg() { | |
198 | if [ ! -e rootdir/var/lib/dpkg/status ]; then | |
199 | local STATUSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/') | |
200 | if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then | |
201 | cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status | |
202 | else | |
203 | echo -n > rootdir/var/lib/dpkg/status | |
204 | fi | |
205 | fi | |
c204d148 | 206 | if $(which dpkg) --assert-multi-arch 2>&1 > /dev/null; then |
53ea1b56 DK |
207 | local ARCHS="$(getarchitectures)" |
208 | if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then | |
209 | DPKGARCH="$(dpkg --print-architecture)" | |
210 | for ARCH in ${ARCHS}; do | |
211 | if [ "${ARCH}" != "${DPKGARCH}" ]; then dpkg --add-architecture ${ARCH}; fi | |
212 | done | |
213 | if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then | |
05343a22 DK |
214 | # dpkg doesn't really check the version as long as it is fully installed, |
215 | # but just to be sure we choose one above the required version | |
216 | insertinstalledpackage 'dpkg' "all" '1.16.2+fake' | |
53ea1b56 DK |
217 | fi |
218 | fi | |
219 | fi | |
8d876415 DK |
220 | } |
221 | ||
75954ae2 | 222 | setupsimplenativepackage() { |
ce9864a8 DK |
223 | local NAME="$1" |
224 | local ARCH="$2" | |
225 | local VERSION="$3" | |
226 | local RELEASE="${4:-unstable}" | |
227 | local DEPENDENCIES="$5" | |
228 | local DESCRIPTION="$6" | |
b7899b00 DK |
229 | local SECTION="${7:-others}" |
230 | local DISTSECTION | |
231 | if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then | |
232 | DISTSECTION="main" | |
233 | else | |
234 | DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)" | |
235 | fi | |
ce9864a8 DK |
236 | local BUILDDIR=incoming/${NAME}-${VERSION} |
237 | mkdir -p ${BUILDDIR}/debian/source | |
238 | cd ${BUILDDIR} | |
239 | echo "* most suckless software product ever" > FEATURES | |
b7899b00 DK |
240 | test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright |
241 | test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low | |
ce9864a8 DK |
242 | |
243 | * Initial release | |
244 | ||
b7899b00 DK |
245 | -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog |
246 | test -e debian/control || echo "Source: $NAME | |
247 | Section: $SECTION | |
ce9864a8 DK |
248 | Priority: optional |
249 | Maintainer: Joe Sixpack <joe@example.org> | |
250 | Build-Depends: debhelper (>= 7) | |
251 | Standards-Version: 3.9.1 | |
252 | ||
875bcb36 DK |
253 | Package: $NAME" > debian/control |
254 | if [ "$ARCH" = 'all' ]; then | |
255 | echo "Architecture: all" >> debian/control | |
256 | else | |
257 | echo "Architecture: any" >> debian/control | |
258 | fi | |
ce9864a8 DK |
259 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control |
260 | if [ -z "$DESCRIPTION" ]; then | |
261 | echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} | |
262 | If you find such a package installed on your system, | |
263 | YOU did something horribly wrong! They are autogenerated | |
264 | und used only by testcases for APT and surf no other propose…" >> debian/control | |
265 | else | |
266 | echo "Description: $DESCRIPTION" >> debian/control | |
267 | fi | |
b7899b00 DK |
268 | test -e debian/compat || echo "7" > debian/compat |
269 | test -e debian/source/format || echo "3.0 (native)" > debian/source/format | |
ce9864a8 | 270 | test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules |
75954ae2 DK |
271 | cd - > /dev/null |
272 | } | |
273 | ||
274 | buildsimplenativepackage() { | |
275 | local NAME="$1" | |
276 | local ARCH="$2" | |
277 | local VERSION="$3" | |
278 | local RELEASE="${4:-unstable}" | |
279 | local DEPENDENCIES="$5" | |
280 | local DESCRIPTION="$6" | |
281 | local SECTION="${7:-others}" | |
d67004e0 | 282 | local PRIORITY="${8:-optional}" |
75954ae2 DK |
283 | local DISTSECTION |
284 | if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then | |
285 | DISTSECTION="main" | |
286 | else | |
287 | DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)" | |
288 | fi | |
5a635ee4 | 289 | local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION} |
b761356f | 290 | |
18331adf | 291 | msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… " |
b761356f DK |
292 | mkdir -p $BUILDDIR/debian/source |
293 | echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES | |
294 | echo "#!/bin/sh | |
295 | echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME} | |
296 | ||
297 | echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright | |
298 | echo "$NAME ($VERSION) $RELEASE; urgency=low | |
299 | ||
300 | * Initial release | |
301 | ||
302 | -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog | |
303 | echo "Source: $NAME | |
304 | Section: $SECTION | |
d67004e0 | 305 | Priority: $PRIORITY |
b761356f | 306 | Maintainer: Joe Sixpack <joe@example.org> |
01f520ce DK |
307 | Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control |
308 | local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')" | |
309 | test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control | |
310 | echo " | |
311 | Package: $NAME" >> ${BUILDDIR}/debian/control | |
b761356f | 312 | |
875bcb36 DK |
313 | if [ "$ARCH" = 'all' ]; then |
314 | echo "Architecture: all" >> ${BUILDDIR}/debian/control | |
315 | else | |
316 | echo "Architecture: any" >> ${BUILDDIR}/debian/control | |
317 | fi | |
01f520ce DK |
318 | local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')" |
319 | test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control | |
b761356f DK |
320 | if [ -z "$DESCRIPTION" ]; then |
321 | echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} | |
322 | If you find such a package installed on your system, | |
323 | YOU did something horribly wrong! They are autogenerated | |
324 | und used only by testcases for APT and surf no other propose…" >> ${BUILDDIR}/debian/control | |
325 | else | |
01f520ce | 326 | echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control |
b761356f | 327 | fi |
01f520ce | 328 | |
b761356f DK |
329 | echo '3.0 (native)' > ${BUILDDIR}/debian/source/format |
330 | local SRCS="$( (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')" | |
b761356f | 331 | for SRC in $SRCS; do |
5a635ee4 | 332 | echo "pool/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist |
b761356f | 333 | done |
84aa13f4 | 334 | |
ea65d079 | 335 | for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do |
84aa13f4 DK |
336 | rm -rf ${BUILDDIR}/debian/tmp |
337 | mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin | |
338 | cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} | |
339 | cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch} | |
340 | (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch) | |
341 | (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums) | |
342 | ||
343 | dpkg-deb --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/.. 2> /dev/null > /dev/null | |
344 | echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist | |
345 | done | |
346 | ||
13845042 DK |
347 | mkdir -p ${BUILDDIR}/../${NAME}_${VERSION} |
348 | cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}/ | |
349 | cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}.changelog | |
5a635ee4 | 350 | rm -rf "${BUILDDIR}" |
b761356f | 351 | msgdone "info" |
75954ae2 DK |
352 | } |
353 | ||
354 | buildpackage() { | |
355 | local BUILDDIR=$1 | |
356 | local RELEASE=$2 | |
357 | local SECTION=$3 | |
ea65d079 | 358 | local ARCH=$(getarchitecture $4) |
75954ae2 DK |
359 | msgninfo "Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… " |
360 | cd $BUILDDIR | |
361 | if [ "$ARCH" = "all" ]; then | |
362 | ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)" | |
363 | fi | |
b7899b00 DK |
364 | local BUILT="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)" |
365 | local PKGS="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")" | |
5ed56f93 | 366 | local SRCS="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')" |
ce9864a8 | 367 | cd - > /dev/null |
b7899b00 | 368 | for PKG in $PKGS; do |
75954ae2 | 369 | echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist |
b7899b00 DK |
370 | done |
371 | for SRC in $SRCS; do | |
75954ae2 | 372 | echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist |
b7899b00 | 373 | done |
cffea9af | 374 | msgdone "info" |
ce9864a8 DK |
375 | } |
376 | ||
377 | buildaptarchive() { | |
ce9864a8 DK |
378 | if [ -d incoming ]; then |
379 | buildaptarchivefromincoming $* | |
380 | else | |
381 | buildaptarchivefromfiles $* | |
382 | fi | |
383 | } | |
384 | ||
385 | createaptftparchiveconfig() { | |
386 | 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 |
387 | if [ -z "$ARCHS" ]; then |
388 | # the pool is empty, so we will operate on faked packages - let us use the configured archs | |
53ea1b56 | 389 | ARCHS="$(getarchitectures)" |
158fda31 | 390 | fi |
ce9864a8 DK |
391 | echo -n 'Dir { |
392 | ArchiveDir "' >> ftparchive.conf | |
393 | echo -n $(readlink -f .) >> ftparchive.conf | |
394 | echo -n '"; | |
395 | CacheDir "' >> ftparchive.conf | |
396 | echo -n $(readlink -f ..) >> ftparchive.conf | |
397 | echo -n '"; | |
b7899b00 DK |
398 | FileListDir "' >> ftparchive.conf |
399 | echo -n $(readlink -f pool/) >> ftparchive.conf | |
400 | echo -n '"; | |
401 | }; | |
402 | Default { | |
bc33e0f0 DK |
403 | Packages::Compress ". gzip bzip2 lzma xz"; |
404 | Sources::Compress ". gzip bzip2 lzma xz"; | |
405 | Contents::Compress ". gzip bzip2 lzma xz"; | |
b7080ced | 406 | Translation::Compress ". gzip bzip2 lzma xz"; |
18331adf | 407 | LongDescription "false"; |
ce9864a8 DK |
408 | }; |
409 | TreeDefault { | |
410 | Directory "pool/"; | |
411 | SrcDirectory "pool/"; | |
412 | }; | |
413 | APT { | |
414 | FTPArchive { | |
415 | Release { | |
416 | Origin "joesixpack"; | |
417 | Label "apttestcases"; | |
418 | Suite "unstable"; | |
419 | Description "repository with dummy packages"; | |
420 | Architectures "' >> ftparchive.conf | |
421 | echo -n "$ARCHS" >> ftparchive.conf | |
422 | echo 'source"; | |
423 | }; | |
424 | }; | |
425 | };' >> ftparchive.conf | |
b7899b00 DK |
426 | for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do |
427 | echo -n 'tree "dists/' >> ftparchive.conf | |
428 | echo -n "$DIST" >> ftparchive.conf | |
429 | echo -n '" { | |
ce9864a8 DK |
430 | Architectures "' >> ftparchive.conf |
431 | echo -n "$ARCHS" >> ftparchive.conf | |
b7899b00 DK |
432 | echo -n 'source"; |
433 | FileList "' >> ftparchive.conf | |
434 | echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf | |
435 | echo -n '"; | |
436 | SourceFileList "' >> ftparchive.conf | |
437 | echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf | |
438 | echo -n '"; | |
439 | Sections "' >> ftparchive.conf | |
440 | 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 | |
441 | echo '"; | |
ce9864a8 | 442 | };' >> ftparchive.conf |
b7899b00 | 443 | done |
ce9864a8 DK |
444 | } |
445 | ||
446 | buildaptftparchivedirectorystructure() { | |
b7899b00 DK |
447 | local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')" |
448 | for DIST in $DISTS; do | |
449 | local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)" | |
450 | for SECTION in $SECTIONS; do | |
451 | local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')" | |
452 | for ARCH in $ARCHS; do | |
453 | mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH} | |
454 | done | |
455 | mkdir -p dists/${DIST}/${SECTION}/source | |
456 | mkdir -p dists/${DIST}/${SECTION}/i18n | |
457 | done | |
ce9864a8 | 458 | done |
ce9864a8 DK |
459 | } |
460 | ||
9b78cda6 DK |
461 | insertpackage() { |
462 | local RELEASE="$1" | |
463 | local NAME="$2" | |
464 | local ARCH="$3" | |
465 | local VERSION="$4" | |
466 | local DEPENDENCIES="$5" | |
d67004e0 DK |
467 | local PRIORITY="${6:-optional}" |
468 | local ARCHS="" | |
ea65d079 | 469 | for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do |
d67004e0 | 470 | if [ "$arch" = "all" ]; then |
53ea1b56 | 471 | ARCHS="$(getarchitectures)" |
d67004e0 DK |
472 | else |
473 | ARCHS="$arch" | |
474 | fi | |
475 | for BUILDARCH in $ARCHS; do | |
476 | local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}" | |
477 | mkdir -p $PPATH aptarchive/dists/${RELEASE}/main/source | |
478 | touch aptarchive/dists/${RELEASE}/main/source/Sources | |
479 | local FILE="${PPATH}/Packages" | |
480 | echo "Package: $NAME | |
481 | Priority: $PRIORITY | |
9b78cda6 | 482 | Section: other |
2c085486 | 483 | Installed-Size: 42 |
9b78cda6 | 484 | Maintainer: Joe Sixpack <joe@example.org> |
d67004e0 | 485 | Architecture: $arch |
2c085486 | 486 | Version: $VERSION |
d67004e0 DK |
487 | Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE |
488 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE | |
489 | echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} | |
9b78cda6 DK |
490 | If you find such a package installed on your system, |
491 | YOU did something horribly wrong! They are autogenerated | |
492 | und used only by testcases for APT and surf no other propose… | |
493 | " >> $FILE | |
d67004e0 | 494 | done |
9b78cda6 DK |
495 | done |
496 | } | |
497 | ||
234675b7 DK |
498 | insertsource() { |
499 | local RELEASE="$1" | |
500 | local NAME="$2" | |
501 | local ARCH="$3" | |
502 | local VERSION="$4" | |
503 | local DEPENDENCIES="$5" | |
504 | local ARCHS="" | |
505 | local SPATH="aptarchive/dists/${RELEASE}/main/source" | |
506 | mkdir -p $SPATH | |
507 | local FILE="${SPATH}/Sources" | |
508 | echo "Package: $NAME | |
509 | Binary: $NAME | |
510 | Version: $VERSION | |
511 | Maintainer: Joe Sixpack <joe@example.org> | |
512 | Architecture: $ARCH" >> $FILE | |
513 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE | |
514 | echo "Files: | |
515 | d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc | |
d5dea0be DK |
516 | d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz |
517 | " >> $FILE | |
234675b7 DK |
518 | } |
519 | ||
dfc2b1be DK |
520 | insertinstalledpackage() { |
521 | local NAME="$1" | |
522 | local ARCH="$2" | |
523 | local VERSION="$3" | |
524 | local DEPENDENCIES="$4" | |
d67004e0 | 525 | local PRIORITY="${5:-optional}" |
53ea1b56 DK |
526 | local FILE='rootdir/var/lib/dpkg/status' |
527 | local INFO='rootdir/var/lib/dpkg/info' | |
ea65d079 | 528 | for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do |
d67004e0 | 529 | echo "Package: $NAME |
dfc2b1be | 530 | Status: install ok installed |
d67004e0 | 531 | Priority: $PRIORITY |
dfc2b1be DK |
532 | Section: other |
533 | Installed-Size: 42 | |
534 | Maintainer: Joe Sixpack <joe@example.org> | |
d67004e0 | 535 | Architecture: $arch |
dfc2b1be | 536 | Version: $VERSION" >> $FILE |
d67004e0 DK |
537 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE |
538 | echo "Description: an autogenerated dummy ${NAME}=${VERSION}/installed | |
dfc2b1be DK |
539 | If you find such a package installed on your system, |
540 | YOU did something horribly wrong! They are autogenerated | |
541 | und used only by testcases for APT and surf no other propose… | |
542 | " >> $FILE | |
53ea1b56 DK |
543 | if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then |
544 | echo -n > ${INFO}/${NAME}:${arch}.list | |
545 | else | |
546 | echo -n > ${INFO}/${NAME}.list | |
547 | fi | |
d67004e0 | 548 | done |
dfc2b1be DK |
549 | } |
550 | ||
551 | ||
ce9864a8 | 552 | buildaptarchivefromincoming() { |
3cbbda3c | 553 | msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…" |
ce9864a8 DK |
554 | cd aptarchive |
555 | [ -e pool ] || ln -s ../incoming pool | |
556 | [ -e ftparchive.conf ] || createaptftparchiveconfig | |
557 | [ -e dists ] || buildaptftparchivedirectorystructure | |
b7899b00 | 558 | msgninfo "\tGenerate Packages, Sources and Contents files… " |
ce9864a8 | 559 | aptftparchive -qq generate ftparchive.conf |
ce9864a8 DK |
560 | cd - > /dev/null |
561 | msgdone "info" | |
9b78cda6 | 562 | generatereleasefiles |
ce9864a8 DK |
563 | } |
564 | ||
565 | buildaptarchivefromfiles() { | |
3cbbda3c | 566 | msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…" |
9b78cda6 DK |
567 | find aptarchive -name 'Packages' -o -name 'Sources' | while read line; do |
568 | msgninfo "\t${line} file… " | |
569 | cat ${line} | gzip > ${line}.gz | |
570 | cat ${line} | bzip2 > ${line}.bz2 | |
8bcbc694 | 571 | cat ${line} | xz --format=lzma > ${line}.lzma |
b7080ced | 572 | cat ${line} | xz > ${line}.xz |
8d876415 | 573 | msgdone "info" |
9b78cda6 DK |
574 | done |
575 | generatereleasefiles | |
576 | } | |
577 | ||
a3bbbab7 DK |
578 | # can be overridden by testcases for their pleasure |
579 | getcodenamefromsuite() { echo -n "$1"; } | |
580 | getreleaseversionfromsuite() { true; } | |
718f797c | 581 | getlabelfromsuite() { true; } |
a3bbbab7 | 582 | |
9b78cda6 | 583 | generatereleasefiles() { |
884a4c0a DK |
584 | # $1 is the Date header and $2 is the ValidUntil header to be set |
585 | # both should be given in notation date/touch can understand | |
9b78cda6 DK |
586 | msgninfo "\tGenerate Release files… " |
587 | if [ -e aptarchive/dists ]; then | |
588 | for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do | |
a3bbbab7 DK |
589 | local SUITE="$(echo "$dir" | cut -d'/' -f 4)" |
590 | local CODENAME="$(getcodenamefromsuite $SUITE)" | |
591 | local VERSION="$(getreleaseversionfromsuite $SUITE)" | |
718f797c | 592 | local LABEL="$(getlabelfromsuite $SUITE)" |
884a4c0a | 593 | if [ -n "$VERSION" ]; then |
718f797c DK |
594 | VERSION="-o APT::FTPArchive::Release::Version=${VERSION}" |
595 | fi | |
596 | if [ -n "$LABEL" ]; then | |
597 | LABEL="-o APT::FTPArchive::Release::Label=${LABEL}" | |
a3bbbab7 | 598 | fi |
884a4c0a DK |
599 | aptftparchive -qq release $dir \ |
600 | -o APT::FTPArchive::Release::Suite="${SUITE}" \ | |
601 | -o APT::FTPArchive::Release::Codename="${CODENAME}" \ | |
718f797c | 602 | ${LABEL} \ |
884a4c0a DK |
603 | ${VERSION} \ |
604 | | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference | |
a3bbbab7 | 605 | if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then |
35faae11 DK |
606 | sed -i '/^Date: / a\ |
607 | NotAutomatic: yes' $dir/Release | |
608 | fi | |
884a4c0a DK |
609 | if [ -n "$1" -a "$1" != "now" ]; then |
610 | sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release | |
611 | fi | |
612 | if [ -n "$2" ]; then | |
613 | sed -i "/^Date: / a\ | |
614 | Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release | |
615 | fi | |
9b78cda6 DK |
616 | done |
617 | else | |
618 | aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference | |
8d876415 | 619 | fi |
884a4c0a | 620 | if [ -n "$1" -a "$1" != "now" ]; then |
fe0f7911 DK |
621 | for release in $(find ./aptarchive -name 'Release'); do |
622 | touch -d "$1" $release | |
623 | done | |
8d876415 | 624 | fi |
b7899b00 | 625 | msgdone "info" |
8d876415 DK |
626 | } |
627 | ||
b7899b00 DK |
628 | setupdistsaptarchive() { |
629 | local APTARCHIVE=$(readlink -f ./aptarchive) | |
630 | rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list | |
631 | rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list | |
632 | for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do | |
633 | SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ') | |
634 | msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… " | |
635 | echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list | |
636 | echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list | |
637 | msgdone "info" | |
638 | done | |
639 | } | |
640 | ||
641 | setupflataptarchive() { | |
ce9864a8 | 642 | local APTARCHIVE=$(readlink -f ./aptarchive) |
8d876415 DK |
643 | if [ -f ${APTARCHIVE}/Packages ]; then |
644 | msgninfo "\tadd deb sources.list line… " | |
645 | echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list | |
646 | msgdone "info" | |
647 | else | |
648 | rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list | |
649 | fi | |
650 | if [ -f ${APTARCHIVE}/Sources ]; then | |
651 | msgninfo "\tadd deb-src sources.list line… " | |
652 | echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list | |
653 | msgdone "info" | |
654 | else | |
655 | rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list | |
656 | fi | |
b7899b00 DK |
657 | } |
658 | ||
659 | setupaptarchive() { | |
660 | buildaptarchive | |
661 | if [ -e aptarchive/dists ]; then | |
662 | setupdistsaptarchive | |
663 | else | |
664 | setupflataptarchive | |
665 | fi | |
f213b6ea | 666 | signreleasefiles |
cd725954 | 667 | msgninfo "\tSync APT's cache with the archive… " |
8d876415 | 668 | aptget update -qq |
cd725954 | 669 | msgdone "info" |
8d876415 DK |
670 | } |
671 | ||
f213b6ea DK |
672 | signreleasefiles() { |
673 | local SIGNER="${1:-Joe Sixpack}" | |
674 | msgninfo "\tSign archive with $SIGNER key… " | |
675 | local SECKEYS="" | |
676 | for KEY in $(find keys/ -name '*.sec'); do | |
677 | SECKEYS="$SECKEYS --secret-keyring $KEY" | |
678 | done | |
679 | local PUBKEYS="" | |
680 | for KEY in $(find keys/ -name '*.pub'); do | |
681 | PUBKEYS="$PUBKEYS --keyring $KEY" | |
682 | done | |
683 | for RELEASE in $(find aptarchive/ -name Release); do | |
684 | gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" -abs -o ${RELEASE}.gpg ${RELEASE} | |
fe0f7911 | 685 | gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" --clearsign -o "$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')" $RELEASE |
f213b6ea DK |
686 | done |
687 | msgdone "info" | |
688 | } | |
689 | ||
690 | changetowebserver() { | |
e6cd40dc DK |
691 | if test -x ${BUILDDIRECTORY}/aptwebserver; then |
692 | cd aptarchive | |
693 | LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/aptwebserver 2> /dev/null > /dev/null & | |
694 | addtrap "kill $!;" | |
695 | cd - > /dev/null | |
696 | elif which weborf > /dev/null; then | |
f213b6ea | 697 | weborf -xb aptarchive/ 2>&1 > /dev/null & |
b720d0bd | 698 | addtrap "kill $!;" |
6e7d39d0 DK |
699 | elif which gatling > /dev/null; then |
700 | cd aptarchive | |
701 | gatling -p 8080 -F -S 2>&1 > /dev/null & | |
702 | addtrap "kill $!;" | |
703 | cd - > /dev/null | |
c5bcc607 DK |
704 | elif which lighttpd > /dev/null; then |
705 | echo "server.document-root = \"$(readlink -f ./aptarchive)\" | |
706 | server.port = 8080 | |
707 | server.stat-cache-engine = \"disable\"" > lighttpd.conf | |
708 | lighttpd -t -f lighttpd.conf >/dev/null || msgdie 'Can not change to webserver: our lighttpd config is invalid' | |
709 | lighttpd -D -f lighttpd.conf 2>/dev/null >/dev/null & | |
710 | addtrap "kill $!;" | |
711 | else | |
712 | msgdie 'You have to install weborf or lighttpd first' | |
713 | return 1 | |
f213b6ea | 714 | fi |
c5bcc607 DK |
715 | local APTARCHIVE="file://$(readlink -f ./aptarchive)" |
716 | for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do | |
717 | sed -i $LIST -e "s#$APTARCHIVE#http://localhost:8080/#" | |
718 | done | |
719 | return 0 | |
f213b6ea DK |
720 | } |
721 | ||
722 | checkdiff() { | |
8d876415 DK |
723 | local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')" |
724 | if [ -n "$DIFFTEXT" ]; then | |
725 | echo | |
726 | echo "$DIFFTEXT" | |
727 | return 1 | |
728 | else | |
729 | return 0 | |
730 | fi | |
731 | } | |
732 | ||
75954ae2 DK |
733 | testfileequal() { |
734 | local FILE="$1" | |
735 | shift | |
736 | msgtest "Test for correctness of file" "$FILE" | |
737 | if [ -z "$*" ]; then | |
f213b6ea | 738 | echo -n "" | checkdiff $FILE - && msgpass || msgfail |
75954ae2 | 739 | else |
f213b6ea | 740 | echo "$*" | checkdiff $FILE - && msgpass || msgfail |
75954ae2 DK |
741 | fi |
742 | } | |
743 | ||
8d876415 DK |
744 | testequal() { |
745 | local COMPAREFILE=$(mktemp) | |
b720d0bd | 746 | addtrap "rm $COMPAREFILE;" |
8d876415 DK |
747 | echo "$1" > $COMPAREFILE |
748 | shift | |
749 | msgtest "Test for equality of" "$*" | |
f213b6ea | 750 | $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail |
8d876415 DK |
751 | } |
752 | ||
685625bd DK |
753 | testequalor2() { |
754 | local COMPAREFILE1=$(mktemp) | |
755 | local COMPAREFILE2=$(mktemp) | |
756 | local COMPAREAGAINST=$(mktemp) | |
b720d0bd | 757 | addtrap "rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;" |
685625bd DK |
758 | echo "$1" > $COMPAREFILE1 |
759 | echo "$2" > $COMPAREFILE2 | |
760 | shift 2 | |
761 | msgtest "Test for equality OR of" "$*" | |
762 | $* 2>&1 1> $COMPAREAGAINST | |
f213b6ea DK |
763 | (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null || |
764 | checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass || | |
765 | ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \ | |
766 | "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" && | |
685625bd DK |
767 | msgfail ) |
768 | } | |
769 | ||
8d876415 | 770 | testshowvirtual() { |
edc0ef10 | 771 | local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual" |
8d876415 DK |
772 | local PACKAGE="$1" |
773 | shift | |
774 | while [ -n "$1" ]; do | |
775 | VIRTUAL="${VIRTUAL} | |
edc0ef10 | 776 | N: Can't select versions from package '$1' as it is purely virtual" |
8d876415 DK |
777 | PACKAGE="${PACKAGE} $1" |
778 | shift | |
779 | done | |
780 | msgtest "Test for virtual packages" "apt-cache show $PACKAGE" | |
781 | VIRTUAL="${VIRTUAL} | |
4bec02c2 | 782 | N: No packages found" |
8d876415 | 783 | local COMPAREFILE=$(mktemp) |
b720d0bd | 784 | addtrap "rm $COMPAREFILE;" |
ea65d079 | 785 | local ARCH="$(getarchitecture 'native')" |
8d876415 | 786 | echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE |
e8379ba3 | 787 | aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail |
8d876415 DK |
788 | } |
789 | ||
790 | testnopackage() { | |
791 | msgtest "Test for non-existent packages" "apt-cache show $*" | |
792 | local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')" | |
793 | if [ -n "$SHOWPKG" ]; then | |
794 | echo | |
795 | echo "$SHOWPKG" | |
796 | msgfail | |
797 | return 1 | |
798 | fi | |
799 | msgpass | |
800 | } | |
01a6e24c DK |
801 | |
802 | testdpkginstalled() { | |
803 | msgtest "Test for correctly installed package(s) with" "dpkg -l $*" | |
87bc1c45 DK |
804 | local PKGS="$(dpkg -l $* | grep '^i' | wc -l)" |
805 | if [ "$PKGS" != $# ]; then | |
01a6e24c DK |
806 | echo $PKGS |
807 | dpkg -l $* | grep '^[a-z]' | |
808 | msgfail | |
809 | return 1 | |
810 | fi | |
811 | msgpass | |
812 | } | |
813 | ||
5cf733e1 DK |
814 | testdpkgnotinstalled() { |
815 | msgtest "Test for correctly not-installed package(s) with" "dpkg -l $*" | |
87bc1c45 | 816 | local PKGS="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)" |
01a6e24c DK |
817 | if [ "$PKGS" != 0 ]; then |
818 | echo | |
819 | dpkg -l $* | grep '^[a-z]' | |
820 | msgfail | |
821 | return 1 | |
822 | fi | |
823 | msgpass | |
824 | } | |
ec7f904e DK |
825 | |
826 | testmarkedauto() { | |
827 | local COMPAREFILE=$(mktemp) | |
828 | addtrap "rm $COMPAREFILE;" | |
829 | if [ -n "$1" ]; then | |
830 | msgtest 'Test for correctly marked as auto-installed' "$*" | |
831 | while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE | |
832 | else | |
833 | msgtest 'Test for correctly marked as auto-installed' 'no package' | |
c98fb5e0 | 834 | echo -n > $COMPAREFILE |
ec7f904e DK |
835 | fi |
836 | aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail | |
837 | } | |
89a1aa5d DK |
838 | |
839 | pause() { | |
840 | echo "STOPPED execution. Press enter to continue" | |
841 | local IGNORE | |
842 | read IGNORE | |
843 | } |