#!/bin/sh
#
# chkconfig:   - 11 89
# description: wpa_supplicant is an implementation of the WPA Supplicant \
#	       component, i.e., the part that runs in the client stations. \
#	       It implements WPA key negotiation with a WPA Authenticator \
#	       and EAP authentication with Authentication Server. In \
#	       addition, it controls the roaming and IEEE 802.11 \
#	       authentication/association of the wlan driver.
# config: /etc/wpa_supplicant.conf
# pidfile: /var/run/wpa_supplicant.pid

# author:       Alexei Takaseev <taf@altlinux.ru>
# version:	2004100700
# changed:	2004100700 initialize release

# Source function library

WITHOUT_RC_COMPAT=1

. /etc/init.d/functions

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

# check if the config files are present
[ -f /etc/wpa_supplicant.conf ] || exit 0

# Source service configuration.
if [ -f /etc/sysconfig/wpa_supplicant ]; then
    . /etc/sysconfig/wpa_supplicant
else
    echo "${0##*/}: configfile /etc/sysconfig/wpa_supplicant does NOT exist !"
    exit 1
fi

PIDFILE=/var/run/wpa_supplicant.pid
LOCKFILE=/var/lock/subsys/wpa_supplicant
RETVAL=0

start() {
    is_yes "$NETWORKING" || return 0
    start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- wpa_supplicant $WPA_SUPPLICANT_OPTIONS
    RETVAL=$?
    return $RETVAL
}

stop() {
    stop_daemon  --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root wpa_supplicant
    RETVAL=$?
    return $RETVAL
}

restart() {
    stop
    start
}

reload() {
    msg_reloading wpa_supplicant
    stop_daemon --expect-user root -HUP wpa_supplicant
    RETVAL=$?
    return $RETVAL
}
 
case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    restart)
	restart
	;;
    reload)
	reload
	;;
    condrestart)
	if [ -e /var/lock/subsys/wpa_supplicant ]; then
    	    restart
	fi
	;;
    condreload)
	if [ -e /var/lock/subsys/wpa_supplicant ]; then
    	    reload
	fi
	;;
    condstop)
	if [ -e /var/lock/subsys/wpa_supplicant ]; then
    	    stop
	fi
	;;
    status)
	status --pidfile "$PIDFILE" --expect-user root wpa_supplicant
        RETVAL=$?
	;;
    *)
	echo $"Usage: wpa_supplicant {start|stop|restart|reload|condrestart|condreload|condstop|status}"
	RETVAL=1
esac

exit $RETVAL
