Magellan Linux

Diff of /alx-src/trunk/tinyalxconfig-ng/functions/config_network.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 392 by niro, Wed Jun 4 18:07:24 2008 UTC revision 454 by niro, Thu Jun 5 19:08:36 2008 UTC
# Line 1  Line 1 
1  # $Header: /home/cvsd/alx-cvs/alx-src/tinyalxconfig-ng/functions/config_network.sh,v 1.2 2008-06-04 18:07:24 niro Exp $  # $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  # configures networkin on the host via mysql db settings
3    
4  get_network_settings()  get_network_settings_old()
5  {  {
6   local x i all DB_NETWORK   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   # all arrays:   # retrieve hostname and domain information
14   # ->  hostname modules domain networking ip netmask dns gateway broadcast   evaluate_table cfg_network
15     export ALX_HOSTNAME="${cfg_network_hostname}"
16     export ALX_DOMAIN="${cfg_network_domain}"
17    
18   all=$(mysqldo "select iface,   # now build a multi-ranged "array" for all interface settings
19   hostname,   declare -i x=0
20   module,  
21   domain,   for iface in ${all_ifaces}
  networking,  
  ip,  
  netmask,  
  dns,  
  gateway,  
  broadcast  
  from cfg_network where serial='${ALX_SERIAL}'")  
   
  # split'em up and put 'em in an array  
  declare -i i=0  
  for x in ${all}  
22   do   do
23   DB_NETWORK[${i}]="${x}"   evaluate_table
24   ((i++))   all=$(mysqldo "select iface,
25   done   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   # and now put in usable var names and export them systemwide   done
72   export ALX_IFACE="${DB_NETWORK[0]:=NULL}"  }
  export ALX_HOSTNAME="${DB_NETWORK[1]:=NULL}"  
  export ALX_MODULE="${DB_NETWORK[2]:=NULL}"  
  export ALX_DOMAIN="${DB_NETWORK[3]:=NULL}"  
  export ALX_NETWORKING="${DB_NETWORK[4]:=NULL}"  
  export ALX_IP="${DB_NETWORK[5]:=NULL}"  
  export ALX_NETMASK="${DB_NETWORK[6]:=NULL}"  
  export ALX_DNS="${DB_NETWORK[7]:=NULL}"  
  export ALX_GATEWAY="${DB_NETWORK[8]:=NULL}"  
  export ALX_BROADCAST="${DB_NETWORK[9]:=NULL}"  
73    
74   # the new mac address hack  check_network_settings_old()
75   export ALX_FORCEMACTO=$(mysqldo "select forcemacto from cfg_network where serial='${ALX_SERIAL}'")  {
76     # sanity checks
77     [[ ${ALX_IFACE} = NULL ]] && return 1
78     [[ ${ALX_HOSTNAME} = NULL ]] && return 1
79     [[ ${ALX_NETWORKING} = NULL ]] && return 1
80    
81   # wireless extensions   # if we get here, everything is ok
82   export ALX_WIRELESS_BITRATE=$(mysqldo "select wireless_bitrate from cfg_network where serial='${ALX_SERIAL}'")   return 0
  export ALX_WIRELESS_CHANNEL=$(mysqldo "select wireless_channel from cfg_network where serial='${ALX_SERIAL}'")  
  export ALX_WIRELESS_ESSID=$(mysqldo "select wireless_essid from cfg_network where serial='${ALX_SERIAL}'")  
  export ALX_WIRELESS_FREQUENCY=$(mysqldo "select wireless_frequency from cfg_network where serial='${ALX_SERIAL}'")  
  export ALX_WIRELESS_MODE=$(mysqldo "select wireless_mode from cfg_network where serial='${ALX_SERIAL}'")  
  export ALX_WIRELESS_NICK=$(mysqldo "select wireless_nick from cfg_network where serial='${ALX_SERIAL}'")  
  export ALX_WIRELESS_AUTH_MODE=$(mysqldo "select wireless_auth_mode from cfg_network where serial='${ALX_SERIAL}'")  
  export ALX_WIRELESS_KEY_LENGTH=$(mysqldo "select wireless_key_length from cfg_network where serial='${ALX_SERIAL}'")  
  export ALX_WIRELESS_KEY=$(mysqldo "select wireless_key from cfg_network where serial='${ALX_SERIAL}'")  
  export ALX_WIRELESS_KEY_ASCII=$(mysqldo "select wireless_key_ascii from cfg_network where serial='${ALX_SERIAL}'")  
83  }  }
84    
85  config_networking()  config_networking_old()
86  {  {
87   local iface   local iface
88    
89   # first of all get the vars   # first of all get the vars
90   get_network_settings   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   # get the right nic
98   if [[ -z ${ALX_IFACE} ]] || [[ ${ALX_IFACE} = NULL ]]   if [[ -z ${ALX_IFACE} ]] || [[ ${ALX_IFACE} = NULL ]]
# Line 74  config_networking() Line 105  config_networking()
105    
106   # remove all old nics and modules configs   # remove all old nics and modules configs
107   find /etc/conf.d -type f -name 'net.*' | xargs rm   find /etc/conf.d -type f -name 'net.*' | xargs rm
  find /etc/modules.d -type f -name 'net.*' | xargs rm  
   
  # update the preliminary network  
  # set an device alias for modprobe.conf  
  [ ! -d /etc/modules.d ] && install -d /etc/modules.d  
  # update only if not the same (to speed up bootprocess - no depmod)  
  if [ ! -f /etc/modules.d/net.${iface} ] ||  
  [[ ${iface} != $(cat /etc/modules.d/net.${iface} | cut -d' ' -f2) ]]  
  then  
  echo "alias ${iface} ${ALX_MODULE}" > /etc/modules.d/net.${iface}  
  fi  
108    
109   # update confd-networking default iface   # update confd-networking default iface
110   [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH}   [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH}
# Line 135  config_networking() Line 155  config_networking()
155   echo "nameserver ${ALX_DNS}" > /etc/resolv.conf   echo "nameserver ${ALX_DNS}" > /etc/resolv.conf
156   fi   fi
157    
  # setup smb.conf (little sed magic:)  
  # first get smb version !  
  local smbconf  
  [[ $(smbd --version | cut -d' ' -f2) > 2.999 ]] && smbconf=smb3.conf || smbconf=smb.conf  
   
  cat ${ALX_SKELETONS}/samba/${smbconf} > /etc/samba/smb.conf  
  sed -i -e "s:\(workgroup = \).*:\1${ALX_DOMAIN}:" /etc/samba/smb.conf  
   
158   # wireless extensions   # wireless extensions
159   local value   local value
160   local var   local var
# Line 199  config_networking() Line 211  config_networking()
211   unset ALX_WIRELESS_KEY_ASCII   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    }

Legend:
Removed from v.392  
changed lines
  Added in v.454