home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / var / lib / dpkg / info / netbase.postinst < prev    next >
Encoding:
Text File  |  2007-03-30  |  4.7 KB  |  181 lines

  1. #!/bin/sh -e
  2.  
  3. if [ "$1" = "configure" ]; then
  4.   . /usr/share/debconf/confmodule
  5. fi
  6.  
  7. # Set an entry in sysctl.conf
  8. set_sysctl() {
  9.     if [ -n "$2" ]; then
  10.         return
  11.     elif [ "$2" = "no" ]; then
  12.         value=0
  13.     else
  14.         value=1
  15.     fi
  16.  
  17.     if [ -e /etc/sysctl.conf ]; then
  18.         if grep "^$1=" /etc/sysctl.conf >/dev/null 2>&1; then
  19.             echo >> /etc/sysctl.conf
  20.             echo "# From /etc/network/options; commented out due to your setting above" >> /etc/sysctl.conf
  21.             echo "#$1=$value" >> /etc/sysctl.conf
  22.         elif grep "^# *$1=" /etc/sysctl.conf >/dev/null 2>&1; then
  23.             sed -i -e "s,^# *$1=.*,$1=$value," /etc/sysctl.conf
  24.         else
  25.             echo >> /etc/sysctl.conf
  26.             echo "# From /etc/network/options" >> /etc/sysctl.conf
  27.             echo "#$1=$value" >> /etc/sysctl.conf
  28.         fi
  29.     else
  30.         echo >> /etc/sysctl.conf
  31.         echo "# From /etc/network/options" >> /etc/sysctl.conf
  32.         echo "#$1=$value" >> /etc/sysctl.conf
  33.     fi
  34. }
  35.  
  36. # Convert the options file into sysctl.conf
  37. migrate_options_file() {
  38.     [ -n "$2" -a -e /etc/network/options ] || return 0
  39.     dpkg --compare-versions "$2" lt "4.24ubuntu1" || return 0
  40.  
  41.     . /etc/network/options
  42.  
  43.     set_sysctl "net/ipv4/conf/all/rp_filter" "$spoofprotect"
  44.     set_sysctl "net/ipv4/ip_forward"         "$ip_forward"
  45.     set_sysctl "net/ipv4/tcp_syncookies"     "$syncookies"
  46.     
  47.     rm -f /etc/network/options
  48. }
  49.  
  50. remove_old_files() {
  51.   rm -f /etc/cron.daily/netbase /etc/network/spoof-protect
  52. }
  53.  
  54. kill_portmapper() {
  55.   if [ "$2" ] && dpkg --compare-versions $2 lt "3.11-2"; then
  56.     if /usr/bin/rpcinfo -u localhost portmapper >/dev/null 2>&1; then
  57.       # portmapper's still running. stop it.
  58.  
  59.       if [ -x /bin/fuser ]; then
  60.         PID=$(/bin/fuser -n tcp sunrpc | sed 's/^.*: *//')
  61.       fi
  62.  
  63.       if [ "$PID" ]; then
  64.         if [ ! -f /var/run/portmap.upgrade-state ]; then
  65.           echo >&2 "Remembering old rpc services... "
  66.           pmap_dump >/var/run/portmap.upgrade-state
  67.           echo >&2 "done."
  68.         fi
  69.         echo >&2 -n "Killing portmapper... "
  70.         kill $PID
  71.         echo >&2 "done."
  72.       fi
  73.     fi
  74.   fi
  75. }
  76.  
  77. update_hosts_file() {
  78.   if [ -f /etc/hosts ] && ! grep -q "ip6-localhost" /etc/hosts; then
  79.     cat >>/etc/hosts <<-EOF
  80.     
  81.     # The following lines are desirable for IPv6 capable hosts
  82.     # (added automatically by netbase upgrade)
  83.     
  84.     ::1     ip6-localhost ip6-loopback
  85.     fe00::0 ip6-localnet
  86.     ff00::0 ip6-mcastprefix
  87.     ff02::1 ip6-allnodes
  88.     ff02::2 ip6-allrouters
  89.     ff02::3 ip6-allhosts
  90. EOF
  91.   fi
  92. }
  93.  
  94. update_initd_networks() {
  95.   if [ "$2" ] && dpkg --compare-versions "$2" lt "3.17-1"; then
  96.     if [ -e /etc/init.d/network ]; then
  97.       cat >> /etc/init.d/network <<EOF
  98.  
  99. # (added automatically by netbase upgrade)
  100. #
  101. # In new Debian installations, this file is deprecated in favour of
  102. # the ifup/ifdown commands (invoked from /etc/init.d/networking), which
  103. # can be configured from the file /etc/network/interfaces.
  104. #
  105. # If you are receiving SIOCADDRT errors, they can be avoided by adding
  106. # a netmask and interface to your "route add -net" lines. eg,
  107. #      route add -net 127.0.0.0
  108. # becomes:
  109. #      route add -net 127.0.0.0 netmask 255.0.0.0 lo
  110. #
  111. # Alternatively, these lines can simply be deleted if you don't use 2.0.x 
  112. # series kernels.
  113. EOF
  114.     fi
  115.   fi
  116. }
  117.  
  118. fix_old_initscript() {
  119.   if [ -e /etc/init.d/netbase ]; then
  120.     mv /etc/init.d/netbase /etc/init.d/netbase.old
  121.   fi
  122.  
  123.   if [ "$2" ] && dpkg --compare-versions "$2" lt "3.18-1"; then
  124.     # only do this for people who were running unstable
  125.     if dpkg --compare-versions "$2" ge "3.16-1"; then
  126.       echo >&2 "BUGFIX: Resetting runlevels at which /etc/init.d/networking is run."
  127.       update-rc.d -f networking remove > /dev/null 2>&1
  128.     fi
  129.  
  130.     update-rc.d -f netbase remove > /dev/null 2>&1
  131.   fi
  132.   if [ "$2" ] && dpkg --compare-versions "$2" lt "4.24ubuntu2"; then
  133.     update-rc.d -f networking remove > /dev/null 2>&1
  134.   fi
  135.  
  136.   # Remove shutdown and reboot links; this init script does not need them.
  137.   if dpkg --compare-versions "$2" lt "4.25ubuntu2"; then
  138.     rm -f /etc/rc0.d/S35networking /etc/rc6.d/S35networking
  139.   fi
  140. }
  141.  
  142. update_rc() {
  143.   update-rc.d networking start 40 S . > /dev/null
  144. }
  145.  
  146. case "$1" in
  147.     configure)
  148.     migrate_options_file "$@"
  149.     #remove_options_file "$@"
  150.     remove_old_files
  151.     kill_portmapper "$@"
  152.     update_hosts_file
  153.     update_initd_networks "$@"
  154.     fix_old_initscript "$@"
  155.     update_rc
  156.     ;;
  157.  
  158.     abort-upgrade|abort-remove|abort-deconfigure)
  159.     ;;
  160.  
  161.     *)
  162.     echo "postinst called with unknown argument '$1'" >&2
  163.     exit 1
  164.     ;;
  165. esac
  166.  
  167.  
  168.  
  169. # shouldn't be necessary? but without it the postinst just hangs on dpkg -i :(
  170. #
  171. # do i have to do this right at the end, or can i do it earlier, for that
  172. # matter?
  173. #
  174. # i may be meant to redirect 3>&1 or something equally weird here :-/
  175. # maybe this isn't necessary anymore (since there shouldn't be any daemons
  176. # in this postinst anymore), but who knows?
  177. #
  178. if [ "$1" = "configure" ]; then
  179.     db_stop 
  180. fi
  181.