#!/bin/sh
addgroup www root
chmod g+w /etc/resolv.conf
chmod g+w /etc/hosts
chmod g+w /etc

chmod +s /bin/busybox
chmod -R 777 /opt/interm
chmod -R 777 /tmp

BIN=/opt/interm/bin
CONF=/opt/interm/conf
SIBO_CONF=/opt/interm/www/html/conf

if [ -x $BIN/xml_util ]; then
	zone=`$BIN/xml_util -r -f $CONF/time.xml -t /config/timezone`
	[ $? != 0 ] && zone=GMT0
	[ -x $BIN/lntz ] && $BIN/lntz $zone

	tserver_en=`$BIN/xml_util -r -f $CONF/time.xml -t /config/pos`
	if [ $? = 0 -a $tserver_en = "server" ]; then
	tserver=`$BIN/xml_util -r -f $CONF/time.xml -t /config/timeserver/url`
        [ $? = 0 ] && rdate -s $tserver
	fi
fi

[ ! -c /dev/factory_reset ] &&  mknod /dev/pmu-n_reset c 251 0
[ ! -c /dev/gpio_ctrl ] &&      mknod /dev/gpio_ctrl c 250 0

for driver in reset_imt gpio_imt; do
        [ -f $BIN/$driver.ko ] && insmod $BIN/$driver.ko
done

if [ -e $BIN/pmu-n_reset ]; then
        $BIN/pmu-n_reset &
fi

killall lighttpd
[ -x /usr/sbin/lighttpd ] && /usr/sbin/lighttpd -f $CONF/lighttpd.conf -m/usr/lib
killall snmpd
[ -x /usr/sbin/snmpd ] && /usr/sbin/snmpd -c $CONF/snmpd.conf

if [ -x $BIN/xml_util ]; then
        use=`$BIN/xml_util -r -f $SIBO_CONF/info_schedule.xml -t /config/use`
        if [ $? = 0 -a $use = "true" ]; then
                $BIN/action_prc &
                $BIN/schedule_prc &
        fi
fi

$BIN/confManager &

$BIN/run_emitTime &

version=`$BIN/xml_util -r -f $CONF/version.xml -t config/value`
echo $version

$BIN/scandevice -D -i eth0 -n `arm-911a` -h 80 -m 80 -v $version

amixer sset 'Playback' 178

if [ -e $BIN/bufClean ]; then
		$BIN/bufClean &
fi
