#!/bin/sh

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

VideoMirrorSensor0=`cat $script_path/videoMirrorFlip.ini | ./busybox grep "VideoMirror_Sensor0:" | ./busybox grep -v grep | sed 's/VideoMirror_Sensor0://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
VideoFlipSensor0=`cat $script_path/videoMirrorFlip.ini | ./busybox grep "VideoFlip_Sensor0:" | ./busybox grep -v grep | sed 's/VideoFlip_Sensor0://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
VideoMirrorSensor1=`cat $script_path/videoMirrorFlip.ini | ./busybox grep "VideoMirror_Sensor1:" | ./busybox grep -v grep | sed 's/VideoMirror_Sensor1://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
VideoFlipSensor1=`cat $script_path/videoMirrorFlip.ini | ./busybox grep "VideoFlip_Sensor1:" | ./busybox grep -v grep | sed 's/VideoFlip_Sensor1://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`

if [ $? != 0 ]; then
	echo "cann't found videoMirrorFlip ini config file"
	exit -1
fi

if [ "$VideoMirrorSensor0" = "yes" ];then
	if [ ! -d "/mnt/mtd/Flags/" ];then
		mkdir -p /mnt/mtd/Flags/
	fi
	touch /mnt/mtd/Flags/Sensor0MirrorOnFlag
else
	rm -rf /mnt/mtd/Flags/Sensor0MirrorOnFlag
fi

if [ "$VideoFlipSensor0" = "yes" ];then
	if [ ! -d "/mnt/mtd/Flags/" ];then
		mkdir -p /mnt/mtd/Flags/
	fi
	touch /mnt/mtd/Flags/Sensor0FlipOnFlag
else
	rm -rf /mnt/mtd/Flags/Sensor0FlipOnFlag
fi

if [ "$VideoMirrorSensor1" = "yes" ];then
	if [ ! -d "/mnt/mtd/Flags/" ];then
		mkdir -p /mnt/mtd/Flags/
	fi
	touch /mnt/mtd/Flags/Sensor1MirrorOnFlag
else
	rm -rf /mnt/mtd/Flags/Sensor1MirrorOnFlag
fi

if [ "$VideoFlipSensor1" = "yes" ];then
	if [ ! -d "/mnt/mtd/Flags/" ];then
		mkdir -p /mnt/mtd/Flags/
	fi
	touch /mnt/mtd/Flags/Sensor1FlipOnFlag
else
	rm -rf /mnt/mtd/Flags/Sensor1FlipOnFlag
fi

if [ "$VideoMirrorSensor0" = "yes" -o "$VideoFlipSensor0" = "yes" -o "$VideoMirrorSensor1" = "yes" -o "$VideoFlipSensor1" = "yes" ];then
	./simple_adec_bind_ao -r 8000 -t g711a -i audio/videoMirrorFlipSuccess.pcm
else
	./simple_adec_bind_ao -r 8000 -t g711a -i audio/videoMirrorFlipResume.pcm
fi
