#!/bin/sh

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

SpkPower=`cat $script_path/spkPower.ini | ./busybox grep "spkPower:" | ./busybox grep -v grep | sed 's/spkPower://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
SpkPowerEnable=`cat $script_path/spkPower.ini | ./busybox grep "spkPowerEnable:" | ./busybox grep -v grep | sed 's/spkPowerEnable://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`
if [ $? != 0 ]; then
	echo "cann't found spkPower ini config file"
	exit -1
fi

if [ "$SpkPowerEnable" = "yes" ];then
	if [ "$SpkPower" = "2W" -o "$SpkPower" = "5W" ];then
		if [ ! -d "/mnt/mtd/Flags/" ];then
			mkdir -p /mnt/mtd/Flags/
		fi
		echo -n "$SpkPower" > /mnt/mtd/Flags/SpkPowerValue
		./playOrRecord -p audio/SpkPowerValueSetSucc.pcm -s 8000 -f 1
	fi
fi

if [ "$SpkPowerEnable" = "no" ];then
	rm -rf /mnt/mtd/Flags/SpkPowerValue
	./playOrRecord -p audio/SpkPowerValueDelSucc.pcm -s 8000 -f 1
fi
