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 1351 by niro, Thu Feb 17 21:44:18 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     # check for running x11 and recreate the xauth cookie with the correct hostname
38     if [[ ! -z $(pidof X) ]]
39     then
40     socket="${value}/unix${MCORE_XORG_DISPLAY}"
41     cookie=$(x11runas "xauth list | sed 's:.*\ \(.*\):\1:'")
42     authtype="MIT-MAGIC-COOKIE-1"
43     # add the new hostname to the xauthority file
44     x11runas "xauth add ${socket} ${authtype} ${cookie}"
45     fi
46  }  }
47    
48  help_network_iface()  help_network_iface()
# Line 34  set_network_iface() Line 61  set_network_iface()
61   local netmask="$4"   local netmask="$4"
62   local broadcast="$5"   local broadcast="$5"
63   local network="$6"   local network="$6"
64   local config   local CONFIG
65    
66   [[ -z ${iface} ]] && help_network_iface && return 1   [[ -z ${iface} ]] && help_network_iface && return 1
67   [[ -z ${networking} ]] && help_network_iface && return 1   [[ -z ${networking} ]] && help_network_iface && return 1
68    
69   config=/etc/conf.d/net.${iface}   if [[ ${networking} = static ]]
70   echo 'ONBOOT="yes"' > ${config}   then
71     [[ -z ${ip} ]] && help_network_iface && return 1
72     [[ -z ${netmask} ]] && help_network_iface && return 1
73     [[ -z ${broadcast} ]] && help_network_iface && return 1
74     [[ -z ${network} ]] && help_network_iface && return 1
75     fi
76    
77     CONFIG="/etc/conf.d/net.${iface}"
78     clearconfig
79     addconfig 'ONBOOT="yes"'
80    
81   case ${networking} in   case ${networking} in
82   static)   static)
83   echo 'NETWORKING="static"' >> ${config}   addconfig 'NETWORKING="static"'
84   echo "IP=\"${ip}\"" >> ${config}   addconfig "IP=\"${ip}\""
85   echo "NETMASK=\"${netmask}\"" >> ${config}   addconfig "NETMASK=\"${netmask}\""
86   echo "BROADCAST=\"${broadcast}\"" >> ${config}   addconfig "BROADCAST=\"${broadcast}\""
87     addconfig "NETWORK=\"${network}\""
88   ;;   ;;
89    
90   dhcp)   dhcp)
91   echo 'NETWORKING="dhcp"' >> ${config}   addconfig 'NETWORKING="dhcp"'
92   #echo 'DHCP_PROG="/sbin/dhcpcd"' >> ${config}   # addconfig 'DHCP_PROG="/sbin/udhcpc"'
93   #echo 'DHCP_START="-t 10"' >> ${config}   # addconfig 'DHCP_START="-t3 -T3 -q -b"'
94   #echo 'DHCP_STOP="-k"' >> ${config}   # addconfig 'DHCP_STOP=""'
95   ;;   ;;
96   esac   esac
97    
98   if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]]   if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]]
99   then   then
100   /etc/init.d/network restart "${iface}"   set_system_service restart network "${iface}"
101   else   else
102   /etc/init.d/network start "${iface}"   set_system_service start network "${iface}"
103   fi   fi
104  }  }
105    
106  set_network_default_gw()  help_network_gateway()
107  {  {
108   local value   mecho "get network.gateway"
109   route add default gw ${value}   mecho " displays the current network gateway"
110   echo "default gw ${value}" > /etc/conf.d/net.routes   mecho
111     mecho "set network.gateway [ip]"
112     mecho " sets the network gateway to [ip]"
113  }  }
114    
115  set_network_dns()  get_network_gateway()
116    {
117     local gw
118     gw=$(ip route | grep default | sed 's:.*via[[:space:]]\(.*\)[[:space:]]dev.*:\1:')
119     echo "${gw}"
120    }
121    
122    set_network_gateway()
123    {
124     local value="$1"
125     local CONFIG
126     local i
127    
128     [[ -z ${value} ]] && help_network_gateway && return 1
129    
130     CONFIG="/etc/conf.d/net.routes"
131     clearconfig
132     addconfig "default gw ${value}"
133    
134     # delete other default gw first
135     for i in $(ip route | grep default | sed 's:.*via\ \(.*\)\ dev.*:\1:')
136     do
137     route del default gw "${i}"
138     done
139     route add default gw "${value}"
140    }
141    
142    help_network_nameserver()
143    {
144     mecho "get network.nameserver"
145     mecho " displays the current nameserver of the system"
146     mecho
147     mecho "set network.nameserver [ip1] [ip2] .. [ipN]"
148     mecho " adds given ips as nameserver to the system"
149    }
150    
151    get_network_nameserver()
152  {  {
  local values="$@"  
153   local dns   local dns
154     local i
155    
156     dns=$(grep nameserver /etc/resolv.conf | sed 's:.*[[:space:]]\(.*\):\1:g')
157     for i in ${dns}
158     do
159     echo "${i}"
160     done
161    }
162    
163    set_network_nameserver()
164    {
165     local values="$@"
166     local CONFIG
167     local i
168    
169     [[ -z ${values} ]] && help_network_nameserver && return 1
170    
171   :> /etc/resolv.conf   CONFIG="/etc/resolv.conf"
172   for dns in ${values}   clearconfig
173     for i in ${values}
174   do   do
175   echo "${dns}" >> /etc/resolv.conf   addconfig "nameserver ${i}"
176   done   done
177  }  }

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