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