1 |
#!/bin/bash |
#!/bin/bash |
2 |
# $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.10 2005-10-11 11:19:58 niro Exp $ |
# $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.13 2007-08-18 18:44:15 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 |
120 |
if [[ $(read_value ONBOOT ${file}) = yes ]] |
if [[ $(read_value ONBOOT ${file}) = yes ]] |
121 |
then |
then |
122 |
iface="$(basename ${file} | sed s/net.//)" |
iface="$(basename ${file} | sed s/net.//)" |
123 |
# exclude backup files |
# exclude backup files and exclude net.routes too |
124 |
case "${iface}" in |
case "${iface}" in |
125 |
*~) ;; |
*~) ;; |
126 |
|
*/net.routes) ;; |
127 |
*) devices="${devices} $(basename ${file} | sed s/net.//)" ;; |
*) devices="${devices} $(basename ${file} | sed s/net.//)" ;; |
128 |
esac |
esac |
129 |
fi |
fi |
197 |
${WIRELESS_WPA_CONFIG} |
${WIRELESS_WPA_CONFIG} |
198 |
fi |
fi |
199 |
|
|
200 |
|
# remove old state dir |
201 |
|
[ -d /var/run/wpa_supplicant ] && rm -rf /var/run/wpa_supplicant |
202 |
|
|
203 |
# now run the wpa_supplicant dameon |
# now run the wpa_supplicant dameon |
204 |
wpa_supplicant -B \ |
wpa_supplicant -B \ |
205 |
-D"${WIRELESS_WPA_DRIVER}" \ |
-D"${WIRELESS_WPA_DRIVER}" \ |
222 |
return 1 |
return 1 |
223 |
fi |
fi |
224 |
|
|
225 |
echo -e ${COLOREDSTAR}"Setting up wlan-ext for ${COLBLUE}${iface}${COLDEFAULT} ... " |
if [[ -n ${WIRELESS_BITRATE} ]] || |
226 |
|
[[ -n ${WIRELESS_CHANNEL} ]] || |
227 |
|
[[ -n ${WIRELESS_ESSID} ]] || |
228 |
|
[[ -n ${WIRELESS_FREQUENCY} ]] || |
229 |
|
[[ -n ${WIRELESS_MODE} ]] || |
230 |
|
[[ -n ${WIRELESS_NICK} ]] || |
231 |
|
[[ -n ${WIRELESS_AUTH_MODE} ]] |
232 |
|
then |
233 |
|
echo -e ${COLOREDSTAR}"Setting up wlan-ext for ${COLBLUE}${iface}${COLDEFAULT} ... " |
234 |
|
fi |
235 |
|
|
236 |
[[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}" |
[[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}" |
237 |
[[ -n ${WIRELESS_CHANNEL} ]] && iwconfig "${iface}" channel "${WIRELESS_CHANNEL}" |
[[ -n ${WIRELESS_CHANNEL} ]] && iwconfig "${iface}" channel "${WIRELESS_CHANNEL}" |
247 |
esac |
esac |
248 |
} |
} |
249 |
|
|
250 |
|
config_bridge_devices() |
251 |
|
{ |
252 |
|
local iface="$1" |
253 |
|
local method="$2" |
254 |
|
|
255 |
|
if [[ -z ${iface} ]] |
256 |
|
then |
257 |
|
echo "BRIDGE: no \$iface given. Aborting setup." |
258 |
|
return 1 |
259 |
|
fi |
260 |
|
|
261 |
|
if [[ -z ${method} ]] |
262 |
|
then |
263 |
|
echo "BRIDGE: no \$method given. Aborting setup." |
264 |
|
return 1 |
265 |
|
fi |
266 |
|
|
267 |
|
# first check for brctl |
268 |
|
if [[ -z $(which brctl) ]] |
269 |
|
then |
270 |
|
echo "brctl not found! Please install 'net-misc/bridge-utils'." |
271 |
|
return 1 |
272 |
|
fi |
273 |
|
|
274 |
|
# check the config |
275 |
|
if [[ -z ${BRIDGE_INTERFACE} ]] |
276 |
|
then |
277 |
|
echo "BRIDGE: no \$BRIDGE_INTERFACE given. Aborting setup." |
278 |
|
return 1 |
279 |
|
fi |
280 |
|
|
281 |
|
case ${method} in |
282 |
|
add) |
283 |
|
# setup the bridge device |
284 |
|
brctl addbr ${iface} |
285 |
|
# enter promiscous mode |
286 |
|
ifconfig ${BRIDGE_INTERFACE} 0.0.0.0 promisc |
287 |
|
# now setup the bridge |
288 |
|
brctl addif ${iface} ${BRIDGE_INTERFACE} |
289 |
|
;; |
290 |
|
remove) |
291 |
|
# bring the interface down |
292 |
|
ifconfig ${BRIDGE_INTERFACE} down |
293 |
|
# remove the interface from the bridge |
294 |
|
brctl delif ${iface} ${BRIDGE_INTERFACE} |
295 |
|
# bring the bridge down |
296 |
|
brctl delbr ${iface} |
297 |
|
;; |
298 |
|
esac |
299 |
|
|
300 |
|
# unset the bridge variable to be safe |
301 |
|
unset BRIDGE_INTERFACE |
302 |
|
# continue to setup generic networking |
303 |
|
} |
304 |
|
|
305 |
|
config_routes() |
306 |
|
{ |
307 |
|
local method="$1" |
308 |
|
local message |
309 |
|
|
310 |
|
# only add and del are allowed |
311 |
|
case ${method} in |
312 |
|
add) message="Adding route ${COLBLUE}${route}${COLDEFAULT} ..." ;; |
313 |
|
del) message="Removing route ${COLBLUE}${route}${COLDEFAULT} ..." ;; |
314 |
|
*) |
315 |
|
echo "config_routes: unsupported \$method '${method}'." |
316 |
|
exit 1 |
317 |
|
;; |
318 |
|
esac |
319 |
|
|
320 |
|
# adds/delete user routes |
321 |
|
if [[ -f /etc/conf.d/net.routes ]] |
322 |
|
then |
323 |
|
( cat /etc/conf.d/net.routes; echo ) | # make sure there is a LF at the end |
324 |
|
while read route |
325 |
|
do |
326 |
|
case "${route}" in |
327 |
|
\#*|"") continue ;; |
328 |
|
esac |
329 |
|
echo -e ${COLOREDSTAR}"${message}" |
330 |
|
route ${method} ${route} |
331 |
|
evaluate_retval |
332 |
|
done |
333 |
|
fi |
334 |
|
} |
335 |
|
|
336 |
networking_start() |
networking_start() |
337 |
{ |
{ |
338 |
local iface dns |
local iface dns routes ALL_INTERFACES |
339 |
|
|
340 |
|
if [[ -z $1 ]] |
341 |
|
then |
342 |
|
ALL_INTERFACES=$(onboot_interface_list ${network_settings}/net.*) |
343 |
|
else |
344 |
|
if [[ -e ${network_settings}/net.$1 ]] |
345 |
|
then |
346 |
|
ALL_INTERFACES="$1" |
347 |
|
else |
348 |
|
${FAILURE} |
349 |
|
echo "Interface $1 does not exist. Aborting" |
350 |
|
${NORMAL} |
351 |
|
exit 1 |
352 |
|
fi |
353 |
|
fi |
354 |
|
|
355 |
# get list of all devices |
# get list of all devices |
356 |
for iface in $(onboot_interface_list ${network_settings}/net.*) |
for iface in ${ALL_INTERFACES} |
357 |
do |
do |
358 |
# checkconfig |
# checkconfig |
359 |
source ${network_settings}/net.${iface} || exit 1 |
source ${network_settings}/net.${iface} || exit 1 |
367 |
evaluate_retval |
evaluate_retval |
368 |
fi |
fi |
369 |
|
|
370 |
|
# setup bridges |
371 |
|
if [[ ${iface} = br[0-9]* ]] |
372 |
|
then |
373 |
|
config_bridge_devices ${iface} add |
374 |
|
fi |
375 |
|
|
376 |
# activate the interface |
# activate the interface |
377 |
ifconfig "${iface}" up |
ifconfig "${iface}" up |
378 |
|
|
387 |
${CURS_UP} |
${CURS_UP} |
388 |
${SET_WWCOL} |
${SET_WWCOL} |
389 |
echo "[DHCP]" |
echo "[DHCP]" |
390 |
loadproc ${DHCP_PROG} ${DHCP_START} |
loadproc ${DHCP_PROG} ${DHCP_START} "${iface}" |
391 |
;; |
;; |
392 |
static|STATIC) |
static|STATIC) |
393 |
${CURS_UP} |
${CURS_UP} |
419 |
done |
done |
420 |
fi |
fi |
421 |
done |
done |
422 |
|
|
423 |
|
# setup user routes |
424 |
|
config_routes add |
425 |
} |
} |
426 |
|
|
427 |
networking_stop() |
networking_stop() |
428 |
{ |
{ |
429 |
|
if [[ -z $1 ]] |
430 |
|
then |
431 |
|
ALL_INTERFACES=$(onboot_interface_list ${network_settings}/net.*) |
432 |
|
else |
433 |
|
if [[ -e ${network_settings}/net.$1 ]] |
434 |
|
then |
435 |
|
ALL_INTERFACES="$1" |
436 |
|
else |
437 |
|
${FAILURE} |
438 |
|
echo "Interface $1 does not exist. Aborting" |
439 |
|
${NORMAL} |
440 |
|
exit 1 |
441 |
|
fi |
442 |
|
fi |
443 |
|
|
444 |
# get list of all devices |
# get list of all devices |
445 |
for iface in $(onboot_interface_list ${network_settings}/net.*) |
for iface in ${ALL_INTERFACES} |
446 |
do |
do |
447 |
source ${network_settings}/net.${iface} || exit 1 |
source ${network_settings}/net.${iface} || exit 1 |
448 |
checkconfig |
checkconfig |
458 |
ifconfig ${iface} down |
ifconfig ${iface} down |
459 |
evaluate_retval |
evaluate_retval |
460 |
|
|
461 |
|
# remove bridges |
462 |
|
if [[ ${iface} = br[0-9]* ]] |
463 |
|
then |
464 |
|
config_bridge_devices ${iface} remove |
465 |
|
fi |
466 |
|
|
467 |
# shutdown dhcp-daemon |
# shutdown dhcp-daemon |
468 |
if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]] |
if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]] |
469 |
then |
then |
481 |
killall wpa_supplicant |
killall wpa_supplicant |
482 |
fi |
fi |
483 |
done |
done |
484 |
|
|
485 |
# remove state dir |
# remove state dir |
486 |
if [ -d /var/run/wpa_supplicant ] |
if [ -d /var/run/wpa_supplicant ] |
487 |
then |
then |
488 |
rm -rf /var/run/wpa_supplicant |
rm -rf /var/run/wpa_supplicant |
489 |
fi |
fi |
490 |
|
|
491 |
|
# delete user routes |
492 |
|
config_routes del |
493 |
} |
} |
494 |
|
|
495 |
case $1 in |
case $1 in |
496 |
start) |
start) |
497 |
networking_start |
networking_start $2 |
498 |
update_svcstatus $1 |
update_svcstatus $1 |
499 |
splash svc_started "$(basename $0)" 0 |
splash svc_started "$(basename $0)" 0 |
500 |
;; |
;; |
501 |
|
|
502 |
stop) |
stop) |
503 |
networking_stop |
networking_stop $2 |
504 |
update_svcstatus $1 |
update_svcstatus $1 |
505 |
splash svc_stopped "$(basename $0)" 0 |
splash svc_stopped "$(basename $0)" 0 |
506 |
;; |
;; |
512 |
;; |
;; |
513 |
|
|
514 |
*) |
*) |
515 |
echo "Usage: $0 {start|stop|restart}" |
echo "Usage: $0 {start|stop|restart} [interface]" |
516 |
exit 1 |
exit 1 |
517 |
;; |
;; |
518 |
esac |
esac |