#!/bin/sh

lAudioTip=$1

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

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

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

echo "DefaultVolumePercentage:$DefaultVolumePercentage, DefaultVolumePercentageSet:$DefaultVolumePercentageSet"
if [ $? != 0 ]; then
	echo "cann't found defaultVolumePercentage ini config file"
	exit -1
fi

if [ "$DefaultVolumePercentageSet" = "yes" ]; then
		if [ "$DefaultVolumePercentage" -lt "300" ] && [ "$DefaultVolumePercentage" -gt "0" ]; then
			if [ ! -d "/mnt/mtd/Flags/" ];then
				mkdir -p /mnt/mtd/Flags/
			fi
			touch /mnt/mtd/Flags/OutVolumeGainPercentFlag
			echo "OutVolumeGainPercent=$DefaultVolumePercentage" > /mnt/mtd/Flags/OutVolumeGainPercentFlag
			if [ "$lAudioTip" != "no" ];then
				./playOrRecord -p audio/setDefaultVolumePercentageSuccess.pcm -s 8000 -f 1
			fi
		else
			echo "invalid DefaultVolumePercentage:$DefaultVolumePercentage" >> $script_path/test
		fi
elif [ "$DefaultVolumePercentageSet" = "no" ]; then
	rm -f /mnt/mtd/Flags/OutVolumeGainPercentFlag
	if [ "$lAudioTip" != "no" ];then
		./playOrRecord -p audio/delDefaultVolumePercentageSuccess.pcm -s 8000 -f 1
	fi
fi
