#!/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
			./simple_adec_bind_ao -r 8000 -t g711a -i 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
		./simple_adec_bind_ao -r 8000 -t g711a -i audio/initIRCutRecover.pcm
	fi
fi
