#!/bin/sh

. /var/config/userlink
GDZIE=/usr/local/share    
SCAR=lista_ddt_13_19.tar.gz

wget -P /tmp $ADRES/$SCAR 2>/dev/null   

if [ -e /tmp/$SCAR ] ; then      

    echo "Cancello la lista canali..."
    echo ""
    rm $GDZIE/enigma2/userbouquet* 2>/dev/null
    rm $GDZIE/enigma2/bouquets* 2>/dev/null
    rm $GDZIE/enigma2/lamed* 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
	sync
    echo "Scrivo la nuova lista canali"
    echo ""
    cd /
    tar -xvzf /tmp/$SCAR -C $GDZIE >/dev/null
    
    sleep 2
    
    cp $GDZIE/enigma2/satellites.xml /etc/tuxbox/satellites.xml
    rm /tmp/$SCAR

    sleep 3
    sync
    echo "Ricarico i nuovi canali in memoria"
    wget -q -O /dev/null http://127.0.0.1/web/servicelistreload?mode=0 2>/dev/null 1>&2
    sleep 4
    echo ""
    echo "Aggiornamento terminato"
    echo ""
else     
    echo "Non ci sono file sul server oppure il server non risponde !"
fi

exit 0