#!/bin/bash

FILE='/root/ip'
read -p "ipaddr:" MYIP
read -p "netmask:" MYMASK

if grep -E "^BOOTPROTO=(dhcp)|(bootp)$" $file &>/dev/null ;then
sed -i "s/^BOOTPROTO=.*/BOOTPROTO=static/g" $file


grep "^IPADDR=.*" $file &>/dev/null && sed -i "s/IPADDR=.*/IPADDR=$MYIP/g" $file || sed -i "/BOOTPROTO=.*/a \IPADDR=$MYIP" $file


grep "^NETMASK=.*" $file &>/dev/null && sed -i "s/NETMASK=.*/NETMASK=$MYMASK/g" $file || sed -i "/BOOTPROTO=.*/a \NETMASK=$MYMASK" $file
fi