#!/bin/sh

lAudioTip=$1

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

WhiteLight=`cat $script_path/whiteLight.ini | ./busybox grep "whiteLight:" | ./busybox grep -v grep | sed 's/whiteLight://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
ExtraLight=`cat $script_path/whiteLight.ini | ./busybox grep "extraLight:" | ./busybox grep -v grep | sed 's/extraLight://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`

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

if [ "$WhiteLight" = "yes" ];then
	if [ ! -d "/mnt/mtd/FactoryCfg/" ];then
		mkdir -p /mnt/mtd/FactoryCfg/
	fi
	
	if [ -f "/mnt/mtd/FactoryCfg/Camera.fac" ];then
		rm -rf /mnt/mtd/FactoryCfg/Camera.fac
	fi
	
	cp -f whiteLight/Camera.fac /mnt/mtd/FactoryCfg/

	if [ "$lAudioTip" != "no" ];then
		./simple_adec_bind_ao -r 8000 -t g711a -i audio/initWhiteLightMode.pcm
	fi
fi

if [ "$WhiteLight" = "no" ];then
	rm -rf /mnt/mtd/FactoryCfg/Camera.fac
	if [ "$lAudioTip" != "no" ];then
		./simple_adec_bind_ao -r 8000 -t g711a -i audio/whiteLightModeDelete.pcm
	fi
fi


if [ "$ExtraLight" = "yes" ];then
	if [ ! -d "/mnt/mtd/FactoryCfg/" ];then
		mkdir -p /mnt/mtd/FactoryCfg/
	fi
	
	if [ -f "/mnt/mtd/FactoryCfg/FbExtraStateCtrl.fac" ];then
		rm -rf /mnt/mtd/FactoryCfg/FbExtraStateCtrl.fac
	fi
	
	cp -f whiteLight/FbExtraStateCtrl.fac /mnt/mtd/FactoryCfg/

	if [ "$lAudioTip" != "no" ];then
		./simple_adec_bind_ao -r 8000 -t g711a -i audio/initExtraLightMode.pcm
	fi
fi

if [ "$ExtraLight" = "no" ];then
	rm -rf /mnt/mtd/FactoryCfg/FbExtraStateCtrl.fac
	if [ "$lAudioTip" != "no" ];then
		./simple_adec_bind_ao -r 8000 -t g711a -i audio/ExtraLightModeDelete.pcm
	fi
fi