dpkg.preinst 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/sh -e
  2. # This script can be called in the following ways:
  3. #
  4. # Before the package is installed:
  5. # <new-preinst> install
  6. #
  7. # Before removed package is upgraded:
  8. # <new-preinst> install <old-version>
  9. #
  10. # Before the package is upgraded:
  11. # <new-preinst> upgrade <old-version>
  12. #
  13. #
  14. # If postrm fails during upgrade or fails on failed upgrade:
  15. # <old-preinst> abort-upgrade <new-version>
  16. # Handle upgrades from pre-conffile dpkg.cfg
  17. upgrade_dpkg_non_conffile()
  18. {
  19. if [ -r /etc/dpkg/dpkg.cfg ]; then
  20. dpkg_cfg_md5="535552ad5ee9145dbc7a34c264df4e59 /etc/dpkg/dpkg.cfg"
  21. if echo "$dpkg_cfg_md5" | md5sum -c >/dev/null 2>&1; then
  22. echo "Removing non-modified dpkg.cfg to be replaced by a conffile ..."
  23. rm -f /etc/dpkg/dpkg.cfg
  24. fi
  25. fi
  26. }
  27. kill_bad_alternatives () {
  28. local IFS=""
  29. admindir=${DPKG_ADMINDIR:-/var/lib/dpkg}
  30. ALTDIR="$admindir/alternatives"
  31. for alt in $ALTDIR/*; do
  32. if [ ! -f $alt ]; then
  33. # In case it's been removed by the code below, or in case
  34. # it's not a real file
  35. continue
  36. fi
  37. {
  38. read mode || continue
  39. read mainlink || continue
  40. while true; do
  41. read slave || break
  42. if [ "$slave" = "" ]; then
  43. break
  44. fi
  45. if [ -e "$ALTDIR/$slave" ]; then
  46. echo "Removing conflicting master alternative $slave (it is slave of $(basename $alt))..."
  47. rm -f "$ALTDIR/$slave"
  48. fi
  49. read slavelink || break
  50. done
  51. } <$alt
  52. done
  53. }
  54. case "$1" in
  55. install)
  56. ;;
  57. upgrade)
  58. # Cleanup bad alternatives that would choke with new
  59. # update-alternatives (see #530633, #531611, #532739, #521760)
  60. if dpkg --compare-versions "$2" lt 1.15.3; then
  61. kill_bad_alternatives
  62. fi
  63. case "$2" in
  64. # Upgrade from pre-conffile dpkg.cfg
  65. 1.9.21 | 1.10.* )
  66. upgrade_dpkg_non_conffile
  67. ;;
  68. esac
  69. ;;
  70. abort-upgrade)
  71. ;;
  72. *)
  73. echo "$0 called with unknown argument \`$1'" 1>&2
  74. exit 1
  75. ;;
  76. esac
  77. #DEBHELPER#
  78. exit 0