#!/bin/sh

ROOTMTD=`/bin/cat /proc/driver/sy_basic_conf | /bin/grep BOOTMTD | /bin/sed -e 's/^BOOTMTD=//g' -e 's/;$//g'`
if [ $ROOTMTD -eq 11 ]; then
	OLDMTD=12
elif [ $ROOTMTD -eq 12 ]; then
	OLDMTD=11
else
	echo "Old rootmtd not found"
	exit 0
fi

mount /dev/mtdblock${OLDMTD} /mnt/nand

cd /mnt/nand
ls -aR > /dev/null
#rm old rfs files
if [ -d bin ]; then
	rm -rf bin dev* etc fwupdate* home lib mnt opt proc root s* tmp u* var web
fi

if [ -d /usr/local/share/snmp/mibs ]; then
	mv /usr/local/share/snmp/mibs .
	cd /usr/local/share/snmp/
	ln -s /mnt/nand/mibs .
fi

if [ ! -f /mnt/nand/SmartPackage.cab ]; then
	if [ -f /web/SmartPackage.cab ]; then
		mv /web/SmartPackage.cab /mnt/nand/
		cd /web/
		ln -s /mnt/nand/SmartPackage.cab .
	fi
fi
if [ ! -f /mnt/nand/SmartViewer.cab ]; then
	if [ -f /web/SmartViewer.cab ]; then
		mv /web/SmartViewer.cab /mnt/nand/
		cd /web/
		ln -s /mnt/nand/SmartViewer.cab .
	fi
fi
if [ -d /opt/ivideon ]; then
	cd /mnt/nand
	mv /opt/ivideon .
	cd /opt
	ln -s /mnt/nand/ivideon .
fi


# move notify_run to another rfs
NOTIFY_RUN_PATH=/opt/nss/bin/notify_run

if [ ! -L $NOTIFY_RUN_PATH ]; then
	if [ -x $NOTIFY_RUN_PATH ]; then
		mv $NOTIFY_RUN_PATH /mnt/nand/
		cd /opt/nss/bin
		ln -s /mnt/nand/notify_run .
	fi
fi

cd /mnt/nand

echo -n "Check fs2 : "
ls -alR * | wc

