#!/bin/sh
FLAGS_DIR="/mnt/mtd/Flags"
SET_MIRROR="initMirrorOn"
SET_FLIP="initFlipOn"
SETTED_MIRROR="MirrorOnFlag"
SETTED_FLIP="FlipOnFlag"

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

MIRROR_CONFG=`cat $script_path/mirrorXflip.ini | ./busybox grep "MirrorSwitch:" | sed 's/MirrorSwitch://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
FLIP_CONFG=`cat $script_path/mirrorXflip.ini | ./busybox grep "FlipSwitch:" | sed 's/FlipSwitch://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
./playOrRecord -p 0 audio/videoConfigStart.pcm
if [ ! -d $FLAGS_DIR ]; then
	mkdir $FLAGS_DIR
fi
# Set Mirror Option
if [ "$MIRROR_CONFG" = "on" ]; then
	./playOrRecord -p 0 audio/engineVideoMirror.pcm
	touch $FLAGS_DIR/$SET_MIRROR
elif [ "$MIRROR_CONFG" = "off" ];then
	./playOrRecord -p 0 audio/closeVideoMirror.pcm
	if [ -f $FLAGS_DIR/$SETTED_MIRROR ]; then
		rm -rf $FLAGS_DIR/$SETTED_MIRROR
	fi
	if [ -f $FLAGS_DIR/$SET_MIRROR ];then
		rm -rf $FLAGS_DIR/$SET_MIRROR
	fi
else
	echo "MirrorSwitch param error."
fi	

# Set Flip Option
if [ "$FLIP_CONFG" = "on" ]; then
	./playOrRecord -p 0 audio/engineVedeoFlip.pcm
	touch $FLAGS_DIR/$SET_FLIP
elif [ "$FLIP_CONFG" = "off" ];then
	./playOrRecord -p 0 audio/closeVideoFlip.pcm
	if [ -f $FLAGS_DIR/$SETTED_FLIP ];then
		rm -rf $FLAGS_DIR/$SETTED_FLIP
	fi
	if [ -f $FLAGS_DIR/$SET_FLIP ];then
		rm -rf $FLAGS_DIR/$SET_FLIP
	fi
else
	echo "FlipSwitch param error."
fi
