You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

235 lines
6.8 KiB

  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. check_update
  123. check_indexes
  124. check_cache
  125. check_install
  126. check_get_source
  127. echo "--- apt-get update with preexisting indexes"
  128. $APT_GET update
  129. check_indexes
  130. check_cache
  131. echo "--- apt-get update with preexisting indexes and pdiff mode"
  132. $APT_GET -o Acquire::PDiffs=true update
  133. check_indexes
  134. check_cache
  135. echo "===== compressed indexes (CLI option) ====="
  136. check_update -o Acquire::GzipIndexes=true
  137. check_indexes compressed
  138. check_cache
  139. check_install
  140. check_get_source
  141. echo "--- apt-get update with preexisting indexes"
  142. $APT_GET -o Acquire::GzipIndexes=true update
  143. check_indexes compressed
  144. check_cache
  145. echo "--- apt-get update with preexisting indexes and pdiff mode"
  146. $APT_GET -o Acquire::GzipIndexes=true -o Acquire::PDiffs=true update
  147. check_indexes compressed
  148. check_cache
  149. echo "===== compressed indexes (apt.conf.d option) ====="
  150. cat <<EOF > etc/apt/apt.conf.d/02compress-indexes
  151. Acquire::GzipIndexes "true";
  152. Acquire::CompressionTypes::Order:: "gz";
  153. EOF
  154. check_update
  155. check_indexes compressed
  156. check_cache
  157. check_install
  158. check_get_source
  159. echo "--- apt-get update with preexisting indexes"
  160. $APT_GET update
  161. check_indexes compressed
  162. check_cache
  163. echo "--- apt-get update with preexisting indexes and pdiff mode"
  164. $APT_GET -o Acquire::PDiffs=true update
  165. check_indexes compressed
  166. check_cache
  167. rm etc/apt/apt.conf.d/02compress-indexes
  168. echo "==== apt-ftparchive ===="
  169. mkdir arch
  170. $APT_GET install -d $TEST_PKG
  171. cp var/cache/apt/archives/$TEST_PKG*.deb arch/
  172. cd arch
  173. $APT_GET source -d $TEST_PKG >/dev/null 2>&1
  174. $APT_FTPARCHIVE packages . | gzip -9 > Packages.gz
  175. $APT_FTPARCHIVE sources . | gzip -9 > Sources.gz
  176. cd ..
  177. echo "deb file://$WORKDIR/arch /
  178. deb-src file://$WORKDIR/arch /" > etc/apt/sources.list
  179. $APT_GET clean
  180. echo "==== uncompressed indexes from local file:// archive ===="
  181. echo "--- apt-get update"
  182. $APT_GET update
  183. check_indexes
  184. check_cache
  185. check_get_source
  186. echo "==== compressed indexes from local file:// archive ===="
  187. echo "--- apt-get update"
  188. $APT_GET -o Acquire::GzipIndexes=true update
  189. # EXFAIL: file:/ URIs currently decompress even with above option
  190. #check_indexes compressed
  191. check_indexes
  192. check_cache
  193. check_get_source
  194. echo "===== ALL TESTS PASSED ====="