#!/bin/bash
# dmjp

. /etc/sysconfig/network

if [ ! -n "$FIFALOBATH_DYN" ] || [ `touch "$FIFALOBATH_DYN"` ]; then
   echo "FIFALOBATH_DYN in /etc/sysconfig/network must be writable" && exit -1
fi

. "$FIFALOBATH_DYN"

eval "
   old_GW=\$GW${interface}
   old_DNS=\$DNS${interface}
   old_NM=\$NM${interface}
   old_IP=\$IP${interface}
"

if [ "$old_GW" != "${new_routers}" ]; then
   echo "export GW${interface}='${new_routers}'" >> "$FIFALOBATH_DYN"
   CHANGED=1
fi

if [ "$old_NM" != "${new_subnet_mask}" ]; then
   echo "export NM${interface}='${new_subnet_mask}'" >> "$FIFALOBATH_DYN"
   CHANGED=1
fi

if [ "$old_IP" != "${new_ip_address}" ]; then
   echo "export IP${interface}='${new_ip_address}'" >> "$FIFALOBATH_DYN"
   CHANGED=1
fi

if [ "$old_DNS" != "${new_domain_name_servers}" ]; then
   echo "export DNS${interface}='${new_domain_name_servers}'" >> "$FIFALOBATH_DYN"
   NEWDNS=1
fi

if [ "${reason}" != "REBOOT" ] && [ -n "${new_ip_address}" ] && [ $CHANGED ]; then
   "$FIFALOBATH" ${interface}
   [ -x /root/src/bash/NetNotice ] && /root/src/bash/NetNotice
elif [ "${reason}" == "RENEW" ] && [ ! -z $NEWDNS ]; then
   "$FIFALOBATH" ${interface} dns
fi

