1 |
#!/bin/bash |
#!/bin/bash |
2 |
# $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 $ |
# $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.19 2008-12-22 22:01: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 |
10 |
#%before: |
#%before: |
11 |
#%after: |
#%after: |
12 |
|
|
13 |
source /etc/sysconfig/rc |
source /etc/conf.d/rc |
14 |
source ${rc_functions} |
source ${rc_functions} |
15 |
|
|
16 |
# read values from files |
# read values from files |
24 |
# global |
# global |
25 |
local ONBOOT |
local ONBOOT |
26 |
local NETWORKING |
local NETWORKING |
27 |
|
|
28 |
# static |
# static |
29 |
local IP |
local IP |
30 |
local NETMASK |
local NETMASK |
60 |
local WIRELESS_NICK |
local WIRELESS_NICK |
61 |
local WIRELESS_NWID |
local WIRELESS_NWID |
62 |
local WIRELESS_POWER |
local WIRELESS_POWER |
63 |
|
local WIRELESS_WPA_DRIVER |
64 |
|
|
65 |
|
local BRIDGE_INTERFACES |
66 |
|
local BRIDGE_STP |
67 |
|
|
68 |
source ${file} |
source ${file} |
69 |
eval value=\$$(echo ${var}) |
eval value=\$$(echo ${var}) |
72 |
|
|
73 |
checkconfig() |
checkconfig() |
74 |
{ |
{ |
75 |
if [ -z "${NETWORKING}" ] |
if [[ -z ${NETWORKING} ]] |
76 |
then |
then |
77 |
echo "NETWORKING missing in net.${interface}, aborted" |
echo "NETWORKING missing in net.${interface}, aborted" |
78 |
exit 1 |
exit 1 |
80 |
|
|
81 |
case "${NETWORKING}" in |
case "${NETWORKING}" in |
82 |
static) |
static) |
83 |
if [ -z "${IP}" ] |
if [[ -z ${IP} ]] |
84 |
then |
then |
85 |
echo "IP missing in net.${interface}, aborted" |
echo "IP missing in net.${interface}, aborted" |
86 |
exit 1 |
exit 1 |
87 |
fi |
fi |
88 |
|
|
89 |
if [ -z "${NETMASK}" ] |
if [[ -z ${NETMASK} ]] |
90 |
then |
then |
91 |
echo -n "NETMASK missing in net.${interface}, " |
echo -n "NETMASK missing in net.${interface}, " |
92 |
echo "using 255.255.255.0" |
echo "using 255.255.255.0" |
93 |
NETMASK=255.255.255.0 |
NETMASK=255.255.255.0 |
94 |
fi |
fi |
95 |
|
|
96 |
if [ -z "${BROADCAST}" ] |
if [[ -z ${BROADCAST} ]] |
97 |
then |
then |
98 |
echo -n "BROADCAST missing in net.${interface}, " |
echo -n "BROADCAST missing in net.${interface}, " |
99 |
echo "using default address" |
echo "using default address" |
101 |
;; |
;; |
102 |
|
|
103 |
dhcp) |
dhcp) |
104 |
if [ -z "${DHCP_PROG}" ] |
if [[ -z ${DHCP_PROG} ]] |
105 |
then |
then |
106 |
echo "DHCP_PROG missing in net.${interface}, aborted" |
echo "DHCP_PROG missing in net.${interface}, aborted" |
107 |
exit 1 |
exit 1 |
195 |
# write default cfg from skeleton |
# write default cfg from skeleton |
196 |
cat ${WIRELESS_WPA_SKEL} > ${WIRELESS_WPA_CONFIG} |
cat ${WIRELESS_WPA_SKEL} > ${WIRELESS_WPA_CONFIG} |
197 |
|
|
198 |
|
local wpa_proto |
199 |
|
case ${WIRELESS_AUTH_MODE} in |
200 |
|
wpa) wpa_proto="WPA" ;; |
201 |
|
wpa2) wpa_proto="WPA2" ;; |
202 |
|
esac |
203 |
|
|
204 |
# setup the network entry |
# setup the network entry |
205 |
sed -i -e "s:@WIRELESS_ESSID@:${WIRELESS_ESSID}:g" \ |
sed -i -e "s:@WIRELESS_ESSID@:${WIRELESS_ESSID}:g" \ |
206 |
-e "s:@WIRELESS_KEY@:${WIRELESS_KEY}:g" \ |
-e "s:@WIRELESS_KEY@:${WIRELESS_KEY_ASCII}:g" \ |
207 |
|
-e "s:@WIRELESS_AUTH_MODE@:${wpa_proto}:g" \ |
208 |
${WIRELESS_WPA_CONFIG} |
${WIRELESS_WPA_CONFIG} |
209 |
fi |
fi |
210 |
|
|
252 |
[[ -n ${WIRELESS_NICK} ]] && iwconfig "${iface}" nick "${WIRELESS_NICK}" |
[[ -n ${WIRELESS_NICK} ]] && iwconfig "${iface}" nick "${WIRELESS_NICK}" |
253 |
|
|
254 |
case "${WIRELESS_AUTH_MODE}" in |
case "${WIRELESS_AUTH_MODE}" in |
255 |
wpa) config_wireless_wpa "${iface}" ;; |
wpa|wpa2) config_wireless_wpa "${iface}" ;; |
256 |
wep|on) config_wireless_wep "${iface}" ;; |
wep|on) config_wireless_wep "${iface}" ;; |
257 |
off) iwconfig "${iface}" enc off ;; |
off) iwconfig "${iface}" enc off ;; |
258 |
esac |
esac |
259 |
} |
} |
260 |
|
|
262 |
{ |
{ |
263 |
local iface="$1" |
local iface="$1" |
264 |
local method="$2" |
local method="$2" |
265 |
|
local bport |
266 |
|
|
267 |
if [[ -z ${iface} ]] |
if [[ -z ${iface} ]] |
268 |
then |
then |
284 |
fi |
fi |
285 |
|
|
286 |
# check the config |
# check the config |
287 |
if [[ -z ${BRIDGE_INTERFACE} ]] |
if [[ -z ${BRIDGE_INTERFACES} ]] |
288 |
then |
then |
289 |
echo "BRIDGE: no \$BRIDGE_INTERFACE given. Aborting setup." |
echo "BRIDGE: no \$BRIDGE_INTERFACES given. Aborting setup." |
290 |
return 1 |
return 1 |
291 |
fi |
fi |
292 |
|
|
294 |
add) |
add) |
295 |
# setup the bridge device |
# setup the bridge device |
296 |
brctl addbr ${iface} |
brctl addbr ${iface} |
297 |
# enter promiscous mode |
for bport in ${BRIDGE_INTERFACES} |
298 |
ifconfig ${BRIDGE_INTERFACE} 0.0.0.0 promisc |
do |
299 |
# now setup the bridge |
# enter promiscous mode |
300 |
brctl addif ${iface} ${BRIDGE_INTERFACE} |
ifconfig ${bport} 0.0.0.0 promisc |
301 |
|
# now setup the bridge |
302 |
|
brctl addif ${iface} ${bport} |
303 |
|
done |
304 |
|
# enable spanning-tree protocol |
305 |
|
case ${BRIDGE_STP} in |
306 |
|
on|off) brctl stp ${iface} ${BRIDGE_STP} ;; |
307 |
|
*) echo "BRIDGE: unkown value \$BRIDGE_STP='$BRIDGE_STP'."; return 1 ;; |
308 |
|
esac |
309 |
;; |
;; |
310 |
|
|
311 |
remove) |
remove) |
312 |
# bring the interface down |
for bport in ${BRIDGE_INTERFACE} |
313 |
ifconfig ${BRIDGE_INTERFACE} down |
do |
314 |
# remove the interface from the bridge |
# bring the interface down |
315 |
brctl delif ${iface} ${BRIDGE_INTERFACE} |
ifconfig ${bport} down |
316 |
|
# remove the interface from the bridge |
317 |
|
brctl delif ${iface} ${bport} |
318 |
|
done |
319 |
# bring the bridge down |
# bring the bridge down |
320 |
brctl delbr ${iface} |
brctl delbr ${iface} |
321 |
;; |
;; |
322 |
esac |
esac |
323 |
|
|
324 |
# unset the bridge variable to be safe |
# unset the bridge variable to be safe |
325 |
unset BRIDGE_INTERFACE |
unset BRIDGE_INTERFACES |
326 |
# continue to setup generic networking |
# continue to setup generic networking |
327 |
} |
} |
328 |
|
|
397 |
config_bridge_devices ${iface} add |
config_bridge_devices ${iface} add |
398 |
fi |
fi |
399 |
|
|
|
# activate the interface |
|
|
ifconfig "${iface}" up |
|
|
|
|
400 |
# now configure wireless_extensions |
# now configure wireless_extensions |
401 |
[ -x /usr/sbin/iwconfig ] && setup_wireless_extensions "${iface}" |
[ -x /usr/sbin/iwconfig ] && setup_wireless_extensions "${iface}" |
402 |
|
|
403 |
echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..." |
echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..." |
404 |
|
|
405 |
|
# activate the interface |
406 |
|
ifconfig "${iface}" up |
407 |
|
|
408 |
# setup static or dhcp |
# setup static or dhcp |
409 |
case ${NETWORKING} in |
case ${NETWORKING} in |
410 |
dhcp|DHCP) |
dhcp|DHCP) |
428 |
echo -e ${COLOREDSTAR}"Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..." |
echo -e ${COLOREDSTAR}"Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..." |
429 |
route add default gateway ${GATEWAY} metric 1 dev ${iface} |
route add default gateway ${GATEWAY} metric 1 dev ${iface} |
430 |
evaluate_retval |
evaluate_retval |
431 |
|
|
432 |
|
unset GATEWAY |
433 |
fi |
fi |
434 |
|
|
435 |
# setup /etc/resolv.conf |
# setup /etc/resolv.conf |
443 |
do |
do |
444 |
echo "nameserver ${dns}" >> /etc/resolv.conf |
echo "nameserver ${dns}" >> /etc/resolv.conf |
445 |
done |
done |
446 |
|
|
447 |
|
unset NAMESERVER |
448 |
fi |
fi |
449 |
done |
done |
450 |
|
|