Magellan Linux

Diff of /mcore-src/trunk/mcore-tools/daemon/client/include/network.client.class

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

revision 1248 by niro, Wed Feb 2 20:20:24 2011 UTC revision 1896 by niro, Fri Nov 4 08:24:27 2011 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     hostname
19    }
20    
21  # set_network_hostname $value  # set_network_hostname $value
22  set_network_hostname()  set_network_hostname()
23  {  {
24   local value="$1"   local value="$1"
25     local CONFIG
26     local socket
27     local cookie
28     local authtype
29    
30   [[ -z ${value} ]] && help_network_hostname && return 1   [[ -z ${value} ]] && help_network_hostname && return 1
31    
32   echo "${value}" > /etc/hostname   CONFIG="/etc/hostname"
33     clearconfig
34     addconfig "${value}"
35   hostname "${value}"   hostname "${value}"
36    
37     # 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     # 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  }  }
59    
60  help_network_iface()  help_network_iface()
# Line 34  set_network_iface() Line 73  set_network_iface()
73   local netmask="$4"   local netmask="$4"
74   local broadcast="$5"   local broadcast="$5"
75   local network="$6"   local network="$6"
76   local config   local CONFIG
77    
78   [[ -z ${iface} ]] && help_network_iface && return 1   [[ -z ${iface} ]] && help_network_iface && return 1
79   [[ -z ${networking} ]] && help_network_iface && return 1   [[ -z ${networking} ]] && help_network_iface && return 1
80    
81   config=/etc/conf.d/net.${iface}   if [[ ${networking} = static ]]
82   echo 'ONBOOT="yes"' > ${config}   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    
89     CONFIG="/etc/conf.d/net.${iface}"
90     clearconfig
91     addconfig 'ONBOOT="yes"'
92    
93   case ${networking} in   case ${networking} in
94   static)   static)
95   echo 'NETWORKING="static"' >> ${config}   addconfig 'NETWORKING="static"'
96   echo "IP=\"${ip}\"" >> ${config}   addconfig "IP=\"${ip}\""
97   echo "NETMASK=\"${netmask}\"" >> ${config}   addconfig "NETMASK=\"${netmask}\""
98   echo "BROADCAST=\"${broadcast}\"" >> ${config}   addconfig "BROADCAST=\"${broadcast}\""
99     addconfig "NETWORK=\"${network}\""
100   ;;   ;;
101    
102   dhcp)   dhcp)
103   echo 'NETWORKING="dhcp"' >> ${config}   addconfig 'NETWORKING="dhcp"'
  #echo 'DHCP_PROG="/sbin/dhcpcd"' >> ${config}  
  #echo 'DHCP_START="-t 10"' >> ${config}  
  #echo 'DHCP_STOP="-k"' >> ${config}  
104   ;;   ;;
105   esac   esac
106    
107   if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]]   if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]]
108   then   then
109   /etc/init.d/network restart "${iface}"   set_system_service restart network "${iface}"
110   else   else
111   /etc/init.d/network start "${iface}"   set_system_service start network "${iface}"
112   fi   fi
113  }  }
114    
115  set_network_default_gw()  help_network_gateway()
116  {  {
117   local value   mecho "get network.gateway"
118   route add default gw ${value}   mecho " displays the current network gateway"
119   echo "default gw ${value}" > /etc/conf.d/net.routes   mecho
120     mecho "set network.gateway [ip]"
121     mecho " sets the network gateway to [ip]"
122  }  }
123    
124  set_network_dns()  get_network_gateway()
125    {
126     local gw
127     gw=$(ip route | grep default | sed 's:.*via[[:space:]]\(.*\)[[:space:]]dev.*:\1:')
128     rvecho "${gw}"
129    }
130    
131    set_network_gateway()
132    {
133     local value="$1"
134     local CONFIG
135     local i
136    
137     [[ -z ${value} ]] && help_network_gateway && return 1
138    
139     CONFIG="/etc/conf.d/net.routes"
140     clearconfig
141     addconfig "default gw ${value}"
142    
143     # delete other default gw first
144     for i in $(ip route | grep default | sed 's:.*via\ \(.*\)\ dev.*:\1:')
145     do
146     route del default gw "${i}"
147     done
148     route add default gw "${value}"
149    }
150    
151    help_network_nameserver()
152    {
153     mecho "get network.nameserver"
154     mecho " displays the current nameserver of the system"
155     mecho
156     mecho "set network.nameserver [ip1] [ip2] .. [ipN]"
157     mecho " adds given ips as nameserver to the system"
158    }
159    
160    get_network_nameserver()
161  {  {
  local values="$@"  
162   local dns   local dns
163     local i
164    
165     dns=$(grep nameserver /etc/resolv.conf | sed 's:.*[[:space:]]\(.*\):\1:g')
166     for i in ${dns}
167     do
168     rvecho "${i}"
169     done
170    }
171    
172    set_network_nameserver()
173    {
174     local values="$@"
175     local CONFIG
176     local i
177    
178     [[ -z ${values} ]] && help_network_nameserver && return 1
179    
180   :> /etc/resolv.conf   CONFIG="/etc/resolv.conf"
181   for dns in ${values}   clearconfig
182     for i in ${values}
183   do   do
184   echo "${dns}" >> /etc/resolv.conf   addconfig "nameserver ${i}"
185   done   done
186  }  }

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