#!/bin/sh

script_path=`echo $0 | awk -F '/' '{for(i=2;i<NF;i++) printf"/"$i}'`
echo  $script_path >> test

getconf()
{
	val=`cat $1 | grep $2: | sed -e "s/$2://g" -e "s/\r//g" -e "s/\n//g" -e "s/$(echo -e '\015')//g"`
	if [ -z "$val" ]; then
		echo "getconf $2 failed" >> test
		./playOrRecord -p audio/getconffail.pcm -s 8000 -f 1
		exit 1
	fi

	echo -n $val
}

mkdir -p /var/Flags
touch /var/Flags/Sofia_Flag_TempKeepOriginIP
touch /var/Flags/Sofia_Flag_TempDisableDHCP

mkdir -p /var/tmp
touch /var/tmp/NotRestoreRoute

#killall routeswitch
#sleep 1

filename=$script_path/eth0.ini
IP=$(getconf $filename IP)
#echo IP=$IP
WG=$(getconf $filename WG)
#echo WG=$WG
NETMASK=$(getconf $filename NETMASK)
#echo NETMASK=$NETMASK

ifconfig eth0 up $IP netmask $NETMASK
route add default gw $WG
#netinit eth2 $IP $NETMASK $WG  
echo $IP $WG $NETMASK  >> test
echo "HOSTIP = $IP\nSUBMASK = $NETMASK\nGATEWAYIP = $WG\n" > /var/network
mount --bind /var/network /mnt/mtd/Config/network

for com_ip in `cat $script_path/computerip.txt`
do
	ping $com_ip &
done

App &

sleep 20
while true
do
	sleep 20
done

exit 0
