#!/bin/sh
### BEGIN INIT INFO
# Provides:          wifi support
# Required-Start:    --
# Required-Stop:     --
# Should-Start:      ifupdown
# Should-Stop:       ifupdown
# Default-Start:     S
# Default-Stop:      0 6
# Short-Description: Launch WIFI manager service
### END INIT INFO

# PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"

. /etc/barix-wifiman.conf

say()
{
    echo "$1"
    logger -t "wifiman" "$1"
}

uci_get()
{
    uci -q get $1
}



WLAN_HELPER=wlan-link-helper
WLANIF=wlan0
PIDFILE=/var/run/wpa_supplicant.$WLANIF.pid
HELPERPIDFILE=/var/run/wlan-helper-$WLANIF.pid




start()
{
    # Check if the environment is sane
    if [ -z "$CONF_DIR" -o -z "$PID_DIR" ]; then
        echo "Missing configuration. This will not work. Abort."
        exit 1
    fi
    
    test -d "$CONF_DIR" || mkdir -p $CONF_DIR
    test -d "$PID_DIR" || mkdir -p $PID_DIR
    
    
    echo -n "Launching barix-wifiman... "
    start-stop-daemon -b -a barix-wifiman -S
    start-stop-daemon -b -a barix-wifi-scand -S
    echo "DONE"    
}

stop()
{
    echo -n "Stopping barix-wifiman... "
    start-stop-daemon -x barix-wifiman -K
    start-stop-daemon -x barix-wifi-scand -K
    echo "OK"
}


case "$1" in
start)
    start
    ;;

stop)
    stop
    ;;
    
restart|reload|force-reload)
    stop
    start
    ;;
*)
    say "$0 {start|stop|restart}"
    exit 1
    ;;
esac

exit 0





