Magellan Linux

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

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

alx-src/trunk/alxconfig-ng/functions/config_network.sh revision 239 by niro, Tue Apr 12 20:46:52 2005 UTC alx-src/branches/alxconf-060/functions/config_network.sh revision 2155 by niro, Tue May 17 21:41:30 2011 UTC
# Line 1  Line 1 
1  # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_network.sh,v 1.4 2005-04-12 20:45:55 niro Exp $  # $Id$
2  # configures networkin on the host via mysql db settings  # configures networking on the host via mysql db settings
3    
4  get_network_settings()  config_networking()
5  {  {
6   local x i all DB_NETWORK   local iface
7     local CONFIG
  #all arrays:  
  # ->  hostname modules domain networking ip netmask dns gateway broadcast  
8    
9   all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   # first of all get the vars
10   "select hostname,   evaluate_table cfg_network
  module,  
  domain,  
  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}  
  do  
  DB_NETWORK[${i}]="${x}"  
  ((i++))  
  done  
11    
12   # and now put them in usable var names and export them systemwide   # get the right nic
13   export ALX_HOSTNAME="${DB_NETWORK[0]:=NULL}"   if [[ -z ${cfg_network_iface} ]] || [[ ${cfg_network_iface} = NULL ]]
14   export ALX_MODULE="${DB_NETWORK[1]:=NULL}"   then
15   export ALX_DOMAIN="${DB_NETWORK[2]:=NULL}"   # default is 'eth0'
16   export ALX_NETWORKING="${DB_NETWORK[3]:=NULL}"   iface="eth0"
17   export ALX_IP="${DB_NETWORK[4]:=NULL}"   else
18   export ALX_NETMASK="${DB_NETWORK[5]:=NULL}"   iface="${cfg_network_iface}"
19   export ALX_DNS="${DB_NETWORK[6]:=NULL}"   fi
  export ALX_GATEWAY="${DB_NETWORK[7]:=NULL}"  
  export ALX_BROADCAST="${DB_NETWORK[8]:=NULL}"  
 }  
20    
21  config_networking()   # remove all old nics and modules configs
22  {   find /etc/conf.d -type f -name 'net.*' | xargs rm
23   #first of all get the vars   find /etc/modprobe.d -type f -name 'net.*' | xargs rm
24   get_network_settings  
25     # update the preliminary network
26     # set an device alias for modprobe.conf
27     [ ! -d /etc/modprobe.d ] && install -d /etc/modprobe.d
28     # update only if not the same (to speed up bootprocess - no depmod)
29     if [ ! -f /etc/modprobe.d/net.${iface}.conf ] ||
30     [[ ${iface} != $(cat /etc/modprobe.d/net.${iface}.conf | cut -d' ' -f2) ]]
31     then
32     CONFIG=/etc/modprobe.d/net.${iface}.conf
33     clearconfig
34     addconfig "alias ${iface} ${cfg_network_module}"
35     fi
36    
37   # debug   # update confd-networking default iface
38   echo "0: ${ALX_HOSTNAME}"   [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH}
39   echo "1: ${ALX_MODULE}"   CONFIG=${SETTINGSPATH}/confd-networking
40   echo "2: ${ALX_DOMAIN}"   clearconfig
41   echo "3: ${ALX_NETWORKING}"   addconfig "${iface}"
  echo "4: ${ALX_IP}"  
  echo "5: ${ALX_NETMASK}"  
  echo "6: ${ALX_DNS}"  
  echo "7: ${ALX_GATEWAY}"  
  echo "8: ${ALX_BROADCAST}"  
42    
43   # hostname && hosts   # hostname && hosts
44   echo "${ALX_HOSTNAME}" > /etc/hostname   CONFIG=/etc/hostname
45   echo -e "127.0.0.1\tlocalhost\t${ALX_HOSTNAME}.${ALX_DOMAIN}\t${ALX_HOSTNAME}" > /etc/hosts   clearconfig
46     addconfig "${cfg_network_hostname}"
47     CONFIG=/etc/hosts
48     clearconfig
49     addconfig -e "127.0.0.1\tlocalhost.${cfg_network_domain}\tlocalhost\t${cfg_network_hostname}"
50     case ${cfg_network_networking} in
51     static|STATIC)
52     # add hostname with valid ip to hosts
53     addconfig -e "${ALX_IP}\t${cfg_network_hostname}.${cfg_network_domain}\t${cfg_network_hostname}"
54     ;;
55     esac
56    
57   # network devices   # network devices
58    
59   # always on boot   # always on boot
60   echo 'ONBOOT="yes"' > /etc/conf.d/net.eth0   CONFIG=/etc/conf.d/net.${iface}
61   echo "NETWORKING=\"${ALX_NETWORKING}\"" >> /etc/conf.d/net.eth0   clearconfig
62    
63   case ${ALX_NETWORKING} in   addconfig 'ONBOOT="yes"'
64     addconfig "NETWORKING=\"${cfg_network_networking}\""
65     case ${cfg_network_networking} in
66   dhcp|DHCP)   dhcp|DHCP)
67   echo 'DHCP_PROG="/sbin/dhcpcd"' >> /etc/conf.d/net.eth0   addconfig "DHCP_PROG=\"${ALX_DHCP_PROG}\""
68   # -k kills the dhcp-cache at system shutdown   addconfig "DHCP_STOP=\"${ALX_DHCP_STOP}\""
  # -z will not  
  echo 'DHCP_STOP="-z"' >> /etc/conf.d/net.eth0  
