#!/bin/sh
# onlineupdate by obi
. /var/etc/autostart/start-config
model=`cat /etc/model`
CMD=$1
TMPNAME=$2
cd /tmp
$CMD $TMPNAME > /dev/null 2>&1
check=`cat /tmp/image | grep AAF_ | grep _tf7700_ | cut -d '"' -f2 | sed '/.kim/d' | sed '/.md5/d' | tail -n1`

if [ "$check" == "top" ]; then
	FILELIST=`cat /tmp/image | grep AAF_ | grep _tf7700_ | cut -d '"' -f8 | sed '/.kim/d' | sed '/.md5/d'`
elif [ "$check" == "450" ]; then
	FILELIST=`cat /tmp/image | grep AAF_ | grep _tf7700_ | cut -d '"' -f6 | sed '/.kim/d' | sed '/.md5/d' | sed 's!./!!'`
else
	FILELIST=`cat /tmp/image | grep AAF_ | grep _tf7700_ | cut -d '"' -f2 | sed '/.kim/d' | sed '/.md5/d'`
fi

NOWIN=`cat /etc/version | cut -d "_" -f2 | sed 's/M//'`
NOW=`expr $NOWIN - $updatelist`

counterror=0
countuptodate=0
for DIR in $FILELIST; do
	counterror=`expr $counterror + 1`
	NEW=`echo $DIR | cut -d "_" -f2 | sed 's/M//'`
	if  [ $NOW -lt $NEW ]; then
		echo "[ONLINEUPDATE] newerfile: $DIR"
		countuptodate=`expr $countuptodate + 1`
		touch /tmp/online/"$DIR"
	fi
done

if [ "$counterror" == "0" ];then
	echo "[ONLINEUPDATE] error"
	exit
fi

if [ "$countuptodate" == "0" ];then
	echo "[ONLINEUPDATE] uptodate"
fi

exit
