Annotation of /mcore-src/trunk/mcore-tools/src/modules/network/network.client.class.in
Parent Directory | Revision Log
Revision 2026 -
(hide annotations)
(download)
Mon Aug 13 11:28:31 2012 UTC (11 years, 8 months ago) by niro
Original Path: mcore-src/trunk/mcore-tools/daemon/client/include/network.client.class
File size: 4095 byte(s)
Mon Aug 13 11:28:31 2012 UTC (11 years, 8 months ago) by niro
Original Path: mcore-src/trunk/mcore-tools/daemon/client/include/network.client.class
File size: 4095 byte(s)
-support $MROOT variable
1 | niro | 1248 | # $Id$ |
2 | |||
3 | provide basic-networking | ||
4 | niro | 1260 | require basic-system |
5 | niro | 1248 | |
6 | help_network_hostname() | ||
7 | { | ||
8 | niro | 1348 | mecho "get network.hostname" |
9 | mecho " displays the current hostname" | ||
10 | 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 | val=$(< /etc/hostname) | ||
25 | fi | ||
26 | |||
27 | rvecho "${val}" | ||
28 | niro | 1348 | } |
29 | |||
30 | niro | 1248 | # set_network_hostname $value |
31 | set_network_hostname() | ||
32 | { | ||
33 | local value="$1" | ||
34 | niro | 1260 | local CONFIG |
35 | niro | 1351 | local socket |
36 | local cookie | ||
37 | local authtype | ||
38 | |||
39 | niro | 1248 | [[ -z ${value} ]] && help_network_hostname && return 1 |
40 | |||
41 | niro | 1260 | CONFIG="/etc/hostname" |
42 | clearconfig | ||
43 | addconfig "${value}" | ||
44 | niro | 1248 | hostname "${value}" |
45 | niro | 1351 | |
46 | niro | 1605 | # update hosts file |
47 | CONFIG="/etc/hosts" | ||
48 | clearconfig | ||
49 | addconfig "127.0.0.1 localhost ${value}" | ||
50 | # add ipv6 defaults | ||
51 | addconfig "::1 ip6-localhost ip6-loopback" | ||
52 | addconfig "fe00::0 ip6-localnet" | ||
53 | addconfig "ff00::0 ip6-mcastprefix" | ||
54 | addconfig "ff02::1 ip6-allnodes" | ||
55 | addconfig "ff02::2 ip6-allrouters" | ||
56 | addconfig "ff02::3 ip6-allhosts" | ||
57 | |||
58 | niro | 1351 | # check for running x11 and recreate the xauth cookie with the correct hostname |
59 | if [[ ! -z $(pidof X) ]] | ||
60 | then | ||
61 | socket="${value}/unix${MCORE_XORG_DISPLAY}" | ||
62 | cookie=$(x11runas "xauth list | sed 's:.*\ \(.*\):\1:'") | ||
63 | authtype="MIT-MAGIC-COOKIE-1" | ||
64 | # add the new hostname to the xauthority file | ||
65 | x11runas "xauth add ${socket} ${authtype} ${cookie}" | ||
66 | fi | ||
67 | niro | 1248 | } |
68 | |||
69 | help_network_iface() | ||
70 | { | ||
71 | mecho "set network.iface [iface] [networking] [ip] [netmask] [broadcast] [network]" | ||
72 | mecho " iface - the interface name" | ||
73 | mecho " networking - may be 'static' or 'dhcp'" | ||
74 | mecho " ip, netmask, broadcast and network are optional and only required on static networking" | ||
75 | } | ||
76 | |||
77 | set_network_iface() | ||
78 | { | ||
79 | local iface="$1" | ||
80 | local networking="$2" | ||
81 | local ip="$3" | ||
82 | local netmask="$4" | ||
83 | local broadcast="$5" | ||
84 | local network="$6" | ||
85 | niro | 1260 | local CONFIG |
86 | niro | 1248 | |
87 | [[ -z ${iface} ]] && help_network_iface && return 1 | ||
88 | [[ -z ${networking} ]] && help_network_iface && return 1 | ||
89 | |||
90 | niro | 1260 | if [[ ${networking} = static ]] |
91 | then | ||
92 | [[ -z ${ip} ]] && help_network_iface && return 1 | ||
93 | [[ -z ${netmask} ]] && help_network_iface && return 1 | ||
94 | [[ -z ${broadcast} ]] && help_network_iface && return 1 | ||
95 | [[ -z ${network} ]] && help_network_iface && return 1 | ||
96 | fi | ||
97 | niro | 1248 | |
98 | niro | 1260 | CONFIG="/etc/conf.d/net.${iface}" |
99 | clearconfig | ||
100 | addconfig 'ONBOOT="yes"' | ||
101 | |||
102 | niro | 1248 | case ${networking} in |
103 | static) | ||
104 | niro | 1260 | addconfig 'NETWORKING="static"' |
105 | addconfig "IP=\"${ip}\"" | ||
106 | addconfig "NETMASK=\"${netmask}\"" | ||
107 | addconfig "BROADCAST=\"${broadcast}\"" | ||
108 | addconfig "NETWORK=\"${network}\"" | ||
109 | niro | 1248 | ;; |
110 | |||
111 | dhcp) | ||
112 | niro | 1260 | addconfig 'NETWORKING="dhcp"' |
113 | niro | 1248 | ;; |
114 | esac | ||
115 | |||
116 | if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]] | ||
117 | then | ||
118 | niro | 1260 | set_system_service restart network "${iface}" |
119 | niro | 1248 | else |
120 | niro | 1260 | set_system_service start network "${iface}" |
121 | niro | 1248 | fi |
122 | } | ||
123 | |||
124 | niro | 1348 | help_network_gateway() |
125 | { | ||
126 | mecho "get network.gateway" | ||
127 | mecho " displays the current network gateway" | ||
128 | mecho | ||
129 | mecho "set network.gateway [ip]" | ||
130 | mecho " sets the network gateway to [ip]" | ||
131 | } | ||
132 | |||
133 | get_network_gateway() | ||
134 | { | ||
135 | local gw | ||
136 | gw=$(ip route | grep default | sed 's:.*via[[:space:]]\(.*\)[[:space:]]dev.*:\1:') | ||
137 | niro | 1646 | rvecho "${gw}" |
138 | niro | 1348 | } |
139 | |||
140 | niro | 1284 | set_network_gateway() |
141 | niro | 1248 | { |
142 | niro | 1284 | local value="$1" |
143 | niro | 1260 | local CONFIG |
144 | local i | ||
145 | |||
146 | niro | 1348 | [[ -z ${value} ]] && help_network_gateway && return 1 |
147 | |||
148 | niro | 1260 | CONFIG="/etc/conf.d/net.routes" |
149 | clearconfig | ||
150 | addconfig "default gw ${value}" | ||
151 | |||
152 | # delete other default gw first | ||
153 | for i in $(ip route | grep default | sed 's:.*via\ \(.*\)\ dev.*:\1:') | ||
154 | do | ||
155 | route del default gw "${i}" | ||
156 | done | ||
157 | route add default gw "${value}" | ||
158 | niro | 1248 | } |
159 | |||
160 | niro | 1348 | help_network_nameserver() |
161 | niro | 1248 | { |
162 | niro | 1348 | mecho "get network.nameserver" |
163 | mecho " displays the current nameserver of the system" | ||
164 | mecho | ||
165 | niro | 1351 | mecho "set network.nameserver [ip1] [ip2] .. [ipN]" |
166 | niro | 1348 | mecho " adds given ips as nameserver to the system" |
167 | } | ||
168 | |||
169 | get_network_nameserver() | ||
170 | { | ||
171 | local dns | ||
172 | local i | ||
173 | |||
174 | dns=$(grep nameserver /etc/resolv.conf | sed 's:.*[[:space:]]\(.*\):\1:g') | ||
175 | for i in ${dns} | ||
176 | do | ||
177 | niro | 1646 | rvecho "${i}" |
178 | niro | 1348 | done |
179 | } | ||
180 | |||
181 | set_network_nameserver() | ||
182 | { | ||
183 | niro | 1248 | local values="$@" |
184 | niro | 1260 | local CONFIG |
185 | local i | ||
186 | niro | 1248 | |
187 | niro | 1348 | [[ -z ${values} ]] && help_network_nameserver && return 1 |
188 | |||
189 | niro | 1260 | CONFIG="/etc/resolv.conf" |
190 | clearconfig | ||
191 | for i in ${values} | ||
192 | niro | 1248 | do |
193 | niro | 1260 | addconfig "nameserver ${i}" |
194 | niro | 1248 | done |
195 | } |