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