Skip to content

Instantly share code, notes, and snippets.

@robertpd
Created October 7, 2015 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertpd/e23ffc063661088a1b3c to your computer and use it in GitHub Desktop.
Save robertpd/e23ffc063661088a1b3c to your computer and use it in GitHub Desktop.
#!/bin/bash
### BEGIN INIT INFO
# Provides: wpa
# Required-Start: $network $syslog $local_fs
# Required-Stop: $network $syslog $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop script for wpa supplicant
# Description: Custom start/stop script for wpa_supplicant.
### END INIT INFO
SELF=`basename $0`
WPA=wpa_supplicant
PROGRAM=/sbin/${WPA}
CONF=/etc/${WPA}.conf
INTERFACE=wlan0
DRIVER=wext
DAEMONMODE="-B"
LOGFILE=/var/log/$WPA.log
function start() {
# TODO: Support multiple interfaces and drivers
OPTIONS="-c $CONF -i $INTERFACE -D $DRIVER $DAEMONMODE"
## You can remove this if you are running 8.10 and up.
# Ubuntu 8.10 and up doesn't need the -w anymore..
# And the logfile option is not valid on 8.04 and lower
local ver=$(lsb_release -sr | sed -e 's/\.//g');
[ $ver -lt 810 ] && OPTIONS="$OPTIONS -w" && LOGFILE=""
##
# Log to a file
[ -n "$LOGFILE" ] && OPTIONS="$OPTIONS -f $LOGFILE"
echo " * Starting wpa supplicant"
eval $PROGRAM $OPTIONS
}
function stop() {
echo " * Stopping wpa supplicant"
wpa_cli -i $INTERFACE terminate
#pkill $PROGRAM ## alternative method
}
function debug() {
stop
DAEMONMODE="-ddd"
start
}
function restart() {
stop
start
}
function status() {
pgrep -lf $PROGRAM
}
function usage() {
echo "Usage: $SELF <start|stop|status|debug>"
return 2
}
case $1 in
start|stop|debug|restart|status) $1 ;;
*) usage ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment