#!/bin/sh

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

singleInfraredLight=`cat $script_path/SingleLight.ini | ./busybox grep "SingleInfraredLight:" | ./busybox grep -v grep | sed 's/SingleInfraredLight://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
singleWhiteLight=`cat $script_path/SingleLight.ini | ./busybox grep "SingleWhiteLight:" | ./busybox grep -v grep | sed 's/SingleWhiteLight://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`

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

if [ "$singleInfraredLight" = "yes" ] && [ "$singleWhiteLight" = "yes" ];then
	./playOrRecord -p audio/forbidInfraredWhiteSetTogether.pcm -s 8000 -f 1
	exit -1
fi

if [ "$singleInfraredLight" = "yes" ] && [ "$singleWhiteLight" = "no" ];then
	rm -rf /mnt/mtd/Flags/DoubleLightCameraFlag
	rm -rf /mnt/mtd/Flags/initDoubleLightCamera
	rm -rf /mnt/mtd/Flags/SingleInfraredLightFlag
	rm -rf /mnt/mtd/Flags/SingleWhiteLightFlag
	
	if [ ! -d "/mnt/mtd/Flags/" ];then
		mkdir -p /mnt/mtd/Flags/
	fi
	touch /mnt/mtd/Flags/SingleInfraredLightFlag
	./playOrRecord -p audio/singleInfraredLightSetSucc.pcm -s 8000 -f 1
fi

if [ "$singleInfraredLight" = "no" ] && [ "$singleWhiteLight" = "yes" ];then
	rm -rf /mnt/mtd/Flags/DoubleLightCameraFlag
	rm -rf /mnt/mtd/Flags/initDoubleLightCamera
	rm -rf /mnt/mtd/Flags/SingleInfraredLightFlag
	rm -rf /mnt/mtd/Flags/SingleWhiteLightFlag
	
	if [ ! -d "/mnt/mtd/Flags/" ];then
		mkdir -p /mnt/mtd/Flags/
	fi
	touch /mnt/mtd/Flags/SingleWhiteLightFlag
	./playOrRecord -p audio/singleWhiteLightSetSucc.pcm -s 8000 -f 1
fi
