#!/bin/sh
# /etc/init.d/wpa_supplicant: Start, stop and restart wpa_supplicant daemon
# on SliTaz, at boot time or with the command line.
#
# To start daemon at boot time, just put the right name in the $RUN_DAEMONS
# variable of /etc/rcS.conf and configure options with /etc/daemons.conf.
#
. /etc/init.d/rc.functions
. /etc/daemons.conf

NAME=wpa_supplicant
DESC="$(_ '%s daemon' wpa_supplicant)"
DAEMON=/usr/bin/wpa_supplicant
OPTIONS=$WPA_OPTIONS
PIDFILE=/var/run/wpa_supplicant.pid

case "$1" in
  start)
    if active_pidfile $PIDFILE $NAME ; then
      _ '%s is already running.' $NAME
      exit 1
    fi
    action 'Starting %s: %s...' "$DESC" $NAME
    $DAEMON $OPTIONS
    status
    ;;
  stop)
    if ! active_pidfile $PIDFILE $NAME ; then
      _ '%s is not running.' $NAME
      exit 1
    fi
    action 'Stopping %s: %s...' "$DESC" $NAME
    kill $(cat $PIDFILE)
    status
    ;;
  restart)
    if ! active_pidfile $PIDFILE $NAME ; then
      _ '%s is not running.' $NAME
      exit 1
    fi
    action 'Restarting %s: %s...' "$DESC" $NAME
    kill $(cat $PIDFILE)
    sleep 2
    $DAEMON $OPTIONS
    status
    ;;
  *)
    emsg "<n><b>$(_ 'Usage:')</b> $0 [start|stop|restart]"
    newline
    exit 1
    ;;
esac

exit 0
