Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2623 - (show annotations) (download) (as text)
Thu Jul 7 13:20:37 2011 UTC (12 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 3673 byte(s)
-configure netbios daemon  if /usr/sbin/nmbd was found on system
1 # $Id$
2 # configures networking on the host via mysql db settings
3
4 config_networking()
5 {
6 local iface
7 local CONFIG
8
9 # first of all get the vars
10 evaluate_table cfg_network
11
12 # get the right nic
13 if [[ -z ${cfg_network_iface} ]] || [[ ${cfg_network_iface} = NULL ]]
14 then
15 # default is 'eth0'
16 iface="eth0"
17 else
18 iface="${cfg_network_iface}"
19 fi
20
21 # remove all old nics and modules configs
22 find /etc/conf.d -type f -name 'net.*' | xargs rm
23 find /etc/modprobe.d -type f -name 'net.*' | xargs rm
24
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 # update confd-networking default iface
38 [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH}
39 CONFIG="${SETTINGSPATH}/confd-networking"
40 clearconfig
41 addconfig "${iface}"
42
43 # hostname && hosts
44 CONFIG="/etc/hostname"
45 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
58
59 # always on boot
60 CONFIG="/etc/conf.d/net.${iface}"
61 clearconfig
62
63 addconfig 'ONBOOT="yes"'
64 addconfig "NETWORKING=\"${cfg_network_networking}\""
65 case ${cfg_network_networking} in
66 dhcp|DHCP)
67 addconfig "DHCP_PROG=\"${ALX_DHCP_PROG}\""
68 addconfig "DHCP_STOP=\"${ALX_DHCP_STOP}\""
69 addconfig "DHCP_START=\"${ALX_DHCP_START}\""
70 ;;
71
72 static|STATIC)
73 addconfig "IP=\"${cfg_network_ip}\""
74 addconfig "NETMASK=\"${cfg_network_netmask}\""
75 addconfig "BROADCAST=\"${cfg_network_broadcast}\""
76 ;;
77 esac
78
79 # force mac address override
80 if [[ ${cfg_network_forcemacto} != NULL ]] && [[ ! -z ${cfg_network_forcemacto} ]]
81 then
82 addconfig "FORCE_MAC_TO=\"${cfg_network_forcemacto}\""
83 fi
84
85 # wireless extensions
86 local value
87 local var
88 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 do
99 # get the value of $var
100 eval value="\${cfg_network_wireless_$(echo ${var})}"
101
102 # write it only if not empty
103 if [[ ! -z ${value} ]] && [[ ${value} != NULL ]]
104 then
105 # add WIRELESS and use uppercases
106 addconfig "WIRELESS_$(echo ${var} | tr [[:lower:] [[:upper:]])=\"${value}\""
107 fi
108
109 # clear value
110 unset value
111 done
112
113 # FIXME !!!
114 # setup wpa-driver (only zydas atm)
115 if [[ ${cfg_network_module} = zd1211 ]]
116 then
117 addconfig "WIRELESS_WPA_DRIVER=zydas"
118 fi
119
120 CONFIG="/etc/conf.d/net.routes"
121 clearconfig
122 # gateway or gateway overrides
123 if [[ ${cfg_network_gateway} != NULL ]] && [[ ! -z ${cfg_network_gateway} ]]
124 then
125 addconfig "default gw ${cfg_network_gateway}"
126 fi
127
128 CONFIG="/etc/resolv.conf"
129 clearconfig
130 # nameserver or nameserver overrides
131 if [[ ${cfg_network_dns} != NULL ]] && [[ ! -z ${cfg_network_dns} ]]
132 then
133 addconfig "nameserver ${cfg_network_dns}"
134 fi
135
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 }