Home | History | Annotate | Line # | Download | only in scripts
solaris revision 1.1
      1  1.1  christos #!/bin/sh  
      2  1.1  christos 
      3  1.1  christos make_resolv_conf() {
      4  1.1  christos   if [ x"$new_domain_name_servers" != x ]; then
      5  1.1  christos     cat /dev/null > /etc/resolv.conf.dhclient
      6  1.1  christos     if [ x"$new_domain_search" != x ]; then
      7  1.1  christos       echo search $new_domain_search >> /etc/resolv.conf.dhclient
      8  1.1  christos     elif [ x"$new_domain_name" != x ]; then
      9  1.1  christos       # Note that the DHCP 'Domain Name Option' is really just a domain
     10  1.1  christos       # name, and that this practice of using the domain name option as
     11  1.1  christos       # a search path is both nonstandard and deprecated.
     12  1.1  christos       echo search $new_domain_name >> /etc/resolv.conf.dhclient
     13  1.1  christos     fi
     14  1.1  christos     for nameserver in $new_domain_name_servers; do
     15  1.1  christos       echo nameserver $nameserver >>/etc/resolv.conf.dhclient
     16  1.1  christos     done
     17  1.1  christos 
     18  1.1  christos     mv /etc/resolv.conf.dhclient /etc/resolv.conf
     19  1.1  christos   fi
     20  1.1  christos }
     21  1.1  christos 
     22  1.1  christos # Must be used on exit.   Invokes the local dhcp client exit hooks, if any.
     23  1.1  christos exit_with_hooks() {
     24  1.1  christos   exit_status=$1
     25  1.1  christos   if [ -f /etc/dhclient-exit-hooks ]; then
     26  1.1  christos     . /etc/dhclient-exit-hooks
     27  1.1  christos   fi
     28  1.1  christos # probably should do something with exit status of the local script
     29  1.1  christos   exit $exit_status
     30  1.1  christos }
     31  1.1  christos 
     32  1.1  christos # Invoke the local dhcp client enter hooks, if they exist.
     33  1.1  christos if [ -f /etc/dhclient-enter-hooks ]; then
     34  1.1  christos   exit_status=0
     35  1.1  christos   . /etc/dhclient-enter-hooks
     36  1.1  christos   # allow the local script to abort processing of this state
     37  1.1  christos   # local script must set exit_status variable to nonzero.
     38  1.1  christos   if [ $exit_status -ne 0 ]; then
     39  1.1  christos     exit $exit_status
     40  1.1  christos   fi
     41  1.1  christos fi
     42  1.1  christos 
     43  1.1  christos if [ x$new_broadcast_address != x ]; then
     44  1.1  christos   new_broadcast_arg="broadcast $new_broadcast_address"
     45  1.1  christos fi
     46  1.1  christos if [ x$old_broadcast_address != x ]; then
     47  1.1  christos   old_broadcast_arg="broadcast $old_broadcast_address"
     48  1.1  christos fi
     49  1.1  christos if [ x$new_subnet_mask != x ]; then
     50  1.1  christos   new_netmask_arg="netmask $new_subnet_mask"
     51  1.1  christos fi
     52  1.1  christos if [ x$old_subnet_mask != x ]; then
     53  1.1  christos   old_netmask_arg="netmask $old_subnet_mask"
     54  1.1  christos fi
     55  1.1  christos if [ x$alias_subnet_mask != x ]; then
     56  1.1  christos   alias_subnet_arg="netmask $alias_subnet_mask"
     57  1.1  christos fi
     58  1.1  christos  if [ x$new_interface_mtu != x ]; then
     59  1.1  christos    mtu_arg="mtu $new_interface_mtu"
     60  1.1  christos  fi
     61  1.1  christos if [ x$IF_METRIC != x ]; then
     62  1.1  christos   metric_arg="metric $IF_METRIC"
     63  1.1  christos fi
     64  1.1  christos 
     65  1.1  christos ifconfig=/sbin/ifconfig
     66  1.1  christos 
     67  1.1  christos release=`uname -r`
     68  1.1  christos release=`expr $release : '\(.*\)\..*'`
     69  1.1  christos relmajor=`echo $release |sed -e 's/^\([^\.]*\)\..*$/\1/'`
     70  1.1  christos relminor=`echo $release |sed -e 's/^.*\.\([^\.]*\)$/\1/'`
     71  1.1  christos 
     72  1.1  christos if [ x$reason = xMEDIUM ]; then
     73  1.1  christos   eval "$ifconfig $interface $medium"
     74  1.1  christos   $ifconfig $interface
     75  1.1  christos   sleep 1
     76  1.1  christos   exit_with_hooks 0
     77  1.1  christos fi
     78  1.1  christos 
     79  1.1  christos if [ x$reason = xPREINIT ]; then
     80  1.1  christos   if [ x$alias_ip_address != x ]; then
     81  1.1  christos     $ifconfig ${interface}:1 0 down > /dev/null 2>&1
     82  1.1  christos     route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
     83  1.1  christos   fi
     84  1.1  christos   if [ $relmajor -gt 5 ] || ( [ $relmajor -eq 5 ] && [ $relminor -ge 5 ] )
     85  1.1  christos   then
     86  1.1  christos 	  # Turn the interface on
     87  1.1  christos 	  $ifconfig $interface plumb
     88  1.1  christos 	  $ifconfig $interface up
     89  1.1  christos   else
     90  1.1  christos       $ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
     91  1.1  christos               broadcast 255.255.255.255 up
     92  1.1  christos   fi 
     93  1.1  christos   exit_with_hooks 0
     94  1.1  christos fi
     95  1.1  christos 
     96  1.1  christos if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
     97  1.1  christos   exit_with_hooks 0;
     98  1.1  christos fi
     99  1.1  christos   
    100  1.1  christos if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
    101  1.1  christos    [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
    102  1.1  christos   current_hostname=`hostname`
    103  1.1  christos   if [ x$current_hostname = x ] || \
    104  1.1  christos      [ x$current_hostname = x$old_host_name ]; then
    105  1.1  christos     if [ x$current_hostname = x ] || \
    106  1.1  christos        [ x$new_host_name != x$old_host_name ]; then
    107  1.1  christos       hostname $new_host_name
    108  1.1  christos     fi
    109  1.1  christos   fi
    110  1.1  christos     
    111  1.1  christos   if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
    112  1.1  christos 		[ x$alias_ip_address != x$old_ip_address ]; then
    113  1.1  christos     $ifconfig ${interface}:1 inet 0 down > /dev/null 2>&1
    114  1.1  christos     route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
    115  1.1  christos   fi
    116  1.1  christos   if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]; then
    117  1.1  christos     $ifconfig ${interface} inet 0 down
    118  1.1  christos     route delete $old_ip_address 127.1 >/dev/null 2>&1
    119  1.1  christos     for router in $old_routers; do
    120  1.1  christos       route delete default $router >/dev/null 2>&1
    121  1.1  christos     done
    122  1.1  christos   fi
    123  1.1  christos   if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
    124  1.1  christos      [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
    125  1.1  christos     eval "$ifconfig $interface inet $new_ip_address $new_netmask_arg \
    126  1.1  christos 			$new_broadcast_arg $mtu_arg $metric_arg $medium"
    127  1.1  christos     route add $new_ip_address 127.1 1 >/dev/null 2>&1
    128  1.1  christos     for router in $new_routers; do
    129  1.1  christos       route add default $router 1 >/dev/null 2>&1
    130  1.1  christos     done
    131  1.1  christos   else                                                                        
    132  1.1  christos     # we haven't changed the address, have we changed other options           
    133  1.1  christos     # that we wish to update?
    134  1.1  christos     if [ x$new_routers != x ] && [ x$new_routers != x$old_routers ] ; then
    135  1.1  christos       # if we've changed routers delete the old and add the new.
    136  1.1  christos       $LOGGER "New Routers: $new_routers"
    137  1.1  christos       for router in $old_routers; do
    138  1.1  christos         route delete default $router >/dev/null 2>&1
    139  1.1  christos       done
    140  1.1  christos       for router in $new_routers; do
    141  1.1  christos         route add default $router 1 >/dev/null 2>&1
    142  1.1  christos       done
    143  1.1  christos     fi
    144  1.1  christos   fi
    145  1.1  christos   if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
    146  1.1  christos    then
    147  1.1  christos     $ifconfig ${interface}:1 inet $alias_ip_address $alias_subnet_arg
    148  1.1  christos     route add $alias_ip_address 127.0.0.1 1
    149  1.1  christos   fi
    150  1.1  christos   make_resolv_conf
    151  1.1  christos   exit_with_hooks 0
    152  1.1  christos fi
    153  1.1  christos 
    154  1.1  christos if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
    155  1.1  christos    || [ x$reason = xSTOP ]; then
    156  1.1  christos   if [ x$alias_ip_address != x ]; then
    157  1.1  christos     $ifconfig ${interface}:1 0 down > /dev/null 2>&1
    158  1.1  christos     route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
    159  1.1  christos   fi
    160  1.1  christos   if [ x$old_ip_address != x ]; then
    161  1.1  christos     $ifconfig $interface inet 0 down
    162  1.1  christos     route delete $old_ip_address 127.1 >/dev/null 2>&1
    163  1.1  christos     for router in $old_routers; do
    164  1.1  christos       route delete default $router >/dev/null 2>&1
    165  1.1  christos     done
    166  1.1  christos   fi
    167  1.1  christos   if [ x$alias_ip_address != x ]; then
    168  1.1  christos     $ifconfig ${interface}:1 inet $alias_ip_address $alias_subnet_arg
    169  1.1  christos     route add $alias_ip_address 127.0.0.1 1
    170  1.1  christos   fi
    171  1.1  christos   exit_with_hooks 0
    172  1.1  christos fi
    173  1.1  christos 
    174  1.1  christos if [ x$reason = xTIMEOUT ]; then
    175  1.1  christos   if [ x$alias_ip_address != x ]; then
    176  1.1  christos     $ifconfig ${interface}:1 0 down > /dev/null 2>&1
    177  1.1  christos     route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
    178  1.1  christos   fi
    179  1.1  christos   eval "$ifconfig $interface inet $new_ip_address $new_netmask_arg \
    180  1.1  christos 			$new_broadcast_arg $mtu_arg $metric_arg $medium"
    181  1.1  christos   sleep 1
    182  1.1  christos   set $new_routers
    183  1.1  christos   if ping -s -n -I 1 $1 64 1; then
    184  1.1  christos     if [ x$new_ip_address != x$alias_ip_address ] && \
    185  1.1  christos 			[ x$alias_ip_address != x ]; then
    186  1.1  christos       $ifconfig ${interface}:1 inet $alias_ip_address $alias_subnet_arg
    187  1.1  christos       route add $alias_ip_address 127.0.0.1 1
    188  1.1  christos     fi
    189  1.1  christos     route add $new_ip_address 127.1 1 >/dev/null 2>&1
    190  1.1  christos     for router in $new_routers; do
    191  1.1  christos       route add default $router 1 >/dev/null 2>&1
    192  1.1  christos     done
    193  1.1  christos     make_resolv_conf
    194  1.1  christos     exit_with_hooks 0
    195  1.1  christos   fi
    196  1.1  christos   $ifconfig $interface inet 0 down
    197  1.1  christos   for router in $old_routers; do
    198  1.1  christos     route delete default $router >/dev/null 2>&1
    199  1.1  christos   done
    200  1.1  christos   exit_with_hooks 1
    201  1.1  christos fi
    202  1.1  christos 
    203  1.1  christos exit_with_hooks 0
    204