#!/bin/sh
#
TMP=/tmp/.keys
echo "syncing disk"
sync

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=75
	echo "checking freespace"
	echo packege size $SIZE kb
	echo freespace size $FREE kb
	if  [ "$FREE" -lt "$SIZE" ]; then
		echo "sorry no freespace left on device"
		exit 1
	else
		echo ok
	fi
fi   
echo "installing OSCam config to use an external CardReader..."
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/keys/oscam.conf ]; then
	echo "saving your actual oscam.conf"
	mv /var/keys/oscam.conf /var/keys/oscam.conf.bak
fi
if [ -e /var/keys/oscam.server ]; then
	echo "saving your actual oscam.server"
	mv /var/keys/oscam.server /var/keys/oscam.server.bak
fi
if [ -e /var/keys/oscam.services ]; then
	echo "saving your actual oscam.services"
	mv /var/keys/oscam.services /var/keys/oscam.services.bak
fi
if [ -e /var/keys/oscam.srvid ]; then
	echo "saving your actual oscam.srvid.oscam"
	mv /var/keys/oscam.srvid /var/keys/oscam.srvid.bak
fi
if [ -e /var/keys/oscam.user ]; then
	echo "saving your actual oscam.user"
	mv /var/keys/oscam.user /var/keys/oscam.user.bak
fi
sync
exit 0