#!/bin/sh
################################################################################
#                                                                              #
# Polish Kathi Team 2009                                                       #
#                                                                              #
# contact: http://pkt.sat-elita.info/                                          #
#                                                                              #
################################################################################

. /var/config/symlink
. /var/config/language.conf

#-------------------------------------------------------------------------------
#language section
#-------------------------------------------------------------------------------

if [ $lang == pl ]; then

  info1="Rozmiar: "
  info2="Kopiuje z /tmp do "
  info3="Klucze pobrane. Restartuje EMU"
  info4="Brak kluczy!"
  info5="Czekaj pobieram klucze ..."
  info6="zrodlo 1 ok"

elif [ $lang == en ]; then

  info1="Size: "
  info2="Copying from /tmp to "
  info3="Keys downloaded. Restarting EMU"
  info4="Key file is missing!"
  info5="Wait. Downloading keys..."
  info6="Source 1 ok"

elif [ $lang == ar ]; then

  info1="الحجم: "
  info2="الى /tmp النسخ من"
  info3="تم تحميل المفاتيح . إعادة تشغيل الإيميو"
  info4="ملف المفاتيح مفقود"
  info5="...أنتظر . تحميل المفاتيح"
  info6="المصدر 1 تمام"
  
elif [ $lang == fr ]; then

  info1="dimension: "
  info2="Copie de /tmp a "
  info3="Telecharge cles et installe. Redemarrez EMU"
  info4="Fichier des cles introuvable!"
  info5="Attendre. Telechargement des cles..."
  info6="Source 1 ok"  
  
elif [ $lang == de ]; then

  info1="Grosse: "
  info2="Kopiere aus /tmp in "
  info3="Keys geladen.EMU wird neugestartet"
  info4="Keine Keys!"
  info5="Lade Keys bitte warten ..."
  info6="Quelle 1 ok"

elif [ $lang == it ]; then

  info1="Dimensioni: "
  info2="Sto copiando da /tmp a "
  info3="Keys scaricate. Sto riavviando l'emulatore"
  info4="Key file non troavato!"
  info5="Attendi. Sto scaricando le keys..."
  info6="Source 1 ok"

elif [ $lang == es ]; then
  info1="Tamano: "
  info2="Copiando de /tmp a "
  info3="Keys Descargadas e Instaladas. Reiniciando la EMU"
  info4="No existen archivos de Keys!"
  info5="Espere. Descargando keys..."
  info6="Encontrado 1 correcto"
     
fi

#-------------------------------------------------------------------------------
#script section
#-------------------------------------------------------------------------------

DownloadNonZero()
{
wget -q $@ -O /tmp/$CO 
SIZE=`ls -l /tmp/$CO | awk '{ print $5 }'`
echo $info1 $SIZE
echo ""
}

Tmp2Keys()
{
if [ -e /tmp/$CO ]
   then
        echo $info2 $@
		echo ""
		cd /tmp/
		cp /tmp/$CO $@/$CO
		chmod 744 $@/*key*
		rm -r /tmp/$CO
		echo $info3
		echo ""
		   $SYMLINK/emustarter.sh
	else
		echo $info4
		echo ""
fi
}

echo $info5
echo ""
CO=camd3.keys
DownloadNonZero "http://www.softcam.tv/deneme6.php?file=camd3.keys"
if [ $SIZE -gt 100 ]
then
  Tmp2Keys /var/keys
  echo $info6
  echo ""
  exit 0
fi

exit 0