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.
8 BUILDDIR
=$(readlink -f $(dirname $0)/..
/build
)
10 TEST_SOURCE
="http://ftp.debian.org/debian unstable contrib"
11 GPG_KEYSERVER
=gpg
-keyserver.de
12 # should be a small package with dependencies satisfiable in TEST_SOURCE, i. e.
13 # ideally no depends at all
14 TEST_PKG
="python-psyco-doc"
16 export LD_LIBRARY_PATH
=$BUILDDIR/bin
18 OPTS
="-qq -o Dir::Bin::Methods=$BUILDDIR/bin/methods -o Debug::NoLocking=true"
20 #DEBUG="-o Debug::pkgCacheGen=true"
21 #DEBUG="-o Debug::pkgAcquire=true"
22 APT_GET
="$BUILDDIR/bin/apt-get $OPTS $DEBUG"
23 APT_CACHE
="$BUILDDIR/bin/apt-cache $OPTS $DEBUG"
24 APT_FTPARCHIVE
="$BUILDDIR/bin/apt-ftparchive"
26 [ -x "$BUILDDIR/bin/apt-get" ] || {
27 echo "please build the tree first" >&2
32 echo "--- apt-get update $@ (no trusted keys)"
34 rm -f etc
/apt
/trusted.gpg etc
/apt
/secring.gpg
35 touch etc
/apt
/trusted.gpg etc
/apt
/secring.gpg
36 find var
/lib
/apt
/lists
/ -type f
| xargs -r rm
38 # first attempt should fail, no trusted GPG key
39 out
=$($APT_GET "$@" update 2>&1)
40 echo "$out" | grep -q NO_PUBKEY
41 key
=$(echo "$out" | sed -n '/NO_PUBKEY/ { s/^.*NO_PUBKEY \([[:alnum:]]\+\)$
/\
1/; p
}')
44 gpg -q --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
47 echo "--- apt-get update $@ (with trusted keys)"
48 find var/lib/apt/lists/ -type f | xargs -r rm
52 # if $1 == "compressed", check that we have compressed indexes, otherwise
55 echo "--- only ${1:-uncompressed} index files present"
57 if [ "$1" = "compressed" ]; then
58 ! test -e var/lib/apt/lists/*_Packages || F=1
59 ! test -e var/lib/apt/lists/*_Sources || F=1
60 test -e var/lib/apt/lists/*_Packages.gz || F=1
61 test -e var/lib/apt/lists/*_Sources.gz || F=1
63 test -e var/lib/apt/lists/*_Packages || F=1
64 test -e var/lib/apt/lists/*_Sources || F=1
65 ! test -e var/lib/apt/lists/*_Packages.gz || F=1
66 ! test -e var/lib/apt/lists/*_Sources.gz || F=1
70 ls -laR var/lib/apt/lists/
75 # test apt-cache commands
77 echo "--- apt-cache commands"
79 $APT_CACHE show $TEST_PKG | grep -q ^Version:
81 $APT_CACHE show $TEST_PKG | grep -q ^Version:
82 rm var/cache/apt/*.bin
83 $APT_CACHE policy $TEST_PKG | egrep -q '500 (http
://|file:/)'
85 $APT_CACHE policy $TEST_PKG | egrep -q '500 (http
://|file:/)'
87 TEST_SRC=`$APT_CACHE show $TEST_PKG | grep ^Source: | awk '{print
$2}'`
88 rm var/cache/apt/*.bin
89 $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
91 $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
94 # test apt-get install
96 echo "--- apt-get install"
98 $APT_GET install -d $TEST_PKG
99 test -e var/cache/apt/archives/$TEST_PKG*.deb
101 ! test -e var/cache/apt/archives/$TEST_PKG*.deb
104 # test apt-get source
106 echo "--- apt-get source"
107 # quiesce: it'll complain about not being able to verify the signature
108 $APT_GET source $TEST_PKG >/dev
/null
2>&1
109 test -f $TEST_SRC_*.dsc
114 ############################################################################
116 ############################################################################
118 echo "===== building sandbox ====="
120 trap "cd /; rm -rf $WORKDIR" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
126 mkdir -p etc
/apt
/preferences.d etc
/apt
/trusted.gpg.d etc
/apt
/apt.conf.d var
/cache
/apt
/archives
/partial var
/lib
/apt
/lists
/partial var
/lib
/dpkg
127 cp /etc
/apt
/trusted.gpg etc
/apt
128 touch var
/lib
/dpkg
/status
129 echo "deb $TEST_SOURCE" > etc
/apt
/sources.list
130 echo "deb-src $TEST_SOURCE" >> etc
/apt
/sources.list
132 # specifying -o RootDir at the command line does not work for
133 # etc/apt/apt.conf.d/ since it is parsed after pkgInitConfig(); $APT_CONFIG is
134 # checked first, so this works
135 echo "RootDir \"$WORKDIR\";" > apt_config
136 export APT_CONFIG
=`pwd`/apt_config
138 echo "===== uncompressed indexes ====="
145 echo "--- apt-get update with preexisting indexes"
150 echo "--- apt-get update with preexisting indexes and pdiff mode"
151 $APT_GET -o Acquire
::PDiffs
=true update
155 echo "===== compressed indexes (CLI option) ====="
156 check_update
-o Acquire
::GzipIndexes
=true
157 check_indexes compressed
162 echo "--- apt-get update with preexisting indexes"
163 $APT_GET -o Acquire
::GzipIndexes
=true update
164 check_indexes compressed
167 echo "--- apt-get update with preexisting indexes and pdiff mode"
168 $APT_GET -o Acquire
::GzipIndexes
=true
-o Acquire
::PDiffs
=true update
169 check_indexes compressed
172 echo "===== compressed indexes (apt.conf.d option) ====="
173 cat <<EOF > etc/apt/apt.conf.d/02compress-indexes
174 Acquire::GzipIndexes "true";
175 Acquire::CompressionTypes::Order:: "gz";
179 check_indexes compressed
184 echo "--- apt-get update with preexisting indexes"
186 check_indexes compressed
189 echo "--- apt-get update with preexisting indexes and pdiff mode"
190 $APT_GET -o Acquire
::PDiffs
=true update
191 check_indexes compressed
194 rm etc
/apt
/apt.conf.d
/02compress-indexes
196 echo "==== apt-ftparchive ===="
198 $APT_GET install -d $TEST_PKG
199 cp var
/cache
/apt
/archives
/$TEST_PKG*.deb arch
/
201 $APT_GET source -d $TEST_PKG >/dev
/null
2>&1
202 $APT_FTPARCHIVE packages .
| gzip -9 > Packages.gz
203 $APT_FTPARCHIVE sources .
| gzip -9 > Sources.gz
206 echo "deb file://$WORKDIR/arch /
207 deb-src file://$WORKDIR/arch /" > etc
/apt
/sources.list
210 echo "==== uncompressed indexes from local file:// archive ===="
211 echo "--- apt-get update"
217 echo "==== compressed indexes from local file:// archive ===="
218 echo "--- apt-get update"
219 $APT_GET -o Acquire
::GzipIndexes
=true update
220 # EXFAIL: file:/ URIs currently decompress even with above option
221 #check_indexes compressed
226 echo "===== ALL TESTS PASSED ====="