]> git.saurik.com Git - apt.git/blame - test/integration/framework
do not load filesize in pkgAcqIndexTrans explicitly
[apt.git] / test / integration / framework
CommitLineData
8d876415
DK
1#!/bin/sh -- # no runable script, just for vi
2
5d76cee1 3EXIT_CODE=0
8c1dd12c 4
8d876415 5# we all like colorful messages
1290422a 6if [ "$MSGCOLOR" != 'NO' ]; then
27cb4f6c 7 if [ ! -t 1 ]; then # but check that we output to a terminal
1290422a
DK
8 export MSGCOLOR='NO'
9 fi
10fi
11
12
13if [ "$MSGCOLOR" != 'NO' ]; then
14 CERROR="\033[1;31m" # red
15 CWARNING="\033[1;33m" # yellow
16 CMSG="\033[1;32m" # green
17 CINFO="\033[1;96m" # light blue
18 CDEBUG="\033[1;94m" # blue
19 CNORMAL="\033[0;39m" # default system console color
20 CDONE="\033[1;32m" # green
21 CPASS="\033[1;32m" # green
22 CFAIL="\033[1;31m" # red
23 CCMD="\033[1;35m" # pink
682a3bf7 24fi
8d876415 25
3c528b91
MO
26msgdie() { printf "${CERROR}E: $1${CNORMAL}\n" >&2; exit 1; }
27msgwarn() { printf "${CWARNING}W: $1${CNORMAL}\n" >&2; }
28msgmsg() { printf "${CMSG}$1${CNORMAL}\n"; }
29msginfo() { printf "${CINFO}I: $1${CNORMAL}\n"; }
30msgdebug() { printf "${CDEBUG}D: $1${CNORMAL}\n"; }
31msgdone() { printf "${CDONE}DONE${CNORMAL}\n"; }
32msgnwarn() { printf "${CWARNING}W: $1${CNORMAL}" >&2; }
33msgnmsg() { printf "${CMSG}$1${CNORMAL}"; }
34msgninfo() { printf "${CINFO}I: $1${CNORMAL}"; }
35msgndebug() { printf "${CDEBUG}D: $1${CNORMAL}"; }
2a2a7ef4
DK
36msgtest() {
37 while [ -n "$1" ]; do
3c528b91
MO
38 printf "${CINFO}$1${CCMD} "
39 printf -- "$(echo "$2" | sed -e 's#^apt\([cgfs]\)#apt-\1#')${CINFO} "
d73840dc
DK
40 shift
41 if [ -n "$1" ]; then shift; else break; fi
2a2a7ef4 42 done
3c528b91 43 printf "…${CNORMAL} "
2a2a7ef4 44}
3c528b91
MO
45msgpass() { printf "${CPASS}PASS${CNORMAL}\n"; }
46msgskip() { printf "${CWARNING}SKIP${CNORMAL}\n" >&2; }
5229b285 47msgfail() {
3c528b91
MO
48 if [ $# -gt 0 ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
49 else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
4d0818cc
MV
50 if [ -n "$APT_DEBUG_TESTS" ]; then
51 bash
52 fi
5229b285
DK
53 EXIT_CODE=$((EXIT_CODE+1));
54}
8d876415
DK
55
56# enable / disable Debugging
fc89263e
DK
57MSGLEVEL=${MSGLEVEL:-3}
58if [ $MSGLEVEL -le 0 ]; then
59 msgdie() { true; }
60fi
61if [ $MSGLEVEL -le 1 ]; then
62 msgwarn() { true; }
63 msgnwarn() { true; }
64fi
65if [ $MSGLEVEL -le 2 ]; then
66 msgmsg() { true; }
67 msgnmsg() { true; }
39cc8228 68 msgtest() { true; }
3c528b91
MO
69 msgpass() { printf " ${CPASS}P${CNORMAL}"; }
70 msgskip() { printf " ${CWARNING}S${CNORMAL}" >&2; }
682a3bf7 71 if [ -n "$CFAIL" ]; then
3c528b91 72 msgfail() { printf " ${CFAIL}FAIL${CNORMAL}" >&2; EXIT_CODE=$((EXIT_CODE+1)); }
682a3bf7 73 else
3c528b91 74 msgfail() { printf " ###FAILED###" >&2; EXIT_CODE=$((EXIT_CODE+1)); }
682a3bf7 75 fi
fc89263e
DK
76fi
77if [ $MSGLEVEL -le 3 ]; then
78 msginfo() { true; }
79 msgninfo() { true; }
80fi
81if [ $MSGLEVEL -le 4 ]; then
82 msgdebug() { true; }
83 msgndebug() { true; }
84fi
85msgdone() {
86 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
87 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
88 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
89 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
90 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
91 true;
92 else
3c528b91 93 printf "${CDONE}DONE${CNORMAL}\n";
fc89263e
DK
94 fi
95}
e43a426e
MV
96getaptconfig() {
97 if [ -f ./aptconfig.conf ]; then
98 echo "./aptconfig.conf"
99 elif [ -f ../aptconfig.conf ]; then
100 echo "../aptconfig.conf"
101 fi
102}
8d876415
DK
103runapt() {
104 msgdebug "Executing: ${CCMD}$*${CDEBUG} "
846856f4
DK
105 local CMD="$1"
106 shift
3b8eb3bc 107 case $CMD in
a311fb96 108 sh|aptitude|*/*|command) ;;
3b8eb3bc
DK
109 *) CMD="${BUILDDIRECTORY}/$CMD";;
110 esac
a311fb96 111 MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH=${LIBRARYPATH} $CMD "$@"
8d876415 112}
846856f4
DK
113aptconfig() { runapt apt-config "$@"; }
114aptcache() { runapt apt-cache "$@"; }
115aptcdrom() { runapt apt-cdrom "$@"; }
116aptget() { runapt apt-get "$@"; }
117aptftparchive() { runapt apt-ftparchive "$@"; }
118aptkey() { runapt apt-key "$@"; }
119aptmark() { runapt apt-mark "$@"; }
4f6d26b4 120aptsortpkgs() { runapt apt-sortpkgs "$@"; }
796673c3 121apt() { runapt apt "$@"; }
3b8eb3bc
DK
122apthelper() { runapt "${APTHELPERBINDIR}/apt-helper" "$@"; }
123aptwebserver() { runapt "${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
124aptitude() { runapt aptitude "$@"; }
8d50b63f 125aptextracttemplates() { runapt apt-extracttemplates "$@"; }
3082603f 126aptinternalsolver() { runapt "${APTINTERNALSOLVER}" "$@"; }
3b8eb3bc 127
158fda31 128dpkg() {
846856f4 129 command dpkg --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log "$@"
158fda31 130}
ce7f128c
DK
131dpkgcheckbuilddeps() {
132 command dpkg-checkbuilddeps --admindir=${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg "$@"
b6b5a542 133}
3fa950f1 134gdb() {
a311fb96 135 local CMD="$1"
ce928105 136 shift
a311fb96 137 runapt command gdb --quiet -ex run "${BUILDDIRECTORY}/$CMD" --args "${BUILDDIRECTORY}/$CMD" "$@"
ae99ce2e 138}
8d876415 139
8c1dd12c 140exitwithstatus() {
f91bd741
MV
141 # error if we about to overflow, but ...
142 # "255 failures ought to be enough for everybody"
5d76cee1
MV
143 if [ $EXIT_CODE -gt 255 ]; then
144 msgdie "Total failure count $EXIT_CODE too big"
f91bd741 145 fi
5d76cee1 146 exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
8c1dd12c
MV
147}
148
804d4a0d
DK
149shellsetedetector() {
150 local exit_status=$?
151 if [ "$exit_status" != '0' ]; then
3c528b91 152 printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n"
804d4a0d
DK
153 if [ "$EXIT_CODE" = '0' ]; then
154 EXIT_CODE="$exit_status"
155 fi
156 fi
157}
158
b720d0bd 159addtrap() {
8437b7d4
DK
160 if [ "$1" = 'prefix' ]; then
161 CURRENTTRAP="$2 $CURRENTTRAP"
162 else
163 CURRENTTRAP="$CURRENTTRAP $1"
164 fi
804d4a0d 165 trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
b720d0bd 166}
8d876415
DK
167
168setupenvironment() {
75954ae2 169 TMPWORKINGDIRECTORY=$(mktemp -d)
5684f71f 170 addtrap "cd /; rm -rf $TMPWORKINGDIRECTORY;"
3cbbda3c 171 msgninfo "Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
5c0dd6fc 172
5684f71f 173 TESTDIRECTORY=$(readlink -f $(dirname $0))
5c0dd6fc
MV
174 # allow overriding the default BUILDDIR location
175 BUILDDIRECTORY=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
3b8eb3bc 176 LIBRARYPATH=${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}
5c0dd6fc 177 METHODSDIR=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
e43a426e 178 APTHELPERBINDIR=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}
c035b655 179 APTWEBSERVERBINDIR=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
3082603f 180 APTINTERNALSOLVER=${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}
8d876415 181 test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
5c0dd6fc
MV
182 # -----
183
8d876415 184 cd $TMPWORKINGDIRECTORY
cd725954 185 mkdir rootdir aptarchive keys
8d876415 186 cd rootdir
b29c3712 187 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
33677a0c 188 mkdir -p var/cache var/lib/apt var/log tmp
cffea9af 189 mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
cd725954 190 touch var/lib/dpkg/available
8d876415 191 mkdir -p usr/lib/apt
9082a1fc 192 ln -s ${METHODSDIR} usr/lib/apt/methods
1f6cf9e7
DK
193 if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then
194 mkdir -p usr/lib/apt/solvers
195 ln -s "${BUILDDIRECTORY}/apt-dump-solver" usr/lib/apt/solvers/dump
196 ln -s "${BUILDDIRECTORY}/apt-internal-solver" usr/lib/apt/solvers/apt
197 echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" > etc/apt/apt.conf.d/externalsolver.conf
198 fi
291a386f
MV
199 # use the autoremove from the BUILDDIRECTORY if its there, otherwise
200 # system
201 if [ -e ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove ]; then
202 ln -s ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove etc/apt/apt.conf.d/01autoremove
203 else
204 ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
205 fi
8d876415 206 cd ..
2c6baa5a 207 local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
53ea1b56
DK
208 if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
209 cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages
8f8169ac 210 fi
4a4ea26c 211 local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
53ea1b56
DK
212 if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then
213 cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources
8f8169ac 214 fi
53ea1b56 215 cp $(find $TESTDIRECTORY -name '*.pub' -o -name '*.sec') keys/
5684f71f 216 chmod 644 $(find keys -name '*.pub' -o -name '*.sec')
cd725954 217 ln -s ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
d6cf2345 218
cffea9af 219 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
94eb3bee 220 echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
8d876415
DK
221 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
222 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
5c0dd6fc 223 echo "Dir::Bin::Methods \"${METHODSDIR}\";" >> aptconfig.conf
12841e83 224 echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
cffea9af
DK
225 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
226 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
227 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
228 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
229 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
846856f4 230 if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
53ea1b56
DK
231 echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf # Added to test multiarch before dpkg is ready for it…
232 fi
cffea9af 233 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
2c085486 234 echo 'quiet::NoUpdate "true";' >> aptconfig.conf
0c8171d7 235 echo 'quiet::NoStatistic "true";' >> aptconfig.conf
d6cf2345
DK
236 # too distracting for users, but helpful to detect changes
237 echo 'Acquire::Progress::Ignore::ShowErrorText "true";' >> aptconfig.conf
0045df3f
DK
238 # in testcases, it can appear as if localhost has a rotation setup,
239 # hide this as we can't really deal with it properly
240 echo 'Acquire::Failure::ShowIP "false";' >> aptconfig.conf
d6cf2345 241
23af9f40 242 echo "Acquire::https::CaInfo \"${TESTDIR}/apt.pem\";" > rootdir/etc/apt/apt.conf.d/99https
d6cf2345 243 echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
276e51dd 244 configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
77a45beb 245
ce7f128c 246 # cleanup the environment a bit
8c617819
MV
247 # prefer our apt binaries over the system apt binaries
248 export PATH="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
be233796 249 export LC_ALL=C.UTF-8
3b8eb3bc 250 unset LANGUAGE APT_CONFIG
ce7f128c
DK
251 unset GREP_OPTIONS DEB_BUILD_PROFILES
252
8d876415
DK
253 msgdone "info"
254}
255
ea65d079
DK
256getarchitecture() {
257 if [ "$1" = "native" -o -z "$1" ]; then
258 eval `aptconfig shell ARCH APT::Architecture`
259 if [ -n "$ARCH" ]; then
260 echo $ARCH
261 else
5834d7a1 262 dpkg --print-architecture
ea65d079
DK
263 fi
264 else
265 echo $1
266 fi
267}
268
53ea1b56
DK
269getarchitectures() {
270 echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
271}
272
3dcdc1f9
DK
273getarchitecturesfromcommalist() {
274 echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
275}
276
8d876415 277configarchitecture() {
18908589
DK
278 {
279 echo "APT::Architecture \"$(getarchitecture $1)\";"
280 while [ -n "$1" ]; do
281 echo "APT::Architectures:: \"$(getarchitecture $1)\";"
282 shift
283 done
284 } >rootdir/etc/apt/apt.conf.d/01multiarch.conf
53ea1b56
DK
285 configdpkg
286}
287
288configdpkg() {
289 if [ ! -e rootdir/var/lib/dpkg/status ]; then
290 local STATUSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/')
291 if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then
292 cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status
293 else
294 echo -n > rootdir/var/lib/dpkg/status
295 fi
296 fi
18908589 297 rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
846856f4 298 if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then
53ea1b56
DK
299 local ARCHS="$(getarchitectures)"
300 if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
301 DPKGARCH="$(dpkg --print-architecture)"
302 for ARCH in ${ARCHS}; do
feae193b 303 if [ "${ARCH}" != "${DPKGARCH}" ]; then
18908589 304 if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then
feae193b 305 # old-style used e.g. in Ubuntu-P – and as it seems travis
18908589
DK
306 echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
307 echo "DPKG::options:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg
feae193b
DK
308 fi
309 fi
53ea1b56
DK
310 done
311 if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
05343a22
DK
312 # dpkg doesn't really check the version as long as it is fully installed,
313 # but just to be sure we choose one above the required version
314 insertinstalledpackage 'dpkg' "all" '1.16.2+fake'
53ea1b56
DK
315 fi
316 fi
317 fi
8d876415
DK
318}
319
276e51dd
DK
320configcompression() {
321 while [ -n "$1" ]; do
322 case "$1" in
3c528b91
MO
323 '.') printf ".\t.\tcat\n";;
324 'gz') printf "gzip\tgz\tgzip\n";;
325 'bz2') printf "bzip2\tbz2\tbzip2\n";;
326 'lzma') printf "lzma\tlzma\txz --format=lzma\n";;
327 'xz') printf "xz\txz\txz\n";;
328 *) printf "$1\t$1\t$1\n";;
276e51dd
DK
329 esac
330 shift
331 done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
332}
333
5f982b9d
DK
334forcecompressor() {
335 COMPRESSOR="$1"
336 COMPRESSOR_CMD="$1"
337 case $COMPRESSOR in
338 gzip) COMPRESS='gz';;
339 bzip2) COMPRESS='bz2';;
340 lzma) COMPRESS='lzma';;
341 xz) COMPRESS='xz';;
342 *) msgdie "Compressor $COMPRESSOR is unknown to framework, so can't be forced by forcecompressor!";;
343 esac
344 local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
345 echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
346Dir::Bin::uncompressed \"/does/not/exist\";
347Dir::Bin::gzip \"/does/not/exist\";
348Dir::Bin::bzip2 \"/does/not/exist\";
349Dir::Bin::lzma \"/does/not/exist\";
350Dir::Bin::xz \"/does/not/exist\";" > "$CONFFILE"
351 if [ -e "/bin/${COMPRESSOR}" ]; then
352 echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
353 elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
354 echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
355 elif [ "${COMPRESSOR}" = 'lzma' ]; then
356 echo 'Dir::Bin::xz "/usr/bin/xz";' >> "$CONFFILE"
357 COMPRESSOR_CMD='xz --format=lzma'
358 else
359 msgtest 'Test for availability of compressor' "${COMPRESSOR}"
360 msgfail
361 fi
362}
363
75954ae2 364setupsimplenativepackage() {
ce9864a8
DK
365 local NAME="$1"
366 local ARCH="$2"
367 local VERSION="$3"
368 local RELEASE="${4:-unstable}"
369 local DEPENDENCIES="$5"
14109555 370 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
18908589
DK
371 If you find such a package installed on your system,
372 something went horribly wrong! They are autogenerated
373 und used only by testcases and surf no other propose…"}"
374
b7899b00
DK
375 local SECTION="${7:-others}"
376 local DISTSECTION
377 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
378 DISTSECTION="main"
379 else
380 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
381 fi
ce9864a8
DK
382 local BUILDDIR=incoming/${NAME}-${VERSION}
383 mkdir -p ${BUILDDIR}/debian/source
384 cd ${BUILDDIR}
385 echo "* most suckless software product ever" > FEATURES
b7899b00
DK
386 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
387 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
ce9864a8
DK
388
389 * Initial release
390
b7899b00
DK
391 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
392 test -e debian/control || echo "Source: $NAME
393Section: $SECTION
ce9864a8
DK
394Priority: optional
395Maintainer: Joe Sixpack <joe@example.org>
396Build-Depends: debhelper (>= 7)
397Standards-Version: 3.9.1
398
875bcb36
DK
399Package: $NAME" > debian/control
400 if [ "$ARCH" = 'all' ]; then
401 echo "Architecture: all" >> debian/control
402 else
403 echo "Architecture: any" >> debian/control
404 fi
ce9864a8 405 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
18908589
DK
406 echo "Description: $DESCRIPTION" >> debian/control
407
b7899b00
DK
408 test -e debian/compat || echo "7" > debian/compat
409 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
ce9864a8 410 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
75954ae2
DK
411 cd - > /dev/null
412}
413
414buildsimplenativepackage() {
415 local NAME="$1"
416 local ARCH="$2"
417 local VERSION="$3"
418 local RELEASE="${4:-unstable}"
419 local DEPENDENCIES="$5"
14109555 420 local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
18908589
DK
421 If you find such a package installed on your system,
422 something went horribly wrong! They are autogenerated
423 und used only by testcases and surf no other propose…"}"
424
75954ae2 425 local SECTION="${7:-others}"
d67004e0 426 local PRIORITY="${8:-optional}"
42c1513b 427 local FILE_TREE="$9"
adff049d 428 local COMPRESS_TYPE="${10:-gzip}"
75954ae2
DK
429 local DISTSECTION
430 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
431 DISTSECTION="main"
432 else
433 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
434 fi
5a635ee4 435 local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
b761356f 436
18331adf 437 msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… "
b761356f
DK
438 mkdir -p $BUILDDIR/debian/source
439 echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
440 echo "#!/bin/sh
441echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
442
443 echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
444 echo "$NAME ($VERSION) $RELEASE; urgency=low
445
446 * Initial release
447
448 -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog
449 echo "Source: $NAME
450Section: $SECTION
d67004e0 451Priority: $PRIORITY
b761356f 452Maintainer: Joe Sixpack <joe@example.org>
01f520ce
DK
453Standards-Version: 3.9.3" > ${BUILDDIR}/debian/control
454 local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')"
455 test -z "$BUILDDEPS" || echo "$BUILDDEPS" >> ${BUILDDIR}/debian/control
456 echo "
457Package: $NAME" >> ${BUILDDIR}/debian/control
b761356f 458
875bcb36
DK
459 if [ "$ARCH" = 'all' ]; then
460 echo "Architecture: all" >> ${BUILDDIR}/debian/control
461 else
462 echo "Architecture: any" >> ${BUILDDIR}/debian/control
463 fi
01f520ce
DK
464 local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')"
465 test -z "$DEPS" || echo "$DEPS" >> ${BUILDDIR}/debian/control
18908589 466 echo "Description: $DESCRIPTION" >> ${BUILDDIR}/debian/control
01f520ce 467
b761356f 468 echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
f1828b69
DK
469 (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' \
470 | while read SRC; do
5a635ee4 471 echo "pool/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
f1828b69 472# if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then
33a22672 473# aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \
bd7fb5aa 474# adv --yes --default-key 'Joe Sixpack' \
f1828b69
DK
475# --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
476# mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC"
477# fi
b761356f 478 done
84aa13f4 479
3dcdc1f9 480 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
84aa13f4
DK
481 rm -rf ${BUILDDIR}/debian/tmp
482 mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
483 cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}
484 cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}
42c1513b
MV
485 if [ -n "$FILE_TREE" ]; then
486 cp -ar "$FILE_TREE" ${BUILDDIR}/debian/tmp
487 fi
42c1513b 488
84aa13f4
DK
489 (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch)
490 (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
846856f4 491 local LOG="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log"
eb9dee96
DK
492 # ensure the right permissions as dpkg-deb ensists
493 chmod 755 ${BUILDDIR}/debian/tmp/DEBIAN
adff049d 494 if ! dpkg-deb -Z${COMPRESS_TYPE} --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/.. >$LOG 2>&1; then
846856f4
DK
495 cat $LOG
496 false
497 fi
498 rm $LOG
84aa13f4
DK
499 echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist
500 done
501
13845042
DK
502 mkdir -p ${BUILDDIR}/../${NAME}_${VERSION}
503 cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}/
504 cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}.changelog
5a635ee4 505 rm -rf "${BUILDDIR}"
b761356f 506 msgdone "info"
75954ae2
DK
507}
508
509buildpackage() {
510 local BUILDDIR=$1
511 local RELEASE=$2
512 local SECTION=$3
ea65d079 513 local ARCH=$(getarchitecture $4)
846856f4
DK
514 local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')"
515 local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")"
516 msgninfo "Build package ${PKGNAME} for ${RELEASE} in ${SECTION}… "
75954ae2
DK
517 cd $BUILDDIR
518 if [ "$ARCH" = "all" ]; then
519 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
520 fi
846856f4
DK
521 if ! dpkg-buildpackage -uc -us -a$ARCH >$BUILDLOG 2>&1 ; then
522 cat $BUILDLOG
523 false
524 fi
525 local PKGS="$(grep '^dpkg-deb: building package' $BUILDLOG | cut -d'/' -f 2 | sed -e "s#'\.##")"
526 local SRCS="$(grep '^dpkg-source: info: building' $BUILDLOG | grep -o '[a-z0-9._+~-]*$')"
ce9864a8 527 cd - > /dev/null
b7899b00 528 for PKG in $PKGS; do
75954ae2 529 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist
b7899b00
DK
530 done
531 for SRC in $SRCS; do
75954ae2 532 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist
b7899b00 533 done
cffea9af 534 msgdone "info"
ce9864a8
DK
535}
536
537buildaptarchive() {
ce9864a8 538 if [ -d incoming ]; then
846856f4 539 buildaptarchivefromincoming "$@"
ce9864a8 540 else
846856f4 541 buildaptarchivefromfiles "$@"
ce9864a8
DK
542 fi
543}
544
545createaptftparchiveconfig() {
276e51dd
DK
546 local COMPRESSORS="$(cut -d' ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
547 COMPRESSORS="${COMPRESSORS%* }"
ce9864a8 548 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
549 if [ -z "$ARCHS" ]; then
550 # the pool is empty, so we will operate on faked packages - let us use the configured archs
53ea1b56 551 ARCHS="$(getarchitectures)"
158fda31 552 fi
ce9864a8
DK
553 echo -n 'Dir {
554 ArchiveDir "' >> ftparchive.conf
555 echo -n $(readlink -f .) >> ftparchive.conf
556 echo -n '";
557 CacheDir "' >> ftparchive.conf
558 echo -n $(readlink -f ..) >> ftparchive.conf
559 echo -n '";
b7899b00
DK
560 FileListDir "' >> ftparchive.conf
561 echo -n $(readlink -f pool/) >> ftparchive.conf
562 echo -n '";
563};
564Default {
276e51dd
DK
565 Packages::Compress "'"$COMPRESSORS"'";
566 Sources::Compress "'"$COMPRESSORS"'";
567 Contents::Compress "'"$COMPRESSORS"'";
568 Translation::Compress "'"$COMPRESSORS"'";
18331adf 569 LongDescription "false";
ce9864a8
DK
570};
571TreeDefault {
572 Directory "pool/";
573 SrcDirectory "pool/";
574};
575APT {
576 FTPArchive {
577 Release {
578 Origin "joesixpack";
579 Label "apttestcases";
580 Suite "unstable";
581 Description "repository with dummy packages";
582 Architectures "' >> ftparchive.conf
583 echo -n "$ARCHS" >> ftparchive.conf
584 echo 'source";
585 };
586 };
587};' >> ftparchive.conf
b7899b00
DK
588 for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
589 echo -n 'tree "dists/' >> ftparchive.conf
590 echo -n "$DIST" >> ftparchive.conf
591 echo -n '" {
ce9864a8
DK
592 Architectures "' >> ftparchive.conf
593 echo -n "$ARCHS" >> ftparchive.conf
b7899b00
DK
594 echo -n 'source";
595 FileList "' >> ftparchive.conf
596 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
597 echo -n '";
598 SourceFileList "' >> ftparchive.conf
599 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
600 echo -n '";
601 Sections "' >> ftparchive.conf
602 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
603 echo '";
ce9864a8 604};' >> ftparchive.conf
b7899b00 605 done
ce9864a8
DK
606}
607
608buildaptftparchivedirectorystructure() {
b7899b00
DK
609 local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
610 for DIST in $DISTS; do
611 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
612 for SECTION in $SECTIONS; do
613 local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
614 for ARCH in $ARCHS; do
615 mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH}
616 done
617 mkdir -p dists/${DIST}/${SECTION}/source
618 mkdir -p dists/${DIST}/${SECTION}/i18n
619 done
ce9864a8 620 done
ce9864a8
DK
621}
622
9b78cda6
DK
623insertpackage() {
624 local RELEASE="$1"
625 local NAME="$2"
626 local ARCH="$3"
627 local VERSION="$4"
628 local DEPENDENCIES="$5"
d67004e0 629 local PRIORITY="${6:-optional}"
14109555 630 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
18908589
DK
631 If you find such a package installed on your system,
632 something went horribly wrong! They are autogenerated
633 und used only by testcases and surf no other propose…"}"
d67004e0 634 local ARCHS=""
3dcdc1f9 635 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
c919ad6e 636 if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
53ea1b56 637 ARCHS="$(getarchitectures)"
d67004e0
DK
638 else
639 ARCHS="$arch"
640 fi
641 for BUILDARCH in $ARCHS; do
642 local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
643 mkdir -p $PPATH aptarchive/dists/${RELEASE}/main/source
644 touch aptarchive/dists/${RELEASE}/main/source/Sources
645 local FILE="${PPATH}/Packages"
646 echo "Package: $NAME
647Priority: $PRIORITY
9b78cda6 648Section: other
2c085486 649Installed-Size: 42
c919ad6e
DK
650Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
651 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
652 echo "Version: $VERSION
d67004e0
DK
653Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
654 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
18908589 655 echo "Description: $DESCRIPTION" >> $FILE
8ba17539 656 echo >> $FILE
d67004e0 657 done
9b78cda6
DK
658 done
659}
660
234675b7
DK
661insertsource() {
662 local RELEASE="$1"
663 local NAME="$2"
664 local ARCH="$3"
665 local VERSION="$4"
666 local DEPENDENCIES="$5"
667 local ARCHS=""
668 local SPATH="aptarchive/dists/${RELEASE}/main/source"
669 mkdir -p $SPATH
670 local FILE="${SPATH}/Sources"
671 echo "Package: $NAME
672Binary: $NAME
673Version: $VERSION
674Maintainer: Joe Sixpack <joe@example.org>
675Architecture: $ARCH" >> $FILE
676 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
677 echo "Files:
678 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc
d5dea0be
DK
679 d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz
680" >> $FILE
234675b7
DK
681}
682
dfc2b1be
DK
683insertinstalledpackage() {
684 local NAME="$1"
685 local ARCH="$2"
686 local VERSION="$3"
687 local DEPENDENCIES="$4"
d67004e0 688 local PRIORITY="${5:-optional}"
d4b4e5ea 689 local STATUS="${6:-install ok installed}"
14109555 690 local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed
18908589
DK
691 If you find such a package installed on your system,
692 something went horribly wrong! They are autogenerated
693 und used only by testcases and surf no other propose…"}"
694
53ea1b56
DK
695 local FILE='rootdir/var/lib/dpkg/status'
696 local INFO='rootdir/var/lib/dpkg/info'
3dcdc1f9 697 for arch in $(getarchitecturesfromcommalist "$ARCH"); do
d67004e0 698 echo "Package: $NAME
d4b4e5ea 699Status: $STATUS
d67004e0 700Priority: $PRIORITY
dfc2b1be
DK
701Section: other
702Installed-Size: 42
703Maintainer: Joe Sixpack <joe@example.org>
dfc2b1be 704Version: $VERSION" >> $FILE
c919ad6e 705 test "$arch" = 'none' || echo "Architecture: $arch" >> $FILE
d67004e0 706 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
18908589
DK
707 echo "Description: $DESCRIPTION" >> $FILE
708 echo >> $FILE
53ea1b56
DK
709 if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then
710 echo -n > ${INFO}/${NAME}:${arch}.list
711 else
712 echo -n > ${INFO}/${NAME}.list
713 fi
d67004e0 714 done
dfc2b1be
DK
715}
716
717
ce9864a8 718buildaptarchivefromincoming() {
3cbbda3c 719 msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
ce9864a8
DK
720 cd aptarchive
721 [ -e pool ] || ln -s ../incoming pool
722 [ -e ftparchive.conf ] || createaptftparchiveconfig
723 [ -e dists ] || buildaptftparchivedirectorystructure
b7899b00 724 msgninfo "\tGenerate Packages, Sources and Contents files… "
ce9864a8 725 aptftparchive -qq generate ftparchive.conf
ce9864a8
DK
726 cd - > /dev/null
727 msgdone "info"
4dbfe436 728 generatereleasefiles "$@"
ce9864a8
DK
729}
730
731buildaptarchivefromfiles() {
3cbbda3c 732 msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
9b78cda6
DK
733 find aptarchive -name 'Packages' -o -name 'Sources' | while read line; do
734 msgninfo "\t${line} file… "
276e51dd 735 compressfile "$line" "$1"
8d876415 736 msgdone "info"
9b78cda6 737 done
e3c62328 738 generatereleasefiles "$@"
9b78cda6
DK
739}
740
276e51dd
DK
741compressfile() {
742 cat ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | while read compressor extension command; do
743 if [ "$compressor" = '.' ]; then
744 if [ -n "$2" ]; then
745 touch -d "$2" "$1"
746 fi
747 continue
748 fi
749 cat "$1" | $command > "${1}.${extension}"
750 if [ -n "$2" ]; then
751 touch -d "$2" "${1}.${extension}"
752 fi
753 done
754}
755
a3bbbab7 756# can be overridden by testcases for their pleasure
bf9e7447
DK
757getcodenamefromsuite() {
758 case "$1" in
759 unstable) echo 'sid';;
760 *) echo -n "$1";;
761 esac
762}
a3bbbab7 763getreleaseversionfromsuite() { true; }
718f797c 764getlabelfromsuite() { true; }
a3bbbab7 765
9b78cda6 766generatereleasefiles() {
884a4c0a
DK
767 # $1 is the Date header and $2 is the ValidUntil header to be set
768 # both should be given in notation date/touch can understand
9b78cda6
DK
769 msgninfo "\tGenerate Release files… "
770 if [ -e aptarchive/dists ]; then
771 for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
a3bbbab7
DK
772 local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
773 local CODENAME="$(getcodenamefromsuite $SUITE)"
774 local VERSION="$(getreleaseversionfromsuite $SUITE)"
718f797c 775 local LABEL="$(getlabelfromsuite $SUITE)"
884a4c0a 776 if [ -n "$VERSION" ]; then
718f797c
DK
777 VERSION="-o APT::FTPArchive::Release::Version=${VERSION}"
778 fi
779 if [ -n "$LABEL" ]; then
780 LABEL="-o APT::FTPArchive::Release::Label=${LABEL}"
a3bbbab7 781 fi
884a4c0a
DK
782 aptftparchive -qq release $dir \
783 -o APT::FTPArchive::Release::Suite="${SUITE}" \
784 -o APT::FTPArchive::Release::Codename="${CODENAME}" \
718f797c 785 ${LABEL} \
884a4c0a
DK
786 ${VERSION} \
787 | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
a3bbbab7 788 if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
35faae11
DK
789 sed -i '/^Date: / a\
790NotAutomatic: yes' $dir/Release
791 fi
884a4c0a
DK
792 if [ -n "$1" -a "$1" != "now" ]; then
793 sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release
794 fi
795 if [ -n "$2" ]; then
796 sed -i "/^Date: / a\
797Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release
798 fi
9b78cda6
DK
799 done
800 else
801 aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
8d876415 802 fi
884a4c0a 803 if [ -n "$1" -a "$1" != "now" ]; then
fe0f7911
DK
804 for release in $(find ./aptarchive -name 'Release'); do
805 touch -d "$1" $release
806 done
8d876415 807 fi
b7899b00 808 msgdone "info"
8d876415
DK
809}
810
b7899b00
DK
811setupdistsaptarchive() {
812 local APTARCHIVE=$(readlink -f ./aptarchive)
813 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
814 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
815 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
816 SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
817 msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
818 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
819 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
820 msgdone "info"
821 done
822}
823
824setupflataptarchive() {
ce9864a8 825 local APTARCHIVE=$(readlink -f ./aptarchive)
8d876415
DK
826 if [ -f ${APTARCHIVE}/Packages ]; then
827 msgninfo "\tadd deb sources.list line… "
828 echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
829 msgdone "info"
830 else
831 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
832 fi
833 if [ -f ${APTARCHIVE}/Sources ]; then
834 msgninfo "\tadd deb-src sources.list line… "
835 echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
836 msgdone "info"
837 else
838 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
839 fi
b7899b00
DK
840}
841
842setupaptarchive() {
4dbfe436
DK
843 local NOUPDATE=0
844 if [ "$1" = '--no-update' ]; then
845 NOUPDATE=1
846 shift
847 fi
848 buildaptarchive "$@"
b7899b00
DK
849 if [ -e aptarchive/dists ]; then
850 setupdistsaptarchive
851 else
852 setupflataptarchive
853 fi
9d653a6d 854 signreleasefiles 'Joe Sixpack'
4dbfe436 855 if [ "1" != "$NOUPDATE" ]; then
5684f71f 856 testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true
b2ea1a47 857 fi
8d876415
DK
858}
859
f213b6ea
DK
860signreleasefiles() {
861 local SIGNER="${1:-Joe Sixpack}"
07cb47e7 862 local REPODIR="${2:-aptarchive}"
f1e1abd8 863 local KEY="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
33a22672 864 local GPG="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
f1e1abd8 865 msgninfo "\tSign archive with $SIGNER key $KEY… "
29a59c46
DK
866 local REXKEY='keys/rexexpired'
867 local SECEXPIREBAK="${REXKEY}.sec.bak"
868 local PUBEXPIREBAK="${REXKEY}.pub.bak"
869 if [ "${SIGNER}" = 'Rex Expired' ]; then
870 # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
871 # option doesn't exist anymore (and using faketime would add a new obscure dependency)
872 # therefore we 'temporary' make the key not expired and restore a backup after signing
873 cp ${REXKEY}.sec $SECEXPIREBAK
874 cp ${REXKEY}.pub $PUBEXPIREBAK
875 local SECUNEXPIRED="${REXKEY}.sec.unexpired"
876 local PUBUNEXPIRED="${REXKEY}.pub.unexpired"
877 if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
878 cp $SECUNEXPIRED ${REXKEY}.sec
879 cp $PUBUNEXPIRED ${REXKEY}.pub
880 else
f1e1abd8
DK
881 if ! printf "expire\n1w\nsave\n" | $GPG --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then
882 cat setexpire.gpg
883 exit 1
884 fi
29a59c46
DK
885 cp ${REXKEY}.sec $SECUNEXPIRED
886 cp ${REXKEY}.pub $PUBUNEXPIRED
887 fi
888 fi
07cb47e7 889 for RELEASE in $(find ${REPODIR}/ -name Release); do
29a59c46 890 $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg ${RELEASE}
e3c62328 891 local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
29a59c46 892 $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
e3c62328
DK
893 # we might have set a specific date for the Release file, so copy it
894 touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg ${INRELEASE}
f213b6ea 895 done
29a59c46
DK
896 if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
897 mv -f $SECEXPIREBAK ${REXKEY}.sec
898 mv -f $PUBEXPIREBAK ${REXKEY}.pub
899 fi
f213b6ea
DK
900 msgdone "info"
901}
902
f2c0ec8b
DK
903webserverconfig() {
904 msgtest "Set webserver config option '${1}' to" "$2"
0d58c26a
DK
905 local DOWNLOG='rootdir/tmp/download-testfile.log'
906 local STATUS='rootdir/tmp/webserverconfig.status'
907 rm -f "$STATUS" "$DOWNLOG"
908 if downloadfile "http://localhost:8080/_config/set/${1}/${2}" "$STATUS" > "$DOWNLOG"; then
f2c0ec8b
DK
909 msgpass
910 else
0d58c26a
DK
911 cat "$DOWNLOG" "$STATUS"
912 msgfail
f2c0ec8b 913 fi
0d58c26a 914 testwebserverlaststatuscode '200'
f2c0ec8b
DK
915}
916
fd46d305
DK
917rewritesourceslist() {
918 local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive")"
919 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
920 sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#http://localhost:8080/#${1}#" -e "s#http://localhost:4433/#${1}#"
921 done
922}
923
5572f6bd
MV
924# wait for up to 10s for a pid file to appear to avoid possible race
925# when a helper is started and dosn't write the PID quick enough
926waitforpidfile() {
927 local PIDFILE="$1"
928 for i in $(seq 10); do
929 if test -s "$PIDFILE"; then
930 return 0
931 fi
932 sleep 1
933 done
934 msgdie "waiting for $PIDFILE failed"
935 return 1
936}
937
f213b6ea 938changetowebserver() {
23af9f40
DK
939 if [ "$1" != '--no-rewrite' ]; then
940 rewritesourceslist 'http://localhost:8080/'
941 else
942 shift
943 fi
5c0dd6fc 944 if test -x ${APTWEBSERVERBINDIR}/aptwebserver; then
fbd29dd6 945 cd aptarchive
a0db467c
DK
946 local LOG="webserver.log"
947 if ! aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1 ; then
bee0670b
DK
948 cat $LOG
949 false
950 fi
5572f6bd 951 waitforpidfile aptwebserver.pid
e3c62328
DK
952 local PID="$(cat aptwebserver.pid)"
953 if [ -z "$PID" ]; then
954 msgdie 'Could not fork aptwebserver successfully'
955 fi
956 addtrap "kill $PID;"
fbd29dd6 957 cd - > /dev/null
c5bcc607 958 else
fbd29dd6 959 msgdie 'You have to build aptwerbserver or install a webserver'
f213b6ea 960 fi
fd46d305
DK
961}
962
963changetohttpswebserver() {
964 if ! which stunnel4 >/dev/null; then
965 msgdie 'You need to install stunnel4 for https testcases'
966 fi
967 if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
dc95fee1 968 changetowebserver --no-rewrite "$@"
fd46d305
DK
969 fi
970 echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid
971cert = ${TESTDIRECTORY}/apt.pem
23af9f40 972output = /dev/null
fd46d305
DK
973
974[https]
975accept = 4433
976connect = 8080
977" > ${TMPWORKINGDIRECTORY}/stunnel.conf
978 stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
5572f6bd 979 waitforpidfile "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
fd46d305 980 local PID="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
5572f6bd
MV
981 if [ -z "$PID" ]; then
982 msgdie 'Could not fork stunnel4 successfully'
983 fi
fd46d305
DK
984 addtrap 'prefix' "kill ${PID};"
985 rewritesourceslist 'https://localhost:4433/'
f213b6ea
DK
986}
987
c45233ea
DK
988changetocdrom() {
989 mkdir -p rootdir/media/cdrom/.disk
990 local CD="$(readlink -f rootdir/media/cdrom)"
a0975c8d
DK
991 echo "acquire::cdrom::mount \"${CD}\";
992acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
993acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
994acquire::cdrom::autodetect 0;" > rootdir/etc/apt/apt.conf.d/00cdrom
c45233ea
DK
995 echo -n "$1" > ${CD}/.disk/info
996 if [ ! -d aptarchive/dists ]; then
997 msgdie 'Flat file archive cdroms can not be created currently'
998 return 1
999 fi
a0975c8d 1000 mv aptarchive/dists "$CD"
c45233ea
DK
1001 ln -s "$(readlink -f ./incoming)" $CD/pool
1002 find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete
a0975c8d
DK
1003 # start with an unmounted disk
1004 mv "${CD}" "${CD}-unmounted"
1005 # we don't want the disk to be modifiable
1006 addtrap 'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
1007 chmod -R -w rootdir/media/cdrom-unmounted/dists
c45233ea
DK
1008}
1009
fd46d305 1010downloadfile() {
0d58c26a 1011 local PROTO="$(echo "$1" | cut -d':' -f 1 )"
3dcdc1f9 1012 apthelper -o Debug::Acquire::${PROTO}=1 \
0d58c26a 1013 download-file "$1" "$2" 2>&1 || true
fd46d305
DK
1014 # only if the file exists the download was successful
1015 if [ -e "$2" ]; then
1016 return 0
1017 else
1018 return 1
1019 fi
1020}
1021
f213b6ea 1022checkdiff() {
846856f4 1023 local DIFFTEXT="$(command diff -u "$@" | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
8d876415 1024 if [ -n "$DIFFTEXT" ]; then
0d58c26a
DK
1025 echo >&2
1026 echo >&2 "$DIFFTEXT"
8d876415
DK
1027 return 1
1028 else
1029 return 0
1030 fi
1031}
1032
75954ae2
DK
1033testfileequal() {
1034 local FILE="$1"
1035 shift
1036 msgtest "Test for correctness of file" "$FILE"
1037 if [ -z "$*" ]; then
f213b6ea 1038 echo -n "" | checkdiff $FILE - && msgpass || msgfail
75954ae2 1039 else
f213b6ea 1040 echo "$*" | checkdiff $FILE - && msgpass || msgfail
75954ae2
DK
1041 fi
1042}
1043
b855a400
DK
1044testempty() {
1045 msgtest "Test for no output of" "$*"
859093da
DK
1046 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
1047 if $* >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
1048 msgpass
1049 else
1050 cat $COMPAREFILE
1051 msgfail
1052 fi
b855a400
DK
1053}
1054
f74a6fa1
DK
1055testequal() {
1056 local MSG='Test of equality of'
1057 if [ "$1" = '--nomsg' ]; then
1058 MSG=''
1059 shift
1060 fi
1061
03938280 1062 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile"
8d876415
DK
1063 echo "$1" > $COMPAREFILE
1064 shift
d2d68aaf 1065
f74a6fa1
DK
1066 if [ -n "$MSG" ]; then
1067 msgtest "$MSG" "$*"
1068 fi
1069 $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
8d876415
DK
1070}
1071
685625bd 1072testequalor2() {
03938280
DK
1073 local COMPAREFILE1="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
1074 local COMPAREFILE2="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
1075 local COMPAREAGAINST="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
685625bd
DK
1076 echo "$1" > $COMPAREFILE1
1077 echo "$2" > $COMPAREFILE2
1078 shift 2
1079 msgtest "Test for equality OR of" "$*"
18908589 1080 $* >$COMPAREAGAINST 2>&1 || true
0d58c26a
DK
1081 if checkdiff $COMPAREFILE1 $COMPAREAGAINST >/dev/null 2>&1 || \
1082 checkdiff $COMPAREFILE2 $COMPAREAGAINST >/dev/null 2>&1
1083 then
0caa5a4c
DK
1084 msgpass
1085 else
1086 echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
1087 checkdiff $COMPAREFILE1 $COMPAREAGAINST || true
1088 echo -n "${CINFO}Diff against OR 2${CNORMAL}"
1089 checkdiff $COMPAREFILE2 $COMPAREAGAINST || true
1090 msgfail
1091 fi
685625bd
DK
1092}
1093
8d876415 1094testshowvirtual() {
edc0ef10 1095 local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
8d876415
DK
1096 local PACKAGE="$1"
1097 shift
1098 while [ -n "$1" ]; do
1099 VIRTUAL="${VIRTUAL}
edc0ef10 1100N: Can't select versions from package '$1' as it is purely virtual"
8d876415
DK
1101 PACKAGE="${PACKAGE} $1"
1102 shift
1103 done
1104 msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
1105 VIRTUAL="${VIRTUAL}
4bec02c2 1106N: No packages found"
03938280 1107 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile"
ea65d079 1108 local ARCH="$(getarchitecture 'native')"
8d876415 1109 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
e8379ba3 1110 aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
8d876415
DK
1111}
1112
1113testnopackage() {
1114 msgtest "Test for non-existent packages" "apt-cache show $*"
846856f4 1115 local SHOWPKG="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
8d876415 1116 if [ -n "$SHOWPKG" ]; then
0d58c26a
DK
1117 echo >&2
1118 echo >&2 "$SHOWPKG"
8d876415 1119 msgfail
0d58c26a
DK
1120 else
1121 msgpass
8d876415 1122 fi
8d876415 1123}
01a6e24c
DK
1124
1125testdpkginstalled() {
1126 msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
846856f4 1127 local PKGS="$(dpkg -l "$@" 2>/dev/null | grep '^i' | wc -l)"
87bc1c45 1128 if [ "$PKGS" != $# ]; then
0d58c26a
DK
1129 echo >&2 $PKGS
1130 dpkg -l "$@" | grep '^[a-z]' >&2
01a6e24c 1131 msgfail
0d58c26a
DK
1132 else
1133 msgpass
01a6e24c 1134 fi
01a6e24c
DK
1135}
1136
5cf733e1
DK
1137testdpkgnotinstalled() {
1138 msgtest "Test for correctly not-installed package(s) with" "dpkg -l $*"
846856f4 1139 local PKGS="$(dpkg -l "$@" 2> /dev/null | grep '^i' | wc -l)"
01a6e24c
DK
1140 if [ "$PKGS" != 0 ]; then
1141 echo
0d58c26a 1142 dpkg -l "$@" | grep '^[a-z]' >&2
01a6e24c 1143 msgfail
0d58c26a
DK
1144 else
1145 msgpass
01a6e24c 1146 fi
01a6e24c 1147}
ec7f904e
DK
1148
1149testmarkedauto() {
03938280 1150 local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
ec7f904e
DK
1151 if [ -n "$1" ]; then
1152 msgtest 'Test for correctly marked as auto-installed' "$*"
1153 while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE
1154 else
1155 msgtest 'Test for correctly marked as auto-installed' 'no package'
c98fb5e0 1156 echo -n > $COMPAREFILE
ec7f904e
DK
1157 fi
1158 aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
1159}
89a1aa5d 1160
0440d936
DK
1161testsuccess() {
1162 if [ "$1" = '--nomsg' ]; then
1163 shift
1164 else
1165 msgtest 'Test for successful execution of' "$*"
1166 fi
03938280 1167 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
0440d936
DK
1168 if $@ >${OUTPUT} 2>&1; then
1169 msgpass
1170 else
07cb47e7 1171 local EXITCODE=$?
0d58c26a
DK
1172 echo >&2
1173 cat >&2 $OUTPUT
07cb47e7 1174 msgfail "exitcode $EXITCODE"
0440d936
DK
1175 fi
1176}
1177
1178testfailure() {
1179 if [ "$1" = '--nomsg' ]; then
1180 shift
1181 else
889b0072 1182 msgtest 'Test for failure in execution of' "$*"
0440d936 1183 fi
03938280 1184 local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
0440d936 1185 if $@ >${OUTPUT} 2>&1; then
07cb47e7 1186 local EXITCODE=$?
0d58c26a
DK
1187 echo >&2
1188 cat >&2 $OUTPUT
07cb47e7 1189 msgfail "exitcode $EXITCODE"
0440d936
DK
1190 else
1191 msgpass
1192 fi
1193}
1194
5684f71f
DK
1195testaccessrights() {
1196 msgtest "Test that file $1 has access rights set to" "$2"
1197 if [ "$2" = "$(stat --format '%a' "$1")" ]; then
1198 msgpass
1199 else
1200 echo >&2
1201 ls -l >&2 "$1"
1202 echo -n >&2 "stat(1) reports access rights: "
1203 stat --format '%a' "$1"
1204 msgfail
1205 fi
1206}
1207
0d58c26a
DK
1208testwebserverlaststatuscode() {
1209 local DOWNLOG='rootdir/tmp/webserverstatus-testfile.log'
1210 local STATUS='rootdir/tmp/webserverstatus-statusfile.log'
1211 rm -f "$DOWNLOG" "$STATUS"
1212 msgtest 'Test last status code from the webserver was' "$1"
1213 downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
1214 if [ "$(cat "$STATUS")" = "$1" ]; then
1215 msgpass
1216 else
1217 echo >&2
1218 if [ -n "$2" ]; then
1219 shift
1220 echo >&2 '#### Additionally provided output files contain:'
1221 cat >&2 "$@"
1222 fi
1223 echo >&2 '#### Download log of the status code:'
1224 cat >&2 "$DOWNLOG"
1225 msgfail "Status was $(cat "$STATUS")"
1226 fi
1227}
1228
89a1aa5d
DK
1229pause() {
1230 echo "STOPPED execution. Press enter to continue"
1231 local IGNORE
1232 read IGNORE
1233}