#!/bin/sh

lAudioTip=$1

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

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

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

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

echo "AOVWorkMode:$AOVWorkMode,AOVPowerMode:$AOVPowerMode"

if [ "$AOVWorkMode" = "no" ] && [ "$AOVPowerMode" = "no" ];then
	rm -rf /mnt/mtd/Flags/initAovWorkMode
	rm -rf /mnt/mtd/FactoryCfg/Dev.fac
	if [ "$lAudioTip" != "no" ];then
		if [ "$AOVWorkMode" = "no" ];then
			./simple_adec_bind_ao -r 8000 -t g711a -i audio/AovWorkModedelete.pcm
		fi
		if [ "$AOVPowerMode" = "no" ];then
			./simple_adec_bind_ao -r 8000 -t g711a -i audio/normalPowerModeDelete.pcm
		fi
	fi
else
	if [ ! -d "/mnt/mtd/FactoryCfg/" ];then
		mkdir -p /mnt/mtd/FactoryCfg/
	fi
	
	if [ -f "/mnt/mtd/FactoryCfg/Dev.fac" ];then
		rm -rf /mnt/mtd/FactoryCfg/Dev.fac
	fi
	
	if [ "$AOVWorkMode" = "no" ];then
		cp -f AovWorkMode/Dev_AovPowerMode.fac /mnt/mtd/FactoryCfg/Dev.fac
		if [ "$lAudioTip" != "no" ];then
			./simple_adec_bind_ao -r 8000 -t g711a -i audio/AovWorkModedelete.pcm
		fi
	elif [ "$AOVPowerMode" = "no" ];then
		cp -f AovWorkMode/Dev_AovWorkMode.fac /mnt/mtd/FactoryCfg/Dev.fac
		if [ "$lAudioTip" != "no" ];then
			./simple_adec_bind_ao -r 8000 -t g711a -i audio/normalPowerModeDelete.pcm
		fi
	else
		cp -f AovWorkMode/Dev_Both.fac /mnt/mtd/FactoryCfg/Dev.fac
	fi
	
	if [ ! -d "/mnt/mtd/Flags/" ];then
		mkdir -p /mnt/mtd/Flags/
	fi
	
	if [ "$AOVWorkMode" = "yes" ];then
		touch /mnt/mtd/Flags/initAovWorkMode
	fi
	if [ "$lAudioTip" != "no" ];then
		if [ "$AOVWorkMode" = "yes" ];then
			./simple_adec_bind_ao -r 8000 -t g711a -i audio/initAovWorkMode.pcm
		fi
		if [ "$AOVPowerMode" = "yes" ];then
			./simple_adec_bind_ao -r 8000 -t g711a -i audio/setNormalPowerModeSuccess.pcm
		fi
	fi
fi

