#!/bin/bash
#auto to exchange network mode in home and office
Work_mode=`grep "BOOTPROTO" /etc/sysconfig/network-scripts/ifcfg-eth1|awk -F = '{print $2}'`
function Office()
{
  if [ "$Work_mode" == "static" ]
     then
       echo "It's working in the mode of Office.!!"
       exit
     else
       sed '4s/dhcp/static/' < /etc/sysconfig/network-scripts/ifcfg-eth1|
       sed '5s/#IPADDR/IPADDR/'| //需要对网卡的配置文件事先做些调整。。
       sed '6s/#NETMASK/NETMASK/'|
       sed '7s/#GATEWAY/GATEWAY/' > /etc/sysconfig/network-scripts/ifcfg-eth2
       rm -rf /etc/sysconfig/network-scripts/ifcfg-eth1 &&
       mv /etc/sysconfig/network-scripts/ifcfg-eth2 /etc/sysconfig/network-scripts/ifcfg-eth1
       service network restart
   fi
 }
function Home()
 {
   if [ "$Work_mode" == "dhcp" ]
     then
       echo "It's working the mode of Home.!!"
       exit
     else
       sed '4s/static/dhcp/' < /etc/sysconfig/network-scripts/ifcfg-eth1|
       sed '5s/IPADDR/#IPADDR/'|
       sed '6s/NETMASK/#NETMASK/'|
       sed '7s/GATEWAY/#GATEWAY/' > /etc/sysconfig/network-scripts/ifcfg-eth2
       rm -rf /etc/sysconfig/network-scripts/ifcfg-eth1 &&
       mv /etc/sysconfig/network-scripts/ifcfg-eth2 /etc/sysconfig/network-scripts/ifcfg-eth1
       service network restart
    fi
  }
case $1 in
      home)Home;;
    office)Office;;
         *)echo $? {home|office}
 esac