#!/bin/sh

lAudioTip=$1

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

echo  $script_path >> test

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

echo LANGUAGE = $LANGUAGE >> test
rm -f /mnt/mtd/Log/SupportLanguage
#echo -e "$LANGUAGE" > /mnt/mtd/Log/SupportLanguage
echo $LANGUAGE > /mnt/mtd/Log/InitialLanguage

if [ $? != 0 ]; then
	if [ "$lAudioTip" != "no" ];then
		./simple_adec_bind_ao -r 8000 -t g711a -i audio/configLanguage_fail.pcm
	fi
	exit -1
fi


LanuageAudioName=audio/configLanguage$LANGUAGE.pcm

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

