#!/bin/sh

. /app/scripts/eipr_type
. /app/config/network_lan.ini

if [ "$EIPR_TYPE" = "REALTEK" ]; then
	LANIF=eth0.1
else
	LANIF=eth0
fi

#if Wi-FI enabled, use bridge interface as LAN side port
if [ "$EIPR_WIFI" = "YES" ]; then
	LANIF=br0
fi

killall maradns

dns_file=/tmp/dnsfile

#line with ip address and subnet mask from ifconfig command
ip_string=$(echo $(ifconfig $LANIF | grep "inet addr:"))

# get ip address
ip=$(echo $ip_string | cut -d: -f2 | cut -d" " -f1)
echo $ip > $dns_file

# get subnet mask
mask=$(echo $ip_string | cut -d: -f4)
echo $mask >> $dns_file

# extract nameserver values from resolv file
file=/etc/resolv.conf
tempfile=/tmp/resolvfile

exec $(cat $file | grep nameserver > $tempfile)

while read line;do
dns=$(echo $(echo $line | cut -d" " -f2))
echo $dns >> $dns_file
done < $tempfile

# delete tempfile
rm $tempfile

# start maradns
/app/bin/config-dns &

exit 0
							
