#!/bin/sh /etc/rc.common
START=99
EXTRA_COMMANDS="status"
EXTRA_HELP="        status Print the status of the service"

start() {
	ifconfig mon0 > /dev/null 2> /dev/null
	if [ $? -ne 0 ] 	
	then
		airmon-ng start wlan0
	fi
	tcpdump -B 128 -i mon0 -s0 -nn -vv -t | grep RA: | /usr/local/allshoppings-cportal/aspcap &
}

stop() {
	echo "stoping as-mac-capture"
	killall -9 aspcap 2> /dev/null
	killall -9 tcpdump 2> /dev/null
}

status() {
	ifconfig mon0 > /dev/null 2> /dev/null
	if [ $? -ne 0 ]; then 
                echo "as-mac-capture is Stopped"
                exit 1                  
	else
		ps|grep aspcap|grep -v grep
		if [ $? -ne 0 ]; then
			echo "as-mac-capture is Stopped"
			exit 1
		else
			echo "as-mac-capture is Running"
		fi
	fi
}

restart() {
	echo "restarting as-mac-capture"
	stop
	sleep 2
	start
}

reload() {
        ifconfig mon0 > /dev/null 2> /dev/null
        if [ $? -ne 0 ]; then
		restart
	else
	        ps|grep aspcap|grep -v grep
	        if [ $? -ne 0 ]; then
			restart
		else
			echo "no need to reload"
		fi
	fi
}
