/[baselayout]/trunk/net/wpa_supplicant.sh
Gentoo

Contents of /trunk/net/wpa_supplicant.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2554 - (show annotations) (download) (as text)
Fri Apr 6 19:38:23 2007 UTC (7 years, 8 months ago) by uberlord
File MIME type: text/x-sh
File size: 4402 byte(s)
Use character classes in sed
1 # Copyright 2004-2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 wpa_supplicant_depend() {
5 program start /sbin/wpa_supplicant
6 after macnet plug
7 before interface
8 provide wireless
9
10 # Prefer us over iwconfig
11 after iwconfig
12 }
13
14 # Only set these functions if not set already
15 # IE, prefer to use iwconfig
16 if ! type _get_ssid >/dev/null 2>/dev/null ; then
17 _get_ssid() {
18 local timeout=5 ssid=
19
20 while [ ${timeout} -gt 0 ] ;do
21 ssid=$(wpa_cli -i"${IFACE}" status | sed -n -e 's/^ssid=//p')
22 if [ -n "${ssid}" ] ; then
23 echo "${ssid}"
24 return 0
25 fi
26 sleep 1
27 timeout=$((timeout - 1))
28 done
29
30 return 1
31 }
32
33 _get_ap_mac_address() {
34 wpa_cli -i"${IFACE}" status | sed -n -e 's/^bssid=\(.*\)$/\1/p' \
35 | tr '[:lower:]' '[:upper:]'
36 }
37 fi
38
39 wpa_supplicant_pre_start() {
40 local opts= cfgfile= ctrl_dir=
41
42 _is_wireless || return 0
43
44 # We don't configure wireless if we're being called from
45 # the background unless we're not currently running
46 if [ "${IN_BACKGROUND}" = "true" ] ; then
47 if service_started_daemon "${SVCNAME}" /sbin/wpa_supplicant ; then
48 SSID=$(_get_ssid "${IFACE}")
49 SSIDVAR=$(_shell_var "${SSID}")
50 save_options "SSID" "${SSID}"
51 metric=2000
52 fi
53 return 0
54 fi
55
56 save_options "SSID" ""
57 eval opts=\$wpa_supplicant_${IFVAR}
58 ebegin "Starting wpa_supplicant on" "${IFVAR}"
59
60
61 if [ -x /sbin/iwconfig ] ; then
62 local x=
63 for x in txpower rate rts frag ; do
64 iwconfig "${IFACE}" "${x}" auto 2>/dev/null
65 done
66 fi
67
68 cfgfile=${opts##* -c}
69 if [ -n "${cfgfile}" -a "${cfgfile}" != "${opts}" ] ; then
70 case "${cfgfile}" in
71 " "*) cfgfile=${cfgfile# *} ;;
72 esac
73 cfgfile=${cfgfile%% *}
74 else
75 # Support new and old style locations
76 cfgfile="/etc/wpa_supplicant/wpa_supplicant-${IFACE}.conf"
77 [ ! -e "${cfgfile}" ] \
78 && cfgfile="/etc/wpa_supplicant/wpa_supplicant.conf"
79 [ ! -e ${cfgfile} ] \
80 && cfgfile="/etc/wpa_supplicant.conf"
81 opts="${opts} -c ${cfgfile}"
82 fi
83
84 if [ ! -f ${cfgfile} ] ; then
85 eend 1 "/etc/wpa_supplicant/wpa_supplicant.conf not found"
86 return 1
87 fi
88
89 # Work out where the ctrl_interface dir is if it's not specified
90 local ctrl_dir=$(sed -n -e 's/[[:space:]]*#.*//g;s/[[:space:]]*$//g;s/^ctrl_interface=//p' "${cfgfile}")
91 if [ -z "${ctrl_dir}" ] ; then
92 ctrl_dir=${opts##* -C}
93 if [ -n "${ctrl_dir}" -a "${ctrl_dir}" != "${opts}" ] ; then
94 case "${ctrl_dir}" in
95 " "*) ctrl_dir=${ctrl_dir# *} ;;
96 esac
97 ctrl_dir=${ctrl_dir%% *}
98 else
99 ctrl_dir="/var/run/wpa_supplicant"
100 opts="${opts} -C ${ctrl_dir}"
101 fi
102 fi
103 save_options ctrl_dir "${ctrl_dir}"
104
105 actfile="/etc/wpa_supplicant/wpa_cli.sh"
106
107 start-stop-daemon --start --exec /sbin/wpa_supplicant \
108 --pidfile "/var/run/wpa_supplicant-${IFACE}.pid" \
109 -- ${opts} -W -B -i "${IFACE}" \
110 -P "/var/run/wpa_supplicant-${IFACE}.pid"
111 eend $? || return 1
112
113 # Starting wpa_supplication-0.4.0, we can get wpa_cli to
114 # start/stop our scripts from wpa_supplicant messages
115 local inact=false
116 service_inactive "${SVCNAME}" && inact=true
117 mark_service_inactive "${SVCNAME}"
118
119 ebegin "Starting wpa_cli on" "${IFACE}"
120 start-stop-daemon --start --exec /bin/wpa_cli \
121 --pidfile "/var/run/wpa_cli-${IFACE}.pid" \
122 -- -a /etc/wpa_supplicant/wpa_cli.sh -p "${ctrl_dir}" -i "${IFACE}" \
123 -P "/var/run/wpa_cli-${IFACE}.pid" -B
124 if eend $? ; then
125 ebegin "Backgrounding ..."
126 exit 1
127 fi
128
129 # wpa_cli failed to start? OK, error here
130 start-stop-daemon --quiet --stop --exec /sbin/wpa_supplicant \
131 --pidfile "/var/run/wpa_supplicant-${IFACE}.pid"
132 ${inact} || mark_service_stopped "${SVCNAME}"
133 return 1
134 }
135
136 wpa_supplicant_post_stop() {
137 if [ "${IN_BACKGROUND}" = "true" ] ; then
138 # Only stop wpa_supplicant if it's not the controlling daemon
139 ! service_started_daemon "${SVCNAME}" /sbin/wpa_supplicant 1
140 fi
141 [ $? != 0 ] && return 0
142
143 local pidfile="/var/run/wpa_cli-${IFACE}.pid"
144 if [ -f ${pidfile} ] ; then
145 ebegin "Stopping wpa_cli on ${IFACE}"
146 start-stop-daemon --stop --exec /bin/wpa_cli \
147 --pidfile "${pidfile}"
148 eend $?
149 fi
150
151 pidfile="/var/run/wpa_supplicant-${IFACE}.pid"
152 if [ -f ${pidfile} ] ; then
153 ebegin "Stopping wpa_supplicant on ${IFACE}"
154 start-stop-daemon --stop --exec /sbin/wpa_supplicant \
155 --pidfile "${pidfile}"
156 eend $?
157 fi
158
159 # If wpa_supplicant exits uncleanly, we need to remove the stale dir
160 [ -S "/var/run/wpa_supplicant/${IFACE}" ] \
161 && rm -f "/var/run/wpa_supplicant/${IFACE}"
162 }
163
164 # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20