#!/bin/sh

echo 2048 > /proc/sys/vm/min_free_kbytes
echo 200 > /proc/sys/vm/vfs_cache_pressure

#解压驱动文件
rm /nfsdir/modules -rf
mkdir -p /nfsdir/modules
cd /nfsdir/modules
cp /mnt/mtd/modules.tar.lzma ./
unlzma modules.tar.lzma
tar -xvf modules.tar
rm modules.tar
#加载驱动文件

cd /nfsdir/modules/
sh /nfsdir/modules/load3520A -i

#删除驱动文件
rm /nfsdir/modules -rf

#解压客户端语言
rm /nfsdir/language -rf
mkdir /nfsdir/language
tar -xzvf /mnt/mtd/WebSites/language.tar.gz -C /nfsdir/language
rm /mnt/mtd/WebSites/language -rf
ln -s /nfsdir/language  /mnt/mtd/WebSites/

#解压DVR端语言
rm /nfsdir/dvr/language -rf
mkdir -p /nfsdir/dvr/language
cd /nfsdir/dvr/language
cp /mnt/mtd/language.tar.lzma ./
unlzma language.tar.lzma
tar -xvf language.tar
rm language.tar
rm /mnt/mtd/language -rf
ln -s /nfsdir/dvr/language  /mnt/mtd/


#解压刻录软件
mkdir -p /nfsdir/sbin
tar -zxvf /mnt/mtd/mkisofs.tar.gz -C /nfsdir/sbin/
ln -s /nfsdir/sbin/mkisofs  /mnt/mtd/mkisofs

rm /upgrade/ -rf
rm /mnt/mtd/preupgrade.sh
rm /mnt/mtd/productcheck

telnetd &


CURDEV_NVR_USE_POE=`grep -i '(nvp' /proc/cmdline`
if [ "$CURDEV_NVR_USE_POE" == "" ];then
		echo "current net is not poe"
		
		export mac=$(cat /etc/init.d/mac.dat)
		ifconfig eth0 down
		ifconfig eth0 hw ether $mac
		ifconfig eth0 up

else 
		echo "current net is poe device"
		
		export mac=$(cat /etc/init.d/mac.dat)              
		ifconfig eth0 down                                 
		ifconfig eth0 hw ether $mac   
		ifconfig eth0 up                     
		       
		ifconfig eth1 down                                 
		ifconfig eth1 hw ether $mac
		ifconfig eth1 up
		ifconfig eth1 10.151.151.1
fi

ifconfig lo up
route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0

mount -t usbfs none /proc/bus/usb

cd /mnt/mtd && ./XDVRStart.hisi ./td3520a &
