dpkg.preinst 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 [ -x /bin/ps ]; then
  81. if ! ps -C dselect >/dev/null; then
  82. return
  83. fi
  84. fi
  85. if ! grep "^Package: *dselect$" /var/lib/dpkg/status >/dev/null; then
  86. echo -n "
  87. IMPORTANT - if you are upgrading this package from within dselect you
  88. _MUST_ install the dselect package first.
  89. The dselect frontend has been split into a separate \`dselect' package,
  90. which has not yet been unpacked onto your system. Continuing the upgrade
  91. will mean that dselect will temporarily be removed from your system, if
  92. this happens within dselect the upgrade will fail.
  93. Type \"yes\" to confirm that you really want to do the upgrade in
  94. spite of my warning above (because you're not running dselect, for
  95. example); if you give any other response we'll back off the upgrade to
  96. give you a change to install the dselect package first.
  97. Continue with upgrade despite separation of dselect ? "
  98. read response
  99. case "$response" in
  100. [Yy][Ee][Ss])
  101. echo "OK, going ahead."
  102. ;;
  103. *)
  104. echo "Aborting dpkg upgrade."
  105. exit 1
  106. ;;
  107. esac
  108. fi
  109. }
  110. # Remove obsolete hd method scripts
  111. remove_hd_method() {
  112. methoddir=/usr/lib/dpkg/methods/hd
  113. if [ -d $methoddir ]; then
  114. echo "Removing obsolete $methoddir ..."
  115. rm -r $methoddir
  116. fi
  117. }
  118. # Handle upgrades from pre-conffile dpkg.cfg
  119. upgrade_dpkg_non_conffile()
  120. {
  121. if [ -r /etc/dpkg/dpkg.cfg ]; then
  122. dpkg_cfg_md5="535552ad5ee9145dbc7a34c264df4e59 /etc/dpkg/dpkg.cfg"
  123. if echo "$dpkg_cfg_md5" | md5sum -c >/dev/null 2>&1; then
  124. echo "Removing non-modified dpkg.cfg to be replaced by a conffile ..."
  125. rm -f /etc/dpkg/dpkg.cfg
  126. fi
  127. fi
  128. }
  129. case "$1" in
  130. install)
  131. ;;
  132. upgrade)
  133. case "$2" in
  134. # Upgrade from non-C dpkg (pre-0.93.50)
  135. 0.93.[01234]* | -)
  136. echo ""
  137. echo "Contemplating upgrade of dpkg from pre-0.93.50 version ..."
  138. confirm_conffile_stomp
  139. confirm_singleton
  140. confirm_dselect_split
  141. remove_hd_method
  142. ;;
  143. # Upgrade from pre-dselect split
  144. 0.93.[5678][0-9]* | 1.[023456789]* | 1.1.* | 1.10 | 1.10.[12] )
  145. confirm_dselect_split
  146. ;;
  147. esac
  148. case "$2" in
  149. # Upgrade from pre-conffile dpkg.cfg
  150. 1.9.21 | 1.10.* )
  151. upgrade_dpkg_non_conffile
  152. ;;
  153. esac
  154. ;;
  155. abort-upgrade)
  156. ;;
  157. *)
  158. echo "$0 called with unknown argument \`$1'" 1>&2
  159. exit 1
  160. ;;
  161. esac
  162. #DEBHELPER#
  163. exit 0