#!/sbin/openrc-run

depend() {
	use net
	after firewall
	provide chilli
}

checkconfig() {
	if [ -f /etc/chilli.conf ]; then
		return 0;
	else
		eerror "Error starting CoovaChilli. Please create /etc/chilli.conf before."
		return 1;
	fi

}

start() {
        checkconfig || return 1
        ebegin "Starting CoovaChilli Captive Portal"
	
	echo 1 > /proc/sys/net/ipv4/ip_forward
	lsmod | grep tun >& /dev/null

	if [ $? -ne 0 ]; then
		modprobe tun >& /dev/null
	fi

        start-stop-daemon --start --pidfile /var/run/chilli/chilli.pid --quiet \
                --exec /usr/sbin/chilli ${CHILLI_OPTS} -- --pidfile=/var/run/chilli/chilli.pid 
        eend $?
}

stop() {
        ebegin "Stopping CoovaChilli Captive Portal"
        start-stop-daemon --stop --pidfile /var/run/chilli.pid --quiet
        eend $?
}
