Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1348 - (hide annotations) (download)
Thu Feb 17 21:20:09 2011 UTC (13 years, 2 months ago) by niro
File size: 3336 byte(s)
- renamed set_network_dns to set_network_nameserver
- added more help descriptions for gateway and nameserver
- added get functions for hostname, gateway and nameserver
- sanitized arguments
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 1248 [[ -z ${value} ]] && help_network_hostname && return 1
27    
28 niro 1260 CONFIG="/etc/hostname"
29     clearconfig
30     addconfig "${value}"
31 niro 1248 hostname "${value}"
32     }
33    
34     help_network_iface()
35     {
36     mecho "set network.iface [iface] [networking] [ip] [netmask] [broadcast] [network]"
37     mecho " iface - the interface name"
38     mecho " networking - may be 'static' or 'dhcp'"
39     mecho " ip, netmask, broadcast and network are optional and only required on static networking"
40     }
41    
42     set_network_iface()
43     {
44     local iface="$1"
45     local networking="$2"
46     local ip="$3"
47     local netmask="$4"
48     local broadcast="$5"
49     local network="$6"
50 niro 1260 local CONFIG
51 niro 1248
52     [[ -z ${iface} ]] && help_network_iface && return 1
53     [[ -z ${networking} ]] && help_network_iface && return 1
54    
55 niro 1260 if [[ ${networking} = static ]]
56     then
57     [[ -z ${ip} ]] && help_network_iface && return 1
58     [[ -z ${netmask} ]] && help_network_iface && return 1
59     [[ -z ${broadcast} ]] && help_network_iface && return 1
60     [[ -z ${network} ]] && help_network_iface && return 1
61     fi
62 niro 1248
63 niro 1260 CONFIG="/etc/conf.d/net.${iface}"
64     clearconfig
65     addconfig 'ONBOOT="yes"'
66    
67 niro 1248 case ${networking} in
68     static)
69 niro 1260 addconfig 'NETWORKING="static"'
70     addconfig "IP=\"${ip}\""
71     addconfig "NETMASK=\"${netmask}\""
72     addconfig "BROADCAST=\"${broadcast}\""
73     addconfig "NETWORK=\"${network}\""
74 niro 1248 ;;
75    
76     dhcp)
77 niro 1260 addconfig 'NETWORKING="dhcp"'
78     # addconfig 'DHCP_PROG="/sbin/udhcpc"'
79     # addconfig 'DHCP_START="-t3 -T3 -q -b"'
80     # addconfig 'DHCP_STOP=""'
81 niro 1248 ;;
82     esac
83    
84     if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]]
85     then
86 niro 1260 set_system_service restart network "${iface}"
87 niro 1248 else
88 niro 1260 set_system_service start network "${iface}"
89 niro 1248 fi
90     }
91    
92 niro 1348 help_network_gateway()
93     {
94     mecho "get network.gateway"
95     mecho " displays the current network gateway"
96     mecho
97     mecho "set network.gateway [ip]"
98     mecho " sets the network gateway to [ip]"
99     }
100    
101     get_network_gateway()
102     {
103     local gw
104     gw=$(ip route | grep default | sed 's:.*via[[:space:]]\(.*\)[[:space:]]dev.*:\1:')
105     echo "${gw}"
106     }
107    
108 niro 1284 set_network_gateway()
109 niro 1248 {
110 niro 1284 local value="$1"
111 niro 1260 local CONFIG
112     local i
113    
114 niro 1348 [[ -z ${value} ]] && help_network_gateway && return 1
115    
116 niro 1260 CONFIG="/etc/conf.d/net.routes"
117     clearconfig
118     addconfig "default gw ${value}"
119    
120     # delete other default gw first
121     for i in $(ip route | grep default | sed 's:.*via\ \(.*\)\ dev.*:\1:')
122     do
123     route del default gw "${i}"
124     done
125     route add default gw "${value}"
126 niro 1248 }
127    
128 niro 1348 help_network_nameserver()
129 niro 1248 {
130 niro 1348 mecho "get network.nameserver"
131     mecho " displays the current nameserver of the system"
132     mecho
133     mecho "set network.dns [ip1] [ip2] .. [ipN]"
134     mecho " adds given ips as nameserver to the system"
135     }
136    
137     get_network_nameserver()
138     {
139     local dns
140     local i
141    
142     dns=$(grep nameserver /etc/resolv.conf | sed 's:.*[[:space:]]\(.*\):\1:g')
143     for i in ${dns}
144     do
145     echo "${i}"
146     done
147     }
148    
149     set_network_nameserver()
150     {
151 niro 1248 local values="$@"
152 niro 1260 local CONFIG
153     local i
154 niro 1248
155 niro 1348 [[ -z ${values} ]] && help_network_nameserver && return 1
156    
157 niro 1260 CONFIG="/etc/resolv.conf"
158     clearconfig
159     for i in ${values}
160 niro 1248 do
161 niro 1260 addconfig "nameserver ${i}"
162 niro 1248 done
163     }