#!/bin/sh

### This file download EMU in tuner ####
#  creating iscan_adm for E2 ipbox900  #
#       http://ipbox900.com.ua         #
########################################

echo "WAIT" > /dev/dbox/fp0
siteurl=http://ipbox900.com.ua
url_list1=http://ipbox900.com.ua/setup/list/list.emu
url_list2=http://ipbox900.com.ua/setup/list/list.config
url_list3=http://ipbox900.com.ua/setup/list/list.keys

emu_folder=/var/new/emu
config_folder=/var/new/config
keys_folder=/var/new/keys
new_folder=/var/new
loader_folder=/var/new/list
emu_tmp=list.emu
config_tmp=list.config
keys_tmp=list.keys

### creat new folder  ###
rm -f $new_folder/*
if [ ! -e $new_folder ]; then
echo "creating folder for lists"
mkdir $new_folder
fi

### creat folder for download lists  ###
rm -f $loader_folder/*
if [ ! -e $loader_folder ]; then
echo "creating folder for lists"
mkdir $loader_folder
fi
chmod 644 $loader_folder/*

### DownLoad List Files ###
cd $loader_folder
wget $url_list1
wget $url_list2
wget $url_list3

###  Creat folder  for new download  ###
if [ ! -e $new_folder ]; then
echo "creating folder for all new"
mkdir $new_folder
fi

if [ ! -e $emu_folder ]; then
echo "creating folder for new emu"
mkdir $emu_folder
fi

if [ ! -e $config_folder ]; then
echo "creating folder for new config"
mkdir $config_folder
fi

if [ ! -e $keys_folder ]; then
echo "creating folder for new keys"
mkdir $keys_folder
fi


### Zagruzka KEYS files ###
cd $keys_folder
rm -f $keys_folder/*
if [ -s $loader_folder/$keys_tmp ]; then
cat $loader_folder/$keys_tmp | while read keys_file
do
wget $siteurl$keys_file 
done
fi 
chmod 644 $keys_folder/*

echo "DOWNLOAD NEW KEYS IN /VAR/NEW/KEYS"
echo "Load Finish" > /dev/dbox/fp0