Magellan Linux

Annotation of /mcore-src/trunk/mcore-tools/src/modules/network/network.client.class.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2668 - (hide annotations) (download)
Fri Dec 4 11:03:31 2015 UTC (8 years, 5 months ago) by niro
File size: 5373 byte(s)
-set_network_iface() is only supported by sysvinit atm
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    
39 niro 1248 [[ -z ${value} ]] && help_network_hostname && return 1
40    
41 niro 2187 CONFIG="@@SYSCONFDIR@@/hostname"
42 niro 1260 clearconfig
43     addconfig "${value}"
44 niro 1248 hostname "${value}"
45 niro 1351
46 niro 1605 # update hosts file
47 niro 2187 CONFIG="@@SYSCONFDIR@@/hosts"
48 niro 1605 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 niro 2398 if [[ ! -z $(pidof X) ]] || [[ -n $(pidof Xorg) ]]
60 niro 1351 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 niro 2076 mecho "get network.iface"
72     mecho " Lists all configured network interfaces"
73     mecho
74 niro 1248 mecho "set network.iface [iface] [networking] [ip] [netmask] [broadcast] [network]"
75 niro 2076 mecho " Configure network interfaces"
76 niro 1248 mecho " iface - the interface name"
77     mecho " networking - may be 'static' or 'dhcp'"
78     mecho " ip, netmask, broadcast and network are optional and only required on static networking"
79     }
80    
81 niro 2076 get_network_iface()
82     {
83     local iface
84 niro 2187 for iface in $(find ${MROOT}@@CONFDDIR@@ -maxdepth 1 -name 'net.*' -printf '%f\n')
85 niro 2076 do
86     case ${iface} in
87     # exclude routes and samples
88     net.sample|net.routes) continue ;;
89     esac
90     rvecho -n "${iface//net.}"
91 niro 2187 ( cat ${MROOT}@@CONFDDIR@@${iface}; echo ) | while read line
92 niro 2076 do
93     rvecho -n ";${line}"
94     done
95     rvecho
96     done
97     }
98    
99 niro 1248 set_network_iface()
100     {
101 niro 2269 local iface="${CLASS_ARGV[0]}"
102     local networking="${CLASS_ARGV[1]}"
103     local ip="${CLASS_ARGV[2]}"
104     local netmask="${CLASS_ARGV[3]}"
105     local broadcast="${CLASS_ARGV[4]}"
106     local network="${CLASS_ARGV[5]}"
107 niro 1260 local CONFIG
108 niro 2032 local dhcp_prog
109 niro 1248
110     [[ -z ${iface} ]] && help_network_iface && return 1
111     [[ -z ${networking} ]] && help_network_iface && return 1
112    
113 niro 1260 if [[ ${networking} = static ]]
114     then
115     [[ -z ${ip} ]] && help_network_iface && return 1
116     [[ -z ${netmask} ]] && help_network_iface && return 1
117     [[ -z ${broadcast} ]] && help_network_iface && return 1
118     [[ -z ${network} ]] && help_network_iface && return 1
119     fi
120 niro 1248
121 niro 2668 if is_provided systemd
122     then
123     decho "set_network_iface() is not supported with systemd, only sysvinit atm"
124     return 0
125     fi
126    
127 niro 2187 CONFIG="@@CONFDDIR@@/net.${iface}"
128 niro 1260 clearconfig
129     addconfig 'ONBOOT="yes"'
130    
131 niro 1248 case ${networking} in
132     static)
133 niro 1260 addconfig 'NETWORKING="static"'
134     addconfig "IP=\"${ip}\""
135     addconfig "NETMASK=\"${netmask}\""
136     addconfig "BROADCAST=\"${broadcast}\""
137     addconfig "NETWORK=\"${network}\""
138 niro 1248 ;;
139    
140     dhcp)
141 niro 1260 addconfig 'NETWORKING="dhcp"'
142 niro 1248 ;;
143     esac
144    
145 niro 2032 if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
146 niro 1248 then
147 niro 2032 if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]]
148     then
149 niro 2667 ${MCORE_LIBDIR}/mcore-system-service --restart --service network "${iface}"
150 niro 2032 else
151 niro 2667 ${MCORE_LIBDIR}/mcore-system-service --start --service network "${iface}"
152 niro 2032 fi
153 niro 1248 else
154 niro 2032 case ${networking} in
155     static)
156     ifconfig "${iface}" "${ip}" netmask "${netmask}" broadcast "${broadcast}"
157     ;;
158     dhcp)
159 niro 2187 source @@CONFDDIR@@/network
160 niro 2032 [[ ! -z $(pidof ${dhcp_prog}) ]] && killall ${DEFAULT_DHCP_PROG}
161     ${DEFAULT_DHCP_PROG} ${DEFAULT_DHCP_START} "${iface}"
162     ;;
163     esac
164 niro 1248 fi
165     }
166    
167 niro 1348 help_network_gateway()
168     {
169     mecho "get network.gateway"
170     mecho " displays the current network gateway"
171     mecho
172     mecho "set network.gateway [ip]"
173     mecho " sets the network gateway to [ip]"
174     }
175    
176     get_network_gateway()
177     {
178     local gw
179     gw=$(ip route | grep default | sed 's:.*via[[:space:]]\(.*\)[[:space:]]dev.*:\1:')
180 niro 1646 rvecho "${gw}"
181 niro 1348 }
182    
183 niro 1284 set_network_gateway()
184 niro 1248 {
185 niro 2269 local value="${CLASS_ARGV[0]}"
186 niro 1260 local CONFIG
187     local i
188    
189 niro 1348 [[ -z ${value} ]] && help_network_gateway && return 1
190    
191 niro 2187 CONFIG="@@CONFDDIR@@/net.routes"
192 niro 1260 clearconfig
193     addconfig "default gw ${value}"
194    
195     # delete other default gw first
196     for i in $(ip route | grep default | sed 's:.*via\ \(.*\)\ dev.*:\1:')
197     do
198     route del default gw "${i}"
199     done
200     route add default gw "${value}"
201 niro 1248 }
202    
203 niro 1348 help_network_nameserver()
204 niro 1248 {
205 niro 1348 mecho "get network.nameserver"
206     mecho " displays the current nameserver of the system"
207     mecho
208 niro 1351 mecho "set network.nameserver [ip1] [ip2] .. [ipN]"
209 niro 1348 mecho " adds given ips as nameserver to the system"
210     }
211    
212     get_network_nameserver()
213     {
214     local dns
215     local i
216    
217 niro 2187 dns=$(grep nameserver @@SYSCONFDIR@@/resolv.conf | sed 's:.*[[:space:]]\(.*\):\1:g')
218 niro 1348 for i in ${dns}
219     do
220 niro 1646 rvecho "${i}"
221 niro 1348 done
222     }
223    
224     set_network_nameserver()
225     {
226 niro 2269 local values="${CLASS_ARGV[*]}"
227 niro 1260 local CONFIG
228     local i
229 niro 1248
230 niro 1348 [[ -z ${values} ]] && help_network_nameserver && return 1
231    
232 niro 2187 CONFIG="@@SYSCONFDIR@@/resolv.conf"
233 niro 1260 clearconfig
234     for i in ${values}
235 niro 1248 do
236 niro 1260 addconfig "nameserver ${i}"
237 niro 1248 done
238     }