dpkg.preinst 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. # Confirm that users are aware that conffile changes will be lost
  17. confirm_conffile_stomp() {
  18. tempfile=/var/lib/dpkg/bp.$$
  19. trap 'status=$?; rm -f $tempfile; exit $status' 0
  20. perl -000 -ne 'print $x if m/^Package:\s+(\S+\n)/im &&
  21. ($x=$1) ne "dpkg\n" &&
  22. m/^Status:.*(unpacked|postinst)/im' \
  23. /var/lib/dpkg/status >$tempfile
  24. if [ -s $tempfile ]; then
  25. echo "
  26. WARNING - have you read the release notes for this upgrade ?
  27. The following packages have been unpacked but not yet configured:"
  28. echo " "`cat $tempfile`
  29. echo -n "
  30. If you proceed with the dpkg upgrade with these packages in this state
  31. you will LOSE ANY CONFIGURATION CHANGES that have been made to their
  32. configuration files. I recommend that you back out of the upgrade
  33. now (see below) and then configure each of these packages using:
  34. dpkg --configure --force-hold <package>
  35. If you do this and it fails for some packages they are broken anyway, in
  36. which case you probably don't have that much to lose by going ahead
  37. with the upgrade.
  38. Type \"yes\" to confirm that you really want to do the upgrade in
  39. spite of my warning above; if you give any other response we'll back
  40. off the upgrade to give you a chance to fix things.
  41. Continue with upgrade despite probable loss of config data ? "
  42. read response
  43. case "$response" in
  44. [Yy][Ee][Ss])
  45. echo "OK, going ahead."
  46. ;;
  47. *)
  48. echo "Aborting dpkg upgrade."
  49. exit 1
  50. ;;
  51. esac
  52. fi
  53. rm -f $tempfile
  54. }
  55. # Confirm that the user isn't upgrading anything else at the same time
  56. confirm_singleton() {
  57. echo -n "
  58. IMPORTANT - you must install this upgrade on its own, not together in
  59. the same dpkg run as any other packages. Otherwise you risk losing
  60. configuration information.
  61. If you say \"no\" to the question below we'll back off the upgrade now,
  62. and you can then do it later using:
  63. dpkg --install dpkg-0.93.51.deb
  64. If you're not sure what to do, say \"no\", and then run that command
  65. (with the appropriate dpkg-*.deb filename) from a root shell prompt.
  66. Are you installing only the dpkg upgrade in this dpkg run ? [y/n] "
  67. read response
  68. case "$response" in
  69. [yY]*|"")
  70. echo "OK, going ahead."
  71. ;;
  72. *)
  73. echo "Aborting dpkg upgrade."
  74. exit 1
  75. ;;
  76. esac
  77. }
  78. # Confirm that dselect got split into it's own package
  79. confirm_dselect_split() {
  80. if ! grep "^Package: *dselect$" /var/lib/dpkg/status >/dev/null; then
  81. echo -n "
  82. IMPORTANT - if you are upgrading this package from within dselect you
  83. _MUST_ install the dselect package first.
  84. The dselect frontend has been split into a separate \`dselect' package,
  85. which has not yet been unpacked onto your system. Continuing the upgrade
  86. will mean that dselect will temporarily be removed from your system, if
  87. this happens within dselect the upgrade will fail.
  88. Type \"yes\" to confirm that you really want to do the upgrade in
  89. spite of my warning above (because you're not running dselect, for
  90. example); if you give any other response we'll back off the upgrade to
  91. give you a change to install the dselect package first.
  92. Continue with upgrade despite separation of dselect ? "
  93. read response
  94. case "$response" in
  95. [Yy][Ee][Ss])
  96. echo "OK, going ahead."
  97. ;;
  98. *)
  99. echo "Aborting dpkg upgrade."
  100. exit 1
  101. ;;
  102. esac
  103. fi
  104. }
  105. # Remove obsolete hd method scripts
  106. remove_hd_method() {
  107. methoddir=/usr/lib/dpkg/methods/hd
  108. if [ -d $methoddir ]; then
  109. echo "Removing obsolete $methoddir ..."
  110. rm -r $methoddir
  111. fi
  112. }
  113. case "$1" in
  114. install)
  115. ;;
  116. upgrade)
  117. case "$2" in
  118. # Upgrade from non-C dpkg (pre-0.93.50)
  119. 0.93.[01234]* | -)
  120. echo ""
  121. echo "Contemplating upgrade of dpkg from pre-0.93.50 version ..."
  122. confirm_conffile_stomp
  123. confirm_singleton
  124. confirm_dselect_split
  125. remove_hd_method
  126. ;;
  127. # Upgrade from pre-dselect split
  128. 0.93.[5678][0-9]* | 1.[023456789]* | 1.1.* | 1.10 | 1.10.[12] )
  129. confirm_dselect_split
  130. ;;
  131. esac
  132. ;;
  133. abort-upgrade)
  134. ;;
  135. *)
  136. echo "$0 called with unknown argument \`$1'" 1>&2
  137. exit 1
  138. ;;
  139. esac
  140. #DEBHELPER#
  141. exit 0