#!/bin/sh

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

SET_IRCUTREVERSE="initIRCutReverse"
SETTED_IRCUTREVERSE="IRCutReverseFlag"
FLAGS_DIR="/mnt/mtd/Flags"

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


if [ "$IRCUTREVERSE" = "yes" ] ||
	[ "$IRCUTREVERSE" = "no" ]
then
	if [ "$IRCUTREVERSE" = "yes" ]; then
		if [ -f $FLAGS_DIR/$SET_IRCUTREVERSE ];then
			rm -f $FLAGS_DIR/$SET_IRCUTREVERSE
		fi
		if [ -f $FLAGS_DIR/$SETTED_IRCUTREVERSE ];then
			rm -f $FLAGS_DIR/$SETTED_IRCUTREVERSE
		fi	
		
		touch $FLAGS_DIR/$SET_IRCUTREVERSE
		if [ -f $FLAGS_DIR/$SET_IRCUTREVERSE ];then
			./playOrRecord -p 0 audio/initIRCutReverse.pcm
		fi
	else
		if [ -f $FLAGS_DIR/$SET_IRCUTREVERSE ];then
			rm -f $FLAGS_DIR/$SET_IRCUTREVERSE
		fi
		if [ -f $FLAGS_DIR/$SETTED_IRCUTREVERSE ];then
			rm -f $FLAGS_DIR/$SETTED_IRCUTREVERSE
		fi
		./playOrRecord -p 0 audio/initIRCutRecover.pcm
	fi
fi
