#!/bin/sh

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

PCIP=`cat $script_path/wifiSetup.ini  | ./busybox grep "PCIP:" | ./busybox grep -v grep | sed 's/PCIP://g' | sed 's/\r//g' | sed 's/\n//g'`
if [ $? != 0 ]; then
	echo "cann't found PCIP in config file"
	exit -1
fi
while [ 1 -eq 1 ]; do
	eth0=`ifconfig | ./busybox grep "eth0" | ./busybox grep -v grep | ./busybox wc -l`
	eth2=`ifconfig | ./busybox grep "eth2" | ./busybox grep -v grep | ./busybox wc -l`

if [ "$eth0" -gt 0 ];then
ifconfig eth0 down
else
sleep 10
fi
if [ "$eth2" -gt 0 ];then
sleep 10
else
ifconfig eth2 up
echo PCIP="$PCIP" >> test
$script_path/wifi.sh
ping -c 1 $PCIP &
fi

done