69   #timeout after 10 seconds   #timeout after 10 seconds
70   echo 'DHCP_START="-t 10"' >> /etc/conf.d/net.eth0   addconfig "DHCP_START=\"${ALX_DHCP_START}\""
71   ;;   ;;
72    
73   static|STATIC)   static|STATIC)
74   # add hostname with valid ip to hosts   addconfig "IP=\"${cfg_network_ip}\""
75   echo -e "${ALX_IP}\t${ALX_HOSTNAME}.${ALX_DOMAIN}\t${ALX_HOSTNAME}" >> /etc/hosts   addconfig "NETMASK=\"${cfg_network_netmask}\""
76   echo "IP=\"${ALX_IP}\"" >> /etc/conf.d/net.eth0   addconfig "BROADCAST=\"${cfg_network_broadcast}\""
  echo "NETMASK=\"${ALX_NETMASK}\"" >> /etc/conf.d/net.eth0  
  echo "BROADCAST=\"${ALX_BROADCAST}\"" >> /etc/conf.d/net.eth0  
77   ;;   ;;
78   esac   esac
79    
80     # force mac address override
81     if [[ ${cfg_network_forcemacto} != NULL ]]
82     then
83     addconfig "FORCE_MAC_TO=\"${cfg_network_forcemacto}\""
84     fi
85    
86     # wireless extensions
87     local value
88     local var
89     for var in bitrate \
90     channel \
91     essid \
92     frequency \
93     mode \
94     nick \
95     auth_mode \
96     key_length \
97     key \
98     key_ascii
99     do
100     # get the value of $var
101     eval value="\${cfg_network_wireless_$(echo ${var})}"
102    
103     # write it only if not empty
104     if [[ -n ${value} ]] && [[ ${value} != NULL ]]
105     then
106     # add WIRELESS and use uppercases
107     addconfig "WIRELESS_$(echo ${var} | tr [[:lower:] [[:upper:]])=\"${value}\""
108     fi
109    
110     # clear value
111     unset value
112     done
113    
114     # FIXME !!!
115     # setup wpa-driver (only zydas atm)
116     if [[ ${cfg_network_module} = zd1211 ]]
117     then
118     addconfig "WIRELESS_WPA_DRIVER=zydas"
119     fi
120    
121     CONFIG=/etc/conf.d/net.routes
122     clearconfig
123   # gateway or gateway overrides   # gateway or gateway overrides
124   if [[ ${ALX_GATEWAY} != NULL ]]   if [[ ${cfg_network_gateway} != NULL ]]
125   then   then
126   echo "GATEWAY=\"${ALX_GATEWAY}\"" >> /etc/conf.d/net.eth0   addconfig "default gw ${cfg_network_gateway}"
  echo 'GATEWAY_IF="eth0"' >> /etc/conf.d/net.eth0  
127   fi   fi
128    
129     CONFIG=/etc/resolv.conf
130     clearconfig
131   # nameserver or nameserver overrides   # nameserver or nameserver overrides
132   if [[ ${ALX_DNS} != NULL ]]   if [[ ${cfg_network_dns} != NULL ]]
133   then   then
134   echo "nameserver ${ALX_DNS}" > /etc/resolv.conf   addconfig "nameserver ${cfg_network_dns}"
135   fi   fi
   
  # unset all vars  
  unset ALX_HOSTNAME  
  unset ALX_MODULE  
  unset ALX_DOMAIN  
  unset ALX_NETWORKING  
  unset ALX_IP  
  unset ALX_NETMASK  
  unset ALX_DNS  
  unset ALX_GATEWAY  
  unset ALX_BROADCAST  
136  }  }

Legend:
Removed from v.239  
changed lines
  Added in v.2155