Contents of /alx-src/tags/alxconf-0_6_13/functions/config_network.sh
Parent Directory | Revision Log
Revision 8044 -
(show annotations)
(download)
(as text)
Tue Dec 29 16:32:09 2015 UTC (8 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 3927 byte(s)
Tue Dec 29 16:32:09 2015 UTC (8 years, 9 months ago) by niro
File MIME type: application/x-sh
File size: 3927 byte(s)
tagged 'alxconf-0_6_13'
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 | # 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 | # remove all old nics and modules configs |
31 | find /etc/conf.d -type f -name 'net.*' | xargs rm |
32 | find /etc/modprobe.d -type f -name 'net.*' | xargs rm |
33 | |
34 | # update the preliminary network |
35 | # set an device alias for modprobe.conf |
36 | [ ! -d /etc/modprobe.d ] && install -d /etc/modprobe.d |
37 | # update only if not the same (to speed up bootprocess - no depmod) |
38 | if [ ! -f /etc/modprobe.d/net.${iface}.conf ] || |
39 | [[ ${iface} != $(cat /etc/modprobe.d/net.${iface}.conf | cut -d' ' -f2) ]] |
40 | then |
41 | CONFIG="/etc/modprobe.d/net.${iface}.conf" |
42 | clearconfig |
43 | addconfig "alias ${iface} ${cfg_network_module}" |
44 | fi |
45 | |
46 | # update confd-networking default iface |
47 | [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH} |
48 | CONFIG="${SETTINGSPATH}/confd-networking" |
49 | clearconfig |
50 | addconfig "${iface}" |
51 | |
52 | # hostname && hosts |
53 | CONFIG="/etc/hostname" |
54 | clearconfig |
55 | addconfig "${cfg_network_hostname}" |
56 | CONFIG="/etc/hosts" |
57 | clearconfig |
58 | addconfig -e "127.0.0.1\tlocalhost.${cfg_network_domain}\tlocalhost\t${cfg_network_hostname}" |
59 | case ${cfg_network_networking} in |
60 | static|STATIC) |
61 | # add hostname with valid ip to hosts |
62 | addconfig -e "${ALX_IP}\t${cfg_network_hostname}.${cfg_network_domain}\t${cfg_network_hostname}" |
63 | ;; |
64 | esac |
65 | |
66 | # network devices |
67 | |
68 | # always on boot |
69 | CONFIG="/etc/conf.d/net.${iface}" |
70 | clearconfig |
71 | |
72 | addconfig 'ONBOOT="yes"' |
73 | addconfig "NETWORKING=\"${cfg_network_networking}\"" |
74 | case ${cfg_network_networking} in |
75 | dhcp|DHCP) |
76 | addconfig "DHCP_PROG=\"${ALX_DHCP_PROG}\"" |
77 | addconfig "DHCP_STOP=\"${ALX_DHCP_STOP}\"" |
78 | addconfig "DHCP_START=\"${ALX_DHCP_START}\"" |
79 | ;; |
80 | |
81 | static|STATIC) |
82 | addconfig "IP=\"${cfg_network_ip}\"" |
83 | addconfig "NETMASK=\"${cfg_network_netmask}\"" |
84 | addconfig "BROADCAST=\"${cfg_network_broadcast}\"" |
85 | ;; |
86 | esac |
87 | |
88 | # force mac address override |
89 | if [[ ${cfg_network_forcemacto} != NULL ]] && [[ ! -z ${cfg_network_forcemacto} ]] |
90 | then |
91 | addconfig "FORCE_MAC_TO=\"${cfg_network_forcemacto}\"" |
92 | fi |
93 | |
94 | # wireless extensions |
95 | local value |
96 | local var |
97 | 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 | do |
108 | # get the value of $var |
109 | eval value="\${cfg_network_wireless_$(echo ${var})}" |
110 | |
111 | # write it only if not empty |
112 | if [[ ! -z ${value} ]] && [[ ${value} != NULL ]] |
113 | then |
114 | # add WIRELESS and use uppercases |
115 | addconfig "WIRELESS_$(echo ${var} | tr [[:lower:] [[:upper:]])=\"${value}\"" |
116 | fi |
117 | |
118 | # clear value |
119 | unset value |
120 | done |
121 | |
122 | # FIXME !!! |
123 | # setup wpa-driver (only zydas atm) |
124 | if [[ ${cfg_network_module} = zd1211 ]] |
125 | then |
126 | addconfig "WIRELESS_WPA_DRIVER=zydas" |
127 | fi |
128 | |
129 | CONFIG="/etc/conf.d/net.routes" |
130 | clearconfig |
131 | # gateway or gateway overrides |
132 | if [[ ${cfg_network_gateway} != NULL ]] && [[ ! -z ${cfg_network_gateway} ]] |
133 | then |
134 | addconfig "default gw ${cfg_network_gateway}" |
135 | fi |
136 | |
137 | CONFIG="/etc/resolv.conf" |
138 | clearconfig |
139 | # nameserver or nameserver overrides |
140 | if [[ ${cfg_network_dns} != NULL ]] && [[ ! -z ${cfg_network_dns} ]] |
141 | then |
142 | addconfig "nameserver ${cfg_network_dns}" |
143 | fi |
144 | |
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 | } |