home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / dpkg / info / udev.postinst < prev    next >
Encoding:
Text File  |  2009-05-14  |  6.1 KB  |  227 lines

  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.  
  18.  
  19. # Remove a no-longer used conffile
  20. rm_conffile()
  21. {
  22.     CONFFILE="$1"
  23.  
  24.     if [ -e "$CONFFILE".dpkg-obsolete ]; then
  25.     echo "Removing obsolete conffile $CONFFILE"
  26.     rm -f "$CONFFILE".dpkg-obsolete
  27.     fi
  28. }
  29.  
  30. # Remove a conffile directory if it's not empty
  31. rm_confdir()
  32. {
  33.     CONFDIR="$1"
  34.  
  35.     if [ -d "$CONFDIR" ]; then
  36.     rmdir "$CONFDIR" 2>/dev/null \
  37.         || echo "Unable to remove $CONFDIR, not empty"
  38.     fi
  39. }
  40.  
  41. # Move a conffile without triggering a dpkg question
  42. mv_conffile() {
  43.     OLDCONFFILE="$1"
  44.     NEWCONFFILE="$2"
  45.  
  46.     if [ -e "$OLDCONFFILE".dpkg-moving ]; then
  47.         echo "Preserving user changes to $NEWCONFFILE"
  48.         mv -f "$NEWCONFFILE" "$NEWCONFFILE".dpkg-new
  49.         mv -f "$OLDCONFFILE".dpkg-moving "$NEWCONFFILE"
  50.     elif [ -e "$OLDCONFFILE".dpkg-bak ]; then
  51.     rm -f "$OLDCONFFILE".dpkg-bak
  52.     fi
  53. }
  54.  
  55.  
  56. # Enable udevadm again
  57. enable_udevadm()
  58. {
  59.     rm -f /sbin/udevadm
  60.     dpkg-divert --local --rename --divert /sbin/udevadm.upgrade \
  61.             --remove /sbin/udevadm
  62. }
  63.  
  64. # Restart the daemon
  65. restart_udevd()
  66. {
  67.     invoke-rc.d udev restart
  68. }
  69.  
  70.  
  71. # Construct the initial device tree (things udev doesn't provide)
  72. create_devices()
  73. {
  74.     # in a vserver environment, mknod will fail; cf. LP: #144685
  75.     if grep -q ^VxID /proc/self/status; then
  76.     return
  77.     fi
  78.  
  79.     rm -f /lib/udev/devices/fd
  80.     ln -sn /proc/self/fd   /lib/udev/devices/fd
  81.  
  82.     rm -f /lib/udev/devices/stdin
  83.     ln -sn /proc/self/fd/0 /lib/udev/devices/stdin
  84.  
  85.     rm -f /lib/udev/devices/stdout
  86.     ln -sn /proc/self/fd/1 /lib/udev/devices/stdout
  87.  
  88.     rm -f /lib/udev/devices/stderr
  89.     ln -sn /proc/self/fd/2 /lib/udev/devices/stderr
  90.  
  91.     rm -f /lib/udev/devices/core
  92.     ln -sn /proc/kcore     /lib/udev/devices/core
  93.  
  94.     rm -f /lib/udev/devices/sndstat
  95.     ln -sn /proc/asound/oss/sndstat /lib/udev/devices/sndstat
  96.  
  97.     rm -f /lib/udev/devices/ppp
  98.     mknod -m 600 /lib/udev/devices/ppp c 108 0
  99.  
  100.     rm -f /lib/udev/devices/loop0
  101.     mknod -m 600 /lib/udev/devices/loop0 b 7 0
  102.  
  103.     rm -f /lib/udev/devices/net/tun
  104.     mknod -m 600 /lib/udev/devices/net/tun c 10 200
  105.  
  106.     rm -f /lib/udev/devices/kmem
  107.     mknod -m 640 /lib/udev/devices/kmem c 1 2
  108.     chgrp kmem /lib/udev/devices/kmem
  109.  
  110.     # Add devices we need to start udevd itself
  111.     rm -f /lib/udev/devices/console
  112.     mknod -m 600 /lib/udev/devices/console c 5 1
  113.  
  114.     rm -f /lib/udev/devices/null
  115.     mknod -m 600 /lib/udev/devices/null c 1 3
  116. }
  117.  
  118.  
  119. # Write the initial copy of the persistent net and cd rules
  120. seed_persistent_rules()
  121. {
  122.     FILE=/etc/udev/rules.d/70-persistent-net.rules
  123.     if [ ! -e $FILE ]; then
  124.     echo "# This file maintains persistent names for network interfaces." > $FILE
  125.     echo "# See udev(7) for syntax." >> $FILE
  126.     echo "#" >> $FILE
  127.     echo "# Entries are automatically added by the 75-persistent-net-generator.rules" >> $FILE
  128.     echo "# file; however you are also free to add your own entries." >> $FILE
  129.     fi
  130.  
  131.     FILE=/etc/udev/rules.d/70-persistent-cd.rules
  132.     if [ ! -e $FILE ]; then
  133.     echo "# This file maintains persistent names for CD/DVD reader and writer devices." > $FILE
  134.     echo "# See udev(7) for syntax." >> $FILE
  135.     echo "#" >> $FILE
  136.     echo "# Entries are automatically added by the 75-cd-aliases-generator.rules" >> $FILE
  137.     echo "# file; however you are also free to add your own entries provided you" >> $FILE
  138.     echo "# add the ENV{GENERATED}="1" flag to your own rules as well." >> $FILE
  139.     fi
  140. }
  141.  
  142.  
  143. # Notify the user that a reboot is required
  144. reboot_required()
  145. {
  146.     if [ -x /usr/share/update-notifier/notify-reboot-required ]; then
  147.     /usr/share/update-notifier/notify-reboot-required
  148.     fi
  149. }
  150.  
  151. # Update the initramfs
  152. update_initramfs()
  153. {
  154.     update-initramfs -u
  155. }
  156.  
  157.  
  158. # Remove Ubuntu rules in favour of upstream ones
  159. rm_ubuntu_rules()
  160. {
  161.     rm_conffile /etc/udev/rules.d/05-options.rules
  162.     rm_conffile /etc/udev/rules.d/05-udev-early.rules
  163.     rm_conffile /etc/udev/rules.d/20-names.rules
  164.     rm_conffile /etc/udev/rules.d/30-cdrom_id.rules
  165.     rm_conffile /etc/udev/rules.d/40-basic-permissions.rules
  166.     rm_conffile /etc/udev/rules.d/40-permissions.rules
  167.     rm_conffile /etc/udev/rules.d/60-persistent-input.rules
  168.     rm_conffile /etc/udev/rules.d/60-persistent-storage-tape.rules
  169.     rm_conffile /etc/udev/rules.d/60-persistent-storage.rules
  170.     rm_conffile /etc/udev/rules.d/60-symlinks.rules
  171.     rm_conffile /etc/udev/rules.d/61-persistent-storage-edd.rules
  172.     rm_conffile /etc/udev/rules.d/65-id-type.rules
  173.     rm_conffile /etc/udev/rules.d/66-persistent-storage-edd.rules
  174.     rm_conffile /etc/udev/rules.d/75-cd-aliases-generator.rules
  175.     rm_conffile /etc/udev/rules.d/75-persistent-net-generator.rules
  176.     rm_conffile /etc/udev/rules.d/80-programs.rules
  177.     rm_conffile /etc/udev/rules.d/90-modprobe.rules
  178.     rm_conffile /etc/udev/rules.d/95-udev-late.rules
  179. }
  180.  
  181. # An old (gutsy-era) version of udev wrote persistent-net.rules using
  182. # ATTRS{}, which no longer works; change to ATTR{}
  183. fix_persistent_net_rules()
  184. {
  185.     if [ -e /etc/udev/rules.d/70-persistent-net.rules ]; then
  186.     sed -i -e 's/\bATTRS{/ATTR{/g' /etc/udev/rules.d/70-persistent-net.rules
  187.     fi
  188. }
  189.  
  190.  
  191. case "$1" in
  192.     configure)
  193.     # Upgrade from intrepid
  194.     if dpkg --compare-versions "$2" lt "140-2"; then
  195.         rm_ubuntu_rules
  196.         fix_persistent_net_rules
  197.     fi
  198.  
  199.     create_devices
  200.     seed_persistent_rules
  201.     restart_udevd
  202.     enable_udevadm
  203.     update_initramfs
  204.     ;;
  205.  
  206.     abort-upgrade|abort-deconfigure|abort-remove)
  207.     ;;
  208.  
  209.     *)
  210.     echo "$0 called with unknown argument \`$1'" 1>&2
  211.     exit 1
  212.     ;;
  213. esac
  214.  
  215. # Automatically added by dh_installinit
  216. if [ -x "/etc/init.d/udev" ]; then
  217.     update-rc.d udev start 10 S . >/dev/null || exit $?
  218. fi
  219. # End automatically added section
  220. # Automatically added by dh_installinit
  221. if [ -x "/etc/init.d/udev-finish" ]; then
  222.     update-rc.d udev-finish start 37 S . >/dev/null || exit $?
  223. fi
  224. # End automatically added section
  225.  
  226. exit 0
  227.