Contents of /mcore-src/trunk/mcore-tools/src/modules/network/network.client.class.in
Parent Directory | Revision Log
Revision 2672 -
(show annotations)
(download)
Fri Dec 4 12:12:07 2015 UTC (8 years, 9 months ago) by niro
File size: 5671 byte(s)
Fri Dec 4 12:12:07 2015 UTC (8 years, 9 months ago) by niro
File size: 5671 byte(s)
-fixed several typos
1 | # $Id$ |
2 | |
3 | provide basic-networking |
4 | require basic-system basic-init |
5 | |
6 | help_network_hostname() |
7 | { |
8 | mecho "get network.hostname" |
9 | mecho " Displays the current hostname" |
10 | mecho |
11 | mecho "set network.hostname [hostname]" |
12 | mecho " Sets the hostname of the system" |
13 | mecho " mcore - the local hostname" |
14 | } |
15 | |
16 | get_network_hostname() |
17 | { |
18 | local val |
19 | |
20 | if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
21 | then |
22 | val=$(hostname) |
23 | else |
24 | val=$(< @@SYSCONFDIR@@/hostname) |
25 | fi |
26 | |
27 | rvecho "${val}" |
28 | } |
29 | |
30 | # set_network_hostname $value |
31 | set_network_hostname() |
32 | { |
33 | local value="${CLASS_ARGV[0]}" |
34 | local CONFIG |
35 | local socket |
36 | local cookie |
37 | local authtype |
38 | local networksvc |
39 | |
40 | [[ -z ${value} ]] && help_network_hostname && return 1 |
41 | |
42 | CONFIG="@@SYSCONFDIR@@/hostname" |
43 | clearconfig |
44 | addconfig "${value}" |
45 | hostname "${value}" |
46 | |
47 | # update hosts file |
48 | CONFIG="@@SYSCONFDIR@@/hosts" |
49 | clearconfig |
50 | addconfig "127.0.0.1 localhost ${value}" |
51 | # add ipv6 defaults |
52 | addconfig "::1 ip6-localhost ip6-loopback" |
53 | addconfig "fe00::0 ip6-localnet" |
54 | addconfig "ff00::0 ip6-mcastprefix" |
55 | addconfig "ff02::1 ip6-allnodes" |
56 | addconfig "ff02::2 ip6-allrouters" |
57 | addconfig "ff02::3 ip6-allhosts" |
58 | |
59 | # check for running x11 and recreate the xauth cookie with the correct hostname |
60 | if [[ ! -z $(pidof X) ]] || [[ -n $(pidof Xorg) ]] |
61 | then |
62 | socket="${value}/unix${MCORE_XORG_DISPLAY}" |
63 | cookie=$(x11runas "xauth list | sed 's:.*\ \(.*\):\1:'") |
64 | authtype="MIT-MAGIC-COOKIE-1" |
65 | # add the new hostname to the xauthority file |
66 | x11runas "xauth add ${socket} ${authtype} ${cookie}" |
67 | fi |
68 | |
69 | # reload network configuration to inform a dhcp server about the changed hostname |
70 | if is_provided systemd |
71 | then |
72 | networksvc="systemd-networkd" |
73 | elif is_provided sysvinit |
74 | then |
75 | networksvc="network" |
76 | fi |
77 | ${MCORE_LIBDIR}/mcore-system-service --restart --service "${networksvc}" |
78 | } |
79 | |
80 | help_network_iface() |
81 | { |
82 | mecho "get network.iface" |
83 | mecho " Lists all configured network interfaces" |
84 | mecho |
85 | mecho "set network.iface [iface] [networking] [ip] [netmask] [broadcast] [network]" |
86 | mecho " Configure network interfaces" |
87 | mecho " iface - the interface name" |
88 | mecho " networking - may be 'static' or 'dhcp'" |
89 | mecho " ip, netmask, broadcast and network are optional and only required on static networking" |
90 | } |
91 | |
92 | get_network_iface() |
93 | { |
94 | local iface |
95 | for iface in $(find ${MROOT}@@CONFDDIR@@ -maxdepth 1 -name 'net.*' -printf '%f\n') |
96 | do |
97 | case ${iface} in |
98 | # exclude routes and samples |
99 | net.sample|net.routes) continue ;; |
100 | esac |
101 | rvecho -n "${iface//net.}" |
102 | ( cat ${MROOT}@@CONFDDIR@@${iface}; echo ) | while read line |
103 | do |
104 | rvecho -n ";${line}" |
105 | done |
106 | rvecho |
107 | done |
108 | } |
109 | |
110 | set_network_iface() |
111 | { |
112 | local iface="${CLASS_ARGV[0]}" |
113 | local networking="${CLASS_ARGV[1]}" |
114 | local ip="${CLASS_ARGV[2]}" |
115 | local netmask="${CLASS_ARGV[3]}" |
116 | local broadcast="${CLASS_ARGV[4]}" |
117 | local network="${CLASS_ARGV[5]}" |
118 | local CONFIG |
119 | local dhcp_prog |
120 | |
121 | [[ -z ${iface} ]] && help_network_iface && return 1 |
122 | [[ -z ${networking} ]] && help_network_iface && return 1 |
123 | |
124 | if [[ ${networking} = static ]] |
125 | then |
126 | [[ -z ${ip} ]] && help_network_iface && return 1 |
127 | [[ -z ${netmask} ]] && help_network_iface && return 1 |
128 | [[ -z ${broadcast} ]] && help_network_iface && return 1 |
129 | [[ -z ${network} ]] && help_network_iface && return 1 |
130 | fi |
131 | |
132 | if is_provided systemd |
133 | then |
134 | decho "set_network_iface() is not supported with systemd, only sysvinit atm" |
135 | return 0 |
136 | fi |
137 | |
138 | CONFIG="@@CONFDDIR@@/net.${iface}" |
139 | clearconfig |
140 | addconfig 'ONBOOT="yes"' |
141 | |
142 | case ${networking} in |
143 | static) |
144 | addconfig 'NETWORKING="static"' |
145 | addconfig "IP=\"${ip}\"" |
146 | addconfig "NETMASK=\"${netmask}\"" |
147 | addconfig "BROADCAST=\"${broadcast}\"" |
148 | addconfig "NETWORK=\"${network}\"" |
149 | ;; |
150 | |
151 | dhcp) |
152 | addconfig 'NETWORKING="dhcp"' |
153 | ;; |
154 | esac |
155 | |
156 | if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
157 | then |
158 | if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]] |
159 | then |
160 | ${MCORE_LIBDIR}/mcore-system-service --restart --service network "${iface}" |
161 | else |
162 | ${MCORE_LIBDIR}/mcore-system-service --start --service network "${iface}" |
163 | fi |
164 | else |
165 | case ${networking} in |
166 | static) |
167 | ifconfig "${iface}" "${ip}" netmask "${netmask}" broadcast "${broadcast}" |
168 | ;; |
169 | dhcp) |
170 | source @@CONFDDIR@@/network |
171 | [[ ! -z $(pidof ${dhcp_prog}) ]] && killall ${DEFAULT_DHCP_PROG} |
172 | ${DEFAULT_DHCP_PROG} ${DEFAULT_DHCP_START} "${iface}" |
173 | ;; |
174 | esac |
175 | fi |
176 | } |
177 | |
178 | help_network_gateway() |
179 | { |
180 | mecho "get network.gateway" |
181 | mecho " displays the current network gateway" |
182 | mecho |
183 | mecho "set network.gateway [ip]" |
184 | mecho " sets the network gateway to [ip]" |
185 | } |
186 | |
187 | get_network_gateway() |
188 | { |
189 | local gw |
190 | gw=$(ip route | grep default | sed 's:.*via[[:space:]]\(.*\)[[:space:]]dev.*:\1:') |
191 | rvecho "${gw}" |
192 | } |
193 | |
194 | set_network_gateway() |
195 | { |
196 | local value="${CLASS_ARGV[0]}" |
197 | local CONFIG |
198 | local i |
199 | |
200 | [[ -z ${value} ]] && help_network_gateway && return 1 |
201 | |
202 | CONFIG="@@CONFDDIR@@/net.routes" |
203 | clearconfig |
204 | addconfig "default gw ${value}" |
205 | |
206 | # delete other default gw first |
207 | for i in $(ip route | grep default | sed 's:.*via\ \(.*\)\ dev.*:\1:') |
208 | do |
209 | route del default gw "${i}" |
210 | done |
211 | route add default gw "${value}" |
212 | } |
213 | |
214 | help_network_nameserver() |
215 | { |
216 | mecho "get network.nameserver" |
217 | mecho " displays the current nameserver of the system" |
218 | mecho |
219 | mecho "set network.nameserver [ip1] [ip2] .. [ipN]" |
220 | mecho " adds given ips as nameserver to the system" |
221 | } |
222 | |
223 | get_network_nameserver() |
224 | { |
225 | local dns |
226 | local i |
227 | |
228 | dns=$(grep nameserver @@SYSCONFDIR@@/resolv.conf | sed 's:.*[[:space:]]\(.*\):\1:g') |
229 | for i in ${dns} |
230 | do |
231 | rvecho "${i}" |
232 | done |
233 | } |
234 | |
235 | set_network_nameserver() |
236 | { |
237 | local values="${CLASS_ARGV[*]}" |
238 | local CONFIG |
239 | local i |
240 | |
241 | [[ -z ${values} ]] && help_network_nameserver && return 1 |
242 | |
243 | CONFIG="@@SYSCONFDIR@@/resolv.conf" |
244 | clearconfig |
245 | for i in ${values} |
246 | do |
247 | addconfig "nameserver ${i}" |
248 | done |
249 | } |