test/test-indexes.sh: Stop hardcoding archive gpg key ID, get it from first failed...
[ntk/apt.git] / test / test-indexes.sh
CommitLineData
31e1187b 1#!/bin/sh -e
2
3# Test behaviour of index retrieval and usage, in particular with uncompressed
4# and gzip compressed indexes.
5# Author: Martin Pitt <martin.pitt@ubuntu.com>
6# (C) 2010 Canonical Ltd.
7
8BUILDDIR=$(readlink -f $(dirname $0)/../build)
9
f4782b42 10TEST_SOURCE="http://ftp.debian.org/debian unstable contrib"
31e1187b 11GPG_KEYSERVER=gpg-keyserver.de
12# should be a small package with dependencies satisfiable in TEST_SOURCE, i. e.
13# ideally no depends at all
14TEST_PKG="python-psyco-doc"
15
16export LD_LIBRARY_PATH=$BUILDDIR/bin
17
18OPTS="-o RootDir=. -o Dir::Bin::Methods=$BUILDDIR/bin/methods -o Debug::NoLocking=true"
19DEBUG=""
20#DEBUG="-o Debug::pkgCacheGen=true"
21#DEBUG="-o Debug::pkgAcquire=true"
22APT_GET="$BUILDDIR/bin/apt-get $OPTS $DEBUG"
23APT_CACHE="$BUILDDIR/bin/apt-cache $OPTS $DEBUG"
24
25[ -x "$BUILDDIR/bin/apt-get" ] || {
26 echo "please build the tree first" >&2
27 exit 1
28}
29
30echo "---- building sandbox----"
31WORKDIR=$(mktemp -d)
32trap "cd /; rm -rf $WORKDIR" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
33cd $WORKDIR
34
35rm -fr etc var
36rm -f home
37ln -s /home home
38mkdir -p etc/apt/preferences.d etc/apt/trusted.gpg.d var/cache/apt/archives/partial var/lib/apt/lists/partial var/lib/dpkg
39cp /etc/apt/trusted.gpg etc/apt
40touch var/lib/dpkg/status
f4782b42 41echo "deb $TEST_SOURCE" > etc/apt/sources.list
42echo "deb-src $TEST_SOURCE" >> etc/apt/sources.list
31e1187b 43
31e1187b 44echo "---- uncompressed update ----"
8d48388e 45# first attempt should fail, no trusted GPG key
46out=$($APT_GET update 2>&1)
47echo "$out" | grep -q NO_PUBKEY
48key=$(echo "$out" | sed -n '/NO_PUBKEY/ { s/^.*NO_PUBKEY \([[:alnum:]]\+\)$/\1/; p}')
49# get keyring
50gpg --no-options --no-default-keyring --secret-keyring etc/apt/secring.gpg --trustdb-name etc/apt/trustdb.gpg --keyring etc/apt/trusted.gpg --primary-keyring etc/apt/trusted.gpg --keyserver $GPG_KEYSERVER --recv-keys $key
31e1187b 51$APT_GET update
8d48388e 52
31e1187b 53test -e var/lib/apt/lists/*_Packages
f4782b42 54test -e var/lib/apt/lists/*_Sources
31e1187b 55! test -e var/lib/apt/lists/*_Packages.gz
f4782b42 56! test -e var/lib/apt/lists/*_Sources.gz
31e1187b 57
58echo "---- uncompressed cache ----"
59$APT_CACHE show $TEST_PKG | grep -q ^Version:
60# again (with cache)
61$APT_CACHE show $TEST_PKG | grep -q ^Version:
62rm var/cache/apt/*.bin
63$APT_CACHE policy $TEST_PKG | grep -q '500 http://'
64# again (with cache)
65$APT_CACHE policy $TEST_PKG | grep -q '500 http://'
66
f4782b42 67TEST_SRC=`$APT_CACHE show $TEST_PKG | grep ^Source: | awk '{print $2}'`
68rm var/cache/apt/*.bin
69$APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
70# again (with cache)
71$APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
72
31e1187b 73echo "---- uncompressed install ----"
74$APT_GET install -d $TEST_PKG
75test -e var/cache/apt/archives/$TEST_PKG*.deb
76$APT_GET clean
77! test -e var/cache/apt/archives/$TEST_PKG*.deb
78
f4782b42 79echo "---- uncompressed get source ----"
80$APT_GET source $TEST_PKG
81test -f $TEST_SRC_*.dsc
82test -d $TEST_SRC-*
83rm -r $TEST_SRC*
84
31e1187b 85echo "----- uncompressed update with preexisting indexes, no pdiff ----"
86$APT_GET -o Acquire::PDiffs=false update
87test -e var/lib/apt/lists/*_Packages
f4782b42 88test -e var/lib/apt/lists/*_Sources
31e1187b 89! test -e var/lib/apt/lists/*_Packages.gz
f4782b42 90! test -e var/lib/apt/lists/*_Sources.gz
31e1187b 91
92echo "----- uncompressed update with preexisting indexes, with pdiff ----"
93$APT_GET -o Acquire::PDiffs=true update
94test -e var/lib/apt/lists/*_Packages
f4782b42 95test -e var/lib/apt/lists/*_Sources
31e1187b 96! test -e var/lib/apt/lists/*_Packages.gz
f4782b42 97! test -e var/lib/apt/lists/*_Sources.gz
31e1187b 98
99echo "----- compressed update ----"
100find var/lib/apt/lists/ -type f | xargs -r rm
101$APT_GET -o Acquire::GzipIndexes=true update
102! test -e var/lib/apt/lists/*_Packages
f4782b42 103! test -e var/lib/apt/lists/*_Sources
31e1187b 104test -e var/lib/apt/lists/*_Packages.gz
f4782b42 105test -e var/lib/apt/lists/*_Sources.gz
31e1187b 106
107echo "---- compressed cache ----"
108$APT_CACHE show $TEST_PKG | grep -q ^Version:
109# again (with cache)
110$APT_CACHE show $TEST_PKG | grep -q ^Version:
111rm var/cache/apt/*.bin
112$APT_CACHE policy $TEST_PKG | grep -q '500 http://'
113# again (with cache)
114$APT_CACHE policy $TEST_PKG | grep -q '500 http://'
115
f4782b42 116TEST_SRC=`$APT_CACHE show $TEST_PKG | grep ^Source: | awk '{print $2}'`
117rm var/cache/apt/*.bin
118$APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
119# again (with cache)
120$APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
121
31e1187b 122echo "---- compressed install ----"
123$APT_GET install -d $TEST_PKG
124! test -e var/cache/apt/archives/$TEST_PKG*.deb
125
f4782b42 126echo "---- compressed get source ----"
127$APT_GET source $TEST_PKG
128test -f $TEST_SRC_*.dsc
129test -d $TEST_SRC-*
130rm -r $TEST_SRC*
131
31e1187b 132echo "----- compressed update with preexisting indexes, no pdiff ----"
133$APT_GET -o Acquire::PDiffs=false -o Acquire::GzipIndexes=true update
134! test -e var/lib/apt/lists/*_Packages
f4782b42 135! test -e var/lib/apt/lists/*_Sources
31e1187b 136test -e var/lib/apt/lists/*_Packages.gz
f4782b42 137test -e var/lib/apt/lists/*_Sources.gz
31e1187b 138
139echo "----- compressed update with preexisting indexes, with pdiff ----"
140$APT_GET -o Acquire::PDiffs=true -o Acquire::GzipIndexes=true update
141! test -e var/lib/apt/lists/*_Packages
f4782b42 142! test -e var/lib/apt/lists/*_Sources
31e1187b 143test -e var/lib/apt/lists/*_Packages.gz
f4782b42 144test -e var/lib/apt/lists/*_Sources.gz
31e1187b 145
146echo "---- ALL TESTS PASSED ----"