Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1351 - (hide annotations) (download)
Thu Feb 17 21:44:18 2011 UTC (13 years, 2 months ago) by niro
File size: 3746 byte(s)
-fixed a typo in the discription of nameserver
-add the new hostname to the x11 authority file to allow x11 interaction without restarting xorg
1 niro 1248 # $Id$
2    
3     provide basic-networking
4 niro 1260 require basic-system
5 niro 1248
6     help_network_hostname()
7     {
8 niro 1348 mecho "get network.hostname"
9     mecho " displays the current hostname"
10     mecho
11 niro 1248 mecho "set network.hostname [hostname]"
12 niro 1348 mecho " Sets the hostname of the system"
13 niro 1248 mecho " mcore - the local hostname"
14     }
15    
16 niro 1348 get_network_hostname()
17     {
18     hostname
19     }
20    
21 niro 1248 # set_network_hostname $value
22     set_network_hostname()
23     {
24     local value="$1"
25 niro 1260 local CONFIG
26 niro 1351 local socket
27     local cookie
28     local authtype
29    
30 niro 1248 [[ -z ${value} ]] && help_network_hostname && return 1
31    
32 niro 1260 CONFIG="/etc/hostname"
33     clearconfig
34     addconfig "${value}"
35 niro 1248 hostname "${value}"
36 niro 1351
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 niro 1248 }
47    
48     help_network_iface()
49     {
50     mecho "set network.iface [iface] [networking] [ip] [netmask] [broadcast] [network]"
51     mecho " iface - the interface name"
52     mecho " networking - may be 'static' or 'dhcp'"
53     mecho " ip, netmask, broadcast and network are optional and only required on static networking"
54     }
55    
56     set_network_iface()
57     {
58     local iface="$1"
59     local networking="$2"
60     local ip="$3"
61     local netmask="$4"
62     local broadcast="$5"
63     local network="$6"
64 niro 1260 local CONFIG
65 niro 1248
66     [[ -z ${iface} ]] && help_network_iface && return 1
67     [[ -z ${networking} ]] && help_network_iface && return 1
68    
69 niro 1260 if [[ ${networking} = static ]]
70     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 niro 1248
77 niro 1260 CONFIG="/etc/conf.d/net.${iface}"
78     clearconfig
79     addconfig 'ONBOOT="yes"'
80    
81 niro 1248 case ${networking} in
82     static)
83 niro 1260 addconfig 'NETWORKING="static"'
84     addconfig "IP=\"${ip}\""
85     addconfig "NETMASK=\"${netmask}\""
86     addconfig "BROADCAST=\"${broadcast}\""
87     addconfig "NETWORK=\"${network}\""
88 niro 1248 ;;
89    
90     dhcp)
91 niro 1260 addconfig 'NETWORKING="dhcp"'
92     # addconfig 'DHCP_PROG="/sbin/udhcpc"'
93     # addconfig 'DHCP_START="-t3 -T3 -q -b"'
94     # addconfig 'DHCP_STOP=""'
95 niro 1248 ;;
96     esac
97    
98     if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]]
99     then
100 niro 1260 set_system_service restart network "${iface}"
101 niro 1248 else
102 niro 1260 set_system_service start network "${iface}"
103 niro 1248 fi
104     }
105    
106 niro 1348 help_network_gateway()
107     {
108     mecho "get network.gateway"
109     mecho " displays the current network gateway"
110     mecho
111     mecho "set network.gateway [ip]"
112     mecho " sets the network gateway to [ip]"
113     }
114    
115     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 niro 1284 set_network_gateway()
123 niro 1248 {
124 niro 1284 local value="$1"
125 niro 1260 local CONFIG
126     local i
127    
128 niro 1348 [[ -z ${value} ]] && help_network_gateway && return 1
129    
130 niro 1260 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 niro 1248 }
141    
142 niro 1348 help_network_nameserver()
143 niro 1248 {
144 niro 1348 mecho "get network.nameserver"
145     mecho " displays the current nameserver of the system"
146     mecho
147 niro 1351 mecho "set network.nameserver [ip1] [ip2] .. [ipN]"
148 niro 1348 mecho " adds given ips as nameserver to the system"
149     }
150    
151     get_network_nameserver()
152     {
153     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 niro 1248 local values="$@"
166 niro 1260 local CONFIG
167     local i
168 niro 1248
169 niro 1348 [[ -z ${values} ]] && help_network_nameserver && return 1
170    
171 niro 1260 CONFIG="/etc/resolv.conf"
172     clearconfig
173     for i in ${values}
174 niro 1248 do
175 niro 1260 addconfig "nameserver ${i}"
176 niro 1248 done
177     }