# /etc/profile: system-wide .profile file for the Bourne shells
trap "" 2

export PATH=/home/bin:/home/scripts:/opt/bin:/bin:/sbin:/usr/bin:/usr/local/jamvm/bin:/opt/scripts:/usr/sbin
export LD_LIBRARY_PATH=/lib/public:/lib/private:/lib/gpl:/lib
KERNELVER=2.6.30

# TMOUT=0 means no busybox shell timeout.
# if you want the busybox shell to timeout after some number of seconds of inactivity,
# change the 0 to the number of seconds, e.g. 300.
export TMOUT=0

echo
firsttime=`echo /var/udhcpd/udhcpd.lease*`
if [ "$firsttime" = "/var/udhcpd/udhcpd.lease*" ]; then
 echo "Loading drivers and kernel modules... "
 echo
# no-op
# create directory in /var mounted for TMPFS
 mknod /var/fuse c 10 229
 chmod a+rw /var/fuse
 mkdir -p /var/log /var/run /var/state/dhcp /var/ppp /var/udhcpd /var/zebra /var/siproxd /var/cache /var/tmp /var/BoBsmb /var/BoBsmb/share /var/BoBsmb/homes /var/BoBsmb/private /var/BoBsmb/locks
 cp  /etc/smbBoB.conf /var/BoBsmb/ 2>/dev/null

 echo > /var/udhcpd/udhcpd.leases

