Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4835 - (hide annotations) (download) (as text)
Mon May 13 11:13:20 2013 UTC (11 years ago) by niro
File MIME type: application/x-sh
File size: 3927 byte(s)
-do not overwrite network configuration if NETWORKING var is empty
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 4835 # never ever overwrite network settings, if NETWORKING is unknown
22     case ${cfg_network_networking} in
23     static|STATIC|dhcp|DHCP) ;;
24     *)
25     echo -e "${COLRED}Received network-settings are not complete, aborting ...${COLDEFAULT}"
26     return 1
27     ;;
28     esac
29    
30 niro 346 # remove all old nics and modules configs
31     find /etc/conf.d -type f -name 'net.*' | xargs rm
32 niro 2120 find /etc/modprobe.d -type f -name 'net.*' | xargs rm
33 niro 346
34     # update the preliminary network
35     # set an device alias for modprobe.conf
36 niro 2120 [ ! -d /etc/modprobe.d ] && install -d /etc/modprobe.d
37 niro 346 # update only if not the same (to speed up bootprocess - no depmod)
38 niro 2120 if [ ! -f /etc/modprobe.d/net.${iface}.conf ] ||
39     [[ ${iface} != $(cat /etc/modprobe.d/net.${iface}.conf | cut -d' ' -f2) ]]
40 niro 346 then
41 niro 2159 CONFIG="/etc/modprobe.d/net.${iface}.conf"
42 niro 2033 clearconfig
43 niro 2145 addconfig "alias ${iface} ${cfg_network_module}"
44 niro 346 fi
45    
46     # update confd-networking default iface
47 niro 371 [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH}
48 niro 2159 CONFIG="${SETTINGSPATH}/confd-networking"
49 niro 2033 clearconfig
50     addconfig "${iface}"
51 niro 346
52 niro 218 # hostname && hosts
53 niro 2159 CONFIG="/etc/hostname"
54 niro 2033 clearconfig
55 niro 2145 addconfig "${cfg_network_hostname}"
56 niro 2159 CONFIG="/etc/hosts"
57 niro 2033 clearconfig
58 niro 2145 addconfig -e "127.0.0.1\tlocalhost.${cfg_network_domain}\tlocalhost\t${cfg_network_hostname}"
59     case ${cfg_network_networking} in
60 niro 2033 static|STATIC)
61     # add hostname with valid ip to hosts
62 niro 2145 addconfig -e "${ALX_IP}\t${cfg_network_hostname}.${cfg_network_domain}\t${cfg_network_hostname}"
63 niro 2033 ;;
64     esac
65 niro 218
66     # network devices
67    
68     # always on boot
69 niro 2159 CONFIG="/etc/conf.d/net.${iface}"
70 niro 2033 clearconfig
71 niro 218
72 niro 2033 addconfig 'ONBOOT="yes"'
73 niro 2145 addconfig "NETWORKING=\"${cfg_network_networking}\""
74     case ${cfg_network_networking} in
75 niro 218 dhcp|DHCP)
76 niro 2155 addconfig "DHCP_PROG=\"${ALX_DHCP_PROG}\""
77     addconfig "DHCP_STOP=\"${ALX_DHCP_STOP}\""
78     addconfig "DHCP_START=\"${ALX_DHCP_START}\""
79 niro 218 ;;
80    
81     static|STATIC)
82 niro 2145 addconfig "IP=\"${cfg_network_ip}\""
83     addconfig "NETMASK=\"${cfg_network_netmask}\""
84     addconfig "BROADCAST=\"${cfg_network_broadcast}\""
85 niro 218 ;;
86     esac
87    
88 niro 276 # force mac address override
89 niro 2159 if [[ ${cfg_network_forcemacto} != NULL ]] && [[ ! -z ${cfg_network_forcemacto} ]]
90 niro 276 then
91 niro 2145 addconfig "FORCE_MAC_TO=\"${cfg_network_forcemacto}\""
92 niro 276 fi
93    
94 niro 346 # wireless extensions
95     local value
96     local var
97 niro 2145 for var in bitrate \
98     channel \
99     essid \
100     frequency \
101     mode \
102     nick \
103     auth_mode \
104     key_length \
105     key \
106     key_ascii
107 niro 346 do
108     # get the value of $var
109 niro 2145 eval value="\${cfg_network_wireless_$(echo ${var})}"
110 niro 346
111     # write it only if not empty
112 niro 2159 if [[ ! -z ${value} ]] && [[ ${value} != NULL ]]
113 niro 346 then
114 niro 2145 # add WIRELESS and use uppercases
115     addconfig "WIRELESS_$(echo ${var} | tr [[:lower:] [[:upper:]])=\"${value}\""
116 niro 346 fi
117    
118     # clear value
119     unset value
120     done
121    
122 niro 2033 # FIXME !!!
123 niro 353 # setup wpa-driver (only zydas atm)
124 niro 2145 if [[ ${cfg_network_module} = zd1211 ]]
125 niro 2033 then
126     addconfig "WIRELESS_WPA_DRIVER=zydas"
127     fi
128 niro 353
129 niro 2159 CONFIG="/etc/conf.d/net.routes"
130 niro 2033 clearconfig
131     # gateway or gateway overrides
132 niro 2159 if [[ ${cfg_network_gateway} != NULL ]] && [[ ! -z ${cfg_network_gateway} ]]
133 niro 2033 then
134 niro 2145 addconfig "default gw ${cfg_network_gateway}"
135 niro 2033 fi
136    
137 niro 2159 CONFIG="/etc/resolv.conf"
138 niro 2033 clearconfig
139     # nameserver or nameserver overrides
140 niro 2159 if [[ ${cfg_network_dns} != NULL ]] && [[ ! -z ${cfg_network_dns} ]]
141 niro 2033 then
142 niro 2145 addconfig "nameserver ${cfg_network_dns}"
143 niro 2033 fi
144 niro 2623
145     # netbios daemon
146     if [[ -x /usr/sbin/nmbd ]]
147     then
148     CONFIG="/etc/samba/smb.conf"
149     clearconfig
150     addconfig "[global]"
151     addconfig "workgroup = ${cfg_network_domain}"
152     addconfig "netbios name = ${cfg_network_hostname}"
153     addconfig "dns proxy = no"
154    
155     rc-config add nmbd &> /dev/null
156     else
157     rc-config del nmbd &> /dev/null
158     fi
159 niro 218 }