#! /bin/ash
	
#   ---------------------------------------------
#   MDEV Support
#   (Requires sysfs support in the kernel)
#   ---------------------------------------------
mount -n -t proc /proc /proc
mount -n -t sysfs sysfs /sys
mount -n -t tmpfs mdev /dev
mkdir /dev/pts
mount -t devpts devpts /dev/pts

#echo -n " Enabling hot-plug          : "
echo "/sbin/mdev" > /proc/sys/kernel/hotplug

#echo -n " Populating /dev            : "
mkdir /dev/input
mkdir /dev/snd
mdev -s

#   ---------------------------------------------
#   Disable power management
#   (Requires sysfs support in the kernel)
#   ---------------------------------------------
# echo -n " Disabling Power mgmt       : "
# echo -n "1" > /sys/power/cpuidle_deepest_state
# status $? 1
	

#   ---------------------------------------------
#   Mount the default file systems
#   ---------------------------------------------
#echo -n " Mounting other filesystems : "
mount -a
mount -t tmpfs tmpfs /mnt

chmod 777 /Storage
#mount -t jffs2 /dev/mtdblock13 /Storage
ubiattach /dev/ubi_ctrl -m 13
if [ "$?" -eq "0" ]
then
   echo "Success."
else
   echo "Erase /dev/mtd13 jffs2 block"
   flash_eraseall /dev/mtd13
   ubiattach /dev/ubi_ctrl -m 13
fi
ubimkvol /dev/ubi0 -N ubiNandFs -m
mount -t ubifs ubi0:ubiNandFs /Storage
mkdir -p /Storage/EventLog
mkdir -p /Storage/ChargeLog
mkdir -p /Storage/SystemLog
mkdir -p /Storage/OCPP
mkdir -p /UsbFlash	
ln -s /mnt /var/www

#   ---------------------------------------------
#   Set PATH
#   ---------------------------------------------
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin

#   ---------------------------------------------
#   Start other daemons
#   ---------------------------------------------
#echo 110 > /sys/class/gpio/export
#echo "out" > /sys/class/gpio/gpio110/direction
#echo 1 > /sys/class/gpio/gpio110/value
#sleep 2
#/sbin/ifconfig eth0 192.168.1.10 netmask 255.255.255.0 
#/sbin/ifconfig eth0 down
#sleep 1
#/sbin/ifconfig eth0 up
#/sbin/route add default gw 192.168.1.1
	
#echo -n " Starting telnetd           	: "
#/usr/sbin/telnetd -l /bin/login
#status $? 0
	
echo -e " Starting SSH           	: \n"
/sbin/dropbear
echo -e " Starting FTPD	  		: \n"
tcpsvd -vE 0.0.0.0 21 ftpd -w -t 30 / &
echo -e " Starting LIGHTTPD		: \n"
/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -m /lib

cp /root/.tmate.conf /
/usr/sbin/crond &

id=CSU3_$(cat /sys/class/net/eth0/address)
echo $id > /etc/hostname
hostname -F /etc/hostname

#status $? 0

#   ---------------------------------------------
#   Softlink
#   ---------------------------------------------		
cd lib
ln -sf libbz2.so.1.0.6 libbz2.so.1
	
#   ---------------------------------------------
#   Start demo app
#   ---------------------------------------------
/root/main &