Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2159 - (hide annotations) (download) (as text)
Wed May 18 14:34:00 2011 UTC (13 years ago) by niro
File MIME type: application/x-sh
File size: 3370 byte(s)
-all filename variables should be escaped to support whitespaces
-check for null and zero values!

1 niro 2001 # $Id$
2     # configures networking on the host via mysql db settings
3 niro 218
4     config_networking()
5     {
6 niro 346 local iface
7 niro 2033 local CONFIG
8 niro 346
9     # first of all get the vars
10 niro 2145 evaluate_table cfg_network
11 niro 218
12 niro 346 # get the right nic
13 niro 2145 if [[ -z ${cfg_network_iface} ]] || [[ ${cfg_network_iface} = NULL ]]
14 niro 346 then
15     # default is 'eth0'
16     iface="eth0"
17     else
18 niro 2145 iface="${cfg_network_iface}"
19 niro 346 fi
20 niro 218
21 niro 346 # remove all old nics and modules configs
22     find /etc/conf.d -type f -name 'net.*' | xargs rm
23 niro 2120 find /etc/modprobe.d -type f -name 'net.*' | xargs rm
24 niro 346
25     # update the preliminary network
26     # set an device alias for modprobe.conf
27 niro 2120 [ ! -d /etc/modprobe.d ] && install -d /etc/modprobe.d
28 niro 346 # update only if not the same (to speed up bootprocess - no depmod)
29 niro 2120 if [ ! -f /etc/modprobe.d/net.${iface}.conf ] ||
30     [[ ${iface} != $(cat /etc/modprobe.d/net.${iface}.conf | cut -d' ' -f2) ]]
31 niro 346 then
32 niro 2159 CONFIG="/etc/modprobe.d/net.${iface}.conf"
33 niro 2033 clearconfig
34 niro 2145 addconfig "alias ${iface} ${cfg_network_module}"
35 niro 346 fi
36    
37     # update confd-networking default iface
38 niro 371 [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH}
39 niro 2159 CONFIG="${SETTINGSPATH}/confd-networking"
40 niro 2033 clearconfig
41     addconfig "${iface}"
42 niro 346
43 niro 218 # hostname && hosts
44 niro 2159 CONFIG="/etc/hostname"
45 niro 2033 clearconfig
46 niro 2145 addconfig "${cfg_network_hostname}"
47 niro 2159 CONFIG="/etc/hosts"
48 niro 2033 clearconfig
49 niro 2145 addconfig -e "127.0.0.1\tlocalhost.${cfg_network_domain}\tlocalhost\t${cfg_network_hostname}"
50     case ${cfg_network_networking} in
51 niro 2033 static|STATIC)
52     # add hostname with valid ip to hosts
53 niro 2145 addconfig -e "${ALX_IP}\t${cfg_network_hostname}.${cfg_network_domain}\t${cfg_network_hostname}"
54 niro 2033 ;;
55     esac
56 niro 218
57     # network devices
58    
59     # always on boot
60 niro 2159 CONFIG="/etc/conf.d/net.${iface}"
61 niro 2033 clearconfig
62 niro 218
63 niro 2033 addconfig 'ONBOOT="yes"'
64 niro 2145 addconfig "NETWORKING=\"${cfg_network_networking}\""
65     case ${cfg_network_networking} in
66 niro 218 dhcp|DHCP)
67 niro 2155 addconfig "DHCP_PROG=\"${ALX_DHCP_PROG}\""
68     addconfig "DHCP_STOP=\"${ALX_DHCP_STOP}\""
69 niro 218 #timeout after 10 seconds
70 niro 2155 addconfig "DHCP_START=\"${ALX_DHCP_START}\""
71 niro 218 ;;
72    
73     static|STATIC)
74 niro 2145 addconfig "IP=\"${cfg_network_ip}\""
75     addconfig "NETMASK=\"${cfg_network_netmask}\""
76     addconfig "BROADCAST=\"${cfg_network_broadcast}\""
77 niro 218 ;;
78     esac
79    
80 niro 276 # force mac address override
81 niro 2159 if [[ ${cfg_network_forcemacto} != NULL ]] && [[ ! -z ${cfg_network_forcemacto} ]]
82 niro 276 then
83 niro 2145 addconfig "FORCE_MAC_TO=\"${cfg_network_forcemacto}\""
84 niro 276 fi
85    
86 niro 346 # wireless extensions
87     local value
88     local var
89 niro 2145 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 niro 346 do
100     # get the value of $var
101 niro 2145 eval value="\${cfg_network_wireless_$(echo ${var})}"
102 niro 346
103     # write it only if not empty
104 niro 2159 if [[ ! -z ${value} ]] && [[ ${value} != NULL ]]
105 niro 346 then
106 niro 2145 # add WIRELESS and use uppercases
107     addconfig "WIRELESS_$(echo ${var} | tr [[:lower:] [[:upper:]])=\"${value}\""
108 niro 346 fi
109    
110     # clear value
111     unset value
112     done
113    
114 niro 2033 # FIXME !!!
115 niro 353 # setup wpa-driver (only zydas atm)
116 niro 2145 if [[ ${cfg_network_module} = zd1211 ]]
117 niro 2033 then
118     addconfig "WIRELESS_WPA_DRIVER=zydas"
119     fi
120 niro 353
121 niro 2159 CONFIG="/etc/conf.d/net.routes"
122 niro 2033 clearconfig
123     # gateway or gateway overrides
124 niro 2159 if [[ ${cfg_network_gateway} != NULL ]] && [[ ! -z ${cfg_network_gateway} ]]
125 niro 2033 then
126 niro 2145 addconfig "default gw ${cfg_network_gateway}"
127 niro 2033 fi
128    
129 niro 2159 CONFIG="/etc/resolv.conf"
130 niro 2033 clearconfig
131     # nameserver or nameserver overrides
132 niro 2159 if [[ ${cfg_network_dns} != NULL ]] && [[ ! -z ${cfg_network_dns} ]]
133 niro 2033 then
134 niro 2145 addconfig "nameserver ${cfg_network_dns}"
135 niro 2033 fi
136 niro 218 }