Contents of /alx-src/trunk/tinyalxconfig-ng/functions/config_network.sh
Parent Directory | Revision Log
Revision 454 -
(show annotations)
(download)
(as text)
Thu Jun 5 19:08:36 2008 UTC (15 years, 10 months ago) by niro
File MIME type: application/x-sh
File size: 9520 byte(s)
Thu Jun 5 19:08:36 2008 UTC (15 years, 10 months ago) by niro
File MIME type: application/x-sh
File size: 9520 byte(s)
- multiple device support - make use of new the mysql-function evaluate_table() - do not split in a retrieve information and configure function; doing it directly
1 | # $Header: /home/cvsd/alx-cvs/alx-src/tinyalxconfig-ng/functions/config_network.sh,v 1.8 2008-06-05 19:08:36 niro Exp $ |
2 | # configures networkin on the host via mysql db settings |
3 | |
4 | get_network_settings_old() |
5 | { |
6 | local all_ifaces |
7 | local iface |
8 | local x |
9 | |
10 | # get a list of all interfaces |
11 | all_ifaces=$(mysqldo "select iface from cfg_interface where serial='${ALX_SERIAL}'") |
12 | |
13 | # retrieve hostname and domain information |
14 | evaluate_table cfg_network |
15 | export ALX_HOSTNAME="${cfg_network_hostname}" |
16 | export ALX_DOMAIN="${cfg_network_domain}" |
17 | |
18 | # now build a multi-ranged "array" for all interface settings |
19 | declare -i x=0 |
20 | |
21 | for iface in ${all_ifaces} |
22 | do |
23 | evaluate_table |
24 | all=$(mysqldo "select iface, |
25 | hostname, |
26 | module, |
27 | domain, |
28 | networking, |
29 | ip, |
30 | netmask, |
31 | dns, |
32 | gateway, |
33 | broadcast |
34 | from cfg_network where serial='${ALX_SERIAL}'") |
35 | |
36 | # split'em up and put 'em in an array |
37 | declare -i i=0 |
38 | for x in ${all} |
39 | do |
40 | DB_NETWORK[${i}]="${x}" |
41 | ((i++)) |
42 | done |
43 | |
44 | # and now put in usable var names and export them systemwide |
45 | export ALX_IFACE="${DB_NETWORK[0]:=NULL}" |
46 | export ALX_HOSTNAME="${DB_NETWORK[1]:=NULL}" |
47 | export ALX_MODULE="${DB_NETWORK[2]:=NULL}" |
48 | export ALX_DOMAIN="${DB_NETWORK[3]:=NULL}" |
49 | export ALX_NETWORKING="${DB_NETWORK[4]:=NULL}" |
50 | export ALX_IP="${DB_NETWORK[5]:=NULL}" |
51 | export ALX_NETMASK="${DB_NETWORK[6]:=NULL}" |
52 | export ALX_DNS="${DB_NETWORK[7]:=NULL}" |
53 | export ALX_GATEWAY="${DB_NETWORK[8]:=NULL}" |
54 | export ALX_BROADCAST="${DB_NETWORK[9]:=NULL}" |
55 | |
56 | # the new mac address hack |
57 | export ALX_FORCEMACTO=$(mysqldo "select forcemacto from cfg_network where serial='${ALX_SERIAL}'") |
58 | |
59 | # wireless extensions |
60 | export ALX_WIRELESS_BITRATE=$(mysqldo "select wireless_bitrate from cfg_network where serial='${ALX_SERIAL}'") |
61 | export ALX_WIRELESS_CHANNEL=$(mysqldo "select wireless_channel from cfg_network where serial='${ALX_SERIAL}'") |
62 | export ALX_WIRELESS_ESSID=$(mysqldo "select wireless_essid from cfg_network where serial='${ALX_SERIAL}'") |
63 | export ALX_WIRELESS_FREQUENCY=$(mysqldo "select wireless_frequency from cfg_network where serial='${ALX_SERIAL}'") |
64 | export ALX_WIRELESS_MODE=$(mysqldo "select wireless_mode from cfg_network where serial='${ALX_SERIAL}'") |
65 | export ALX_WIRELESS_NICK=$(mysqldo "select wireless_nick from cfg_network where serial='${ALX_SERIAL}'") |
66 | export ALX_WIRELESS_AUTH_MODE=$(mysqldo "select wireless_auth_mode from cfg_network where serial='${ALX_SERIAL}'") |
67 | export ALX_WIRELESS_KEY_LENGTH=$(mysqldo "select wireless_key_length from cfg_network where serial='${ALX_SERIAL}'") |
68 | export ALX_WIRELESS_KEY=$(mysqldo "select wireless_key from cfg_network where serial='${ALX_SERIAL}'") |
69 | export ALX_WIRELESS_KEY_ASCII=$(mysqldo "select wireless_key_ascii from cfg_network where serial='${ALX_SERIAL}'") |
70 | |
71 | done |
72 | } |
73 | |
74 | check_network_settings_old() |
75 | { |
76 | # sanity checks |
77 | [[ ${ALX_IFACE} = NULL ]] && return 1 |
78 | [[ ${ALX_HOSTNAME} = NULL ]] && return 1 |
79 | [[ ${ALX_NETWORKING} = NULL ]] && return 1 |
80 | |
81 | # if we get here, everything is ok |
82 | return 0 |
83 | } |
84 | |
85 | config_networking_old() |
86 | { |
87 | local iface |
88 | |
89 | # first of all get the vars |
90 | get_network_settings |
91 | if ! check_network_settings |
92 | then |
93 | echo -e "${COLYELLOW}Could not retrieve network settings, doing nothing ...${COLDEFAULT}" |
94 | return 1 |
95 | fi |
96 | |
97 | # get the right nic |
98 | if [[ -z ${ALX_IFACE} ]] || [[ ${ALX_IFACE} = NULL ]] |
99 | then |
100 | # default is 'eth0' |
101 | iface="eth0" |
102 | else |
103 | iface="${ALX_IFACE}" |
104 | fi |
105 | |
106 | # remove all old nics and modules configs |
107 | find /etc/conf.d -type f -name 'net.*' | xargs rm |
108 | |
109 | # update confd-networking default iface |
110 | [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH} |
111 | echo "${iface}" > ${SETTINGSPATH}/confd-networking |
112 | |
113 | # hostname && hosts |
114 | echo "${ALX_HOSTNAME}" > /etc/hostname |
115 | echo -e "127.0.0.1\tlocalhost.${ALX_DOMAIN}\tlocalhost\t${ALX_HOSTNAME}" > /etc/hosts |
116 | |
117 | # network devices |
118 | |
119 | # always on boot |
120 | echo 'ONBOOT="yes"' > /etc/conf.d/net.${iface} |
121 | echo "NETWORKING=\"${ALX_NETWORKING}\"" >> /etc/conf.d/net.${iface} |
122 | |
123 | case ${ALX_NETWORKING} in |
124 | dhcp|DHCP) |
125 | echo 'DHCP_PROG="/sbin/udhcpc"' >> /etc/conf.d/net.${iface} |
126 | # timeout after 10 seconds and quit after retrieving a lease |
127 | echo 'DHCP_START="-t 10 -q"' >> /etc/conf.d/net.${iface} |
128 | ;; |
129 | |
130 | static|STATIC) |
131 | # add hostname with valid ip to hosts |
132 | echo -e "${ALX_IP}\t${ALX_HOSTNAME}.${ALX_DOMAIN}\t${ALX_HOSTNAME}" >> /etc/hosts |
133 | echo "IP=\"${ALX_IP}\"" >> /etc/conf.d/net.${iface} |
134 | echo "NETMASK=\"${ALX_NETMASK}\"" >> /etc/conf.d/net.${iface} |
135 | echo "BROADCAST=\"${ALX_BROADCAST}\"" >> /etc/conf.d/net.${iface} |
136 | ;; |
137 | esac |
138 | |
139 | # gateway or gateway overrides |
140 | if [[ ${ALX_GATEWAY} != NULL ]] |
141 | then |
142 | echo "GATEWAY=\"${ALX_GATEWAY}\"" >> /etc/conf.d/net.${iface} |
143 | echo "GATEWAY_IF=\"${iface}\"" >> /etc/conf.d/net.${iface} |
144 | fi |
145 | |
146 | # force mac address override |
147 | if [[ ${ALX_FORCEMACTO} != NULL ]] |
148 | then |
149 | echo "FORCE_MAC_TO=\"${ALX_FORCEMACTO}\"" >> /etc/conf.d/net.${iface} |
150 | fi |
151 | |
152 | # nameserver or nameserver overrides |
153 | if [[ ${ALX_DNS} != NULL ]] |
154 | then |
155 | echo "nameserver ${ALX_DNS}" > /etc/resolv.conf |
156 | fi |
157 | |
158 | # wireless extensions |
159 | local value |
160 | local var |
161 | for var in ALX_WIRELESS_BITRATE \ |
162 | ALX_WIRELESS_CHANNEL \ |
163 | ALX_WIRELESS_ESSID \ |
164 | ALX_WIRELESS_FREQUENCY \ |
165 | ALX_WIRELESS_MODE \ |
166 | ALX_WIRELESS_NICK \ |
167 | ALX_WIRELESS_AUTH_MODE \ |
168 | ALX_WIRELESS_KEY_LENGTH \ |
169 | ALX_WIRELESS_KEY \ |
170 | ALX_WIRELESS_KEY_ASCII |
171 | do |
172 | # get the value of $var |
173 | eval value=\$$(echo ${var}) |
174 | |
175 | # write it only if not empty |
176 | if [[ -n ${value} ]] && [[ ${value} != NULL ]] |
177 | then |
178 | # remove ALX_ from var |
179 | echo "${var/ALX_/}=\"${value}\"" >> /etc/conf.d/net.${iface} |
180 | fi |
181 | |
182 | # clear value |
183 | unset value |
184 | done |
185 | |
186 | # setup wpa-driver (only zydas atm) |
187 | [[ ${ALX_MODULE} = zd1211 ]] && \ |
188 | echo "WIRELESS_WPA_DRIVER=zydas" >> /etc/conf.d/net.${iface} |
189 | |
190 | # unset all vars |
191 | unset ALX_HOSTNAME |
192 | unset ALX_MODULE |
193 | unset ALX_DOMAIN |
194 | unset ALX_NETWORKING |
195 | unset ALX_IP |
196 | unset ALX_NETMASK |
197 | unset ALX_DNS |
198 | unset ALX_GATEWAY |
199 | unset ALX_BROADCAST |
200 | unset ALX_FORCEMACTO |
201 | unset ALX_IFACE |
202 | unset ALX_WIRELESS_BITRATE |
203 | unset ALX_WIRELESS_CHANNEL |
204 | unset ALX_WIRELESS_ESSID |
205 | unset ALX_WIRELESS_FREQUENCY |
206 | unset ALX_WIRELESS_MODE |
207 | unset ALX_WIRELESS_NICK |
208 | unset ALX_WIRELESS_AUTH_MODE |
209 | unset ALX_WIRELESS_KEY_LENGTH |
210 | unset ALX_WIRELESS_KEY |
211 | unset ALX_WIRELESS_KEY_ASCII |
212 | } |
213 | |
214 | # needs exported iface variable! |
215 | add_iface_cfg() |
216 | { |
217 | echo "$@" >> /etc/conf.d/net.${iface} |
218 | } |
219 | |
220 | config_networking() |
221 | { |
222 | local iface |
223 | |
224 | # retrieve informations about hostname and co |
225 | evaluate_table cfg_network |
226 | |
227 | # configure hostname and domain settings: |
228 | echo "${cfg_network_hostanme}" > /etc/hostname |
229 | echo -e "127.0.0.1\tlocalhost.${cfg_network_domain}\tlocalhost\t${cfg_network_hostname}" > /etc/hosts |
230 | |
231 | # if ! check_network_settings |
232 | # then |
233 | # echo -e "${COLYELLOW}Could not retrieve network settings, doing nothing ...${COLDEFAULT}" |
234 | # return 1 |
235 | # fi |
236 | |
237 | # remove all old nics and modules configs |
238 | find /etc/conf.d -type f -name 'net.*' | xargs rm |
239 | |
240 | # # update confd-networking default iface |
241 | # [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH} |
242 | # echo "${iface}" > ${SETTINGSPATH}/confd-networking |
243 | |
244 | # configure all available interfaces but activate only the default_iface! |
245 | iface_list=$(mysqldo "select iface from cfg_interfaces where serial='${ALX_SERIAL}'") |
246 | |
247 | for iface in ${iface_list} |
248 | do |
249 | # initialize the config |
250 | :> /etc/conf.d/net.${iface} |
251 | |
252 | # retrieve information from mysql |
253 | evaluate_table cfg_interfaces "where serial='${ALX_SERIAL}' and iface='${iface}'" |
254 | |
255 | if [[ ${iface} = ${cfg_network_default_iface} ]] |
256 | then |
257 | add_iface_cfg "ONBOOT=yes" |
258 | else |
259 | add_iface_cfg "ONBOOT=no" |
260 | fi |
261 | |
262 | add_iface_cfg NETWORKING=${cfg_interfaces_networking} |
263 | |
264 | case ${cfg_interfaces_networking} in |
265 | dhcp|DHCP) |
266 | add_iface_cfg "DHCP_PROG=/sbin/udhcpc" |
267 | # timeout after 10 seconds and quit after retrieving a lease |
268 | add_iface_cfg 'DHCP_START="-t 10 -q"' |
269 | ;; |
270 | |
271 | static|STATIC) |
272 | # add hostname with valid ip to hosts |
273 | echo -e "${cfg_interfaces_ip}\t${cfg_interfaces_hostname}.${cfg_interfaces_domain}\t${cfg_interfaces_hostname}" >> /etc/hosts |
274 | add_iface_cfg "IP=${cfg_interfaces_ip}" |
275 | add_iface_cfg "NETMASK=${cfg_interfaces_netmask}" |
276 | add_iface_cfg "BROADCAST=${cfg_interfaces_broadcast}" |
277 | ;; |
278 | esac |
279 | |
280 | # gateway or gateway overrides |
281 | if [[ ${cfg_interfaces_gateway} != NULL ]] |
282 | then |
283 | add_iface_cfg "GATEWAY=${cfg_interfaces_gateway}" |
284 | fi |
285 | |
286 | # nameserver or nameserver overrides |
287 | if [[ ${cfg_interfaces_dns} != NULL ]] |
288 | then |
289 | add_iface_cfg "NAMESERVER="${cfg_interfaces_dns}"" |
290 | fi |
291 | |
292 | # force mac address override |
293 | if [[ ${cfg_interfaces_forcemacto} != NULL ]] |
294 | then |
295 | add_iface_cfg FORCE_MAC_TO=${cfg_interfaces_forcemacto} |
296 | fi |
297 | |
298 | # wireless extensions |
299 | local value |
300 | local var |
301 | for var in cfg_interfaces_wireless_bitrate \ |
302 | cfg_interfaces_wireless_channel \ |
303 | cfg_interfaces_wireless_essid \ |
304 | cfg_interfaces_wireless_frequency \ |
305 | cfg_interfaces_wireless_mode \ |
306 | cfg_interfaces_wireless_nick \ |
307 | cfg_interfaces_wireless_auth_mode \ |
308 | cfg_interfaces_wireless_key_length \ |
309 | cfg_interfaces_wireless_key \ |
310 | cfg_interfaces_wireless_key_ascii |
311 | do |
312 | # get the value of $var |
313 | eval value=\$$(echo ${var}) |
314 | |
315 | # write it only if not empty |
316 | if [[ -n ${value} ]] && [[ ${value} != NULL ]] |
317 | then |
318 | # remove cfg_interfaces_from var and convert to upcase |
319 | add_iface_cfg "$(echo ${var/cfg_network_/} | tr '[:lower:]' '[:upper:]')=${value}" |
320 | fi |
321 | |
322 | # clear value |
323 | unset value |
324 | done |
325 | |
326 | # setup wpa-driver (only zydas atm) |
327 | case ${cfg_interfaces_module} in |
328 | zd1211) add_iface_cfg "WIRELESS_WPA_DRIVER=zydas" ;; |
329 | esac |
330 | done |
331 | } |