#!/bin/sh

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
	./playOrRecord -p 0 audio/supportPtzDirectionControl.pcm
fi

if [ "$PtzDirectionControl" = "no" ];then
	rm -rf /mnt/mtd/Flags/SupportPtzDirectionControlFlag
	./playOrRecord -p 0 audio/notSupportPtzDirectionControl.pcm
fi

if [ "$PtzDirectionLimitHorizontal" = "yes" ];then
	if [ ! -d "/mnt/mtd/Flags/" ];then
		mkdir -p /mnt/mtd/Flags/
	fi
	touch /mnt/mtd/Flags/SupportPtzDirectionHorizontalFlag
	./playOrRecord -p 0 audio/supportPtzDirectionHorizontal.pcm
fi

if [ "$PtzDirectionLimitHorizontal" = "no" ];then
	rm -rf /mnt/mtd/Flags/SupportPtzDirectionHorizontalFlag
	./playOrRecord -p 0 audio/notSupportPtzDirectionHorizontal.pcm
fi

if [ "$PtzDirectionLimitVertical" = "yes" ];then
	if [ ! -d "/mnt/mtd/Flags/" ];then
		mkdir -p /mnt/mtd/Flags/
	fi
	touch /mnt/mtd/Flags/SupportPtzDirectionVerticalFlag
	./playOrRecord -p 0 audio/supportPtzDirectionVertical.pcm
fi

if [ "$PtzDirectionLimitVertical" = "no" ];then
	rm -rf /mnt/mtd/Flags/SupportPtzDirectionVerticalFlag
	./playOrRecord -p 0 audio/notSupportPtzDirectionVertical.pcm
fi
