Magellan Linux

Annotation of /alx-src/branches/alxconf-060/functions/config_network.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2033 - (hide annotations) (download) (as text)
Wed May 11 09:10:33 2011 UTC (13 years ago) by niro
File MIME type: application/x-sh
File size: 5771 byte(s)
-make use of the new addconfig() && clearconfig() functions
1 niro 2001 # $Id$
2     # configures networking on the host via mysql db settings
3 niro 218
4     get_network_settings()
5     {
6     local x i all DB_NETWORK
7    
8 niro 346 # all arrays:
9 niro 218 # -> hostname modules domain networking ip netmask dns gateway broadcast
10    
11 niro 367 all=$(mysqldo "select iface,
12     hostname,
13 niro 346 module,
14     domain,
15     networking,
16     ip,
17     netmask,
18     dns,
19     gateway,
20 niro 367 broadcast
21 niro 218 from cfg_network where serial='${ALX_SERIAL}'")
22    
23 niro 346 # split'em up and put 'em in an array
24 niro 218 declare -i i=0
25     for x in ${all}
26     do
27     DB_NETWORK[${i}]="${x}"
28     ((i++))
29     done
30    
31 niro 276 # and now put in usable var names and export them systemwide
32 niro 367 export ALX_IFACE="${DB_NETWORK[0]:=NULL}"
33     export ALX_HOSTNAME="${DB_NETWORK[1]:=NULL}"
34     export ALX_MODULE="${DB_NETWORK[2]:=NULL}"
35     export ALX_DOMAIN="${DB_NETWORK[3]:=NULL}"
36     export ALX_NETWORKING="${DB_NETWORK[4]:=NULL}"
37     export ALX_IP="${DB_NETWORK[5]:=NULL}"
38     export ALX_NETMASK="${DB_NETWORK[6]:=NULL}"
39     export ALX_DNS="${DB_NETWORK[7]:=NULL}"
40     export ALX_GATEWAY="${DB_NETWORK[8]:=NULL}"
41     export ALX_BROADCAST="${DB_NETWORK[9]:=NULL}"
42 niro 276
43     # the new mac address hack
44 niro 346 export ALX_FORCEMACTO=$(mysqldo "select forcemacto from cfg_network where serial='${ALX_SERIAL}'")
45    
46     # wireless extensions
47     export ALX_WIRELESS_BITRATE=$(mysqldo "select wireless_bitrate from cfg_network where serial='${ALX_SERIAL}'")
48     export ALX_WIRELESS_CHANNEL=$(mysqldo "select wireless_channel from cfg_network where serial='${ALX_SERIAL}'")
49     export ALX_WIRELESS_ESSID=$(mysqldo "select wireless_essid from cfg_network where serial='${ALX_SERIAL}'")
50     export ALX_WIRELESS_FREQUENCY=$(mysqldo "select wireless_frequency from cfg_network where serial='${ALX_SERIAL}'")
51     export ALX_WIRELESS_MODE=$(mysqldo "select wireless_mode from cfg_network where serial='${ALX_SERIAL}'")
52     export ALX_WIRELESS_NICK=$(mysqldo "select wireless_nick from cfg_network where serial='${ALX_SERIAL}'")
53     export ALX_WIRELESS_AUTH_MODE=$(mysqldo "select wireless_auth_mode from cfg_network where serial='${ALX_SERIAL}'")
54     export ALX_WIRELESS_KEY_LENGTH=$(mysqldo "select wireless_key_length from cfg_network where serial='${ALX_SERIAL}'")
55     export ALX_WIRELESS_KEY=$(mysqldo "select wireless_key from cfg_network where serial='${ALX_SERIAL}'")
56     export ALX_WIRELESS_KEY_ASCII=$(mysqldo "select wireless_key_ascii from cfg_network where serial='${ALX_SERIAL}'")
57 niro 218 }
58    
59     config_networking()
60     {
61 niro 346 local iface
62 niro 2033 local CONFIG
63 niro 346
64     # first of all get the vars
65 niro 218 get_network_settings
66    
67 niro 346 # get the right nic
68     if [[ -z ${ALX_IFACE} ]] || [[ ${ALX_IFACE} = NULL ]]
69     then
70     # default is 'eth0'
71     iface="eth0"
72     else
73     iface="${ALX_IFACE}"
74     fi
75 niro 218
76 niro 346 # remove all old nics and modules configs
77     find /etc/conf.d -type f -name 'net.*' | xargs rm
78     find /etc/modules.d -type f -name 'net.*' | xargs rm
79    
80     # update the preliminary network
81     # set an device alias for modprobe.conf
82     [ ! -d /etc/modules.d ] && install -d /etc/modules.d
83     # update only if not the same (to speed up bootprocess - no depmod)
84     if [ ! -f /etc/modules.d/net.${iface} ] ||
85     [[ ${iface} != $(cat /etc/modules.d/net.${iface} | cut -d' ' -f2) ]]
86     then
87 niro 2033 CONFIG=/etc/modules.d/net.${iface}
88     clearconfig
89     addconfig "alias ${iface} ${ALX_MODULE}"
90 niro 346 fi
91    
92     # update confd-networking default iface
93 niro 371 [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH}
94 niro 2033 CONFIG=${SETTINGSPATH}/confd-networking
95     clearconfig
96     addconfig "${iface}"
97 niro 346
98 niro 218 # hostname && hosts
99 niro 2033 CONFIG=/etc/hostname
100     clearconfig
101     addconfig "${ALX_HOSTNAME}"
102     CONFIG=/etc/hosts
103     clearconfig
104     addconfig -e "127.0.0.1\tlocalhost.${ALX_DOMAIN}\tlocalhost\t${ALX_HOSTNAME}"
105     case ${ALX_NETWORKING} in
106     static|STATIC)
107     # add hostname with valid ip to hosts
108     addconfig -e "${ALX_IP}\t${ALX_HOSTNAME}.${ALX_DOMAIN}\t${ALX_HOSTNAME}"
109     ;;
110     esac
111 niro 218
112     # network devices
113    
114     # always on boot
115 niro 2033 CONFIG=/etc/conf.d/net.${iface}
116     clearconfig
117 niro 218
118 niro 2033 addconfig 'ONBOOT="yes"'
119     addconfig "NETWORKING=\"${ALX_NETWORKING}\""
120 niro 218 case ${ALX_NETWORKING} in
121     dhcp|DHCP)
122 niro 2033 addconfig 'DHCP_PROG="/sbin/udhcpc"'
123     addconfig 'DHCP_STOP=""'
124 niro 218 #timeout after 10 seconds
125 niro 2033 addconfig 'DHCP_START="-t 10"'
126 niro 218 ;;
127    
128     static|STATIC)
129 niro 2033 addconfig "IP=\"${ALX_IP}\""
130     addconfig "NETMASK=\"${ALX_NETMASK}\""
131     addconfig "BROADCAST=\"${ALX_BROADCAST}\""
132 niro 218 ;;
133     esac
134    
135 niro 276 # force mac address override
136     if [[ ${ALX_FORCEMACTO} != NULL ]]
137     then
138 niro 2033 addconfig "FORCE_MAC_TO=\"${ALX_FORCEMACTO}\""
139 niro 276 fi
140    
141 niro 346 # wireless extensions
142     local value
143     local var
144     for var in ALX_WIRELESS_BITRATE \
145     ALX_WIRELESS_CHANNEL \
146     ALX_WIRELESS_ESSID \
147     ALX_WIRELESS_FREQUENCY \
148     ALX_WIRELESS_MODE \
149     ALX_WIRELESS_NICK \
150     ALX_WIRELESS_AUTH_MODE \
151     ALX_WIRELESS_KEY_LENGTH \
152     ALX_WIRELESS_KEY \
153     ALX_WIRELESS_KEY_ASCII
154     do
155     # get the value of $var
156     eval value=\$$(echo ${var})
157    
158     # write it only if not empty
159     if [[ -n ${value} ]] && [[ ${value} != NULL ]]
160     then
161     # remove ALX_ from var
162 niro 2033 addconfig "${var/ALX_/}=\"${value}\""
163 niro 346 fi
164    
165     # clear value
166     unset value
167     done
168    
169 niro 2033 # FIXME !!!
170 niro 353 # setup wpa-driver (only zydas atm)
171 niro 2033 if [[ ${ALX_MODULE} = zd1211 ]]
172     then
173     addconfig "WIRELESS_WPA_DRIVER=zydas"
174     fi
175 niro 353
176 niro 2033 CONFIG=/etc/conf.d/net.routes
177     clearconfig
178     # gateway or gateway overrides
179     if [[ ${ALX_GATEWAY} != NULL ]]
180     then
181     addconfig "default gw ${ALX_GATEWAY}"
182     fi
183    
184     CONFIG=/etc/resolv.conf
185     clearconfig
186     # nameserver or nameserver overrides
187     if [[ ${ALX_DNS} != NULL ]]
188     then
189     addconfig "nameserver ${ALX_DNS}"
190     fi
191    
192 niro 218 # unset all vars
193     unset ALX_HOSTNAME
194     unset ALX_MODULE
195     unset ALX_DOMAIN
196     unset ALX_NETWORKING
197     unset ALX_IP
198     unset ALX_NETMASK
199     unset ALX_DNS
200     unset ALX_GATEWAY
201     unset ALX_BROADCAST
202 niro 346 unset ALX_FORCEMACTO
203     unset ALX_IFACE
204     unset ALX_WIRELESS_BITRATE
205     unset ALX_WIRELESS_CHANNEL
206     unset ALX_WIRELESS_ESSID
207     unset ALX_WIRELESS_FREQUENCY
208     unset ALX_WIRELESS_MODE
209     unset ALX_WIRELESS_NICK
210     unset ALX_WIRELESS_AUTH_MODE
211     unset ALX_WIRELESS_KEY_LENGTH
212     unset ALX_WIRELESS_KEY
213     unset ALX_WIRELESS_KEY_ASCII
214 niro 218 }