#!/bin/sh 
####################################################################################
#                     SoftCam.Key update for Relook v1.0                           #
#          Script for the update of SoftCam.Key by the Web for Relook              #
#                                  by skybor                                       #
####################################################################################
#Variable de definition
MGCAMDKEYFILE=/var/keys/SoftCam.Key
UPDURL="http://byksat.kabel1.cz/dreambox/SoftCam.Key"

echo ""
echo "SoftCam.Key Update For Relook"
echo "-----------------------------"
echo ""

wget -q -O - $UPDURL > /tmp/SoftCam.Key

echo "File downloaded"

nkey=`awk -F " " '{if (($1 == "N" ||"n") && ($2 == "4101") && ($3 == "00")){print $4}}' /tmp/SoftCam.Key` 

awk -v key=$nkey -F " " '{ if (($1 == "N" ||"n") && ($2 == "4101") && ($3 == "00")) {print $0; $3="10" }; print $0}' /tmp/SoftCam.Key > /tmp/SoftCam.tmp

cp /tmp/SoftCam.tmp /tmp/SoftCam.Key

nkey=`awk -F " " '{if (($1 == "V" ||"v") && ($2 == "007C00") && ($3 == "01")){print $4}}' /tmp/SoftCam.Key` 

awk -v key=$nkey -F " " '{ if (($1 == "V" ||"v") && ($2 == "007C00") && ($3 == "01")) {print $0; $1="T" }; print $0 }' /tmp/SoftCam.Key > /tmp/SoftCam.tmp

cp /tmp/SoftCam.tmp $MGCAMDKEYFILE 

rm /tmp/SoftCam.Key
rm /tmp/SoftCam.tmp

echo ""
echo "New SoftCam.Key"
echo -e "Tak, a ted to bude hrat!" > /tmp/mg.osd
sleep 1
mgctl restart
sleep 1
echo `cat /var/keys/.emu` restarted > /tmp/mg.osd
