home *** CD-ROM | disk | FTP | other *** search
/ ftp.sberbank.sumy.ua / 2014.11.ftp.sberbank.sumy.ua.tar / ftp.sberbank.sumy.ua / incoming / sxtech / sbin / dhclient-script < prev    next >
Text File  |  2014-08-29  |  7KB  |  233 lines

  1. #!/bin/sh
  2. #
  3. # $Id: freebsd,v 1.13.2.4 2002/06/09 22:37:55 murray Exp $
  4. #
  5. # $FreeBSD: src/contrib/isc-dhcp/client/scripts/freebsd,v 1.9.2.6 2003/03/02 16:42:38 murray Exp $
  6.  
  7. if [ -x /usr/bin/logger ]; then
  8.     LOGGER="/usr/bin/logger -s -p user.notice -t dhclient"
  9. else
  10.     LOGGER=echo
  11. fi
  12.  
  13. make_resolv_conf() {
  14.   if [ x"$new_domain_name_servers" != x ]; then
  15.     if [ "x$new_domain_name" != x ]; then
  16.       rm /var/etc/resolv.conf
  17.       echo search $new_domain_name >/var/etc/resolv.conf
  18.     else
  19.       rm /var/etc/resolv.conf
  20.     fi
  21.     for nameserver in $new_domain_name_servers; do
  22.       echo nameserver $nameserver >>/var/etc/resolv.conf
  23.     done
  24.   fi
  25. }
  26.  
  27. # Must be used on exit.   Invokes the local dhcp client exit hooks, if any.
  28. exit_with_hooks() {
  29.   exit_status=$1
  30.   if [ -f /etc/dhclient-exit-hooks ]; then
  31.     . /etc/dhclient-exit-hooks
  32.   fi
  33. # probably should do something with exit status of the local script
  34.   exit $exit_status
  35. }
  36.  
  37. # Invoke the local dhcp client enter hooks, if they exist.
  38. if [ -f /etc/dhclient-enter-hooks ]; then
  39.   exit_status=0
  40.   . /etc/dhclient-enter-hooks
  41.   # allow the local script to abort processing of this state
  42.   # local script must set exit_status variable to nonzero.
  43.   if [ $exit_status -ne 0 ]; then
  44.     exit $exit_status
  45.   fi
  46. fi
  47.  
  48. if [ x$new_network_number != x ]; then
  49.    $LOGGER New Network Number: $new_network_number
  50. fi
  51.  
  52. if [ x$new_broadcast_address != x ]; then
  53.  $LOGGER New Broadcast Address: $new_broadcast_address
  54.   new_broadcast_arg="broadcast $new_broadcast_address"
  55. fi
  56. if [ x$old_broadcast_address != x ]; then
  57.   old_broadcast_arg="broadcast $old_broadcast_address"
  58. fi
  59. if [ x$new_subnet_mask != x ]; then
  60.   new_netmask_arg="netmask $new_subnet_mask"
  61. fi
  62. if [ x$old_subnet_mask != x ]; then
  63.   old_netmask_arg="netmask $old_subnet_mask"
  64. fi
  65. if [ x$alias_subnet_mask != x ]; then
  66.   alias_subnet_arg="netmask $alias_subnet_mask"
  67. fi
  68.  
  69. if [ x$reason = xMEDIUM ]; then
  70.   eval "ifconfig $interface $medium"
  71.   eval "ifconfig $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1
  72.   sleep 1
  73.   exit_with_hooks 0
  74. fi
  75.  
  76. if [ x$reason = xPREINIT ]; then
  77.   if [ x$alias_ip_address != x ]; then
  78.     ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
  79.     route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
  80.   fi
  81.   ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
  82.         broadcast 255.255.255.255 up
  83.   exit_with_hooks 0
  84. fi
  85.  
  86. if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
  87.   exit_with_hooks 0;
  88. fi
  89.   
  90. if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
  91.    [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
  92.   current_hostname=`/bin/hostname`
  93.   if [ x$current_hostname = x ] || \
  94.      [ x$current_hostname = x$old_host_name ]; then
  95.     if [ x$current_hostname = x ] || \
  96.        [ x$new_host_name != x$old_host_name ]; then
  97.       $LOGGER "New Hostname: $new_host_name"
  98.       hostname $new_host_name
  99.     fi
  100.   fi
  101.   if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
  102.         [ x$alias_ip_address != x$old_ip_address ]; then
  103.     ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
  104.     route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
  105.   fi
  106.   if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]
  107.    then
  108.     eval "ifconfig $interface inet -alias $old_ip_address $medium"
  109.     route delete $old_ip_address 127.1 >/dev/null 2>&1
  110.     for router in $old_routers; do
  111.       route delete default $router >/dev/null 2>&1
  112.     done
  113.     if [ -n "$old_static_routes" ]; then
  114.       set -- $old_static_routes
  115.       while [ $# -gt 1 ]; do
  116.     route delete $1 $2
  117.     shift; shift
  118.       done
  119.     fi
  120.     arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' |sh
  121.   fi
  122.   if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
  123.      [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
  124.     eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
  125.                     $new_broadcast_arg $medium"
  126.     $LOGGER "New IP Address ($interface): $new_ip_address"
  127.     $LOGGER "New Subnet Mask ($interface): $new_subnet_mask"
  128.     $LOGGER "New Broadcast Address ($interface): $new_broadcast_address"
  129.     if [ -n "$new_routers" ]; then
  130.       $LOGGER "New Routers: $new_routers"
  131.     fi
  132.     route add $new_ip_address 127.1 >/dev/null 2>&1
  133.     for router in $new_routers; do
  134.       route add default $router >/dev/null 2>&1
  135.     done
  136.     if [ -n "$new_static_routes" ]; then
  137.       $LOGGER "New Static Routes: $new_static_routes"
  138.       set -- $new_static_routes
  139.       while [ $# -gt 1 ]; do
  140.     route add $1 $2
  141.     shift; shift
  142.       done
  143.     fi
  144.   fi
  145.   if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
  146.    then
  147.     ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
  148.     route add $alias_ip_address 127.0.0.1
  149.   fi
  150.   make_resolv_conf
  151.   exit_with_hooks 0
  152. fi
  153.  
  154. if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
  155.    || [ x$reason = xSTOP ]; then
  156.   if [ x$alias_ip_address != x ]; then
  157.     ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
  158.     route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
  159.   fi
  160.   if [ x$old_ip_address != x ]; then
  161.     eval "ifconfig $interface inet -alias $old_ip_address $medium"
  162.     route delete $old_ip_address 127.1 >/dev/null 2>&1
  163.     for router in $old_routers; do
  164.       route delete default $router >/dev/null 2>&1
  165.     done
  166.     if [ -n "$old_static_routes" ]; then
  167.       set -- $old_static_routes
  168.       while [ $# -gt 1 ]; do
  169.     route delete $1 $2
  170.     shift; shift
  171.       done
  172.     fi
  173.     arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' \
  174.                         |sh >/dev/null 2>&1
  175.   fi
  176.   if [ x$alias_ip_address != x ]; then
  177.     ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
  178.     route add $alias_ip_address 127.0.0.1
  179.   fi
  180.   exit_with_hooks 0
  181. fi
  182.  
  183. if [ x$reason = xTIMEOUT ]; then
  184.   if [ x$alias_ip_address != x ]; then
  185.     ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
  186.     route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
  187.   fi
  188.   eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
  189.                     $new_broadcast_arg $medium"
  190.   $LOGGER "New IP Address ($interface): $new_ip_address"
  191.   $LOGGER "New Subnet Mask ($interface): $new_subnet_mask"
  192.   $LOGGER "New Broadcast Address ($interface): $new_broadcast_address"
  193.   sleep 1
  194.   if [ -n "$new_routers" ]; then
  195.     $LOGGER "New Routers: $new_routers"
  196.     set -- $new_routers
  197.     if ping -q -c 1 $1; then
  198.       if [ x$new_ip_address != x$alias_ip_address ] && \
  199.             [ x$alias_ip_address != x ]; then
  200.     ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
  201.     route add $alias_ip_address 127.0.0.1
  202.       fi
  203.       route add $new_ip_address 127.1 >/dev/null 2>&1
  204.       for router in $new_routers; do
  205.     route add default $router >/dev/null 2>&1
  206.       done
  207.       set -- $new_static_routes
  208.       while [ $# -gt 1 ]; do
  209.     route add $1 $2
  210.     shift; shift
  211.       done
  212.       make_resolv_conf
  213.       exit_with_hooks 0
  214.     fi
  215.   fi
  216.   eval "ifconfig $interface inet -alias $new_ip_address $medium"
  217.   for router in $old_routers; do
  218.     route delete default $router >/dev/null 2>&1
  219.   done
  220.   if [ -n "$old_static_routes" ]; then
  221.     set -- $old_static_routes
  222.     while [ $# -gt 1 ]; do
  223.       route delete $1 $2
  224.       shift; shift
  225.     done
  226.   fi
  227.   arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' \
  228.                             |sh >/dev/null 2>&1
  229.   exit_with_hooks 1
  230. fi
  231.  
  232. exit_with_hooks 0
  233.