Annotation of /trunk/magellan-initscripts/etc/rc.d/init.d/network
Parent Directory | Revision Log
Revision 243 -
(hide annotations)
(download)
Tue Sep 20 20:22:05 2005 UTC (19 years ago) by niro
File size: 5085 byte(s)
Tue Sep 20 20:22:05 2005 UTC (19 years ago) by niro
File size: 5085 byte(s)
added basic wireless support
1 | niro | 2 | #!/bin/bash |
2 | niro | 243 | # $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.5 2005-09-20 20:22:05 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 | local iface | ||
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 | 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 | echo -e ${COLOREDSTAR}"Setting up default gateway ..." | ||
171 | niro | 243 | route add default gateway ${GATEWAY} metric 1 dev ${iface} |
172 | niro | 2 | evaluate_retval |
173 | fi | ||
174 | |||
175 | niro | 243 | # setup wlan extensions |
176 | if [ -x /usr/sbin/iwconfig ] | ||
177 | then | ||
178 | [[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}" | ||
179 | [[ -n ${WIRELESS_CHANNEL} ]] && iwconfig "${iface}" channel "${WIRELESS_CHANNEL}" | ||
180 | [[ -n ${WIRELESS_ESSID} ]] && iwconfig "${iface}" essid "${WIRELESS_ESSID}" | ||
181 | [[ -n ${WIRELESS_FREQUENCY} ]] && iwconfig "${iface}" freq "${WIRELESS_FREQUENCY}" | ||
182 | [[ -n ${WIRELESS_MODE} ]] && iwconfig "${iface}" mode "${WIRELESS_MODE}" | ||
183 | [[ -n ${WIRELESS_NICK} ]] && iwconfig "${iface}" nick "${WIRELESS_NICK}" | ||
184 | [[ -n ${WIRELESS_AUTH_MODE} ]] && iwconfig "${iface}" enc "${WIRELESS_AUTH_MODE}" | ||
185 | [[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}" | ||
186 | [[ -n ${WIRELESS_KEY} ]] && iwconfig "${iface}" key "${WIRELESS_KEY}" | ||
187 | [[ -n ${WIRELESS_KEY_ASCII} ]] && iwconfig "${iface}" key s:"${WIRELESS_KEY_ASCII}" | ||
188 | fi | ||
189 | done | ||
190 | } | ||
191 | niro | 2 | |
192 | niro | 243 | networking_stop() |
193 | { | ||
194 | # get list of all devices | ||
195 | for iface in $(onboot_interface_list ${network_settings}/net.*) | ||
196 | do | ||
197 | source ${network_settings}/net.${iface} || exit 1 | ||
198 | checkconfig | ||
199 | |||
200 | if [[ -n ${GATEWAY} ]] | ||
201 | niro | 2 | then |
202 | echo -e ${COLOREDSTAR}"Removing default gateway ..." | ||
203 | route del -net default | ||
204 | evaluate_retval | ||
205 | fi | ||
206 | |||
207 | niro | 243 | echo -e ${COLOREDSTAR}"Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..." |
208 | ifconfig ${iface} down | ||
209 | evaluate_retval | ||
210 | niro | 2 | |
211 | niro | 243 | # shutdown dhcp-daemon |
212 | if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]] | ||
213 | then | ||
214 | echo -e ${COLOREDSTAR}"Stopping the dhcp-daemon ..." | ||
215 | ${CURS_UP} | ||
216 | ${SET_WWCOL} | ||
217 | echo "[$(basename ${DHCP_PROG})]" | ||
218 | ${DHCP_PROG} ${DHCP_STOP} | ||
219 | evaluate_retval | ||
220 | fi | ||
221 | done | ||
222 | } | ||
223 | niro | 2 | |
224 | niro | 243 | case $1 in |
225 | start) | ||
226 | networking_start | ||
227 | niro | 2 | update_svcstatus $1 |
228 | niro | 243 | splash svc_started "$(basename $0)" 0 |
229 | ;; | ||
230 | |||
231 | stop) | ||
232 | networking_stop | ||
233 | update_svcstatus $1 | ||
234 | niro | 2 | splash svc_stopped "$(basename $0)" 0 |
235 | ;; | ||
236 | |||
237 | restart) | ||
238 | $0 stop | ||
239 | sleep 1 | ||
240 | $0 start | ||
241 | ;; | ||
242 | |||
243 | *) | ||
244 | echo "Usage: $0 {start|stop|restart}" | ||
245 | exit 1 | ||
246 | ;; | ||
247 | esac |
Properties
Name | Value |
---|---|
svn:executable | * |