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 1248 by niro, Wed Feb 2 20:20:24 2011 UTC mcore-src/trunk/mcore-tools/src/modules/network/network.client.class.in revision 2186 by niro, Fri Jan 10 14:26:15 2014 UTC
# Line 1  Line 1 
1  # $Id$  # $Id$
2    
3  provide basic-networking  provide basic-networking
4    require basic-system
5    
6  help_network_hostname()  help_network_hostname()
7  {  {
8     mecho "get network.hostname"
9     mecho " Displays the current hostname"
10     mecho
11   mecho "set network.hostname [hostname]"   mecho "set network.hostname [hostname]"
12     mecho " Sets the hostname of the system"
13   mecho "  mcore - the local hostname"   mecho "  mcore - the local hostname"
14  }  }
15    
16    get_network_hostname()
17    {
18     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    }
29    
30  # set_network_hostname $value  # set_network_hostname $value
31  set_network_hostname()  set_network_hostname()
32  {  {
33   local value="$1"   local value="$1"
34     local CONFIG
35     local socket
36     local cookie
37     local authtype
38    
39   [[ -z ${value} ]] && help_network_hostname && return 1   [[ -z ${value} ]] && help_network_hostname && return 1
40    
41   echo "${value}" > /etc/hostname   CONFIG="/etc/hostname"
42     clearconfig
43     addconfig "${value}"
44   hostname "${value}"   hostname "${value}"
45    
46     # 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     # 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  }  }
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}/etc/conf.d -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}/etc/conf.d/${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="$1"
# Line 34  set_network_iface() Line 104  set_network_iface()
104   local netmask="$4"   local netmask="$4"
105   local broadcast="$5"   local broadcast="$5"
106   local network="$6"   local network="$6"
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
112    
113   config=/etc/conf.d/net.${iface}   if [[ ${networking} = static ]]
114   echo 'ONBOOT="yes"' > ${config}   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    
121     CONFIG="/etc/conf.d/net.${iface}"
122     clearconfig
123     addconfig 'ONBOOT="yes"'
124    
125   case ${networking} in   case ${networking} in
126   static)   static)
127   echo 'NETWORKING="static"' >> ${config}   addconfig 'NETWORKING="static"'
128   echo "IP=\"${ip}\"" >> ${config}   addconfig "IP=\"${ip}\""
129   echo "NETMASK=\"${netmask}\"" >> ${config}   addconfig "NETMASK=\"${netmask}\""
130   echo "BROADCAST=\"${broadcast}\"" >> ${config}   addconfig "BROADCAST=\"${broadcast}\""
131     addconfig "NETWORK=\"${network}\""
132   ;;   ;;
133    
134   dhcp)   dhcp)
135   echo 'NETWORKING="dhcp"' >> ${config}   addconfig 'NETWORKING="dhcp"'
  #echo 'DHCP_PROG="/sbin/dhcpcd"' >> ${config}  
  #echo 'DHCP_START="-t 10"' >> ${config}  
  #echo 'DHCP_STOP="-k"' >> ${config}  
136   ;;   ;;
137   esac   esac
138    
139   if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]]   if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
140   then   then
141   /etc/init.d/network restart "${iface}"   if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]]
142     then
143     set_system_service restart network "${iface}"
144     else
145     set_system_service start network "${iface}"
146     fi
147   else   else
148   /etc/init.d/network start "${iface}"   case ${networking} in
149     static)
150     ifconfig "${iface}" "${ip}" netmask "${netmask}" broadcast "${broadcast}"
151     ;;
152     dhcp)
153     source /etc/conf.d/network
154     [[ ! -z $(pidof ${dhcp_prog}) ]] && killall ${DEFAULT_DHCP_PROG}
155     ${DEFAULT_DHCP_PROG} ${DEFAULT_DHCP_START} "${iface}"
156     ;;
157     esac
158   fi   fi
159  }  }
160    
161  set_network_default_gw()  help_network_gateway()
162  {  {
163   local value   mecho "get network.gateway"
164   route add default gw ${value}   mecho " displays the current network gateway"
165   echo "default gw ${value}" > /etc/conf.d/net.routes   mecho
166     mecho "set network.gateway [ip]"
167     mecho " sets the network gateway to [ip]"
168  }  }
169    
170  set_network_dns()  get_network_gateway()
171    {
172     local gw
173     gw=$(ip route | grep default | sed 's:.*via[[:space:]]\(.*\)[[:space:]]dev.*:\1:')
174     rvecho "${gw}"
175    }
176    
177    set_network_gateway()
178    {
179     local value="$1"
180     local CONFIG
181     local i
182    
183     [[ -z ${value} ]] && help_network_gateway && return 1
184    
185     CONFIG="/etc/conf.d/net.routes"
186     clearconfig
187     addconfig "default gw ${value}"
188    
189     # delete other default gw first
190     for i in $(ip route | grep default | sed 's:.*via\ \(.*\)\ dev.*:\1:')
191     do
192     route del default gw "${i}"
193     done
194     route add default gw "${value}"
195    }
196    
197    help_network_nameserver()
198    {
199     mecho "get network.nameserver"
200     mecho " displays the current nameserver of the system"
201     mecho
202     mecho "set network.nameserver [ip1] [ip2] .. [ipN]"
203     mecho " adds given ips as nameserver to the system"
204    }
205    
206    get_network_nameserver()
207  {  {
  local values="$@"  
208   local dns   local dns
209     local i
210    
211     dns=$(grep nameserver /etc/resolv.conf | sed 's:.*[[:space:]]\(.*\):\1:g')
212     for i in ${dns}
213     do
214     rvecho "${i}"
215     done
216    }
217    
218    set_network_nameserver()
219    {
220     local values="$@"
221     local CONFIG
222     local i
223    
224     [[ -z ${values} ]] && help_network_nameserver && return 1
225    
226   :> /etc/resolv.conf   CONFIG="/etc/resolv.conf"
227   for dns in ${values}   clearconfig
228     for i in ${values}
229   do   do
230   echo "${dns}" >> /etc/resolv.conf   addconfig "nameserver ${i}"
231   done   done
232  }  }

Legend:
Removed from v.1248  
changed lines
  Added in v.2186