#!/bin/sh -e # This script can be called in the following ways: # # After the package was installed: # configure # # # If prerm fails during upgrade or fails on failed upgrade: # abort-upgrade # # If prerm fails during deconfiguration of a package: # abort-deconfigure in-favour # removing # # If prerm fails during replacement due to conflict: # abort-remove in-favour # Remove a no-longer used conffile rm_conffile() { CONFFILE="$1" if [ -e "$CONFFILE".dpkg-obsolete ]; then echo "Removing obsolete conffile $CONFFILE" rm -f "$CONFFILE".dpkg-obsolete fi } # Remove a conffile directory if it's not empty rm_confdir() { CONFDIR="$1" if [ -d "$CONFDIR" ]; then rmdir "$CONFDIR" 2>/dev/null \ || echo "Unable to remove $CONFDIR, not empty" fi } # Move a conffile without triggering a dpkg question mv_conffile() { OLDCONFFILE="$1" NEWCONFFILE="$2" if [ -e "$OLDCONFFILE".dpkg-moving ]; then echo "Preserving user changes to $NEWCONFFILE" mv -f "$NEWCONFFILE" "$NEWCONFFILE".dpkg-new mv -f "$OLDCONFFILE".dpkg-moving "$NEWCONFFILE" elif [ -e "$OLDCONFFILE".dpkg-bak ]; then rm -f "$OLDCONFFILE".dpkg-bak fi } # Enable udevadm again enable_udevadm() { if [ -e /sbin/udevadm.upgrade ]; then rm -f /sbin/udevadm dpkg-divert --local --rename --divert /sbin/udevadm.upgrade \ --remove /sbin/udevadm fi } # Restart the daemon restart_udevd() { restart udev || true } # Construct the initial device tree (things udev doesn't provide) create_devices() { # in a vserver environment, mknod will fail; cf. LP: #144685 if grep -q ^VxID /proc/self/status; then return fi rm -f /lib/udev/devices/fd ln -sn /proc/self/fd /lib/udev/devices/fd rm -f /lib/udev/devices/stdin ln -sn /proc/self/fd/0 /lib/udev/devices/stdin rm -f /lib/udev/devices/stdout ln -sn /proc/self/fd/1 /lib/udev/devices/stdout rm -f /lib/udev/devices/stderr ln -sn /proc/self/fd/2 /lib/udev/devices/stderr rm -f /lib/udev/devices/core ln -sn /proc/kcore /lib/udev/devices/core rm -f /lib/udev/devices/sndstat ln -sn /proc/asound/oss/sndstat /lib/udev/devices/sndstat rm -f /lib/udev/devices/ppp mknod -m 600 /lib/udev/devices/ppp c 108 0 rm -f /lib/udev/devices/loop0 mknod -m 600 /lib/udev/devices/loop0 b 7 0 rm -f /lib/udev/devices/net/tun mknod -m 600 /lib/udev/devices/net/tun c 10 200 # Add devices we need to start udevd itself rm -f /lib/udev/devices/console mknod -m 600 /lib/udev/devices/console c 5 1 rm -f /lib/udev/devices/null mknod -m 600 /lib/udev/devices/null c 1 3 } # Remove things from the initial device tree that are no longer required remove_devices() { rm -f /lib/udev/devices/MAKEDEV rm -f /lib/udev/devices/kmem } # Write the initial copy of the persistent net and cd rules seed_persistent_rules() { FILE=/etc/udev/rules.d/70-persistent-net.rules if [ ! -e $FILE ]; then echo "# This file maintains persistent names for network interfaces." > $FILE echo "# See udev(7) for syntax." >> $FILE echo "#" >> $FILE echo "# Entries are automatically added by the 75-persistent-net-generator.rules" >> $FILE echo "# file; however you are also free to add your own entries." >> $FILE fi FILE=/etc/udev/rules.d/70-persistent-cd.rules if [ ! -e $FILE ]; then echo "# This file maintains persistent names for CD/DVD reader and writer devices." > $FILE echo "# See udev(7) for syntax." >> $FILE echo "#" >> $FILE echo "# Entries are automatically added by the 75-cd-aliases-generator.rules" >> $FILE echo "# file; however you are also free to add your own entries provided you" >> $FILE echo "# add the ENV{GENERATED}="1" flag to your own rules as well." >> $FILE fi } # Notify the user that a reboot is required reboot_required() { if [ -x /usr/share/update-notifier/notify-reboot-required ]; then /usr/share/update-notifier/notify-reboot-required fi } # Update the initramfs update_initramfs() { update-initramfs -u } # Remove Ubuntu rules in favour of upstream ones rm_ubuntu_rules() { rm_conffile /etc/udev/rules.d/05-options.rules rm_conffile /etc/udev/rules.d/05-udev-early.rules rm_conffile /etc/udev/rules.d/20-names.rules rm_conffile /etc/udev/rules.d/30-cdrom_id.rules rm_conffile /etc/udev/rules.d/40-basic-permissions.rules rm_conffile /etc/udev/rules.d/40-permissions.rules rm_conffile /etc/udev/rules.d/60-persistent-input.rules rm_conffile /etc/udev/rules.d/60-persistent-storage-tape.rules rm_conffile /etc/udev/rules.d/60-persistent-storage.rules rm_conffile /etc/udev/rules.d/60-symlinks.rules rm_conffile /etc/udev/rules.d/61-persistent-storage-edd.rules rm_conffile /etc/udev/rules.d/65-id-type.rules rm_conffile /etc/udev/rules.d/66-persistent-storage-edd.rules rm_conffile /etc/udev/rules.d/75-cd-aliases-generator.rules rm_conffile /etc/udev/rules.d/75-persistent-net-generator.rules rm_conffile /etc/udev/rules.d/80-programs.rules rm_conffile /etc/udev/rules.d/90-modprobe.rules rm_conffile /etc/udev/rules.d/95-udev-late.rules } # An old (gutsy-era) version of udev wrote persistent-net.rules using # ATTRS{}, which no longer works; change to ATTR{} fix_persistent_net_rules() { if [ -e /etc/udev/rules.d/70-persistent-net.rules ]; then sed -i -e 's/\bATTRS{/ATTR{/g' /etc/udev/rules.d/70-persistent-net.rules fi } case "$1" in configure) # Upgrade from intrepid if dpkg --compare-versions "$2" lt "140-2"; then rm_ubuntu_rules fix_persistent_net_rules fi # Upgrade from jaunty if dpkg --compare-versions "$2" lt "141-3"; then remove_devices rm_conffile /etc/scsi_id.config fi create_devices seed_persistent_rules restart_udevd enable_udevadm update_initramfs ;; abort-upgrade|abort-deconfigure|abort-remove) ;; *) echo "$0 called with unknown argument \`$1'" 1>&2 exit 1 ;; esac # Automatically added by dh_installinit update-rc.d -f udev remove >/dev/null || exit $? # End automatically added section # Automatically added by dh_installinit update-rc.d -f udev-finish remove >/dev/null || exit $? # End automatically added section exit 0