Contents of /trunk/magellan-initscripts/etc/rc.d/init.d/network
Parent Directory
|
Revision Log
Revision 265 -
(show annotations)
(download)
Sun Oct 9 22:31:13 2005 UTC (18 years, 7 months ago) by niro
File size: 5681 byte(s)
Sun Oct 9 22:31:13 2005 UTC (18 years, 7 months ago) by niro
File size: 5681 byte(s)
fixed a typo
1 | #!/bin/bash |
2 | # $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.8 2005-10-09 22:31:13 niro Exp $ |
3 | |
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 | source ${rc_functions} |
15 | |
16 | # 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}" ] |
72 | then |
73 | echo "NETWORKING missing in net.${interface}, aborted" |
74 | exit 1 |
75 | fi |
76 | |
77 | case "${NETWORKING}" in |
78 | static) |
79 | if [ -z "${IP}" ] |
80 | then |
81 | echo "IP missing in net.${interface}, aborted" |
82 | exit 1 |
83 | fi |
84 | |
85 | if [ -z "${NETMASK}" ] |
86 | 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 | if [ -z "${BROADCAST}" ] |
93 | then |
94 | echo -n "BROADCAST missing in net.${interface}, " |
95 | echo "using default address" |
96 | fi |
97 | ;; |
98 | |
99 | dhcp) |
100 | if [ -z "${DHCP_PROG}" ] |
101 | then |
102 | echo "DHCP_PROG missing in net.${interface}, aborted" |
103 | exit 1 |
104 | fi |
105 | ;; |
106 | |
107 | esac |
108 | } |
109 | |
110 | # onboot_interface_list /path/to/files* |
111 | onboot_interface_list() |
112 | { |
113 | local file |
114 | local devices |
115 | local iface |
116 | |
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.//)" ;; |
127 | esac |
128 | fi |
129 | done |
130 | |
131 | echo "${devices}" |
132 | } |
133 | |
134 | networking_start() |
135 | { |
136 | local iface dns |
137 | |
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 | ;; |
158 | 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 | |
167 | # setup def gw |
168 | if [[ -n ${GATEWAY} ]] |
169 | then |
170 | echo -e ${COLOREDSTAR}"Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..." |
171 | route add default gateway ${GATEWAY} metric 1 dev ${iface} |
172 | evaluate_retval |
173 | fi |
174 | |
175 | # 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 | # 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 | if [[ -n ${WIRELESS_AUTH_MODE} ]] |
198 | then |
199 | case ${WIRELESS_AUTH_MODE} in |
200 | wpa) echo "Using wpa";; |
201 | wep|on) iwconfig "${iface}" enc on ;; |
202 | off) iwconfig "${iface}" enc off ;; |
203 | *) echo "Unkown Wireless_Auth_Mode '${WIRELESS_AUTH_MODE}'." ;; |
204 | esac |
205 | fi |
206 | [[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}" |
207 | [[ -n ${WIRELESS_KEY} ]] && iwconfig "${iface}" key "${WIRELESS_KEY}" |
208 | [[ -n ${WIRELESS_KEY_ASCII} ]] && iwconfig "${iface}" key s:"${WIRELESS_KEY_ASCII}" |
209 | fi |
210 | done |
211 | } |
212 | |
213 | networking_stop() |
214 | { |
215 | # get list of all devices |
216 | for iface in $(onboot_interface_list ${network_settings}/net.*) |
217 | do |
218 | source ${network_settings}/net.${iface} || exit 1 |
219 | checkconfig |
220 | |
221 | if [[ -n ${GATEWAY} ]] |
222 | then |
223 | echo -e ${COLOREDSTAR}"Removing default gateway ..." |
224 | route del -net default |
225 | evaluate_retval |
226 | fi |
227 | |
228 | echo -e ${COLOREDSTAR}"Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..." |
229 | ifconfig ${iface} down |
230 | evaluate_retval |
231 | |
232 | # shutdown dhcp-daemon |
233 | if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]] |
234 | then |
235 | echo -e ${COLOREDSTAR}"Stopping the dhcp-daemon ..." |
236 | ${CURS_UP} |
237 | ${SET_WWCOL} |
238 | echo "[$(basename ${DHCP_PROG})]" |
239 | ${DHCP_PROG} ${DHCP_STOP} |
240 | evaluate_retval |
241 | fi |
242 | done |
243 | } |
244 | |
245 | case $1 in |
246 | start) |
247 | networking_start |
248 | update_svcstatus $1 |
249 | splash svc_started "$(basename $0)" 0 |
250 | ;; |
251 | |
252 | stop) |
253 | networking_stop |
254 | update_svcstatus $1 |
255 | splash svc_stopped "$(basename $0)" 0 |
256 | ;; |
257 | |
258 | restart) |
259 | $0 stop |
260 | sleep 1 |
261 | $0 start |
262 | ;; |
263 | |
264 | *) |
265 | echo "Usage: $0 {start|stop|restart}" |
266 | exit 1 |
267 | ;; |
268 | esac |
Properties
Name | Value |
---|---|
svn:executable | * |