--- mcore-src/trunk/mcore-tools/daemon/client/include/network.client.class 2011/02/02 20:20:24 1248 +++ mcore-src/trunk/mcore-tools/daemon/client/include/network.client.class 2011/11/04 08:24:27 1896 @@ -1,21 +1,60 @@ # $Id$ provide basic-networking +require basic-system help_network_hostname() { + mecho "get network.hostname" + mecho " displays the current hostname" + mecho mecho "set network.hostname [hostname]" + mecho " Sets the hostname of the system" mecho " mcore - the local hostname" } +get_network_hostname() +{ + hostname +} + # set_network_hostname $value set_network_hostname() { local value="$1" + local CONFIG + local socket + local cookie + local authtype + [[ -z ${value} ]] && help_network_hostname && return 1 - echo "${value}" > /etc/hostname + CONFIG="/etc/hostname" + clearconfig + addconfig "${value}" hostname "${value}" + + # update hosts file + CONFIG="/etc/hosts" + clearconfig + addconfig "127.0.0.1 localhost ${value}" + # add ipv6 defaults + addconfig "::1 ip6-localhost ip6-loopback" + addconfig "fe00::0 ip6-localnet" + addconfig "ff00::0 ip6-mcastprefix" + addconfig "ff02::1 ip6-allnodes" + addconfig "ff02::2 ip6-allrouters" + addconfig "ff02::3 ip6-allhosts" + + # check for running x11 and recreate the xauth cookie with the correct hostname + if [[ ! -z $(pidof X) ]] + then + socket="${value}/unix${MCORE_XORG_DISPLAY}" + cookie=$(x11runas "xauth list | sed 's:.*\ \(.*\):\1:'") + authtype="MIT-MAGIC-COOKIE-1" + # add the new hostname to the xauthority file + x11runas "xauth add ${socket} ${authtype} ${cookie}" + fi } help_network_iface() @@ -34,53 +73,114 @@ local netmask="$4" local broadcast="$5" local network="$6" - local config + local CONFIG [[ -z ${iface} ]] && help_network_iface && return 1 [[ -z ${networking} ]] && help_network_iface && return 1 - config=/etc/conf.d/net.${iface} - echo 'ONBOOT="yes"' > ${config} + if [[ ${networking} = static ]] + then + [[ -z ${ip} ]] && help_network_iface && return 1 + [[ -z ${netmask} ]] && help_network_iface && return 1 + [[ -z ${broadcast} ]] && help_network_iface && return 1 + [[ -z ${network} ]] && help_network_iface && return 1 + fi + + CONFIG="/etc/conf.d/net.${iface}" + clearconfig + addconfig 'ONBOOT="yes"' case ${networking} in static) - echo 'NETWORKING="static"' >> ${config} - echo "IP=\"${ip}\"" >> ${config} - echo "NETMASK=\"${netmask}\"" >> ${config} - echo "BROADCAST=\"${broadcast}\"" >> ${config} + addconfig 'NETWORKING="static"' + addconfig "IP=\"${ip}\"" + addconfig "NETMASK=\"${netmask}\"" + addconfig "BROADCAST=\"${broadcast}\"" + addconfig "NETWORK=\"${network}\"" ;; dhcp) - echo 'NETWORKING="dhcp"' >> ${config} - #echo 'DHCP_PROG="/sbin/dhcpcd"' >> ${config} - #echo 'DHCP_START="-t 10"' >> ${config} - #echo 'DHCP_STOP="-k"' >> ${config} + addconfig 'NETWORKING="dhcp"' ;; esac if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]] then - /etc/init.d/network restart "${iface}" + set_system_service restart network "${iface}" else - /etc/init.d/network start "${iface}" + set_system_service start network "${iface}" fi } -set_network_default_gw() +help_network_gateway() { - local value - route add default gw ${value} - echo "default gw ${value}" > /etc/conf.d/net.routes + mecho "get network.gateway" + mecho " displays the current network gateway" + mecho + mecho "set network.gateway [ip]" + mecho " sets the network gateway to [ip]" } -set_network_dns() +get_network_gateway() +{ + local gw + gw=$(ip route | grep default | sed 's:.*via[[:space:]]\(.*\)[[:space:]]dev.*:\1:') + rvecho "${gw}" +} + +set_network_gateway() +{ + local value="$1" + local CONFIG + local i + + [[ -z ${value} ]] && help_network_gateway && return 1 + + CONFIG="/etc/conf.d/net.routes" + clearconfig + addconfig "default gw ${value}" + + # delete other default gw first + for i in $(ip route | grep default | sed 's:.*via\ \(.*\)\ dev.*:\1:') + do + route del default gw "${i}" + done + route add default gw "${value}" +} + +help_network_nameserver() +{ + mecho "get network.nameserver" + mecho " displays the current nameserver of the system" + mecho + mecho "set network.nameserver [ip1] [ip2] .. [ipN]" + mecho " adds given ips as nameserver to the system" +} + +get_network_nameserver() { - local values="$@" local dns + local i + + dns=$(grep nameserver /etc/resolv.conf | sed 's:.*[[:space:]]\(.*\):\1:g') + for i in ${dns} + do + rvecho "${i}" + done +} + +set_network_nameserver() +{ + local values="$@" + local CONFIG + local i + + [[ -z ${values} ]] && help_network_nameserver && return 1 - :> /etc/resolv.conf - for dns in ${values} + CONFIG="/etc/resolv.conf" + clearconfig + for i in ${values} do - echo "${dns}" >> /etc/resolv.conf + addconfig "nameserver ${i}" done }