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