#add by saxon.tseng, save access code to /var/DECT
 mkdir -p /var/DECT
 echo > /var/DECT/ac_pin 
 echo > /var/DECT/handset1 
 echo > /var/DECT/handset2 
 echo > /var/DECT/handset3 
 echo > /var/DECT/handset4 
 echo > /var/DECT/handset5 
 echo > /var/DECT/handset6
 chmod 755 /var/DECT 
 chmod 775 /var/DECT/*
#for upload fail can use original firmware
if [ -s "/etc/DECT/fwu/sitel_dect.fwu" ]; then
 mkdir -p /var/DECT/fwu
 cp /etc/DECT/fwu/sitel_dect.fwu /var/DECT/fwu/sitel_dect.fwu
 cp /etc/DECT/fwu/sitel_dect.hex /var/DECT/fwu/sitel_dect.hex
fi
#added end

#added by chihyi.chen for webdav and samba
mkdir -p /var/log/lighttpd
echo > /var/log/lighttpd/error.log
echo > /var/log/lighttpd/access.log
cat /etc/lighttpd.conf.org  > /var/lighttpd.conf
ln -s /var/usb /var/webdav

mkdir -p /var/locks
mkdir -p /var/BoBsmb
mkdir -p /var/tmp
mkdir -p /var/BoBsmb/lib/charset
mkdir -p /var/BoBsmb/private
mkdir -p /var/BoBsmb/var/locks
mkdir -p /var/BoBsmb/smbvar
cp /bin/CP850.so /var/BoBsmb/lib/charset/CP850.so
#end

 ifconfig lo 127.0.0.1 netmask 255.0.0.0 broadcast 127.255.255.255 up
# /etc/modules_install /lib/modules/$KERNELVER/extra
 test -e /lib/modules/$KERNELVER/extra/bcm_log.ko && insmod /lib/modules/$KERNELVER/extra/bcm_log.ko
 test -e /lib/modules/$KERNELVER/extra/bcm_ingqos.ko && insmod /lib/modules/$KERNELVER/extra/bcm_ingqos.ko
 test -e /lib/modules/$KERNELVER/extra/bcm_bpm.ko && insmod /lib/modules/$KERNELVER/extra/bcm_bpm.ko
 test -e /lib/modules/$KERNELVER/extra/pktflow.ko && insmod /lib/modules/$KERNELVER/extra/pktflow.ko fcacheMaxEntries=1024
 test -e /lib/modules/$KERNELVER/extra/pktcmf.ko && insmod /lib/modules/$KERNELVER/extra/pktcmf.ko
 test -e /lib/modules/$KERNELVER/extra/bcmfap.ko && insmod /lib/modules/$KERNELVER/extra/bcmfap.ko
 test -e /etc/cmf/cmfcfg && /etc/cmf/cmfcfg
 test -e /lib/modules/$KERNELVER/extra/profdrvdd.ko && insmod /lib/modules/$KERNELVER/extra/profdrvdd.ko
 test -e /lib/modules/$KERNELVER/extra/bcmxtmcfg.ko && insmod /lib/modules/$KERNELVER/extra/bcmxtmcfg.ko
 test -e /lib/modules/$KERNELVER/extra/atmapi.ko && insmod /lib/modules/$KERNELVER/extra/atmapi.ko
 test -e /lib/modules/$KERNELVER/extra/adsldd.ko && insmod /lib/modules/$KERNELVER/extra/adsldd.ko
 test -e /lib/modules/$KERNELVER/extra/blaa_dd.ko && insmod /lib/modules/$KERNELVER/extra/blaa_dd.ko
 test -e /lib/modules/$KERNELVER/extra/bcmprocfs.ko && insmod /lib/modules/$KERNELVER/extra/bcmprocfs.ko
# test -e /lib/modules/$KERNELVER/kernel/net/ipv6/ipv6.ko && insmod /lib/modules/$KERNELVER/kernel/net/ipv6/ipv6.ko
 test -e /lib/modules/$KERNELVER/kernel/net/atm/br2684.ko && insmod /lib/modules/$KERNELVER/kernel/net/atm/br2684.ko
 test -e /lib/modules/$KERNELVER/extra/linux-kernel-bde.ko && insmod /lib/modules/$KERNELVER/extra/linux-kernel-bde.ko
 test -e /lib/modules/$KERNELVER/extra/linux-user-bde.ko && insmod /lib/modules/$KERNELVER/extra/linux-user-bde.ko
 # enet depends on moca depends on i2c
 test -e /lib/modules/$KERNELVER/extra/i2c_bcm6xxx.ko && insmod /lib/modules/$KERNELVER/extra/i2c_bcm6xxx.ko
 test -e /lib/modules/$KERNELVER/extra/bcm3450.ko && insmod /lib/modules/$KERNELVER/extra/bcm3450.ko
 test -e /lib/modules/$KERNELVER/extra/gpon_i2c.ko && insmod /lib/modules/$KERNELVER/extra/gpon_i2c.ko
 test -e /lib/modules/$KERNELVER/extra/laser_i2c.ko && insmod /lib/modules/$KERNELVER/extra/laser_i2c.ko
 test -e /lib/modules/$KERNELVER/extra/bcmmoca.ko && insmod /lib/modules/$KERNELVER/extra/bcmmoca.ko
 test -e /lib/modules/$KERNELVER/extra/bcm_enet.ko && insmod /lib/modules/$KERNELVER/extra/bcm_enet.ko
 test -e /lib/modules/$KERNELVER/extra/bcmsw.ko && insmod /lib/modules/$KERNELVER/extra/bcmsw.ko && ifconfig bcmsw up
 test -e /lib/modules/$KERNELVER/extra/bcm_usb.ko && insmod /lib/modules/$KERNELVER/extra/bcm_usb.ko
 test -e /lib/modules/$KERNELVER/extra/bcmarl.ko && insmod /lib/modules/$KERNELVER/extra/bcmarl.ko

#WLAN Module
 test -e /lib/modules/$KERNELVER/extra/wl.ko && insmod /lib/modules/$KERNELVER/extra/wl.ko
 test -e /etc/wlan/rtecdc.trx && mount -t usbfs none /proc/bus/usb && /bin/bcmdl /etc/wlan/rtecdc.trx && sleep 2 && insmod /lib/modules/$KERNELVER/extra/wl-usb.ko
 
 test -e /lib/modules/$KERNELVER/extra/dect.ko && insmod /lib/modules/$KERNELVER/extra/dect.ko 
 test -e /lib/modules/$KERNELVER/extra/dectshim.ko && insmod /lib/modules/$KERNELVER/extra/dectshim.ko 
 test -e /lib/modules/$KERNELVER/extra/dspdd.ko && insmod /lib/modules/$KERNELVER/extra/dspdd.ko
 test -e /lib/modules/$KERNELVER/extra/endpointdd.ko && insmod /lib/modules/$KERNELVER/extra/endpointdd.ko
 test -e /lib/modules/$KERNELVER/extra/p8021ag.ko && insmod /lib/modules/$KERNELVER/extra/p8021ag.ko

# other modules
 test -e /lib/modules/$KERNELVER/extra/isdn.ko && insmod /lib/modules/$KERNELVER/extra/isdn.ko
 test -e /lib/modules/$KERNELVER/kernel/drivers/isdn/capi/capi.ko && insmod /lib/modules/$KERNELVER/kernel/drivers/isdn/capi/capi.ko 
 test -e /lib/modules/$KERNELVER/extra/bcmgpon.ko && insmod /lib/modules/$KERNELVER/extra/bcmgpon.ko
 test -e /lib/modules/$KERNELVER/extra/bcmvlan.ko && insmod /lib/modules/$KERNELVER/extra/bcmvlan.ko
 test -e /lib/modules/$KERNELVER/extra/pwrmngtd.ko && insmod /lib/modules/$KERNELVER/extra/pwrmngtd.ko
 test -e /lib/modules/$KERNELVER/kernel/drivers/char/hw_random/rng-core.ko && insmod /lib/modules/$KERNELVER/kernel/drivers/char/hw_random/rng-core.ko
 test -e /lib/modules/$KERNELVER/extra/bcmtrng.ko && insmod /lib/modules/$KERNELVER/extra/bcmtrng.ko

 test -e /lib/modules/$KERNELVER/extra/laser_dev.ko && insmod /lib/modules/$KERNELVER/extra/laser_dev.ko

# gponolt test tool
 test -e /bin/gponolt && /bin/gponolt --daemon
 
 # if engineering debug tools are being built, as indicated by presence of
 # dumpsysinfo.sh, then save a copy of bootup messages for dumping later
 test -e /opt/scripts/dumpsysinfo.sh && /bin/dmesg > /var/tmp/bootupmessages

# modify by daniel, eliminate the error message when there's no Internet Module built-in
#if [ "$BUILD_INTERNETRADIO" != "" ]; then 
# usb sound & hid modules
test -e /lib/modules/$KERNELVER/kernel/sound/soundcore.ko && insmod /lib/modules/$KERNELVER/kernel/sound/soundcore.ko
test -e /lib/modules/$KERNELVER/kernel/drivers/input/input-core.ko && insmod /lib/modules/$KERNELVER/kernel/drivers/input/input-core.ko
test -e /lib/modules/$KERNELVER/kernel/drivers/hid/hid.ko && insmod /lib/modules/$KERNELVER/kernel/drivers/hid/hid.ko
test -e /lib/modules/$KERNELVER/kernel/drivers/hid/usbhid/usbhid.ko && insmod /lib/modules/$KERNELVER/kernel/drivers/hid/usbhid/usbhid.ko
test -e /lib/modules/$KERNELVER/kernel/sound/core/snd.ko && insmod /lib/modules/$KERNELVER/kernel/sound/core/snd.ko
test -e /lib/modules/$KERNELVER/kernel/sound/core/snd-page-alloc.ko && insmod /lib/modules/$KERNELVER/kernel/sound/core/snd-page-alloc.ko
test -e /lib/modules/$KERNELVER/kernel/sound/core/seq/snd-seq-device.ko && insmod /lib/modules/$KERNELVER/kernel/sound/core/seq/snd-seq-device.ko
test -e /lib/modules/$KERNELVER/kernel/sound/core/snd-rawmidi.ko && insmod /lib/modules/$KERNELVER/kernel/sound/core/snd-rawmidi.ko
test -e /lib/modules/$KERNELVER/kernel/sound/usb/snd-usb-lib.ko && insmod /lib/modules/$KERNELVER/kernel/sound/usb/snd-usb-lib.ko
test -e /lib/modules/$KERNELVER/kernel/sound/core/snd-hwdep.ko && insmod /lib/modules/$KERNELVER/kernel/sound/core/snd-hwdep.ko
test -e /lib/modules/$KERNELVER/kernel/sound/core/snd-timer.ko && insmod /lib/modules/$KERNELVER/kernel/sound/core/snd-timer.ko
test -e /lib/modules/$KERNELVER/kernel/sound/core/snd-pcm.ko && insmod /lib/modules/$KERNELVER/kernel/sound/core/snd-pcm.ko
test -e /lib/modules/$KERNELVER/kernel/sound/usb/snd-usb-audio.ko && insmod /lib/modules/$KERNELVER/kernel/sound/usb/snd-usb-audio.ko
test -e /lib/modules/$KERNELVER/kernel/sound/core/oss/snd-mixer-oss.ko && insmod /lib/modules/$KERNELVER/kernel/sound/core/oss/snd-mixer-oss.ko
test -e /lib/modules/$KERNELVER/kernel/sound/core/oss/snd-pcm-oss.ko && insmod /lib/modules/$KERNELVER/kernel/sound/core/oss/snd-pcm-oss.ko
test -e /lib/modules/$KERNELVER/kernel/sound/core/seq/snd-seq.ko && insmod /lib/modules/$KERNELVER/kernel/sound/core/seq/snd-seq.ko
test -e /lib/modules/$KERNELVER/kernel/sound/core/seq/snd-seq-midi-event.ko && insmod /lib/modules/$KERNELVER/kernel/sound/core/seq/snd-seq-midi-event.ko
test -e /lib/modules/$KERNELVER/kernel/sound/core/seq/snd-seq-midi.ko && insmod /lib/modules/$KERNELVER/kernel/sound/core/seq/snd-seq-midi.ko
test -e /lib/modules/$KERNELVER/kernel/drivers/input/evdev.ko && insmod /lib/modules/$KERNELVER/kernel/drivers/input/evdev.ko
#fi
 mknod /var/dsp c 14 3
 mknod /var/mixer c 14 0
 mkdir /var/input

 mknod /var/input/event0 c 13 64
 mknod /var/input/event1 c 13 65
 mknod /var/input/event2 c 13 66
 mknod /var/input/event3 c 13 67
 mknod /var/input/event4 c 13 68
 mknod /var/input/event5 c 13 69
 mknod /var/input/event6 c 13 70
 mknod /var/input/event7 c 13 71

 #for USB proc filesystem
 mount -t usbfs none /proc/bus/usb
 
 if [ -d /am ]; then
 echo "Mounting the filesystem ......."
 mount -t jffs2 /dev/mtdblock1 /am/messages
 fi 

# echo "Starting iinet energy services!"
 #iihf upload
 #iihf-zigbee
# if [ -e /bin/iihf-wd ] && [ -e /sbin/lighttpd ] && [ -e /etc/lighttpd.conf.es ] ; then
#      echo "starting web server 2"
#      iihf-wd
#      lighttpd -f /etc/lighttpd.conf.es
# else
#      echo "iihf-wd or ligghttpd not exist.."
# fi



 # As final step in system bootup, start smd, which will start configuration
 # management system (CMS)
 smd

 
 route add default gw 192.168.0.1
 echo "nameserver 202.103.24.68" > /etc/resolv.conf
fi

