#!/bin/sh

if [ -e /etc/default/static ];then
        source /etc/default/static
else
	echo "No static config found" && exit 0
fi;

[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1

case "$1" in
	deconfig|renew|bound)
		if [ "$interface" == "eth0" ];then
			/sbin/ip addr add ${IP}/${SN} brd + dev eth0 label eth0:static
			/sbin/ip route add default via ${GW} dev eth0 metric 11
			/sbin/ip route add default via ${GW} dev eth0 metric 11 table 100
		fi;

		if [ "${DNS1}" ];then
			echo "nameserver ${DNS1}" > /tmp/static_resolv
		elif [ -e /tmp/static_resolv ];then
			rm /tmp/static_resolv
		fi;
		if [ "${DNS2}" ];then
			echo "nameserver ${DNS2}" >> /tmp/static_resolv
		fi;

		if [ -e /tmp/static_resolv ];then
			cat /tmp/static_resolv |/sbin/resolvconf -a eth0.static
			rm /tmp/static_resolv
		else
			/sbin/resolvconf -d eth0.static
		fi;
		;;
esac
