#!/bin/sh

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

MotorInitEnable=`cat $script_path/motorInit.ini | ./busybox grep "motorInitEnable:" | ./busybox grep -v grep | sed 's/motorInitEnable://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
if [ $? != 0 ]; then
	echo "cann't found motorInit ini config file"
	exit -1
fi

XPostion=`cat $script_path/motorInit.ini | ./busybox grep "xPostion:" | ./busybox grep -v grep | sed 's/xPostion://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
YPostion=`cat $script_path/motorInit.ini | ./busybox grep "yPostion:" | ./busybox grep -v grep | sed 's/yPostion://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`

if [ "$MotorInitEnable" = "yes" ];then
	mkdir -p /mnt/mtd/Log/
	echo "x_init=$XPostion y_init=$YPostion" > /mnt/mtd/Log/motorinit
	./playOrRecord -p audio/motorInitSetSucc.pcm -s 8000 -f 1
fi

if [ "$MotorInitEnable" = "no" ];then
	rm -rf /mnt/mtd/Log/motorinit
	./playOrRecord -p audio/motorInitDelSucc.pcm -s 8000 -f 1
fi
