apt-cdrom-check 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/sh
  2. #
  3. # helper to check if we actually have an ubuntu CD
  4. #
  5. # Returncode:
  6. # 0 - no ubuntu CD
  7. # 1 - CD with packages
  8. # 2 - dist-upgrader CD
  9. # 3 - aptoncd media
  10. # (if the returncodes change, make sure to update src/cdroms.c)
  11. #
  12. mount_point="$1"
  13. aptoncd_file="$mount_point/aptoncd.info"
  14. # sanity checks
  15. if [ -z "$mount_point" ]; then
  16. exit 0
  17. fi
  18. if [ -f "$aptoncd_file" ]; then
  19. exit 3
  20. fi
  21. if [ ! -d "$mount_point/ubuntu" ] && [ ! -f "$mount_point/cdromupgrade" ]; then
  22. exit 0
  23. fi
  24. # check if there are "Packages" files on the cd (and ignore the
  25. # debian-installer dir)
  26. find "$mount_point/dists/" -name "Packages.gz" | grep -q -v debian-installer
  27. # 1 means "no lines were selected" in grep (no Packages file but the
  28. # debian-installer ones)
  29. if [ $? -eq 1 ]; then
  30. exit 0
  31. fi
  32. # get some apt-config vars
  33. label_start=0
  34. cdrom_id=""
  35. apt_dir="/"
  36. apt_state_dir="var/lib/apt/"
  37. apt_cdrom_list="cdrom.list"
  38. eval $(apt-config shell apt_dir Dir \
  39. apt_state_dir Dir::State \
  40. apt_cdrom_list Dir::State::cdroms)
  41. # identifying ... [afkdsjaf] line
  42. line=$(apt-cdrom -d="$1" -m ident|grep "\[.*\]")
  43. # remove the stuff before "Identifying... [dasjflkd]" -> "dasjflkd"
  44. line=${line%]*}
  45. cdrom_id=${line#*\[}
  46. if [ -z "$cdrom_id" ]; then
  47. # something bad happened here, we return "not yet scanned" as
  48. # fallback (because we are cheap)
  49. return 1
  50. fi
  51. # [cdrom-id] -> cdrom-id
  52. if grep -s -q "$cdrom_id" $apt_dir$apt_state_dir$apt_cdrom_list; then
  53. # already in sources.list, ignore
  54. exit 0
  55. fi
  56. # so this is a CD we don't know yet and it has packages. good!
  57. THIS_VERSION=$(lsb_release -sr)
  58. VERSION_ON_MEDIA=$(awk {'print $2'} "$mount_point/.disk/info")
  59. # now check if it contains a signed dist-upgrader
  60. for d in "$mount_point"/dists/*/main/dist-upgrader/binary-all/; do
  61. if [ -d "$d" ]; then
  62. # ok, we have one, now check the authentication
  63. GPG="gpgv --ignore-time-conflict --keyring /etc/apt/trusted.gpg"
  64. if $GPG "$d/"*.tar.gz.gpg "$d"/*.tar.gz; then
  65. # verified ok, we have a valid upgrader, if it was not ok, the
  66. # fallback to the end is ok because we still have packages on it
  67. if dpkg --compare-versions "$THIS_VERSION" lt "$VERSION_ON_MEDIA"; then
  68. exit 2
  69. fi
  70. fi
  71. fi
  72. done
  73. # we got an ubuntu CD with packages
  74. if dpkg --compare-versions "$THIS_VERSION" lt "$VERSION_ON_MEDIA"; then
  75. exit 1
  76. fi