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