Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1248 - (hide annotations) (download)
Wed Feb 2 20:20:24 2011 UTC (13 years, 3 months ago) by niro
File size: 1786 byte(s)
-initial version
1 niro 1248 # $Id$
2    
3     provide basic-networking
4    
5     help_network_hostname()
6     {
7     mecho "set network.hostname [hostname]"
8     mecho " mcore - the local hostname"
9     }
10    
11     # set_network_hostname $value
12     set_network_hostname()
13     {
14     local value="$1"
15     [[ -z ${value} ]] && help_network_hostname && return 1
16    
17     echo "${value}" > /etc/hostname
18     hostname "${value}"
19     }
20    
21     help_network_iface()
22     {
23     mecho "set network.iface [iface] [networking] [ip] [netmask] [broadcast] [network]"
24     mecho " iface - the interface name"
25     mecho " networking - may be 'static' or 'dhcp'"
26     mecho " ip, netmask, broadcast and network are optional and only required on static networking"
27     }
28    
29     set_network_iface()
30     {
31     local iface="$1"
32     local networking="$2"
33     local ip="$3"
34     local netmask="$4"
35     local broadcast="$5"
36     local network="$6"
37     local config
38    
39     [[ -z ${iface} ]] && help_network_iface && return 1
40     [[ -z ${networking} ]] && help_network_iface && return 1
41    
42     config=/etc/conf.d/net.${iface}
43     echo 'ONBOOT="yes"' > ${config}
44    
45     case ${networking} in
46     static)
47     echo 'NETWORKING="static"' >> ${config}
48     echo "IP=\"${ip}\"" >> ${config}
49     echo "NETMASK=\"${netmask}\"" >> ${config}
50     echo "BROADCAST=\"${broadcast}\"" >> ${config}
51     ;;
52    
53     dhcp)
54     echo 'NETWORKING="dhcp"' >> ${config}
55     #echo 'DHCP_PROG="/sbin/dhcpcd"' >> ${config}
56     #echo 'DHCP_START="-t 10"' >> ${config}
57     #echo 'DHCP_STOP="-k"' >> ${config}
58     ;;
59     esac
60    
61     if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]]
62     then
63     /etc/init.d/network restart "${iface}"
64     else
65     /etc/init.d/network start "${iface}"
66     fi
67     }
68    
69     set_network_default_gw()
70     {
71     local value
72     route add default gw ${value}
73     echo "default gw ${value}" > /etc/conf.d/net.routes
74     }
75    
76     set_network_dns()
77     {
78     local values="$@"
79     local dns
80    
81     :> /etc/resolv.conf
82     for dns in ${values}
83     do
84     echo "${dns}" >> /etc/resolv.conf
85     done
86     }