Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 367 - (hide annotations) (download) (as text)
Tue Oct 11 12:09:52 2005 UTC (18 years, 7 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/functions/config_network.sh
File MIME type: application/x-sh
File size: 6239 byte(s)
fixed some stupid logic issues

1 niro 367 # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_network.sh,v 1.13 2005-10-11 12:09:52 niro Exp $
2 niro 218 # configures networkin on the host via mysql db settings
3    
4     get_network_settings()
5     {
6     local x i all DB_NETWORK
7    
8 niro 346 # all arrays:
9 niro 218 # -> hostname modules domain networking ip netmask dns gateway broadcast
10    
11 niro 367 all=$(mysqldo "select iface,
12     hostname,
13 niro 346 module,
14     domain,
15     networking,
16     ip,
17     netmask,
18     dns,
19     gateway,
20 niro 367 broadcast
21 niro 218 from cfg_network where serial='${ALX_SERIAL}'")
22    
23 niro 346 # split'em up and put 'em in an array
24 niro 218 declare -i i=0
25     for x in ${all}
26     do
27     DB_NETWORK[${i}]="${x}"
28     ((i++))
29     done
30    
31 niro 276 # and now put in usable var names and export them systemwide
32 niro 367 export ALX_IFACE="${DB_NETWORK[0]:=NULL}"
33     export ALX_HOSTNAME="${DB_NETWORK[1]:=NULL}"
34     export ALX_MODULE="${DB_NETWORK[2]:=NULL}"
35     export ALX_DOMAIN="${DB_NETWORK[3]:=NULL}"
36     export ALX_NETWORKING="${DB_NETWORK[4]:=NULL}"
37     export ALX_IP="${DB_NETWORK[5]:=NULL}"
38     export ALX_NETMASK="${DB_NETWORK[6]:=NULL}"
39     export ALX_DNS="${DB_NETWORK[7]:=NULL}"
40     export ALX_GATEWAY="${DB_NETWORK[8]:=NULL}"
41     export ALX_BROADCAST="${DB_NETWORK[9]:=NULL}"
42 niro 276
43     # the new mac address hack
44 niro 346 export ALX_FORCEMACTO=$(mysqldo "select forcemacto from cfg_network where serial='${ALX_SERIAL}'")
45    
46     # wireless extensions
47     export ALX_WIRELESS_BITRATE=$(mysqldo "select wireless_bitrate from cfg_network where serial='${ALX_SERIAL}'")
48     export ALX_WIRELESS_CHANNEL=$(mysqldo "select wireless_channel from cfg_network where serial='${ALX_SERIAL}'")
49     export ALX_WIRELESS_ESSID=$(mysqldo "select wireless_essid from cfg_network where serial='${ALX_SERIAL}'")
50     export ALX_WIRELESS_FREQUENCY=$(mysqldo "select wireless_frequency from cfg_network where serial='${ALX_SERIAL}'")
51     export ALX_WIRELESS_MODE=$(mysqldo "select wireless_mode from cfg_network where serial='${ALX_SERIAL}'")
52     export ALX_WIRELESS_NICK=$(mysqldo "select wireless_nick from cfg_network where serial='${ALX_SERIAL}'")
53     export ALX_WIRELESS_AUTH_MODE=$(mysqldo "select wireless_auth_mode from cfg_network where serial='${ALX_SERIAL}'")
54     export ALX_WIRELESS_KEY_LENGTH=$(mysqldo "select wireless_key_length from cfg_network where serial='${ALX_SERIAL}'")
55     export ALX_WIRELESS_KEY=$(mysqldo "select wireless_key from cfg_network where serial='${ALX_SERIAL}'")
56     export ALX_WIRELESS_KEY_ASCII=$(mysqldo "select wireless_key_ascii from cfg_network where serial='${ALX_SERIAL}'")
57 niro 218 }
58    
59     config_networking()
60     {
61 niro 346 local iface
62    
63     # first of all get the vars
64 niro 218 get_network_settings
65    
66 niro 346 # get the right nic
67     if [[ -z ${ALX_IFACE} ]] || [[ ${ALX_IFACE} = NULL ]]
68     then
69     # default is 'eth0'
70     iface="eth0"
71     else
72     iface="${ALX_IFACE}"
73     fi
74 niro 218
75 niro 346 # remove all old nics and modules configs
76     find /etc/conf.d -type f -name 'net.*' | xargs rm
77     find /etc/modules.d -type f -name 'net.*' | xargs rm
78    
79     # update the preliminary network
80     # set an device alias for modprobe.conf
81     [ ! -d /etc/modules.d ] && install -d /etc/modules.d
82     # update only if not the same (to speed up bootprocess - no depmod)
83     if [ ! -f /etc/modules.d/net.${iface} ] ||
84     [[ ${iface} != $(cat /etc/modules.d/net.${iface} | cut -d' ' -f2) ]]
85     then
86     echo "alias ${iface} ${ALX_MODULE}" > /etc/modules.d/net.${iface}
87     fi
88    
89     # update confd-networking default iface
90     echo "${iface}" > ${SETTINGSPATH}/confd-networking
91    
92 niro 218 # hostname && hosts
93     echo "${ALX_HOSTNAME}" > /etc/hostname
94 niro 255 echo -e "127.0.0.1\tlocalhost.${ALX_DOMAIN}\tlocalhost\t${ALX_HOSTNAME}" > /etc/hosts
95 niro 218
96     # network devices
97    
98     # always on boot
99 niro 346 echo 'ONBOOT="yes"' > /etc/conf.d/net.${iface}
100     echo "NETWORKING=\"${ALX_NETWORKING}\"" >> /etc/conf.d/net.${iface}
101 niro 218
102     case ${ALX_NETWORKING} in
103     dhcp|DHCP)
104 niro 346 echo 'DHCP_PROG="/sbin/dhcpcd"' >> /etc/conf.d/net.${iface}
105 niro 218 # -k kills the dhcp-cache at system shutdown
106     # -z will not
107 niro 346 echo 'DHCP_STOP="-z"' >> /etc/conf.d/net.${iface}
108 niro 218 #timeout after 10 seconds
109 niro 346 echo 'DHCP_START="-t 10"' >> /etc/conf.d/net.${iface}
110 niro 218 ;;
111    
112     static|STATIC)
113     # add hostname with valid ip to hosts
114     echo -e "${ALX_IP}\t${ALX_HOSTNAME}.${ALX_DOMAIN}\t${ALX_HOSTNAME}" >> /etc/hosts
115 niro 346 echo "IP=\"${ALX_IP}\"" >> /etc/conf.d/net.${iface}
116     echo "NETMASK=\"${ALX_NETMASK}\"" >> /etc/conf.d/net.${iface}
117     echo "BROADCAST=\"${ALX_BROADCAST}\"" >> /etc/conf.d/net.${iface}
118 niro 218 ;;
119     esac
120    
121     # gateway or gateway overrides
122     if [[ ${ALX_GATEWAY} != NULL ]]
123     then
124 niro 346 echo "GATEWAY=\"${ALX_GATEWAY}\"" >> /etc/conf.d/net.${iface}
125     echo "GATEWAY_IF=\"${iface}\"" >> /etc/conf.d/net.${iface}
126 niro 218 fi
127    
128 niro 276 # force mac address override
129     if [[ ${ALX_FORCEMACTO} != NULL ]]
130     then
131 niro 346 echo "FORCE_MAC_TO=\"${ALX_FORCEMACTO}\"" >> /etc/conf.d/net.${iface}
132 niro 276 fi
133    
134 niro 218 # nameserver or nameserver overrides
135     if [[ ${ALX_DNS} != NULL ]]
136     then
137     echo "nameserver ${ALX_DNS}" > /etc/resolv.conf
138     fi
139    
140 niro 266 # setup smb.conf (little sed magic:)
141 niro 290 # first get smb version !
142     local smbconf
143 niro 303 [[ $(smbd --version | cut -d' ' -f2) > 2.999 ]] && smbconf=smb3.conf || smbconf=smb.conf
144 niro 290
145     cat ${ALX_SKELETONS}/samba/${smbconf} > /etc/samba/smb.conf
146 niro 266 sed -i -e "s:\(workgroup = \).*:\1${ALX_DOMAIN}:" /etc/samba/smb.conf
147    
148 niro 346 # wireless extensions
149     local value
150     local var
151     for var in ALX_WIRELESS_BITRATE \
152     ALX_WIRELESS_CHANNEL \
153     ALX_WIRELESS_ESSID \
154     ALX_WIRELESS_FREQUENCY \
155     ALX_WIRELESS_MODE \
156     ALX_WIRELESS_NICK \
157     ALX_WIRELESS_AUTH_MODE \
158     ALX_WIRELESS_KEY_LENGTH \
159     ALX_WIRELESS_KEY \
160     ALX_WIRELESS_KEY_ASCII
161     do
162     # get the value of $var
163     eval value=\$$(echo ${var})
164    
165     # write it only if not empty
166     if [[ -n ${value} ]] && [[ ${value} != NULL ]]
167     then
168     # remove ALX_ from var
169     echo "${var/ALX_/}=\"${value}\"" >> /etc/conf.d/net.${iface}
170     fi
171    
172     # clear value
173     unset value
174     done
175    
176 niro 353 # setup wpa-driver (only zydas atm)
177     [[ ${ALX_MODULE} = zd1211 ]] && \
178     echo "WIRELESS_WPA_DRIVER=zydas" >> /etc/conf.d/net.${iface}
179    
180 niro 218 # unset all vars
181     unset ALX_HOSTNAME
182     unset ALX_MODULE
183     unset ALX_DOMAIN
184     unset ALX_NETWORKING
185     unset ALX_IP
186     unset ALX_NETMASK
187     unset ALX_DNS
188     unset ALX_GATEWAY
189     unset ALX_BROADCAST
190 niro 346 unset ALX_FORCEMACTO
191     unset ALX_IFACE
192     unset ALX_WIRELESS_BITRATE
193     unset ALX_WIRELESS_CHANNEL
194     unset ALX_WIRELESS_ESSID
195     unset ALX_WIRELESS_FREQUENCY
196     unset ALX_WIRELESS_MODE
197     unset ALX_WIRELESS_NICK
198     unset ALX_WIRELESS_AUTH_MODE
199     unset ALX_WIRELESS_KEY_LENGTH
200     unset ALX_WIRELESS_KEY
201     unset ALX_WIRELESS_KEY_ASCII
202 niro 218 }
203 niro 255