summaryrefslogtreecommitdiff
path: root/network/wifi-radar/rc.wifi-radar
blob: 488f1480865d0a41cdfb98343b28d4e476da9a5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
#
# Start/Stop the WiFi-Radar daemon
#

# get the wifi interface from rc.inet1.conf if it is set
. /etc/rc.d/rc.inet1.conf
INTERFACE="${IFNAME[4]}"
PIDFILE=/var/run/wifi.pid

start() {
  # use the forced interface found in rc.inet1.conf or guess it
  [ ! "$INTERFACE" ] && INTERFACE="$(iwconfig 2>/dev/null | grep ESSID | head -n1 | cut -d " " -f 1)"
  sed -i "s/^[ \t]*interface[ \t]*=[ \t]*.*/interface = $INTERFACE/" /etc/wifi-radar.conf

  if [ -e "${PIDFILE}" ]; then
    echo "Found existing ${PIDFILE}! Stopping first before starting"
    stop
  fi
  echo "Starting WiFi-Radar: "
  /usr/sbin/wifi-radar --daemon 1> /dev/null 2> /dev/null &
   ps -e | grep wifi-radar | cut -d" " -f2 > ${PIDFILE}
}
 
stop() {
  echo "Stopping WiFi-Radar: "
  if [ -e "${PIDFILE}" ]; then
    kill $(cat ${PIDFILE}) 1> /dev/null 2> /dev/null
    rm -f ${PIDFILE}
  fi
killall wifi-radar 1> /dev/null 2> /dev/null
}
 
restart() {
  stop
  sleep 2
  start
}
 
status() {
  if [ -e ${PIDFILE} ]; then
    echo "The WiFi-Radar daemon is running."
  else
    echo "The WiFi-Radar daemon is not running"
  fi
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart}"
        ;;
esac