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

revision 1248 by niro, Wed Feb 2 20:20:24 2011 UTC revision 2032 by niro, Mon Aug 13 11:59:21 2012 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()
# Line 34  set_network_iface() Line 82  set_network_iface()
82   local netmask="$4"   local netmask="$4"
83   local broadcast="$5"   local broadcast="$5"
84   local network="$6"   local network="$6"
85   local config   local CONFIG
86     local dhcp_prog
87    
88   [[ -z ${iface} ]] && help_network_iface && return 1   [[ -z ${iface} ]] && help_network_iface && return 1
89   [[ -z ${networking} ]] && help_network_iface && return 1   [[ -z ${networking} ]] && help_network_iface && return 1
90    
91   config=/etc/conf.d/net.${iface}   if [[ ${networking} = static ]]
92   echo 'ONBOOT="yes"' > ${config}   then
93     [[ -z ${ip} ]] && help_network_iface && return 1
94     [[ -z ${netmask} ]] && help_network_iface && return 1
95     [[ -z ${broadcast} ]] && help_network_iface && return 1
96     [[ -z ${network} ]] && help_network_iface && return 1
97     fi
98    
99     CONFIG="/etc/conf.d/net.${iface}"
100     clearconfig
101     addconfig 'ONBOOT="yes"'
102    
103   case ${networking} in   case ${networking} in
104   static)   static)
105   echo 'NETWORKING="static"' >> ${config}   addconfig 'NETWORKING="static"'
106   echo "IP=\"${ip}\"" >> ${config}   addconfig "IP=\"${ip}\""
107   echo "NETMASK=\"${netmask}\"" >> ${config}   addconfig "NETMASK=\"${netmask}\""
108   echo "BROADCAST=\"${broadcast}\"" >> ${config}   addconfig "BROADCAST=\"${broadcast}\""
109     addconfig "NETWORK=\"${network}\""
110   ;;   ;;
111    
112   dhcp)   dhcp)
113   echo 'NETWORKING="dhcp"' >> ${config}   addconfig 'NETWORKING="dhcp"'
  #echo 'DHCP_PROG="/sbin/dhcpcd"' >> ${config}  
  #echo 'DHCP_START="-t 10"' >> ${config}  
  #echo 'DHCP_STOP="-k"' >> ${config}  
114   ;;   ;;
115   esac   esac
116    
117   if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]]   if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
118   then   then
119   /etc/init.d/network restart "${iface}"   if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]]
120     then
121     set_system_service restart network "${iface}"
122     else
123     set_system_service start network "${iface}"
124     fi
125   else   else
126   /etc/init.d/network start "${iface}"   case ${networking} in
127     static)
128     ifconfig "${iface}" "${ip}" netmask "${netmask}" broadcast "${broadcast}"
129     ;;
130     dhcp)
131     source /etc/conf.d/network
132     [[ ! -z $(pidof ${dhcp_prog}) ]] && killall ${DEFAULT_DHCP_PROG}
133     ${DEFAULT_DHCP_PROG} ${DEFAULT_DHCP_START} "${iface}"
134     ;;
135     esac
136   fi   fi
137  }  }
138    
139  set_network_default_gw()  help_network_gateway()
140  {  {
141   local value   mecho "get network.gateway"
142   route add default gw ${value}   mecho " displays the current network gateway"
143   echo "default gw ${value}" > /etc/conf.d/net.routes   mecho
144     mecho "set network.gateway [ip]"
145     mecho " sets the network gateway to [ip]"
146  }  }
147    
148  set_network_dns()  get_network_gateway()
149    {
150     local gw
151     gw=$(ip route | grep default | sed 's:.*via[[:space:]]\(.*\)[[:space:]]dev.*:\1:')
152     rvecho "${gw}"
153    }
154    
155    set_network_gateway()
156    {
157     local value="$1"
158     local CONFIG
159     local i
160    
161     [[ -z ${value} ]] && help_network_gateway && return 1
162    
163     CONFIG="/etc/conf.d/net.routes"
164     clearconfig
165     addconfig "default gw ${value}"
166    
167     # delete other default gw first
168     for i in $(ip route | grep default | sed 's:.*via\ \(.*\)\ dev.*:\1:')
169     do
170     route del default gw "${i}"
171     done
172     route add default gw "${value}"
173    }
174    
175    help_network_nameserver()
176    {
177     mecho "get network.nameserver"
178     mecho " displays the current nameserver of the system"
179     mecho
180     mecho "set network.nameserver [ip1] [ip2] .. [ipN]"
181     mecho " adds given ips as nameserver to the system"
182    }
183    
184    get_network_nameserver()
185  {  {
  local values="$@"  
186   local dns   local dns
187     local i
188    
189     dns=$(grep nameserver /etc/resolv.conf | sed 's:.*[[:space:]]\(.*\):\1:g')
190     for i in ${dns}
191     do
192     rvecho "${i}"
193     done
194    }
195    
196    set_network_nameserver()
197    {
198     local values="$@"
199     local CONFIG
200     local i
201    
202     [[ -z ${values} ]] && help_network_nameserver && return 1
203    
204   :> /etc/resolv.conf   CONFIG="/etc/resolv.conf"
205   for dns in ${values}   clearconfig
206     for i in ${values}
207   do   do
208   echo "${dns}" >> /etc/resolv.conf   addconfig "nameserver ${i}"
209   done   done
210  }  }

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