test-indexes.sh 6.9 KB

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