-
Notifications
You must be signed in to change notification settings - Fork 0
/
wireless
executable file
·124 lines (101 loc) · 2.51 KB
/
wireless
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
if [ -z $WIRELESS_INTERFACE ]; then
WIRELESS_INTERFACE=wlan0
fi
if [ -z $ESSID_LIST ]; then
ESSID_LIST=/etc/essids
fi
if [ -z $WPA_SUPPLICANT_CONF ]; then
WPA_SUPPLICANT_CONF=/etc/wpa_supplicant.conf
fi
IFCONFIG="/sbin/ifconfig $WIRELESS_INTERFACE"
IWLIST="/usr/sbin/iwlist $WIRELESS_INTERFACE"
IWCONFIG="/usr/sbin/iwconfig $WIRELESS_INTERFACE"
WPA_SUPPLICANT_PIDFILE="/var/run/wpa_supplicant-$WIRELESS_INTERFACE.pid"
DHCPCD_PIDFILE="/var/run/dhcpcd-$WIRELESS_INTERFACE.pid"
WPA_SUPPLICANT="/usr/sbin/wpa_supplicant -B -i $WIRELESS_INTERFACE -c $WPA_SUPPLICANT_CONF -P $WPA_SUPPLICANT_PIDFILE"
DHCPCD="/usr/sbin/dhcpcd $WIRELESS_INTERFACE"
case "$1" in
start)
if [ $($IFCONFIG 2> /dev/null | grep inet | wc -l) -ne 0 ] ; then
echo "Wireless Network is already running. Try 'wireless restart'"
stat_fail
exit
fi
stat_busy "Starting Wireless Network"
if [ -n $WIRELESS_MODULE ]; then
modprobe $WIRELESS_MODULE
fi
$IFCONFIG up
SCAN=$($IWLIST scan)
essid_file=$ESSID_LIST
exec<$essid_file
while read line
do
if [[ -n $line && $line != \#* && $(echo $SCAN | grep "ESSID:\"$line\"" | head -n 1 | wc -l) -eq 1 ]] ; then
ESSID=$line
$IWCONFIG essid "$ESSID"
if [[ $( $IWCONFIG | grep "ESSID:\"$ESSID\"" | wc -l ) -ne 1 ]] ; then
echo "Unable to associate with \"$ESSID\""
stat_fail
exit 1
fi
$WPA_SUPPLICANT
sleep 1
if [ -z $( $DHCPCD 2> /dev/null | grep "leased \([0-9]\{0,3\}\.\?\)\{4\}") ] ; then
add_daemon wireless
echo "Connected to $ESSID"
stat_done
exit
fi
echo "Unable to get IP address"
stat_fail
exit 1
fi
done
echo "No recognised APs found"
stat_fail
exit 1
;;
stop)
if [ $( $IFCONFIG | grep inet | wc -l) != "0" ] ; then
stat_busy "Stopping Wireless Network"
if [ -e $DHCPCD_PIDFILE ] ; then
kill $(cat $DHCPCD_PIDFILE)
fi
if [ -e $WPA_SUPPLICANT_PIDFILE ] ; then
kill $(cat $WPA_SUPPLICANT_PIDFILE)
fi
$IFCONFIG down
if [ -n $WIRELESS_MODULE ]; then
modprobe -r $WIRELESS_MODULE
fi
rm_daemon wireless
stat_done
exit
else
echo "Wireless Network is not running."
stat_fail
exit 1
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
status)
if [ $( $IFCONFIG 2> /dev/null | grep inet | wc -l) -ne 0 ] ; then
IWCONFIG
IFCONFIG
else
echo "Wireless network is not running" >&2
fi
;;
*)
echo "usage: $0 {start|stop|restart|status}"
;;
esac
# vim: set ts=2 sw=2 noet: