]>
Commit | Line | Data |
---|---|---|
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 | ||
8 | BUILDDIR=$(readlink -f $(dirname $0)/../build) | |
9 | ||
f4782b42 | 10 | TEST_SOURCE="http://ftp.debian.org/debian unstable contrib" |
31e1187b | 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 | ||
81563bc1 | 18 | OPTS="-qq -o Dir::Bin::Methods=$BUILDDIR/bin/methods -o Debug::NoLocking=true" |
31e1187b | 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" | |
c19625e7 | 24 | APT_FTPARCHIVE="$BUILDDIR/bin/apt-ftparchive" |
31e1187b | 25 | |
26 | [ -x "$BUILDDIR/bin/apt-get" ] || { | |
27 | echo "please build the tree first" >&2 | |
28 | exit 1 | |
29 | } | |
30 | ||
2aab191f | 31 | check_update() { |
32 | echo "--- apt-get update $@ (no trusted keys)" | |
33 | ||
34 | rm -f etc/apt/trusted.gpg etc/apt/secring.gpg | |
35 | touch etc/apt/trusted.gpg etc/apt/secring.gpg | |
08abac55 | 36 | find var/lib/apt/lists/ -type f | xargs -r rm |
0311890f | 37 | |
38 | # first attempt should fail, no trusted GPG key | |
2aab191f | 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}') | |
0311890f | 42 | |
2aab191f | 43 | # get keyring |
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 | |
45 | ||
0311890f | 46 | # now it should work |
2aab191f | 47 | echo "--- apt-get update $@ (with trusted keys)" |
08abac55 | 48 | find var/lib/apt/lists/ -type f | xargs -r rm |
2aab191f | 49 | $APT_GET "$@" update |
50 | } | |
51 | ||
8d60bef0 | 52 | # if $1 == "compressed", check that we have compressed indexes, otherwise |
53 | # uncompressed ones | |
54 | check_indexes() { | |
2aab191f | 55 | echo "--- only ${1:-uncompressed} index files present" |
8d60bef0 | 56 | local F |
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 | |
62 | else | |
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 | |
67 | fi | |
68 | ||
69 | if [ -n "$F" ]; then | |
2aab191f | 70 | ls -laR var/lib/apt/lists/ |
8d60bef0 | 71 | exit 1 |
72 | fi | |
73 | } | |
74 | ||
2aab191f | 75 | # test apt-cache commands |
76 | check_cache() { | |
77 | echo "--- apt-cache commands" | |
78 | ||
79 | $APT_CACHE show $TEST_PKG | grep -q ^Version: | |
80 | # again (with cache) | |
81 | $APT_CACHE show $TEST_PKG | grep -q ^Version: | |
82 | rm var/cache/apt/*.bin | |
c19625e7 | 83 | $APT_CACHE policy $TEST_PKG | egrep -q '500 (http://|file:/)' |
2aab191f | 84 | # again (with cache) |
c19625e7 | 85 | $APT_CACHE policy $TEST_PKG | egrep -q '500 (http://|file:/)' |
2aab191f | 86 | |
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: | |
90 | # again (with cache) | |
91 | $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary: | |
92 | } | |
93 | ||
94 | # test apt-get install | |
95 | check_install() { | |
96 | echo "--- apt-get install" | |
97 | ||
98 | $APT_GET install -d $TEST_PKG | |
99 | test -e var/cache/apt/archives/$TEST_PKG*.deb | |
100 | $APT_GET clean | |
101 | ! test -e var/cache/apt/archives/$TEST_PKG*.deb | |
102 | } | |
103 | ||
104 | # test apt-get source | |
105 | check_get_source() { | |
106 | echo "--- apt-get source" | |
594bfe6a | 107 | # quiesce: it'll complain about not being able to verify the signature |
108 | $APT_GET source $TEST_PKG >/dev/null 2>&1 | |
2aab191f | 109 | test -f $TEST_SRC_*.dsc |
110 | test -d $TEST_SRC-* | |
111 | rm -r $TEST_SRC* | |
112 | } | |
113 | ||
114 | ############################################################################ | |
115 | # main | |
116 | ############################################################################ | |
117 | ||
118 | echo "===== building sandbox =====" | |
31e1187b | 119 | WORKDIR=$(mktemp -d) |
120 | trap "cd /; rm -rf $WORKDIR" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM | |
121 | cd $WORKDIR | |
122 | ||
123 | rm -fr etc var | |
124 | rm -f home | |
125 | ln -s /home home | |
81563bc1 | 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 |
31e1187b | 127 | cp /etc/apt/trusted.gpg etc/apt |
128 | touch var/lib/dpkg/status | |
f4782b42 | 129 | echo "deb $TEST_SOURCE" > etc/apt/sources.list |
130 | echo "deb-src $TEST_SOURCE" >> etc/apt/sources.list | |
31e1187b | 131 | |
81563bc1 | 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 | |
c19625e7 | 135 | echo "RootDir \"$WORKDIR\";" > apt_config |
81563bc1 | 136 | export APT_CONFIG=`pwd`/apt_config |
137 | ||
915f0520 MP |
138 | echo "==== no indexes ====" |
139 | echo '--- apt-get check works without indexes' | |
140 | [ -z `$APT_GET check` ] | |
141 | echo '--- apt-cache policy works without indexes' | |
142 | $APT_CACHE policy bash >/dev/null | |
143 | echo '--- apt-cache show works without indexes' | |
144 | ! LC_MESSAGES=C $APT_CACHE show bash 2>&1| grep -q 'E: No packages found' | |
145 | ||
2aab191f | 146 | echo "===== uncompressed indexes =====" |
d88a49c8 | 147 | echo 'Acquire::GzipIndexes "false";' > etc/apt/apt.conf.d/02compress-indexes |
2aab191f | 148 | check_update |
8d60bef0 | 149 | check_indexes |
2aab191f | 150 | check_cache |
151 | check_install | |
152 | check_get_source | |
31e1187b | 153 | |
2aab191f | 154 | echo "--- apt-get update with preexisting indexes" |
155 | $APT_GET update | |
8d60bef0 | 156 | check_indexes |
eee5ab3c | 157 | check_cache |
31e1187b | 158 | |
2aab191f | 159 | echo "--- apt-get update with preexisting indexes and pdiff mode" |
31e1187b | 160 | $APT_GET -o Acquire::PDiffs=true update |
8d60bef0 | 161 | check_indexes |
eee5ab3c | 162 | check_cache |
31e1187b | 163 | |
0311890f | 164 | echo "===== compressed indexes (CLI option) =====" |
2aab191f | 165 | check_update -o Acquire::GzipIndexes=true |
8d60bef0 | 166 | check_indexes compressed |
2aab191f | 167 | check_cache |
168 | check_install | |
169 | check_get_source | |
31e1187b | 170 | |
2aab191f | 171 | echo "--- apt-get update with preexisting indexes" |
08abac55 | 172 | $APT_GET -o Acquire::GzipIndexes=true update |
321798be | 173 | check_indexes compressed |
eee5ab3c | 174 | check_cache |
31e1187b | 175 | |
2aab191f | 176 | echo "--- apt-get update with preexisting indexes and pdiff mode" |
08abac55 | 177 | $APT_GET -o Acquire::GzipIndexes=true -o Acquire::PDiffs=true update |
321798be | 178 | check_indexes compressed |
eee5ab3c | 179 | check_cache |
31e1187b | 180 | |
0311890f | 181 | echo "===== compressed indexes (apt.conf.d option) =====" |
182 | cat <<EOF > etc/apt/apt.conf.d/02compress-indexes | |
183 | Acquire::GzipIndexes "true"; | |
184 | Acquire::CompressionTypes::Order:: "gz"; | |
185 | EOF | |
186 | ||
187 | check_update | |
188 | check_indexes compressed | |
189 | check_cache | |
190 | check_install | |
191 | check_get_source | |
192 | ||
193 | echo "--- apt-get update with preexisting indexes" | |
194 | $APT_GET update | |
195 | check_indexes compressed | |
196 | check_cache | |
197 | ||
198 | echo "--- apt-get update with preexisting indexes and pdiff mode" | |
199 | $APT_GET -o Acquire::PDiffs=true update | |
200 | check_indexes compressed | |
201 | check_cache | |
202 | ||
c19625e7 | 203 | rm etc/apt/apt.conf.d/02compress-indexes |
204 | ||
205 | echo "==== apt-ftparchive ====" | |
206 | mkdir arch | |
207 | $APT_GET install -d $TEST_PKG | |
208 | cp var/cache/apt/archives/$TEST_PKG*.deb arch/ | |
209 | cd arch | |
210 | $APT_GET source -d $TEST_PKG >/dev/null 2>&1 | |
211 | $APT_FTPARCHIVE packages . | gzip -9 > Packages.gz | |
212 | $APT_FTPARCHIVE sources . | gzip -9 > Sources.gz | |
213 | cd .. | |
214 | ||
215 | echo "deb file://$WORKDIR/arch / | |
216 | deb-src file://$WORKDIR/arch /" > etc/apt/sources.list | |
217 | $APT_GET clean | |
218 | ||
219 | echo "==== uncompressed indexes from local file:// archive ====" | |
220 | echo "--- apt-get update" | |
221 | $APT_GET update | |
222 | check_indexes | |
223 | check_cache | |
224 | check_get_source | |
225 | ||
226 | echo "==== compressed indexes from local file:// archive ====" | |
227 | echo "--- apt-get update" | |
228 | $APT_GET -o Acquire::GzipIndexes=true update | |
9a3a552a | 229 | # EXFAIL: file:/ URIs currently decompress even with above option |
230 | #check_indexes compressed | |
231 | check_indexes | |
c19625e7 | 232 | check_cache |
233 | check_get_source | |
234 | ||
2aab191f | 235 | echo "===== ALL TESTS PASSED =====" |