]> git.saurik.com Git - apt.git/blob - test/test-indexes.sh
test-indexes.sh: quiesce apt-get source; we know that we cannot verify package signatures
[apt.git] / test / test-indexes.sh
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
8 BUILDDIR=$(readlink -f $(dirname $0)/../build)
9
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"
15
16 export LD_LIBRARY_PATH=$BUILDDIR/bin
17
18 OPTS="-qq -o Dir::Bin::Methods=$BUILDDIR/bin/methods -o Debug::NoLocking=true"
19 DEBUG=""
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
25 [ -x "$BUILDDIR/bin/apt-get" ] || {
26 echo "please build the tree first" >&2
27 exit 1
28 }
29
30 check_update() {
31 echo "--- apt-get update $@ (no trusted keys)"
32
33 rm -f etc/apt/trusted.gpg etc/apt/secring.gpg
34 touch etc/apt/trusted.gpg etc/apt/secring.gpg
35 find var/lib/apt/lists/ -type f | xargs -r rm
36
37 # first attempt should fail, no trusted GPG key
38 out=$($APT_GET "$@" update 2>&1)
39 echo "$out" | grep -q NO_PUBKEY
40 key=$(echo "$out" | sed -n '/NO_PUBKEY/ { s/^.*NO_PUBKEY \([[:alnum:]]\+\)$/\1/; p}')
41
42 # get keyring
43 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
44
45 # now it should work
46 echo "--- apt-get update $@ (with trusted keys)"
47 find var/lib/apt/lists/ -type f | xargs -r rm
48 $APT_GET "$@" update
49 }
50
51 # if $1 == "compressed", check that we have compressed indexes, otherwise
52 # uncompressed ones
53 check_indexes() {
54 echo "--- only ${1:-uncompressed} index files present"
55 local F
56 if [ "$1" = "compressed" ]; then
57 ! test -e var/lib/apt/lists/*_Packages || F=1
58 ! test -e var/lib/apt/lists/*_Sources || F=1
59 test -e var/lib/apt/lists/*_Packages.gz || F=1
60 test -e var/lib/apt/lists/*_Sources.gz || F=1
61 else
62 test -e var/lib/apt/lists/*_Packages || F=1
63 test -e var/lib/apt/lists/*_Sources || F=1
64 ! test -e var/lib/apt/lists/*_Packages.gz || F=1
65 ! test -e var/lib/apt/lists/*_Sources.gz || F=1
66 fi
67
68 if [ -n "$F" ]; then
69 ls -laR var/lib/apt/lists/
70 exit 1
71 fi
72 }
73
74 # test apt-cache commands
75 check_cache() {
76 echo "--- apt-cache commands"
77
78 $APT_CACHE show $TEST_PKG | grep -q ^Version:
79 # again (with cache)
80 $APT_CACHE show $TEST_PKG | grep -q ^Version:
81 rm var/cache/apt/*.bin
82 $APT_CACHE policy $TEST_PKG | grep -q '500 http://'
83 # again (with cache)
84 $APT_CACHE policy $TEST_PKG | grep -q '500 http://'
85
86 TEST_SRC=`$APT_CACHE show $TEST_PKG | grep ^Source: | awk '{print $2}'`
87 rm var/cache/apt/*.bin
88 $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
89 # again (with cache)
90 $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
91 }
92
93 # test apt-get install
94 check_install() {
95 echo "--- apt-get install"
96
97 $APT_GET install -d $TEST_PKG
98 test -e var/cache/apt/archives/$TEST_PKG*.deb
99 $APT_GET clean
100 ! test -e var/cache/apt/archives/$TEST_PKG*.deb
101 }
102
103 # test apt-get source
104 check_get_source() {
105 echo "--- apt-get source"
106 # quiesce: it'll complain about not being able to verify the signature
107 $APT_GET source $TEST_PKG >/dev/null 2>&1
108 test -f $TEST_SRC_*.dsc
109 test -d $TEST_SRC-*
110 rm -r $TEST_SRC*
111 }
112
113 ############################################################################
114 # main
115 ############################################################################
116
117 echo "===== building sandbox ====="
118 WORKDIR=$(mktemp -d)
119 trap "cd /; rm -rf $WORKDIR" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
120 cd $WORKDIR
121
122 rm -fr etc var
123 rm -f home
124 ln -s /home home
125 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
126 cp /etc/apt/trusted.gpg etc/apt
127 touch var/lib/dpkg/status
128 echo "deb $TEST_SOURCE" > etc/apt/sources.list
129 echo "deb-src $TEST_SOURCE" >> etc/apt/sources.list
130
131 # specifying -o RootDir at the command line does not work for
132 # etc/apt/apt.conf.d/ since it is parsed after pkgInitConfig(); $APT_CONFIG is
133 # checked first, so this works
134 echo 'RootDir ".";' > apt_config
135 export APT_CONFIG=`pwd`/apt_config
136
137 echo "===== uncompressed indexes ====="
138 check_update
139 check_indexes
140 check_cache
141 check_install
142 check_get_source
143
144 echo "--- apt-get update with preexisting indexes"
145 $APT_GET update
146 check_indexes
147 check_cache
148
149 echo "--- apt-get update with preexisting indexes and pdiff mode"
150 $APT_GET -o Acquire::PDiffs=true update
151 check_indexes
152 check_cache
153
154 echo "===== compressed indexes (CLI option) ====="
155 check_update -o Acquire::GzipIndexes=true
156 check_indexes compressed
157 check_cache
158 check_install
159 check_get_source
160
161 echo "--- apt-get update with preexisting indexes"
162 $APT_GET -o Acquire::GzipIndexes=true update
163 check_indexes compressed
164 check_cache
165
166 echo "--- apt-get update with preexisting indexes and pdiff mode"
167 $APT_GET -o Acquire::GzipIndexes=true -o Acquire::PDiffs=true update
168 check_indexes compressed
169 check_cache
170
171 echo "===== compressed indexes (apt.conf.d option) ====="
172 cat <<EOF > etc/apt/apt.conf.d/02compress-indexes
173 Acquire::GzipIndexes "true";
174 Acquire::CompressionTypes::Order:: "gz";
175 EOF
176
177 check_update
178 check_indexes compressed
179 check_cache
180 check_install
181 check_get_source
182
183 echo "--- apt-get update with preexisting indexes"
184 $APT_GET update
185 check_indexes compressed
186 check_cache
187
188 echo "--- apt-get update with preexisting indexes and pdiff mode"
189 $APT_GET -o Acquire::PDiffs=true update
190 check_indexes compressed
191 check_cache
192
193 echo "===== ALL TESTS PASSED ====="