#!/bin/sh /etc/rc.common

# uptime_limit is 5 mintues
uptime_limit=300

START=99

bulkfw=$(uci -q get cameo.bulkfw.value)

boot() {
	start
	return
}

get_uptime()
{
	cat /proc/uptime | cut -d. -f 1
}

start()
{
	local uptime
	local remaining_time

#	while [ ! -f "/tmp/done" ]
#	do
#		sleep 1
#	done

	if [ -f /tmp/run/bulkagent.pid ]; then
		echo "bulkagent already running "$(cat /tmp/run/bulkagent.pid) > /dev/console
		exit 1
	fi
	
	ln -s /sbin/bulkagent /tmp/bulkagent_smac
	/tmp/bulkagent_smac -S 192.168.0.1 &
	
	# Wait uptime > uptime_limit then terminate bulkagent_smac
	
	
	if [ $bulkfw = "1" ]; then
		echo "Is bulkfw [$bulkfw]... ======>" > dev/console
		touch /tmp/test_mode
  	return
  fi
	
	echo "start check_bulkagent_smac ======>" > dev/console
	/sbin/check_bulkagent_smac.sh &    
}

stop()
{
	killall bulkagent_smac
	sleep 1
	killall -9 bulkagent_smac
	rm /tmp/run/bulkagent.pid
	return
}
