dpkg.postinst 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #!/bin/sh -e
  2. # This script can be called in the following ways:
  3. #
  4. # After the package was installed:
  5. # <postinst> configure <old-version>
  6. #
  7. #
  8. # If prerm fails during upgrade or fails on failed upgrade:
  9. # <old-postinst> abort-upgrade <new-version>
  10. #
  11. # If prerm fails during removal:
  12. # <old-postinst> abort-remove
  13. #
  14. # If prerm fails during deconfiguration of a package:
  15. # <postinst> abort-deconfigure in-favour <new-package> <version>
  16. # removing <old-package> <version>
  17. #
  18. # If prerm fails during replacement due to conflict:
  19. # <postinst> abort-remove in-favour <new-package> <version>
  20. # Create the database files if they don't already exist
  21. create_database() {
  22. admindir=/var/lib/dpkg
  23. for file in diversions statoverride status; do
  24. if [ ! -f "$admindir/$file" ]; then
  25. touch "$admindir/$file"
  26. fi
  27. done
  28. }
  29. # Move the info directory from /usr/info to /usr/share/info
  30. move_info_directory() {
  31. if [ -d /usr/info ] && [ ! -L /usr/info ] \
  32. && [ -f /usr/info/dir ] && [ ! -L /usr/info/dir ]
  33. then
  34. echo "Moving /usr/info/dir to /usr/share/info/dir ..."
  35. mv /usr/info/dir /usr/share/info/dir
  36. if [ -f /usr/info/dir.old ]; then
  37. mv /usr/info/dir.old /usr/share/info/dir.old
  38. fi
  39. fi
  40. }
  41. # Remove the /usr/info symlinks we used to generate
  42. remove_info_symlink() {
  43. if [ -L /usr/info ]; then
  44. echo "Removing /usr/info symlink ..."
  45. rm /usr/info
  46. elif [ -L /usr/info/dir ]; then
  47. echo "Removing /usr/info/dir symlink ..."
  48. rm /usr/info/dir
  49. fi
  50. }
  51. # Repair damage to /usr/info caused by broken install-info
  52. fix_damaged_info() {
  53. echo -n "
  54. The version of dpkg you're upgrading from had a problem with the
  55. install-info program used to maintain the /usr/info/dir file. It may
  56. have corrupted the file, for example by placing new entries for the
  57. menu in it before the \`* Menu' line (thus making them ineffective) or
  58. by creating several identical sections.
  59. I can try to sort these problems out, but beware that this process is
  60. not guaranteed not to mess up a dir file which has things that look
  61. like menu entries in the introductory paragraphs. The distributed dir
  62. files do not do this, so if you haven't edited /usr/info/dir it's
  63. almost certainly safe to say \"yes\" to the next question.
  64. If you say \"no\" you may wish to check and/or edit /usr/info/dir yourself.
  65. Try to check/repair /usr/info/dir automatically ? [y/n] "
  66. read response
  67. case "$response" in
  68. [yY]*|"")
  69. echo "Checking/repairing /usr/info/dir ..."
  70. cleanup-info --unsafe
  71. ;;
  72. *)
  73. echo "OK, leaving it alone."
  74. ;;
  75. esac
  76. }
  77. # Remove stop links from runlevels which also have start links
  78. # Dates back to the days when update-rc.d was part of dpkg.
  79. remove_duplicate_daemons() {
  80. for lvl in 0 1 2 3 4 5 6; do
  81. cd /etc/rc$lvl.d
  82. for kill in K[0-9][0-9]*; do
  83. if [ -n "`echo \"x$kill\" | tr -d 0-9A-Za-z_-`" ]; then
  84. continue
  85. fi
  86. start="`echo $kill | sed -e 's/^K/S/'`"
  87. if ! [ -L $start ] && [ -L $kill ] \
  88. || [ "`ls -Li $kill 2>/dev/null | awk '{print $1}'`" != \
  89. "`ls -Li $start 2>/dev/null | awk '{print $1}'`" ]
  90. then
  91. continue
  92. fi
  93. removes="$removes rc$lvl.d/$kill"
  94. done
  95. done
  96. if [ -n "$removes" ]; then
  97. echo -n "
  98. Some daemons and similar services whose scripts have links in the
  99. /etc/rcN.d directories have both start (S) and stop (K) links in
  100. some runlevels. Thus these services get stopped and immediately
  101. restarted at some runlevel changes, which is probably not what
  102. you want.
  103. I can remove these probably-spurious K links if you like:
  104. $removes
  105. If you're not sure what to do, say \"no\", and then run delete them
  106. by hand later.
  107. Shall I remove these links ? [y/n] "
  108. read response
  109. case "$response" in
  110. [yY]*|"")
  111. echo "Removing duplicate K links ..."
  112. cd /etc
  113. rm $removes
  114. ;;
  115. *)
  116. echo "OK, leaving them."
  117. ;;
  118. esac
  119. fi
  120. }
  121. # Create log file and set default permissions if possible
  122. create_logfile() {
  123. logfile=/var/log/dpkg.log
  124. touch $logfile
  125. chmod 640 $logfile
  126. chown root:adm $logfile 2>/dev/null || chown 0:4 $logfile
  127. }
  128. case "$1" in
  129. configure)
  130. create_database
  131. create_logfile
  132. case "$2" in
  133. 0.* | 1.0.* | 1.1.0 | 1.1.0[^0-9]* | '' )
  134. remove_duplicate_daemons
  135. ;;
  136. 1.1.6 | 1.1.6elf | 1.2.[0123] | 1.2.[0123]elf)
  137. fix_damaged_info
  138. ;;
  139. esac
  140. move_info_directory
  141. remove_info_symlink
  142. ;;
  143. abort-upgrade|abort-deconfigure|abort-remove)
  144. ;;
  145. *)
  146. echo "$0 called with unknown argument \`$1'" 1>&2
  147. exit 1
  148. ;;
  149. esac
  150. #DEBHELPER#
  151. exit 0