Magellan Linux

Annotation of /trunk/initscripts/sysvinit/rc/network

Parent Directory Parent Directory | Revision Log Revision Log


Revision 245 - (hide annotations) (download)
Thu Sep 22 22:15:38 2005 UTC (18 years, 7 months ago) by niro
Original Path: trunk/magellan-initscripts/etc/rc.d/init.d/network
File size: 5490 byte(s)
- fixed non needed gateway if
- added mutiple nameserver support

1 niro 2 #!/bin/bash
2 niro 245 # $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.6 2005-09-22 22:15:38 niro Exp $
3 niro 2
4     #%rlevels: 0:k 1:k 2:k 3:s 4:s 5:s 6:k
5     #%start: 20
6     #%stop: 80
7    
8     #deps
9     #%needs:
10     #%before:
11     #%after:
12    
13     source /etc/sysconfig/rc
14 niro 20 source ${rc_functions}
15 niro 2
16 niro 243 # 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 niro 20 if [ -z "${NETWORKING}" ]
72 niro 2 then
73     echo "NETWORKING missing in net.${interface}, aborted"
74     exit 1
75     fi
76    
77 niro 20 case "${NETWORKING}" in
78 niro 2 static)
79 niro 20 if [ -z "${IP}" ]
80 niro 2 then
81     echo "IP missing in net.${interface}, aborted"
82     exit 1
83     fi
84    
85 niro 20 if [ -z "${NETMASK}" ]
86 niro 2 then
87     echo -n "NETMASK missing in net.${interface}, "
88     echo "using 255.255.255.0"
89     NETMASK=255.255.255.0
90     fi
91    
92 niro 20 if [ -z "${BROADCAST}" ]
93 niro 2 then
94     echo -n "BROADCAST missing in net.${interface}, "
95     echo "using default address"
96     fi
97     ;;
98 niro 20
99 niro 2 dhcp)
100 niro 20 if [ -z "${DHCP_PROG}" ]
101 niro 2 then
102     echo "DHCP_PROG missing in net.${interface}, aborted"
103     exit 1
104     fi
105     ;;
106 niro 20
107 niro 2 esac
108     }
109    
110 niro 243 # onboot_interface_list /path/to/files*
111     onboot_interface_list()
112     {
113     local file
114     local devices
115     local iface
116 niro 2
117 niro 243 # 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 niro 2 *~) ;;
126 niro 243 *) devices="${devices} $(basename ${file} | sed s/net.//)" ;;
127     esac
128     fi
129     done
130 niro 181
131 niro 243 echo "${devices}"
132     }
133 niro 181
134 niro 243 networking_start()
135     {
136 niro 245 local iface dns
137 niro 243
138     # get list of all devices
139     for iface in $(onboot_interface_list ${network_settings}/net.*)
140     do
141     # checkconfig
142     source ${network_settings}/net.${iface} || exit 1
143     checkconfig
144    
145     echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..."
146    
147     # setup mac
148     [ -n "${FORCE_MAC_TO}" ] && ifconfig ${iface} hw ether "${FORCE_MAC_TO}"
149    
150     # setup static or dhcp
151     case ${NETWORKING} in
152     dhcp|DHCP)
153     ${CURS_UP}
154     ${SET_WWCOL}
155     echo "[DHCP]"
156     loadproc ${DHCP_PROG} ${DHCP_START}
157 niro 2 ;;
158 niro 243 static|STATIC)
159     ${CURS_UP}
160     ${SET_WWCOL}
161     echo "[STATIC]"
162     ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}"
163     evaluate_retval
164     ;;
165     esac
166 niro 2
167 niro 243 # setup def gw
168     if [[ -n ${GATEWAY} ]]
169 niro 2 then
170 niro 245 echo -e ${COLOREDSTAR}"Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..."
171 niro 243 route add default gateway ${GATEWAY} metric 1 dev ${iface}
172 niro 2 evaluate_retval
173     fi
174    
175 niro 245 # setup /etc/resolv.conf
176     if [[ -n ${NAMESERVER} ]]
177     then
178     echo -e ${COLOREDSTAR}"Setting up all nameserver for ${COLBLUE}${iface}${COLDEFAULT} ..."
179    
180     # whipe out the old one
181     echo "# Generated by the magellan-initscripts for ${iface}" > /etc/resolv.conf
182     for dns in ${NAMESERVER}
183     do
184     echo "nameserver ${dns}" >> /etc/resolv.conf
185     done
186     fi
187    
188 niro 243 # setup wlan extensions
189     if [ -x /usr/sbin/iwconfig ]
190     then
191     [[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}"
192     [[ -n ${WIRELESS_CHANNEL} ]] && iwconfig "${iface}" channel "${WIRELESS_CHANNEL}"
193     [[ -n ${WIRELESS_ESSID} ]] && iwconfig "${iface}" essid "${WIRELESS_ESSID}"
194     [[ -n ${WIRELESS_FREQUENCY} ]] && iwconfig "${iface}" freq "${WIRELESS_FREQUENCY}"
195     [[ -n ${WIRELESS_MODE} ]] && iwconfig "${iface}" mode "${WIRELESS_MODE}"
196     [[ -n ${WIRELESS_NICK} ]] && iwconfig "${iface}" nick "${WIRELESS_NICK}"
197     [[ -n ${WIRELESS_AUTH_MODE} ]] && iwconfig "${iface}" enc "${WIRELESS_AUTH_MODE}"
198     [[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}"
199     [[ -n ${WIRELESS_KEY} ]] && iwconfig "${iface}" key "${WIRELESS_KEY}"
200     [[ -n ${WIRELESS_KEY_ASCII} ]] && iwconfig "${iface}" key s:"${WIRELESS_KEY_ASCII}"
201     fi
202     done
203     }
204 niro 2
205 niro 243 networking_stop()
206     {
207     # get list of all devices
208     for iface in $(onboot_interface_list ${network_settings}/net.*)
209     do
210     source ${network_settings}/net.${iface} || exit 1
211     checkconfig
212    
213     if [[ -n ${GATEWAY} ]]
214 niro 2 then
215     echo -e ${COLOREDSTAR}"Removing default gateway ..."
216     route del -net default
217     evaluate_retval
218     fi
219    
220 niro 243 echo -e ${COLOREDSTAR}"Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..."
221     ifconfig ${iface} down
222     evaluate_retval
223 niro 2
224 niro 243 # shutdown dhcp-daemon
225     if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]]
226     then
227     echo -e ${COLOREDSTAR}"Stopping the dhcp-daemon ..."
228     ${CURS_UP}
229     ${SET_WWCOL}
230     echo "[$(basename ${DHCP_PROG})]"
231     ${DHCP_PROG} ${DHCP_STOP}
232     evaluate_retval
233     fi
234     done
235     }
236 niro 2
237 niro 243 case $1 in
238     start)
239     networking_start
240 niro 2 update_svcstatus $1
241 niro 243 splash svc_started "$(basename $0)" 0
242     ;;
243    
244     stop)
245     networking_stop
246     update_svcstatus $1
247 niro 2 splash svc_stopped "$(basename $0)" 0
248     ;;
249    
250     restart)
251     $0 stop
252     sleep 1
253     $0 start
254     ;;
255    
256     *)
257     echo "Usage: $0 {start|stop|restart}"
258     exit 1
259     ;;
260     esac

Properties

Name Value
svn:executable *