#!/bin/bash

set -x

# kill process if it is running
#kill_process()
#{
#	running_process=$(ps -A|grep ${1})
#	if [ -n "$running_process" ]; then
#		killall -s SIGTERM $running_process;
#		sleep 1;
#		return 0;
#	fi
#	return -1;
#}

down_interface()
{
	ifconfig ${1} down 2>/dev/null
}

# kill "wpa_supplicant" deamon if it is running
main_daemon=wpa_supplicant
#kill_process $main_daemon
killall $main_daemon

# remove interface directory if it exists
if [ -d /var/run/$main_daemon ]; then
	rm -rf /var/run/$main_daemon
fi

if [ -n "$1" ]; then
	down_interface $1;
fi

#The following sets up wired interface (e.g. eth0)
# which isn't necessarily what we want
# and worse actually results in the failure of testbed_sta if no wired i.f.
#hack -Ted# if [ -n "$2" ]; then
#hack -Ted# 	down_interface $2;
#hack -Ted# fi

