#!/bin/sh

if [ -x /apps/etc/update.net ]
then
        /apps/etc/update.net
fi
# Create default directories for application.
# This will be useful while system not be installed correctly.
[ -d /apps/app ] || mkdir /apps/app
[ -d /data/backup ] || mkdir /data/backup
[ -d /data/backup/temp ] || mkdir /data/backup/temp
[ -d /apps/app/data ] || ln -s /data /apps/app
[ -d /mnt/usb ] || mkdir /mnt/usb
[ -d /mnt/mmc ] || mkdir /mnt/mmc

[ -f /lib/modules/2.6.24.3/modules.dep ] || /sbin/depmod

. /usr/pzdf_tslib/setenv.sh
cd /apps/app
# add by huhb
export PATH=$PATH:/apps/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/apps/lib

#if [ -f /apps/mnt/user.db ] && ! [ -f /mnt/mmc/user.db ] ; 
#then
#	/bin/cp /apps/mnt/user.db /mnt/mmc/user.db
#fi

/bin/cp /apps/app/mmc.sh /etc/udev/scripts/mmc.sh


#zpf 2019.07.25 for dhcpc be kicked out error found at zhejianggaofa
#zpf 2020.06.15 the new busybox has some error in tar command
#so we recover to the old, don't cp the new one
if [ -f /apps/app/busybox.new.dhcp ] ; then
	/bin/cp /apps/app/busybox.new.dhcp /bin/busybox
	chmod +x /bin/busybox
fi

#add by huhb
if [ -f /apps/app/update_net_daemon ]
then
	# Start up application.
	[ -x update_net_daemon ] || chmod +x update_net_daemon
		./update_net_daemon &
else	
	# Application installed incompletely.
	showstr 10 200 "update_net_daemon application not found !"&
fi

if [ -f /apps/app/bms_client ]
then
	[ -x /apps/app/bms_client ] || chmod +x /apps/app/bms_client
	./bms_client -d 
	sleep 1
else
	echo ".client application not found..." >> /data/test.log
	showstr 10 200 "bms_client.client application not found!"&
	sleep 3
fi

#zpf 2020.02.17 for new bms_client, remove daemon
#if [ -f /apps/app/AppServiceNet ]
#then
#	[ -x /apps/app/AppServiceNet ] || chmod +x /apps/app/AppServiceNet
#	./AppServiceNet -dpf &
#	sleep 1
#else
#	showstr 10 200 "AppServiceNet application not found!"&
#	sleep 3
#fi

#sleep 1
#sqlite3 /data/local/user.db 'select cfg_name,cfg_value from sysconfig where cfg_name like "RecordUpload%%"' > /tmp/trans
#ENABLE=`awk -F"|" '{if($1=="RecordUploadEnabled"){print $2}}' /tmp/trans`
#rm -rf /tmp/trans

#if [ ! -z $ENABLE ] && [ $ENABLE = "1" ];then
#/apps/app/clit &
#sleep 3
#chmod +x /apps/update/clit_restart

echo "*/1 * * * * /apps/update/clit_restart" > /tmp/crontab
/usr/bin/install -d /var/spool/cron/crontabs
/usr/bin/install /tmp/crontab /var/spool/cron/crontabs/root
/usr/sbin/crond &
rm -f /tmp/crontab
#fi

#/sbin/ifconfig eth0 192.168.0.232 up
if [ -f /apps/etc/hw_io_reset.sh ]
then
	if [ -x /apps/etc/hw_io_reset.sh]
	then
		/apps/etc/hw_io_reset.sh
	fi
fi

if [ -f /apps/app/a7658n ]
then
	# Start up application.
	[ -x a7658n ] || chmod +x a7658n
		./a7658n &
else	
	# Application installed incompletely.
	showstr 10 200 "No applet found !"&
fi

