dpkg.preinst 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. ALTDIR="/var/lib/dpkg/alternatives"
  30. for alt in $ALTDIR/*; do
  31. if [ ! -e $alt ]; then
  32. # In case it's been removed by the code below
  33. continue
  34. fi
  35. {
  36. read mode
  37. read mainlink
  38. while true; do
  39. read slave
  40. if [ "$slave" = "" ]; then
  41. break
  42. fi
  43. if [ -e "$ALTDIR/$slave" ]; then
  44. echo "Removing conflicting master alternative $slave (it is slave of $(basename $alt))..."
  45. rm -f "$ALTDIR/$slave"
  46. fi
  47. read slavelink
  48. done
  49. } <$alt
  50. done
  51. }
  52. case "$1" in
  53. install)
  54. ;;
  55. upgrade)
  56. # Cleanup bad alternatives that would choke with new
  57. # update-alternatives (see #530633, #531611, #532739, #521760)
  58. if dpkg --compare-versions "$2" lt 1.15.3; then
  59. kill_bad_alternatives
  60. fi
  61. case "$2" in
  62. # Upgrade from pre-conffile dpkg.cfg
  63. 1.9.21 | 1.10.* )
  64. upgrade_dpkg_non_conffile
  65. ;;
  66. esac
  67. ;;
  68. abort-upgrade)
  69. ;;
  70. *)
  71. echo "$0 called with unknown argument \`$1'" 1>&2
  72. exit 1
  73. ;;
  74. esac
  75. #DEBHELPER#
  76. exit 0