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.
 
 
 
 
 
 

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