#!/bin/sh

#resolv.conf This file should not be modified -- make local changes to
# /etc/ppp/ip-up.local instead

#LOGDEVICE=$6
#REALDEVICE=$1
#WAN_IP=$4

#export PATH=/sbin:/usr/sbin:/bin:/usr/bin

#if [ $# -lt 1 ]; then echo "Usage: $1 {dhcpc | static}"; exit 1 ; fi

#eval `flash get DNS_MODE`
eval `flash get DNS1`
eval `flash get DNS2`
eval `flash get DNS3`
# DNS Setting

DNS_MODE=0
if [ "$DNS1" != '0.0.0.0' ]; then
	DNS_MODE=1
fi
if [ "$DNS2" != '0.0.0.0' ]; then
	DNS_MODE=1
fi
if [ "$DNS3" != '0.0.0.0' ]; then
	DNS_MODE=1
fi

if [ "$1" = "dhcpc" ]; then
		/bin/rdisc -s &
		/bin/rdisc -f
		/bin/cat /etc/resolv.master /etc/udhcpc/resolv.conf > /etc/resolv.conf

elif [ "$1" = "static" ]; then
	if [ $DNS_MODE != 1 ]; then
		echo "nameserver 168.95.1.1" > /etc/resolv.conf
	fi

else
	/bin/cat /etc/resolv.master /etc/ppp/resolv.conf > /etc/resolv.conf
fi

dnrd -k
#dnrd setting, dns -> /etc/resolv.conf
if [ $DNS_MODE = 1 ]; then
	if [ "$DNS1" != '0.0.0.0' ]; then
		dnrd -s $DNS1
	fi
	if [ "$DNS2" != '0.0.0.0' ]; then
		dnrd -s $DNS2
	fi
	if [ "$DNS3" != '0.0.0.0' ]; then
		dnrd -s $DNS3
	fi
else
	#rm /var/run/dns-tmp
	cat /etc/resolv.conf | grep "nameserver" > jj5
	cut -f 2 -d" " jj5 > jj6
	line=`cat jj6 | wc -l`
  	num=1
  	while [ $num -le $line ];
	do
		pat=` head -n $num jj6 | tail -n 1`
		echo -n " -s $pat" >> jj7
		echo "$pat" >> /var/run/dns-tmp
#		eval `dnrd -s $pat`
		num=`expr $num + 1`
	done
	echo "" >> /var/run/dns-tmp
	pat=` head -n $num jj7 | tail -n 1`
	eval `dnrd $pat`
	rm jj5
	rm jj6
	rm jj7
fi

#echo "lesetime ---> $lease"

#echo "********** set Time Zone **********"
/bin/sntp.sh

echo "********** run firewall.sh **********"
/bin/firewall.sh

exit 0
