#!/bin/sh
#
TMP=/tmp/.set
echo "syncing disk"
sync
#lamedb 218
#sattelites 50
#rest 22
if [ `df | grep /dev/mtdblock | grep var | sed 's/ \+/ /g' | cut -d ' ' -f4 | tail -n1 | wc -l` -eq 1 ]; then
	SPACE=`df | grep /dev/mtdblock | grep var | sed 's/ \+/ /g' | cut -d ' ' -f4 | tail -n1`
	FREE=`expr $SPACE - 100`
	SIZE=345
	MIN=10
	echo "check freespace"
	if [ -e /var/usr/local/share/enigma2/lamedb ]; then
		echo skipped lamdb allready installed
		du /var/usr/local/share/enigma2/lamedb > /tmp/.sub
		SUB=`cat /tmp/.sub | cut -d / -f1 | sed 's/ \+/ /g'`
		MIN=`expr $MIN + $SUB`
	fi
	if [ -e /var/usr/local/share/enigma2/satellites.xml ]; then
		echo skipped satellites.xml allready installed
		du /var/usr/local/share/enigma2/satellites.xml > /tmp/.sub
		SUB=`cat /tmp/.sub | cut -d / -f1 | sed 's/ \+/ /g'`
		MIN=`expr $MIN + $SUB`
	fi
	echo packege size $SIZE kb
	echo package skiped $MIN kb
	SIZEEND=`expr $SIZE - $MIN`
	echo package install $SIZEEND kb
	echo freespace size $FREE kb
	if  [ "$FREE" -lt "$SIZEEND" ]; then
		echo "sorry no freespace on device"
		exit 1
	else
		echo ok
	fi
fi   
echo "install settings ..."
echo "checking OS"
if  [ `cat /etc/motd | grep AAF | grep M | grep rev | wc -l` -eq 0 ]; then                      
	echo ---------------------------
	echo DONT USE this IPK Package!!
	echo ---
	echo Only for AAF Image!!
	echo ---------------------------
	exit 1
fi
if [ -e /var/usr/local/share/enigma2/settings_installed ]; then
	TYPE=`cat /var/usr/local/share/enigma2/settings_installed`
	echo -----------------------------------
	echo ""
	echo remove $TYPE Settings first !!
	echo ""
	echo -----------------------------------

	exit 1
fi
echo "remove /var/usr/local/share/enigma2/*.tv"
rm -rf /var/usr/local/share/enigma2/*.tv
echo "remove /var/usr/local/share/enigma2/*.radio"
rm -rf /var/usr/local/share/enigma2/*.radio
echo "remove /var/usr/local/share/enigma2/satellites.xml"
rm -rf /var/usr/local/share/enigma2/satellites.xml
echo "remove /var/usr/local/share/enigma2/lamedb"
rm -rf /var/usr/local/share/enigma2/lamedb
echo "remove /var/usr/local/share/enigma2/userbouquet.*"
rm -rf /var/usr/local/share/enigma2/userbouquet.*

exit 0
