#!/bin/sh

. /var/config/userlink
GDZIE=/usr/local/share    

wget -P /tmp $ADRES/lista_nuova.tar.gz 2>/dev/null   

if [ -e /tmp/lista_nuova.tar.gz ] ; then      

    echo "Cancello la lista canali..."
    echo ""
    rm $GDZIE/enigma2/userbouquet* 2>/dev/null
    rm $GDZIE/enigma2/bouquets* 2>/dev/null
    rm $GDZIE/enigma2/lamedb 2>/dev/null
    rm $GDZIE/enigma2/satellites.xml 2>/dev/null
    rm $GDZIE/enigma2/whitelist 2>/dev/null
    rm $GDZIE/enigma2/blacklist 2>/dev/null
    rm /etc/tuxbox/satellites.xml 2>/dev/null
    
    sleep 3

    echo "Scrivo la nuova lista canali"
    echo ""
    cd /
    tar -xvzf /tmp/lista_nuova.tar.gz -C $GDZIE >/dev/null
    
    sleep 2
    
    cp $GDZIE/enigma2/satellites.xml /etc/tuxbox/satellites.xml
    rm /tmp/lista_nuova.tar.gz

    sleep 3
    
    echo "Aggiornamento terminato"
    echo ""
    echo "Riavvio tra 5 secondi..."
    sleep 5
    killall -9 enigma2

else     
    echo "Non ci sono file sul server oppure il server non risponde !"
fi

exit 0