Annotation of /mcore-src/trunk/mcore-tools/src/modules/network/network.client.class.in
Parent Directory | Revision Log
Revision 2672 -
(hide annotations)
(download)
Fri Dec 4 12:12:07 2015 UTC (8 years, 5 months ago) by niro
File size: 5671 byte(s)
Fri Dec 4 12:12:07 2015 UTC (8 years, 5 months ago) by niro
File size: 5671 byte(s)
-fixed several typos
1 | niro | 1248 | # $Id$ |
2 | |||
3 | provide basic-networking | ||
4 | niro | 2667 | require basic-system basic-init |
5 | niro | 1248 | |
6 | help_network_hostname() | ||
7 | { | ||
8 | niro | 1348 | mecho "get network.hostname" |
9 | niro | 2076 | mecho " Displays the current hostname" |
10 | niro | 1348 | mecho |
11 | niro | 1248 | mecho "set network.hostname [hostname]" |
12 | niro | 1348 | mecho " Sets the hostname of the system" |
13 | niro | 1248 | mecho " mcore - the local hostname" |
14 | } | ||
15 | |||
16 | niro | 1348 | get_network_hostname() |
17 | { | ||
18 | niro | 2026 | local val |
19 | |||
20 | if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] | ||
21 | then | ||
22 | val=$(hostname) | ||
23 | else | ||
24 | niro | 2187 | val=$(< @@SYSCONFDIR@@/hostname) |
25 | niro | 2026 | fi |
26 | |||
27 | rvecho "${val}" | ||
28 | niro | 1348 | } |
29 | |||
30 | niro | 1248 | # set_network_hostname $value |
31 | set_network_hostname() | ||
32 | { | ||
33 | niro | 2269 | local value="${CLASS_ARGV[0]}" |
34 | niro | 1260 | local CONFIG |
35 | niro | 1351 | local socket |
36 | local cookie | ||
37 | local authtype | ||
38 | niro | 2669 | local networksvc |
39 | niro | 1351 | |
40 | niro | 1248 | [[ -z ${value} ]] && help_network_hostname && return 1 |
41 | |||
42 | niro | 2187 | CONFIG="@@SYSCONFDIR@@/hostname" |
43 | niro | 1260 | clearconfig |
44 | addconfig "${value}" | ||
45 | niro | 1248 | hostname "${value}" |
46 | niro | 1351 | |
47 | niro | 1605 | # update hosts file |
48 | niro | 2187 | CONFIG="@@SYSCONFDIR@@/hosts" |
49 | niro | 1605 | 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 | niro | 1351 | # check for running x11 and recreate the xauth cookie with the correct hostname |
60 | niro | 2398 | if [[ ! -z $(pidof X) ]] || [[ -n $(pidof Xorg) ]] |
61 | niro | 1351 | 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 | niro | 2669 | |
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 | niro | 2672 | then |
75 | niro | 2669 | networksvc="network" |
76 | fi | ||
77 | niro | 2672 | ${MCORE_LIBDIR}/mcore-system-service --restart --service "${networksvc}" |
78 | niro | 1248 | } |
79 | |||
80 | help_network_iface() | ||
81 | { | ||
82 | niro | 2076 | mecho "get network.iface" |
83 | mecho " Lists all configured network interfaces" | ||
84 | mecho | ||
85 | niro | 1248 | mecho "set network.iface [iface] [networking] [ip] [netmask] [broadcast] [network]" |
86 | niro | 2076 | mecho " Configure network interfaces" |
87 | niro | 1248 | 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 | niro | 2076 | get_network_iface() |
93 | { | ||
94 | local iface | ||
95 | niro | 2187 | for iface in $(find ${MROOT}@@CONFDDIR@@ -maxdepth 1 -name 'net.*' -printf '%f\n') |
96 | niro | 2076 | do |
97 | case ${iface} in | ||
98 | # exclude routes and samples | ||
99 | net.sample|net.routes) continue ;; | ||
100 | esac | ||
101 | rvecho -n "${iface//net.}" | ||
102 | niro | 2187 | ( cat ${MROOT}@@CONFDDIR@@${iface}; echo ) | while read line |
103 | niro | 2076 | do |
104 | rvecho -n ";${line}" | ||
105 | done | ||
106 | rvecho | ||
107 | done | ||
108 | } | ||
109 | |||
110 | niro | 1248 | set_network_iface() |
111 | { | ||
112 | niro | 2269 | 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 | niro | 1260 | local CONFIG |
119 | niro | 2032 | local dhcp_prog |
120 | niro | 1248 | |
121 | [[ -z ${iface} ]] && help_network_iface && return 1 | ||
122 | [[ -z ${networking} ]] && help_network_iface && return 1 | ||
123 | |||
124 | niro | 1260 | 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 | niro | 1248 | |
132 | niro | 2668 | 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 | niro | 2187 | CONFIG="@@CONFDDIR@@/net.${iface}" |
139 | niro | 1260 | clearconfig |
140 | addconfig 'ONBOOT="yes"' | ||
141 | |||
142 | niro | 1248 | case ${networking} in |
143 | static) | ||
144 | niro | 1260 | addconfig 'NETWORKING="static"' |
145 | addconfig "IP=\"${ip}\"" | ||
146 | addconfig "NETMASK=\"${netmask}\"" | ||
147 | addconfig "BROADCAST=\"${broadcast}\"" | ||
148 | addconfig "NETWORK=\"${network}\"" | ||
149 | niro | 1248 | ;; |
150 | |||
151 | dhcp) | ||
152 | niro | 1260 | addconfig 'NETWORKING="dhcp"' |
153 | niro | 1248 | ;; |
154 | esac | ||
155 | |||
156 | niro | 2032 | if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] |
157 | niro | 1248 | then |
158 | niro | 2032 | if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]] |
159 | then | ||
160 | niro | 2667 | ${MCORE_LIBDIR}/mcore-system-service --restart --service network "${iface}" |
161 | niro | 2032 | else |
162 | niro | 2667 | ${MCORE_LIBDIR}/mcore-system-service --start --service network "${iface}" |
163 | niro | 2032 | fi |
164 | niro | 1248 | else |
165 | niro | 2032 | case ${networking} in |
166 | static) | ||
167 | ifconfig "${iface}" "${ip}" netmask "${netmask}" broadcast "${broadcast}" | ||
168 | ;; | ||
169 | dhcp) | ||
170 | niro | 2187 | source @@CONFDDIR@@/network |
171 | niro | 2032 | [[ ! -z $(pidof ${dhcp_prog}) ]] && killall ${DEFAULT_DHCP_PROG} |
172 | ${DEFAULT_DHCP_PROG} ${DEFAULT_DHCP_START} "${iface}" | ||
173 | ;; | ||
174 | esac | ||
175 | niro | 1248 | fi |
176 | } | ||
177 | |||
178 | niro | 1348 | 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 | niro | 1646 | rvecho "${gw}" |
192 | niro | 1348 | } |
193 | |||
194 | niro | 1284 | set_network_gateway() |
195 | niro | 1248 | { |
196 | niro | 2269 | local value="${CLASS_ARGV[0]}" |
197 | niro | 1260 | local CONFIG |
198 | local i | ||
199 | |||
200 | niro | 1348 | [[ -z ${value} ]] && help_network_gateway && return 1 |
201 | |||
202 | niro | 2187 | CONFIG="@@CONFDDIR@@/net.routes" |
203 | niro | 1260 | 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 | niro | 1248 | } |
213 | |||
214 | niro | 1348 | help_network_nameserver() |
215 | niro | 1248 | { |
216 | niro | 1348 | mecho "get network.nameserver" |
217 | mecho " displays the current nameserver of the system" | ||
218 | mecho | ||
219 | niro | 1351 | mecho "set network.nameserver [ip1] [ip2] .. [ipN]" |
220 | niro | 1348 | mecho " adds given ips as nameserver to the system" |
221 | } | ||
222 | |||
223 | get_network_nameserver() | ||
224 | { | ||
225 | local dns | ||
226 | local i | ||
227 | |||
228 | niro | 2187 | dns=$(grep nameserver @@SYSCONFDIR@@/resolv.conf | sed 's:.*[[:space:]]\(.*\):\1:g') |
229 | niro | 1348 | for i in ${dns} |
230 | do | ||
231 | niro | 1646 | rvecho "${i}" |
232 | niro | 1348 | done |
233 | } | ||
234 | |||
235 | set_network_nameserver() | ||
236 | { | ||
237 | niro | 2269 | local values="${CLASS_ARGV[*]}" |
238 | niro | 1260 | local CONFIG |
239 | local i | ||
240 | niro | 1248 | |
241 | niro | 1348 | [[ -z ${values} ]] && help_network_nameserver && return 1 |
242 | |||
243 | niro | 2187 | CONFIG="@@SYSCONFDIR@@/resolv.conf" |
244 | niro | 1260 | clearconfig |
245 | for i in ${values} | ||
246 | niro | 1248 | do |
247 | niro | 1260 | addconfig "nameserver ${i}" |
248 | niro | 1248 | done |
249 | } |