]> git.saurik.com Git - apt.git/blame_incremental - test/test-indexes.sh
test-indexes: Use /etc/apt from temporary work dir, not from system
[apt.git] / test / test-indexes.sh
... / ...
CommitLineData
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
10TEST_SOURCE="http://ftp.debian.org/debian unstable contrib"
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="-qq -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
30check_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 out=$($APT_GET "$@" update 2>&1)
36 echo "$out" | grep -q NO_PUBKEY
37 key=$(echo "$out" | sed -n '/NO_PUBKEY/ { s/^.*NO_PUBKEY \([[:alnum:]]\+\)$/\1/; p}')
38 # get keyring
39 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
40
41 echo "--- apt-get update $@ (with trusted keys)"
42 $APT_GET "$@" update
43}
44
45# if $1 == "compressed", check that we have compressed indexes, otherwise
46# uncompressed ones
47check_indexes() {
48 echo "--- only ${1:-uncompressed} index files present"
49 local F
50 if [ "$1" = "compressed" ]; then
51 ! test -e var/lib/apt/lists/*_Packages || F=1
52 ! test -e var/lib/apt/lists/*_Sources || F=1
53 test -e var/lib/apt/lists/*_Packages.gz || F=1
54 test -e var/lib/apt/lists/*_Sources.gz || F=1
55 else
56 test -e var/lib/apt/lists/*_Packages || F=1
57 test -e var/lib/apt/lists/*_Sources || F=1
58 ! test -e var/lib/apt/lists/*_Packages.gz || F=1
59 ! test -e var/lib/apt/lists/*_Sources.gz || F=1
60 fi
61
62 if [ -n "$F" ]; then
63 ls -laR var/lib/apt/lists/
64 exit 1
65 fi
66}
67
68# test apt-cache commands
69check_cache() {
70 echo "--- apt-cache commands"
71
72 $APT_CACHE show $TEST_PKG | grep -q ^Version:
73 # again (with cache)
74 $APT_CACHE show $TEST_PKG | grep -q ^Version:
75 rm var/cache/apt/*.bin
76 $APT_CACHE policy $TEST_PKG | grep -q '500 http://'
77 # again (with cache)
78 $APT_CACHE policy $TEST_PKG | grep -q '500 http://'
79
80 TEST_SRC=`$APT_CACHE show $TEST_PKG | grep ^Source: | awk '{print $2}'`
81 rm var/cache/apt/*.bin
82 $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
83 # again (with cache)
84 $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
85}
86
87# test apt-get install
88check_install() {
89 echo "--- apt-get install"
90
91 $APT_GET install -d $TEST_PKG
92 test -e var/cache/apt/archives/$TEST_PKG*.deb
93 $APT_GET clean
94 ! test -e var/cache/apt/archives/$TEST_PKG*.deb
95}
96
97# test apt-get source
98check_get_source() {
99 echo "--- apt-get source"
100 $APT_GET source $TEST_PKG
101 test -f $TEST_SRC_*.dsc
102 test -d $TEST_SRC-*
103 rm -r $TEST_SRC*
104}
105
106############################################################################
107# main
108############################################################################
109
110echo "===== building sandbox ====="
111WORKDIR=$(mktemp -d)
112trap "cd /; rm -rf $WORKDIR" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
113cd $WORKDIR
114
115rm -fr etc var
116rm -f home
117ln -s /home home
118mkdir -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
119cp /etc/apt/trusted.gpg etc/apt
120touch var/lib/dpkg/status
121echo "deb $TEST_SOURCE" > etc/apt/sources.list
122echo "deb-src $TEST_SOURCE" >> etc/apt/sources.list
123
124# specifying -o RootDir at the command line does not work for
125# etc/apt/apt.conf.d/ since it is parsed after pkgInitConfig(); $APT_CONFIG is
126# checked first, so this works
127echo 'RootDir ".";' > apt_config
128export APT_CONFIG=`pwd`/apt_config
129
130echo "===== uncompressed indexes ====="
131# first attempt should fail, no trusted GPG key
132check_update
133check_indexes
134check_cache
135check_install
136check_get_source
137
138echo "--- apt-get update with preexisting indexes"
139$APT_GET update
140check_indexes
141
142echo "--- apt-get update with preexisting indexes and pdiff mode"
143$APT_GET -o Acquire::PDiffs=true update
144check_indexes
145
146echo "===== compressed indexes ====="
147find var/lib/apt/lists/ -type f | xargs -r rm
148check_update -o Acquire::GzipIndexes=true
149check_indexes compressed
150check_cache
151check_install
152check_get_source
153
154echo "--- apt-get update with preexisting indexes"
155check_update -o Acquire::GzipIndexes=true
156check_indexes
157
158echo "--- apt-get update with preexisting indexes and pdiff mode"
159check_update -o Acquire::GzipIndexes=true -o Acquire::PDiffs=true update
160check_indexes
161
162echo "===== ALL TESTS PASSED ====="