#!/bin/sh

lAudioTip=$1

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

PtzDirectionControl=`cat $script_path/ptzDirection.ini | ./busybox grep "ptzDirectionControl:" | ./busybox grep -v grep | sed 's/ptzDirectionControl://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
PtzDirectionLimitHorizontal=`cat $script_path/ptzDirection.ini | ./busybox grep "ptzDirectionLimitHorizontal:" | ./busybox grep -v grep | sed 's/ptzDirectionLimitHorizontal://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
PtzDirectionLimitVertical=`cat $script_path/ptzDirection.ini | ./busybox grep "ptzDirectionLimitVertical:" | ./busybox grep -v grep | sed 's/ptzDirectionLimitVertical://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`

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

if [ "$PtzDirectionControl" = "yes" ];then
	if [ ! -d "/mnt/mtd/Flags/" ];then
		mkdir -p /mnt/mtd/Flags/
	fi
	touch /mnt/mtd/Flags/SupportPtzDirectionControlFlag
	if [ "$lAudioTip" != "no" ];then
		./simple_adec_bind_ao -r 8000 -t g711a -i audio/supportPtzDirectionControl.pcm
	fi
fi

if [ "$PtzDirectionControl" = "no" ];then
	rm -rf /mnt/mtd/Flags/SupportPtzDirectionControlFlag
	if [ "$lAudioTip" != "no" ];then
		./simple_adec_bind_ao -r 8000 -t g711a -i audio/notSupportPtzDirectionControl.pcm
	fi
fi

if [ "$PtzDirectionLimitHorizontal" = "yes" ];then
	if [ ! -d "/mnt/mtd/Flags/" ];then
		mkdir -p /mnt/mtd/Flags/
	fi
	touch /mnt/mtd/Flags/SupportPtzDirectionHorizontalFlag
	if [ "$lAudioTip" != "no" ];then
		./simple_adec_bind_ao -r 8000 -t g711a -i audio/supportPtzDirectionHorizontal.pcm
	fi
fi

if [ "$PtzDirectionLimitHorizontal" = "no" ];then
	rm -rf /mnt/mtd/Flags/SupportPtzDirectionHorizontalFlag
	if [ "$lAudioTip" != "no" ];then
		./simple_adec_bind_ao -r 8000 -t g711a -i audio/notSupportPtzDirectionHorizontal.pcm
	fi
fi

if [ "$PtzDirectionLimitVertical" = "yes" ];then
	if [ ! -d "/mnt/mtd/Flags/" ];then
		mkdir -p /mnt/mtd/Flags/
	fi
	touch /mnt/mtd/Flags/SupportPtzDirectionVerticalFlag
	if [ "$lAudioTip" != "no" ];then
		./simple_adec_bind_ao -r 8000 -t g711a -i audio/supportPtzDirectionVertical.pcm
	fi
fi

if [ "$PtzDirectionLimitVertical" = "no" ];then
	rm -rf /mnt/mtd/Flags/SupportPtzDirectionVerticalFlag
	if [ "$lAudioTip" != "no" ];then
		./simple_adec_bind_ao -r 8000 -t g711a -i audio/notSupportPtzDirectionVertical.pcm
	fi
fi
