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

model=`cat /etc/model`
linuxver=`uname -a`; linuxver=${linuxver#*_}; linuxver=${linuxver%_*}

echo""
echo "Checking your Boxtype...."
echo "Some Plugins will not work correctly on your $model!"
echo ""

if [ "$model" = "ufs912" ] ; then
	echo "Your $model supports Wireless-Lan out-of-the-box"
	echo "No plugin neccessary, aborting installation..."
	exit 0
fi

if [ "$linuxver" = "stm24" ] ; then
	echo "Linux Version: $linuxver OK"
else
	echo "Sorry! This Plugin is not for your $model with ($linuxver)!!! It will not work correctly!!!"
	echo "Aborting installation..."
	exit 1
fi

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=56
	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

	echo "checking swapstick..."
	if [ ! -d /var/swap/bin/ ]; then
	    echo "no swapstick found!"
	    exit 1
	fi
	echo "swapstick found!"
fi

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
echo "installing wireless plugin ..."	sync
exit 0