#!/bin/sh

IFNAME=`iwconfig 2> /dev/null | grep "IEEE 802.11" | awk '{print $1}'`

start() {
  if [ -x /usr/sbin/wpa_supplicant ] ; then
    wpa_supplicant -B -c /etc/wpa_supplicant.conf -i $IFNAME
  fi
  if [ -x /usr/sbin/wpa_cli ] ; then
    wpa_cli -a /usr/sbin/wpa_action.sh -B
  fi
}

stop() {
  killall wpa_supplicant
}

case "$1" in
start)
  start
  ;;
stop)
  stop
  ;;
restart)
  stop
  sleep 3
  start
  ;;
*)
  echo $"Usage: $0 {start|stop|restart}"
  exit 1
  ;;
esac
exit 0
