Magellan Linux

Annotation of /mcore-src/trunk/mcore-tools/src/modules/network/network.client.class.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1260 - (hide annotations) (download)
Fri Feb 4 20:01:16 2011 UTC (13 years, 3 months ago) by niro
Original Path: mcore-src/trunk/mcore-tools/daemon/client/include/network.client.class
File size: 2338 byte(s)
- requires basic-system for restarting system services
- always use CONFIG=, clearconfig, addconfig paradigma
- better sanity checks in set_network_iface()

1 niro 1248 # $Id$
2    
3     provide basic-networking
4 niro 1260 require basic-system
5 niro 1248
6     help_network_hostname()
7     {
8     mecho "set network.hostname [hostname]"
9     mecho " mcore - the local hostname"
10     }
11    
12     # set_network_hostname $value
13     set_network_hostname()
14     {
15     local value="$1"
16 niro 1260 local CONFIG
17 niro 1248 [[ -z ${value} ]] && help_network_hostname && return 1
18    
19 niro 1260 CONFIG="/etc/hostname"
20     clearconfig
21     addconfig "${value}"
22 niro 1248 hostname "${value}"
23     }
24    
25     help_network_iface()
26     {
27     mecho "set network.iface [iface] [networking] [ip] [netmask] [broadcast] [network]"
28     mecho " iface - the interface name"
29     mecho " networking - may be 'static' or 'dhcp'"
30     mecho " ip, netmask, broadcast and network are optional and only required on static networking"
31     }
32    
33     set_network_iface()
34     {
35     local iface="$1"
36     local networking="$2"
37     local ip="$3"
38     local netmask="$4"
39     local broadcast="$5"
40     local network="$6"
41 niro 1260 local CONFIG
42 niro 1248
43     [[ -z ${iface} ]] && help_network_iface && return 1
44     [[ -z ${networking} ]] && help_network_iface && return 1
45    
46 niro 1260 if [[ ${networking} = static ]]
47     then
48     [[ -z ${ip} ]] && help_network_iface && return 1
49     [[ -z ${netmask} ]] && help_network_iface && return 1
50     [[ -z ${broadcast} ]] && help_network_iface && return 1
51     [[ -z ${network} ]] && help_network_iface && return 1
52     fi
53 niro 1248
54 niro 1260 CONFIG="/etc/conf.d/net.${iface}"
55     clearconfig
56     addconfig 'ONBOOT="yes"'
57    
58 niro 1248 case ${networking} in
59     static)
60 niro 1260 addconfig 'NETWORKING="static"'
61     addconfig "IP=\"${ip}\""
62     addconfig "NETMASK=\"${netmask}\""
63     addconfig "BROADCAST=\"${broadcast}\""
64     addconfig "NETWORK=\"${network}\""
65 niro 1248 ;;
66    
67     dhcp)
68 niro 1260 addconfig 'NETWORKING="dhcp"'
69     # addconfig 'DHCP_PROG="/sbin/udhcpc"'
70     # addconfig 'DHCP_START="-t3 -T3 -q -b"'
71     # addconfig 'DHCP_STOP=""'
72 niro 1248 ;;
73     esac
74    
75     if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]]
76     then
77 niro 1260 set_system_service restart network "${iface}"
78 niro 1248 else
79 niro 1260 set_system_service start network "${iface}"
80 niro 1248 fi
81     }
82    
83     set_network_default_gw()
84     {
85     local value
86 niro 1260 local CONFIG
87     local i
88    
89     CONFIG="/etc/conf.d/net.routes"
90     clearconfig
91     addconfig "default gw ${value}"
92    
93     # delete other default gw first
94     for i in $(ip route | grep default | sed 's:.*via\ \(.*\)\ dev.*:\1:')
95     do
96     route del default gw "${i}"
97     done
98     route add default gw "${value}"
99 niro 1248 }
100    
101     set_network_dns()
102     {
103     local values="$@"
104 niro 1260 local CONFIG
105     local i
106 niro 1248
107 niro 1260 CONFIG="/etc/resolv.conf"
108     clearconfig
109     for i in ${values}
110 niro 1248 do
111 niro 1260 addconfig "nameserver ${i}"
112 niro 1248 done
113     }