]> git.saurik.com Git - apt.git/blob - test/test-indexes.sh
d79e9e7e4575a685e2fdf514948375aa77d4e75a
[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="-o RootDir=. -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 # if $1 == "compressed", check that we have compressed indexes, otherwise
31 # uncompressed ones
32 check_indexes() {
33 local F
34 if [ "$1" = "compressed" ]; then
35 ! test -e var/lib/apt/lists/*_Packages || F=1
36 ! test -e var/lib/apt/lists/*_Sources || F=1
37 test -e var/lib/apt/lists/*_Packages.gz || F=1
38 test -e var/lib/apt/lists/*_Sources.gz || F=1
39 else
40 test -e var/lib/apt/lists/*_Packages || F=1
41 test -e var/lib/apt/lists/*_Sources || F=1
42 ! test -e var/lib/apt/lists/*_Packages.gz || F=1
43 ! test -e var/lib/apt/lists/*_Sources.gz || F=1
44 fi
45
46 if [ -n "$F" ]; then
47 ls -l var/lib/apt/lists/
48 exit 1
49 fi
50 }
51
52 echo "---- building sandbox----"
53 WORKDIR=$(mktemp -d)
54 trap "cd /; rm -rf $WORKDIR" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
55 cd $WORKDIR
56
57 rm -fr etc var
58 rm -f home
59 ln -s /home home
60 mkdir -p etc/apt/preferences.d etc/apt/trusted.gpg.d var/cache/apt/archives/partial var/lib/apt/lists/partial var/lib/dpkg
61 cp /etc/apt/trusted.gpg etc/apt
62 touch var/lib/dpkg/status
63 echo "deb $TEST_SOURCE" > etc/apt/sources.list
64 echo "deb-src $TEST_SOURCE" >> etc/apt/sources.list
65
66 echo "---- uncompressed update ----"
67 # first attempt should fail, no trusted GPG key
68 out=$($APT_GET update 2>&1)
69 echo "$out" | grep -q NO_PUBKEY
70 key=$(echo "$out" | sed -n '/NO_PUBKEY/ { s/^.*NO_PUBKEY \([[:alnum:]]\+\)$/\1/; p}')
71 # get keyring
72 gpg --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
73 $APT_GET update
74 check_indexes
75
76 echo "---- uncompressed cache ----"
77 $APT_CACHE show $TEST_PKG | grep -q ^Version:
78 # again (with cache)
79 $APT_CACHE show $TEST_PKG | grep -q ^Version:
80 rm var/cache/apt/*.bin
81 $APT_CACHE policy $TEST_PKG | grep -q '500 http://'
82 # again (with cache)
83 $APT_CACHE policy $TEST_PKG | grep -q '500 http://'
84
85 TEST_SRC=`$APT_CACHE show $TEST_PKG | grep ^Source: | awk '{print $2}'`
86 rm var/cache/apt/*.bin
87 $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
88 # again (with cache)
89 $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
90
91 echo "---- uncompressed install ----"
92 $APT_GET install -d $TEST_PKG
93 test -e var/cache/apt/archives/$TEST_PKG*.deb
94 $APT_GET clean
95 ! test -e var/cache/apt/archives/$TEST_PKG*.deb
96
97 echo "---- uncompressed get source ----"
98 $APT_GET source $TEST_PKG
99 test -f $TEST_SRC_*.dsc
100 test -d $TEST_SRC-*
101 rm -r $TEST_SRC*
102
103 echo "----- uncompressed update with preexisting indexes, no pdiff ----"
104 $APT_GET -o Acquire::PDiffs=false update
105 check_indexes
106
107 echo "----- uncompressed update with preexisting indexes, with pdiff ----"
108 $APT_GET -o Acquire::PDiffs=true update
109 check_indexes
110
111 echo "----- compressed update ----"
112 find var/lib/apt/lists/ -type f | xargs -r rm
113 $APT_GET -o Acquire::GzipIndexes=true update
114 check_indexes compressed
115
116 echo "---- compressed cache ----"
117 $APT_CACHE show $TEST_PKG | grep -q ^Version:
118 # again (with cache)
119 $APT_CACHE show $TEST_PKG | grep -q ^Version:
120 rm var/cache/apt/*.bin
121 $APT_CACHE policy $TEST_PKG | grep -q '500 http://'
122 # again (with cache)
123 $APT_CACHE policy $TEST_PKG | grep -q '500 http://'
124
125 TEST_SRC=`$APT_CACHE show $TEST_PKG | grep ^Source: | awk '{print $2}'`
126 rm var/cache/apt/*.bin
127 $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
128 # again (with cache)
129 $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
130
131 echo "---- compressed install ----"
132 $APT_GET install -d $TEST_PKG
133 ! test -e var/cache/apt/archives/$TEST_PKG*.deb
134
135 echo "---- compressed get source ----"
136 $APT_GET source $TEST_PKG
137 test -f $TEST_SRC_*.dsc
138 test -d $TEST_SRC-*
139 rm -r $TEST_SRC*
140
141 echo "----- compressed update with preexisting indexes, no pdiff ----"
142 $APT_GET -o Acquire::PDiffs=false -o Acquire::GzipIndexes=true update
143 check_indexes compressed
144
145 echo "----- compressed update with preexisting indexes, with pdiff ----"
146 $APT_GET -o Acquire::PDiffs=true -o Acquire::GzipIndexes=true update
147 check_indexes compressed
148
149 echo "---- ALL TESTS PASSED ----"