#!/bin/bash

CONF_FILE=/etc/eToken.conf
ETOKEN_DEB=pkiclient-5.00.59-0_i386.deb

print_menu ()
{
	echo
	echo
	echo " Choose Client Language:"
	echo "------------------------"
	echo "1. English.....(En)"
	echo "2. Spanish.....(Es)"
	echo "3. Franch......(Fr)"
	echo "4. Italian.....(It)"
	echo "5. Japanese....(Jp)"
	echo "6. Korean......(Ko)"
	echo "7. Russian.....(Ru)"
	echo "8. Chinese.....(Zh)"
	echo "9. Portoguese..(Pt)"
	echo "10. Thai.......(Th)"
	echo
	echo -n "Your choice [1-10] -->"
	return 0
}

set_lang_code ()
{
	lang=$1
	echo "Installing Language code ${lang}."
	cat ${CONF_FILE} | sed -e "s/LanguageId=[A-Z][a-z]/LanguageId=${lang}/" > /tmp/eToken.conf.new
	mv /tmp/eToken.conf.new ${CONF_FILE}
	echo "Done!"
	return 0
}

set_lang ()
{
	lang=En
	if [ $1 == "1" ] ; then
		lang=En
	elif [ $1 == "2" ] ; then
		lang=Es
	elif [ $1 == "3" ] ; then
		lang=Fr
	elif [ $1 == "4" ] ; then
		lang=It
	elif [ $1 == "5" ] ; then
		lang=Jp
	elif [ $1 == "6" ] ; then
		lang=Ko
	elif [ $1 == "7" ] ; then
		lang=Ru
	elif [ $1 == "8" ] ; then
		lang=Zh
	elif [ $1 == "9" ] ; then
		lang=Pt
	elif [ $1 == "10" ] ; then
		lang=Th
	else
		echo "Error: only 1-10"
		return 1
	fi
	set_lang_code ${lang}
	return 0
}

check_root ()
{
if [ ! "$UID" ] ; then
	echo "Please run this script as root!"
	exit 1
fi
return 0
}


check_root
INSTALLED=`dpkg --get-selections | grep pkiclient | awk -F" " ' { print $2 } '`

if [ "$INSTALLED" != "install" ]  ; then
	if ! dpkg -i $ETOKEN_DEB ; then
		echo "Error installing deb."
		exit 1
	fi
fi
if [ -z $1 ] ; then
	print_menu
	read choice
	set_lang ${choice}
else
	if [ $1 == "En" -o $1 == "Es" -o $1 == "Fr" -o $1 == "It" -o $1 == "Jp" -o $1 == "Ko" -o $1 == "Ru" -o $1 == "Zh" -o $1 == "Pt" -o $1 == "Th" ] ; then
		set_lang_code $1
	else
		echo "Unknown language id: $1."
		exit 1
	fi
fi




	
	
