Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

mcore-src/trunk/mcore-tools/daemon/client/include/network.client.class revision 1896 by niro, Fri Nov 4 08:24:27 2011 UTC mcore-src/trunk/mcore-tools/src/modules/network/network.client.class.in revision 2668 by niro, Fri Dec 4 11:03:31 2015 UTC
# Line 1  Line 1 
1  # $Id$  # $Id$
2    
3  provide basic-networking  provide basic-networking
4  require basic-system  require basic-system basic-init
5    
6  help_network_hostname()  help_network_hostname()
7  {  {
8   mecho "get network.hostname"   mecho "get network.hostname"
9   mecho " displays the current hostname"   mecho " Displays the current hostname"
10   mecho   mecho
11   mecho "set network.hostname [hostname]"   mecho "set network.hostname [hostname]"
12   mecho " Sets the hostname of the system"   mecho " Sets the hostname of the system"
# Line 15  help_network_hostname() Line 15  help_network_hostname()
15    
16  get_network_hostname()  get_network_hostname()
17  {  {
18   hostname   local val
19    
20     if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
21     then
22     val=$(hostname)
23     else
24     val=$(< @@SYSCONFDIR@@/hostname)
25     fi
26    
27     rvecho "${val}"
28  }  }
29    
30  # set_network_hostname $value  # set_network_hostname $value
31  set_network_hostname()  set_network_hostname()
32  {  {
33   local value="$1"   local value="${CLASS_ARGV[0]}"
34   local CONFIG   local CONFIG
35   local socket   local socket
36   local cookie   local cookie
# Line 29  set_network_hostname() Line 38  set_network_hostname()
38    
39   [[ -z ${value} ]] && help_network_hostname && return 1   [[ -z ${value} ]] && help_network_hostname && return 1
40    
41   CONFIG="/etc/hostname"   CONFIG="@@SYSCONFDIR@@/hostname"
42   clearconfig   clearconfig
43   addconfig "${value}"   addconfig "${value}"
44   hostname "${value}"   hostname "${value}"
45    
46   # update hosts file   # update hosts file
47   CONFIG="/etc/hosts"   CONFIG="@@SYSCONFDIR@@/hosts"
48   clearconfig   clearconfig
49   addconfig "127.0.0.1 localhost ${value}"   addconfig "127.0.0.1 localhost ${value}"
50   # add ipv6 defaults   # add ipv6 defaults
# Line 47  set_network_hostname() Line 56  set_network_hostname()
56   addconfig "ff02::3 ip6-allhosts"   addconfig "ff02::3 ip6-allhosts"
57    
58   # check for running x11 and recreate the xauth cookie with the correct hostname   # check for running x11 and recreate the xauth cookie with the correct hostname
59   if [[ ! -z $(pidof X) ]]   if [[ ! -z $(pidof X) ]]  || [[ -n $(pidof Xorg) ]]
60   then   then
61   socket="${value}/unix${MCORE_XORG_DISPLAY}"   socket="${value}/unix${MCORE_XORG_DISPLAY}"
62   cookie=$(x11runas "xauth list | sed 's:.*\ \(.*\):\1:'")   cookie=$(x11runas "xauth list | sed 's:.*\ \(.*\):\1:'")
# Line 59  set_network_hostname() Line 68  set_network_hostname()
68    
69  help_network_iface()  help_network_iface()
70  {  {
71     mecho "get network.iface"
72     mecho " Lists all configured network interfaces"
73     mecho
74   mecho "set network.iface [iface] [networking] [ip] [netmask] [broadcast] [network]"   mecho "set network.iface [iface] [networking] [ip] [netmask] [broadcast] [network]"
75     mecho " Configure network interfaces"
76   mecho "  iface - the interface name"   mecho "  iface - the interface name"
77   mecho "  networking - may be 'static' or 'dhcp'"   mecho "  networking - may be 'static' or 'dhcp'"
78   mecho "  ip, netmask, broadcast and network are optional and only required on static networking"   mecho "  ip, netmask, broadcast and network are optional and only required on static networking"
79  }  }
80    
81    get_network_iface()
82    {
83     local iface
84     for iface in $(find ${MROOT}@@CONFDDIR@@ -maxdepth 1 -name 'net.*' -printf '%f\n')
85     do
86     case ${iface} in
87     # exclude routes and samples
88     net.sample|net.routes) continue ;;
89     esac
90     rvecho -n "${iface//net.}"
91     ( cat ${MROOT}@@CONFDDIR@@${iface}; echo ) | while read line
92     do
93     rvecho -n ";${line}"
94     done
95     rvecho
96     done
97    }
98    
99  set_network_iface()  set_network_iface()
100  {  {
101   local iface="$1"   local iface="${CLASS_ARGV[0]}"
102   local networking="$2"   local networking="${CLASS_ARGV[1]}"
103   local ip="$3"   local ip="${CLASS_ARGV[2]}"
104   local netmask="$4"   local netmask="${CLASS_ARGV[3]}"
105   local broadcast="$5"   local broadcast="${CLASS_ARGV[4]}"
106   local network="$6"   local network="${CLASS_ARGV[5]}"
107   local CONFIG   local CONFIG
108     local dhcp_prog
109    
110   [[ -z ${iface} ]] && help_network_iface && return 1   [[ -z ${iface} ]] && help_network_iface && return 1
111   [[ -z ${networking} ]] && help_network_iface && return 1   [[ -z ${networking} ]] && help_network_iface && return 1
# Line 86  set_network_iface() Line 118  set_network_iface()
118   [[ -z ${network} ]] && help_network_iface && return 1   [[ -z ${network} ]] && help_network_iface && return 1
119   fi   fi
120    
121   CONFIG="/etc/conf.d/net.${iface}"   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     CONFIG="@@CONFDDIR@@/net.${iface}"
128   clearconfig   clearconfig
129   addconfig 'ONBOOT="yes"'   addconfig 'ONBOOT="yes"'
130    
# Line 104  set_network_iface() Line 142  set_network_iface()
142   ;;   ;;
143   esac   esac
144    
145   if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]]   if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
146   then   then
147   set_system_service restart network "${iface}"   if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]]
148     then
149     ${MCORE_LIBDIR}/mcore-system-service --restart --service network "${iface}"
150     else
151     ${MCORE_LIBDIR}/mcore-system-service --start --service network "${iface}"
152     fi
153   else   else
154   set_system_service start network "${iface}"   case ${networking} in
155     static)
156     ifconfig "${iface}" "${ip}" netmask "${netmask}" broadcast "${broadcast}"
157     ;;
158     dhcp)
159     source @@CONFDDIR@@/network
160     [[ ! -z $(pidof ${dhcp_prog}) ]] && killall ${DEFAULT_DHCP_PROG}
161     ${DEFAULT_DHCP_PROG} ${DEFAULT_DHCP_START} "${iface}"
162     ;;
163     esac
164   fi   fi
165  }  }
166    
# Line 130  get_network_gateway() Line 182  get_network_gateway()
182    
183  set_network_gateway()  set_network_gateway()
184  {  {
185   local value="$1"   local value="${CLASS_ARGV[0]}"
186   local CONFIG   local CONFIG
187   local i   local i
188    
189   [[ -z ${value} ]] && help_network_gateway && return 1   [[ -z ${value} ]] && help_network_gateway && return 1
190    
191   CONFIG="/etc/conf.d/net.routes"   CONFIG="@@CONFDDIR@@/net.routes"
192   clearconfig   clearconfig
193   addconfig "default gw ${value}"   addconfig "default gw ${value}"
194    
# Line 162  get_network_nameserver() Line 214  get_network_nameserver()
214   local dns   local dns
215   local i   local i
216    
217   dns=$(grep nameserver /etc/resolv.conf | sed 's:.*[[:space:]]\(.*\):\1:g')   dns=$(grep nameserver @@SYSCONFDIR@@/resolv.conf | sed 's:.*[[:space:]]\(.*\):\1:g')
218   for i in ${dns}   for i in ${dns}
219   do   do
220   rvecho "${i}"   rvecho "${i}"
# Line 171  get_network_nameserver() Line 223  get_network_nameserver()
223    
224  set_network_nameserver()  set_network_nameserver()
225  {  {
226   local values="$@"   local values="${CLASS_ARGV[*]}"
227   local CONFIG   local CONFIG
228   local i   local i
229    
230   [[ -z ${values} ]] && help_network_nameserver && return 1   [[ -z ${values} ]] && help_network_nameserver && return 1
231    
232   CONFIG="/etc/resolv.conf"   CONFIG="@@SYSCONFDIR@@/resolv.conf"
233   clearconfig   clearconfig
234   for i in ${values}   for i in ${values}
235   do   do

Legend:
Removed from v.1896  
changed lines
  Added in v.2668