Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1348 - (show 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 # $Id$
2
3 provide basic-networking
4 require basic-system
5
6 help_network_hostname()
7 {
8 mecho "get network.hostname"
9 mecho " displays the current hostname"
10 mecho
11 mecho "set network.hostname [hostname]"
12 mecho " Sets the hostname of the system"
13 mecho " mcore - the local hostname"
14 }
15
16 get_network_hostname()
17 {
18 hostname
19 }
20
21 # set_network_hostname $value
22 set_network_hostname()
23 {
24 local value="$1"
25 local CONFIG
26 [[ -z ${value} ]] && help_network_hostname && return 1
27
28 CONFIG="/etc/hostname"
29 clearconfig
30 addconfig "${value}"
31 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 local CONFIG
51
52 [[ -z ${iface} ]] && help_network_iface && return 1
53 [[ -z ${networking} ]] && help_network_iface && return 1
54
55 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
63 CONFIG="/etc/conf.d/net.${iface}"
64 clearconfig
65 addconfig 'ONBOOT="yes"'
66
67 case ${networking} in
68 static)
69 addconfig 'NETWORKING="static"'
70 addconfig "IP=\"${ip}\""
71 addconfig "NETMASK=\"${netmask}\""
72 addconfig "BROADCAST=\"${broadcast}\""
73 addconfig "NETWORK=\"${network}\""
74 ;;
75
76 dhcp)
77 addconfig 'NETWORKING="dhcp"'
78 # addconfig 'DHCP_PROG="/sbin/udhcpc"'
79 # addconfig 'DHCP_START="-t3 -T3 -q -b"'
80 # addconfig 'DHCP_STOP=""'
81 ;;
82 esac
83
84 if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]]
85 then
86 set_system_service restart network "${iface}"
87 else
88 set_system_service start network "${iface}"
89 fi
90 }
91
92 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 set_network_gateway()
109 {
110 local value="$1"
111 local CONFIG
112 local i
113
114 [[ -z ${value} ]] && help_network_gateway && return 1
115
116 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 }
127
128 help_network_nameserver()
129 {
130 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 local values="$@"
152 local CONFIG
153 local i
154
155 [[ -z ${values} ]] && help_network_nameserver && return 1
156
157 CONFIG="/etc/resolv.conf"
158 clearconfig
159 for i in ${values}
160 do
161 addconfig "nameserver ${i}"
162 done
163 }