1 |
#!/bin/bash |
#!/bin/bash |
2 |
|
# $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.11 2005-10-21 15:24:25 niro Exp $ |
3 |
|
|
4 |
#%rlevels: 0:k 1:k 2:k 3:s 4:s 5:s 6:k |
#%rlevels: 0:k 1:k 2:k 3:s 4:s 5:s 6:k |
5 |
#%start: 20 |
#%start: 20 |
13 |
source /etc/sysconfig/rc |
source /etc/sysconfig/rc |
14 |
source ${rc_functions} |
source ${rc_functions} |
15 |
|
|
16 |
checkconfig() { |
# read values from files |
17 |
|
read_value() |
18 |
|
{ |
19 |
|
local var="$1" |
20 |
|
local file="$2" |
21 |
|
local value |
22 |
|
|
23 |
|
# local all possible vars |
24 |
|
# global |
25 |
|
local ONBOOT |
26 |
|
local NETWORKING |
27 |
|
|
28 |
|
# static |
29 |
|
local IP |
30 |
|
local NETMASK |
31 |
|
local BROADCAST |
32 |
|
local NETWORKING |
33 |
|
local FORCE_MAC_TO |
34 |
|
|
35 |
|
# dhcp |
36 |
|
local DHCP_PROG |
37 |
|
local DHCP_START |
38 |
|
local DHCP_STOP |
39 |
|
|
40 |
|
# default gw |
41 |
|
local GATEWAY |
42 |
|
local GATEWAY_IF |
43 |
|
|
44 |
|
# wireless extensions |
45 |
|
local WIRELESS_AP |
46 |
|
local WIRELESS_AUTH_MODE |
47 |
|
local WIRELESS_BITRATE |
48 |
|
local WIRELESS_CHANNEL |
49 |
|
local WIRELESS_DEFAULT_KEY |
50 |
|
local WIRELESS_ESSID |
51 |
|
local WIRELESS_FREQUENCY |
52 |
|
local WIRELESS_KEY |
53 |
|
local WIRELESS_KEY_ASCII |
54 |
|
local WIRELESS_KEY_0 |
55 |
|
local WIRELESS_KEY_1 |
56 |
|
local WIRELESS_KEY_2 |
57 |
|
local WIRELESS_KEY_3 |
58 |
|
local WIRELESS_KEY_LENGTH |
59 |
|
local WIRELESS_MODE |
60 |
|
local WIRELESS_NICK |
61 |
|
local WIRELESS_NWID |
62 |
|
local WIRELESS_POWER |
63 |
|
|
64 |
|
source ${file} |
65 |
|
eval value=\$$(echo ${var}) |
66 |
|
echo "${value}" |
67 |
|
} |
68 |
|
|
69 |
|
checkconfig() |
70 |
|
{ |
71 |
if [ -z "${NETWORKING}" ] |
if [ -z "${NETWORKING}" ] |
72 |
then |
then |
73 |
echo "NETWORKING missing in net.${interface}, aborted" |
echo "NETWORKING missing in net.${interface}, aborted" |
107 |
esac |
esac |
108 |
} |
} |
109 |
|
|
110 |
|
# onboot_interface_list /path/to/files* |
111 |
case "$1" in |
onboot_interface_list() |
112 |
start) |
{ |
113 |
for file in $(grep -il "ONBOOT=\"yes\"" ${network_settings}/net.*) |
local file |
114 |
do |
local devices |
115 |
interface=$(basename ${file} | sed s/net.//) |
local iface |
116 |
case "${interface}" in |
|
117 |
|
# get list of all devices |
118 |
|
for file in $@ |
119 |
|
do |
120 |
|
if [[ $(read_value ONBOOT ${file}) = yes ]] |
121 |
|
then |
122 |
|
iface="$(basename ${file} | sed s/net.//)" |
123 |
|
# exclude backup files |
124 |
|
case "${iface}" in |
125 |
*~) ;; |
*~) ;; |
126 |
*) |
*) devices="${devices} $(basename ${file} | sed s/net.//)" ;; |
|
source ${network_settings}/net.${interface} || exit 1 |
|
|
checkconfig |
|
|
case "${NETWORKING}" in |
|
|
dhcp) |
|
|
echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${interface}${COLDEFAULT} ..." |
|
|
${CURS_UP} |
|
|
${SET_WWCOL} |
|
|
echo "[DHCP]" |
|
|
loadproc ${DHCP_PROG} ${DHCP_START} |
|
|
;; |
|
|
static) |
|
|
echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${interface}${COLDEFAULT} ..." |
|
|
${CURS_UP} |
|
|
${SET_WWCOL} |
|
|
echo "[STATIC]" |
|
|
ifconfig ${interface} ${IP} netmask ${NETMASK} broadcast ${BROADCAST} |
|
|
evaluate_retval |
|
|
;; |
|
|
esac |
|
|
;; |
|
127 |
esac |
esac |
128 |
done |
fi |
129 |
|
done |
130 |
|
|
131 |
|
echo "${devices}" |
132 |
|
} |
133 |
|
|
134 |
|
config_wireless_wep() |
135 |
|
{ |
136 |
|
local iface="$1" |
137 |
|
|
138 |
|
if [[ -z ${iface} ]] |
139 |
|
then |
140 |
|
echo "WEP: no \$iface given. Aborting setup." |
141 |
|
return 1 |
142 |
|
fi |
143 |
|
|
144 |
|
${CURS_UP} |
145 |
|
${SET_WWCOL} |
146 |
|
echo "[AUTH: WEP]" |
147 |
|
|
148 |
|
iwconfig "${iface}" enc on |
149 |
|
[[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}" |
150 |
|
[[ -n ${WIRELESS_KEY} ]] && iwconfig "${iface}" key "${WIRELESS_KEY}" |
151 |
|
[[ -n ${WIRELESS_KEY_ASCII} ]] && iwconfig "${iface}" key s:"${WIRELESS_KEY_ASCII}" |
152 |
|
} |
153 |
|
|
154 |
|
config_wireless_wpa() |
155 |
|
{ |
156 |
|
local iface="$1" |
157 |
|
|
158 |
|
if [[ -z ${iface} ]] |
159 |
|
then |
160 |
|
echo "WPA: no \$iface given. Aborting setup." |
161 |
|
return 1 |
162 |
|
fi |
163 |
|
|
164 |
|
if [ ! -x /sbin/wpa_supplicant ] |
165 |
|
then |
166 |
|
echo "WPA: wpa_supplicant not installed. Aborting setup." |
167 |
|
return 1 |
168 |
|
fi |
169 |
|
|
170 |
|
${CURS_UP} |
171 |
|
${SET_WWCOL} |
172 |
|
echo "[AUTH: WPA]" |
173 |
|
|
174 |
|
# get default settings |
175 |
|
[[ -f /etc/conf.d/wpa_supplicant ]] && source /etc/conf.d/wpa_supplicant |
176 |
|
|
177 |
|
# check the configuration |
178 |
|
[[ -z ${WIRELESS_WPA_CONFIG} ]] && WIRELESS_WPA_CONFIG=/etc/wpa_supplicant.auto |
179 |
|
[[ -z ${WIRELESS_WPA_SKEL} ]] && WIRELESS_WPA_SKEL=/etc/conf.d/wpa_supplicant.skel |
180 |
|
if [[ -z ${WIRELESS_WPA_DRIVER} ]] |
181 |
|
then |
182 |
|
echo "WPA: WIRELESS_WPA_DRIVER given. Aborting setup." |
183 |
|
return 1 |
184 |
|
fi |
185 |
|
|
186 |
|
# write a config with the settings from net.${iface} |
187 |
|
# only wpa-psk ! all other needs manual setup |
188 |
|
if [[ ${WIRELESS_WPA_AUTOCONF} = true ]] |
189 |
|
then |
190 |
|
# write default cfg from skeleton |
191 |
|
cat ${WIRELESS_WPA_SKEL} > ${WIRELESS_WPA_CONFIG} |
192 |
|
|
193 |
|
# setup the network entry |
194 |
|
sed -i -e "s:@WIRELESS_ESSID@:${WIRELESS_ESSID}:g" \ |
195 |
|
-e "s:@WIRELESS_KEY@:${WIRELESS_KEY}:g" \ |
196 |
|
${WIRELESS_WPA_CONFIG} |
197 |
|
fi |
198 |
|
|
199 |
|
# remove old state dir |
200 |
|
[ -d /var/run/wpa_supplicant ] && rm -rf /var/run/wpa_supplicant |
201 |
|
|
202 |
|
# now run the wpa_supplicant dameon |
203 |
|
wpa_supplicant -B \ |
204 |
|
-D"${WIRELESS_WPA_DRIVER}" \ |
205 |
|
-c"${WIRELESS_WPA_CONFIG}" \ |
206 |
|
-i"${iface}" \ |
207 |
|
${WIRELESS_WPA_OPTS} |
208 |
|
|
209 |
|
# echo wait 5 seconds |
210 |
|
echo " Waiting 5 seconds to retrieve authentification reply ... " |
211 |
|
sleep 5 |
212 |
|
} |
213 |
|
|
214 |
|
setup_wireless_extensions() |
215 |
|
{ |
216 |
|
local iface="$1" |
217 |
|
|
218 |
|
if [[ -z ${iface} ]] |
219 |
|
then |
220 |
|
echo "WIRELESS_EXTENSIONS: no \$iface given. Aborting setup." |
221 |
|
return 1 |
222 |
|
fi |
223 |
|
|
224 |
|
if [[ -n ${WIRELESS_BITRATE} ]] || |
225 |
|
[[ -n ${WIRELESS_CHANNEL} ]] || |
226 |
|
[[ -n ${WIRELESS_ESSID} ]] || |
227 |
|
[[ -n ${WIRELESS_FREQUENCY} ]] || |
228 |
|
[[ -n ${WIRELESS_MODE} ]] || |
229 |
|
[[ -n ${WIRELESS_NICK} ]] || |
230 |
|
[[ -n ${WIRELESS_AUTH_MODE} ]] |
231 |
|
then |
232 |
|
echo -e ${COLOREDSTAR}"Setting up wlan-ext for ${COLBLUE}${iface}${COLDEFAULT} ... " |
233 |
|
fi |
234 |
|
|
235 |
if [ -n "${GATEWAY}" -a -n "${GATEWAY_IF}" ] |
[[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}" |
236 |
|
[[ -n ${WIRELESS_CHANNEL} ]] && iwconfig "${iface}" channel "${WIRELESS_CHANNEL}" |
237 |
|
[[ -n ${WIRELESS_ESSID} ]] && iwconfig "${iface}" essid "${WIRELESS_ESSID}" |
238 |
|
[[ -n ${WIRELESS_FREQUENCY} ]] && iwconfig "${iface}" freq "${WIRELESS_FREQUENCY}" |
239 |
|
[[ -n ${WIRELESS_MODE} ]] && iwconfig "${iface}" mode "${WIRELESS_MODE}" |
240 |
|
[[ -n ${WIRELESS_NICK} ]] && iwconfig "${iface}" nick "${WIRELESS_NICK}" |
241 |
|
|
242 |
|
case "${WIRELESS_AUTH_MODE}" in |
243 |
|
wpa) config_wireless_wpa "${iface}" ;; |
244 |
|
wep|on) config_wireless_wep "${iface}" ;; |
245 |
|
off) iwconfig "${iface}" enc off ;; |
246 |
|
esac |
247 |
|
} |
248 |
|
|
249 |
|
networking_start() |
250 |
|
{ |
251 |
|
local iface dns |
252 |
|
|
253 |
|
# get list of all devices |
254 |
|
for iface in $(onboot_interface_list ${network_settings}/net.*) |
255 |
|
do |
256 |
|
# checkconfig |
257 |
|
source ${network_settings}/net.${iface} || exit 1 |
258 |
|
checkconfig |
259 |
|
|
260 |
|
# setup mac |
261 |
|
if [ -n "${FORCE_MAC_TO}" ] |
262 |
then |
then |
263 |
echo -e ${COLOREDSTAR}"Setting up default gateway ..." |
echo -e ${COLOREDSTAR}"Faking MAC to ${FORCE_MAC_TO} for ${COLBLUE}${iface}${COLDEFAULT} ... " |
264 |
route add default gateway ${GATEWAY} metric 1 \ |
ifconfig "${iface}" hw ether "${FORCE_MAC_TO}" |
|
dev ${GATEWAY_IF} |
|
265 |
evaluate_retval |
evaluate_retval |
266 |
fi |
fi |
267 |
|
|
268 |
update_svcstatus $1 |
# activate the interface |
269 |
splash svc_started "$(basename $0)" 0 |
ifconfig "${iface}" up |
270 |
;; |
|
271 |
|
# now configure wireless_extensions |
272 |
|
[ -x /usr/sbin/iwconfig ] && setup_wireless_extensions "${iface}" |
273 |
|
|
274 |
|
echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..." |
275 |
|
|
276 |
|
# setup static or dhcp |
277 |
|
case ${NETWORKING} in |
278 |
|
dhcp|DHCP) |
279 |
|
${CURS_UP} |
280 |
|
${SET_WWCOL} |
281 |
|
echo "[DHCP]" |
282 |
|
loadproc ${DHCP_PROG} ${DHCP_START} "${iface}" |
283 |
|
;; |
284 |
|
static|STATIC) |
285 |
|
${CURS_UP} |
286 |
|
${SET_WWCOL} |
287 |
|
echo "[STATIC]" |
288 |
|
ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}" |
289 |
|
evaluate_retval |
290 |
|
;; |
291 |
|
esac |
292 |
|
|
293 |
stop) |
# setup def gw |
294 |
if [ -n "${GATEWAY}" ] |
if [[ -n ${GATEWAY} ]] |
295 |
|
then |
296 |
|
echo -e ${COLOREDSTAR}"Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..." |
297 |
|
route add default gateway ${GATEWAY} metric 1 dev ${iface} |
298 |
|
evaluate_retval |
299 |
|
fi |
300 |
|
|
301 |
|
# setup /etc/resolv.conf |
302 |
|
if [[ -n ${NAMESERVER} ]] |
303 |
|
then |
304 |
|
echo -e ${COLOREDSTAR}"Setting up all nameserver for ${COLBLUE}${iface}${COLDEFAULT} ..." |
305 |
|
|
306 |
|
# whipe out the old one |
307 |
|
echo "# Generated by the magellan-initscripts for ${iface}" > /etc/resolv.conf |
308 |
|
for dns in ${NAMESERVER} |
309 |
|
do |
310 |
|
echo "nameserver ${dns}" >> /etc/resolv.conf |
311 |
|
done |
312 |
|
fi |
313 |
|
done |
314 |
|
} |
315 |
|
|
316 |
|
networking_stop() |
317 |
|
{ |
318 |
|
# get list of all devices |
319 |
|
for iface in $(onboot_interface_list ${network_settings}/net.*) |
320 |
|
do |
321 |
|
source ${network_settings}/net.${iface} || exit 1 |
322 |
|
checkconfig |
323 |
|
|
324 |
|
if [[ -n ${GATEWAY} ]] |
325 |
then |
then |
326 |
echo -e ${COLOREDSTAR}"Removing default gateway ..." |
echo -e ${COLOREDSTAR}"Removing default gateway ..." |
327 |
route del -net default |
route del -net default |
328 |
evaluate_retval |
evaluate_retval |
329 |
fi |
fi |
330 |
|
|
331 |
for file in $(grep -il "ONBOOT=\"yes\"" ${network_settings}/net.*) |
echo -e ${COLOREDSTAR}"Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..." |
332 |
do |
ifconfig ${iface} down |
333 |
interface=$(basename ${file} | sed s/net.//) |
evaluate_retval |
334 |
case "${interface}" in |
|
335 |
*~) ;; |
# shutdown dhcp-daemon |
336 |
*) |
if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]] |
337 |
#$network_devices/ifdown $interface |
then |
338 |
source ${network_settings}/net.${interface} || exit 1 |
echo -e ${COLOREDSTAR}"Stopping the dhcp-daemon ..." |
339 |
checkconfig |
${CURS_UP} |
340 |
echo -e ${COLOREDSTAR}"Bringing down interface ${COLBLUE}${interface}${COLDEFAULT} ..." |
${SET_WWCOL} |
341 |
ifconfig ${interface} down |
echo "[$(basename ${DHCP_PROG})]" |
342 |
evaluate_retval |
${DHCP_PROG} ${DHCP_STOP} "${iface}" |
343 |
|
evaluate_retval |
344 |
#shutdown dhcp-daemon |
fi |
|
if [ "${NETWORKING}" == dhcp ] |
|
|
then |
|
|
my_runlevel="`runlevel | cut -d ' ' -f2`" |
|
|
if [ -n "$(pidof ${DHCP_PROG})" ] |
|
|
then |
|
|
echo -e ${COLOREDSTAR}"Stopping the dhcp-daemon ..." |
|
|
${CURS_UP} |
|
|
${SET_WWCOL} |
|
|
echo "[$(basename ${DHCP_PROG})]" |
|
|
${DHCP_PROG} ${DHCP_STOP} |
|
|
evaluate_retval |
|
|
fi |
|
|
fi |
|
|
;; |
|
|
esac |
|
|
done |
|
345 |
|
|
346 |
|
# shutdown wpa_supplicant daemon |
347 |
|
if [[ -n $(pidof wpa_supplicant) ]] |
348 |
|
then |
349 |
|
killall wpa_supplicant |
350 |
|
fi |
351 |
|
done |
352 |
|
|
353 |
|
# remove state dir |
354 |
|
if [ -d /var/run/wpa_supplicant ] |
355 |
|
then |
356 |
|
rm -rf /var/run/wpa_supplicant |
357 |
|
fi |
358 |
|
} |
359 |
|
|
360 |
|
case $1 in |
361 |
|
start) |
362 |
|
networking_start |
363 |
|
update_svcstatus $1 |
364 |
|
splash svc_started "$(basename $0)" 0 |
365 |
|
;; |
366 |
|
|
367 |
|
stop) |
368 |
|
networking_stop |
369 |
update_svcstatus $1 |
update_svcstatus $1 |
370 |
splash svc_stopped "$(basename $0)" 0 |
splash svc_stopped "$(basename $0)" 0 |
371 |
;; |
;; |