#!/bin/bash
#
# wlan
#
# chkconfig:   - 23 88
# description: wlan_control
# processname: wlan-control
#
### BEGIN INIT INFO
# Provides: wlan
# Required-Start: $local_fs messagebus
# Required-Stop: $local_fs messagebus
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop wlan-control
# Description: determines if wlan should be started
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

exec="/usr/sbin/wlan-control"
prog=$(basename $exec)
lockfile=/var/lock/subsys/$prog

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

start() {
	echo -n $"Starting $prog: "
	if [ -n "$LAN" -a -n "$WLAN" -a ! -f $lockfile  ]; then
		$prog $LAN $WLAN >/dev/null 2>&1 &
	fi
	retval=$?
	[ $retval -eq 0 ] && success || failure
	echo
	[ $retval -eq 0 ] && touch $lockfile
	return $retval
}

stop() {
	echo -n $"Stopping $prog: "
	killproc $prog 2>/dev/null
	retval=$?
	[ $retval -eq 0 ] && success || failure
	echo
	[ $retval -eq 0 ] && rm -f $lockfile
	return $retval
}

restart() {
	stop
	start
}

reload() {
	pkill -HUP $prog
}

force_reload() {
	restart
}

fdr_status() {
	status $prog
}


case "$1" in
	start|stop|restart|reload)
  		$1
		;;
	force-reload)
		force_reload
		;;
	status)
		fdr_status
		;;
	condrestart|try-restart)
		[ -f $lockfile ] && restart
		;;
	*)
		echo $"Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}"
		exit 1
esac

