#!/bin/sh

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

FullDuplexTalk=`cat $script_path/talk.ini | ./busybox grep "fullDuplexTalk:" | ./busybox grep -v grep | sed 's/fullDuplexTalk://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`

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

if [ "$FullDuplexTalk" = "yes" ];then
	if [ ! -d "/mnt/mtd/Flags/" ];then
		mkdir -p /mnt/mtd/Flags/
	fi
	touch /mnt/mtd/Flags/FullDuplexTalkFlag
	if [ -d "/mnt/mtd/Flags/HalfDuplexTalkFlag" ];then
		rm -rf /mnt/mtd/Flags/HalfDuplexTalkFlag
	fi
	./playOrRecord -p 0 audio/fullDuplexTalk.pcm
fi

if [ "$FullDuplexTalk" = "no" ];then
	if [ ! -d "/mnt/mtd/Flags/" ];then
		mkdir -p /mnt/mtd/Flags/
	fi
	touch /mnt/mtd/Flags/HalfDuplexTalkFlag
	if [ -d "/mnt/mtd/Flags/FullDuplexTalkFlag" ];then
		rm -rf /mnt/mtd/Flags/FullDuplexTalkFlag
	fi
	./playOrRecord -p 0 audio/halfDuplexTalk.pcm
fi
