dpkg.postinst 4.1 KB

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