Magellan Linux

Annotation of /alx-src/trunk/alxconfig-ng/functions/config_network.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2802 - (hide annotations) (download) (as text)
Mon Aug 29 20:20:48 2011 UTC (12 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 3673 byte(s)
-merged branch alxconfig-0_6_0 into trunk
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     addconfig "DHCP_START=\"${ALX_DHCP_START}\""
70 niro 218 ;;
71    
72     static|STATIC)
73 niro 2145 addconfig "IP=\"${cfg_network_ip}\""
74     addconfig "NETMASK=\"${cfg_network_netmask}\""
75     addconfig "BROADCAST=\"${cfg_network_broadcast}\""
76 niro 218 ;;
77     esac
78    
79 niro 276 # force mac address override
80 niro 2159 if [[ ${cfg_network_forcemacto} != NULL ]] && [[ ! -z ${cfg_network_forcemacto} ]]
81 niro 276 then
82 niro 2145 addconfig "FORCE_MAC_TO=\"${cfg_network_forcemacto}\""
83 niro 276 fi
84    
85 niro 346 # wireless extensions
86     local value
87     local var
88 niro 2145 for var in bitrate \
89     channel \
90     essid \
91     frequency \
92     mode \
93     nick \
94     auth_mode \
95     key_length \
96     key \
97     key_ascii
98 niro 346 do
99     # get the value of $var
100 niro 2145 eval value="\${cfg_network_wireless_$(echo ${var})}"
101 niro 346
102     # write it only if not empty
103 niro 2159 if [[ ! -z ${value} ]] && [[ ${value} != NULL ]]
104 niro 346 then
105 niro 2145 # add WIRELESS and use uppercases
106     addconfig "WIRELESS_$(echo ${var} | tr [[:lower:] [[:upper:]])=\"${value}\""
107 niro 346 fi
108    
109     # clear value
110     unset value
111     done
112    
113 niro 2033 # FIXME !!!
114 niro 353 # setup wpa-driver (only zydas atm)
115 niro 2145 if [[ ${cfg_network_module} = zd1211 ]]
116 niro 2033 then
117     addconfig "WIRELESS_WPA_DRIVER=zydas"
118     fi
119 niro 353
120 niro 2159 CONFIG="/etc/conf.d/net.routes"
121 niro 2033 clearconfig
122     # gateway or gateway overrides
123 niro 2159 if [[ ${cfg_network_gateway} != NULL ]] && [[ ! -z ${cfg_network_gateway} ]]
124 niro 2033 then
125 niro 2145 addconfig "default gw ${cfg_network_gateway}"
126 niro 2033 fi
127    
128 niro 2159 CONFIG="/etc/resolv.conf"
129 niro 2033 clearconfig
130     # nameserver or nameserver overrides
131 niro 2159 if [[ ${cfg_network_dns} != NULL ]] && [[ ! -z ${cfg_network_dns} ]]
132 niro 2033 then
133 niro 2145 addconfig "nameserver ${cfg_network_dns}"
134 niro 2033 fi
135 niro 2623
136     # netbios daemon
137     if [[ -x /usr/sbin/nmbd ]]
138     then
139     CONFIG="/etc/samba/smb.conf"
140     clearconfig
141     addconfig "[global]"
142     addconfig "workgroup = ${cfg_network_domain}"
143     addconfig "netbios name = ${cfg_network_hostname}"
144     addconfig "dns proxy = no"
145    
146     rc-config add nmbd &> /dev/null
147     else
148     rc-config del nmbd &> /dev/null
149     fi
150 niro 218 }