--- mcore-src/trunk/mcore-tools/daemon/client/include/network.client.class 2011/02/04 20:01:16 1260 +++ mcore-src/trunk/mcore-tools/src/modules/network/network.client.class.in 2014/01/10 14:26:15 2186 @@ -5,31 +5,97 @@ 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() +{ + local val + + if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] + then + val=$(hostname) + else + val=$(< /etc/hostname) + fi + + rvecho "${val}" +} + # 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 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() { + mecho "get network.iface" + mecho " Lists all configured network interfaces" + mecho mecho "set network.iface [iface] [networking] [ip] [netmask] [broadcast] [network]" + mecho " Configure network interfaces" mecho " iface - the interface name" mecho " networking - may be 'static' or 'dhcp'" mecho " ip, netmask, broadcast and network are optional and only required on static networking" } +get_network_iface() +{ + local iface + for iface in $(find ${MROOT}/etc/conf.d -maxdepth 1 -name 'net.*' -printf '%f\n') + do + case ${iface} in + # exclude routes and samples + net.sample|net.routes) continue ;; + esac + rvecho -n "${iface//net.}" + ( cat ${MROOT}/etc/conf.d/${iface}; echo ) | while read line + do + rvecho -n ";${line}" + done + rvecho + done +} + set_network_iface() { local iface="$1" @@ -39,6 +105,7 @@ local broadcast="$5" local network="$6" local CONFIG + local dhcp_prog [[ -z ${iface} ]] && help_network_iface && return 1 [[ -z ${networking} ]] && help_network_iface && return 1 @@ -66,26 +133,55 @@ dhcp) addconfig 'NETWORKING="dhcp"' - # addconfig 'DHCP_PROG="/sbin/udhcpc"' - # addconfig 'DHCP_START="-t3 -T3 -q -b"' - # addconfig 'DHCP_STOP=""' ;; esac - if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]] + if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] then - set_system_service restart network "${iface}" + if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]] + then + set_system_service restart network "${iface}" + else + set_system_service start network "${iface}" + fi else - set_system_service start network "${iface}" + case ${networking} in + static) + ifconfig "${iface}" "${ip}" netmask "${netmask}" broadcast "${broadcast}" + ;; + dhcp) + source /etc/conf.d/network + [[ ! -z $(pidof ${dhcp_prog}) ]] && killall ${DEFAULT_DHCP_PROG} + ${DEFAULT_DHCP_PROG} ${DEFAULT_DHCP_START} "${iface}" + ;; + esac fi } -set_network_default_gw() +help_network_gateway() { - local value + mecho "get network.gateway" + mecho " displays the current network gateway" + mecho + mecho "set network.gateway [ip]" + mecho " sets the network gateway to [ip]" +} + +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}" @@ -98,12 +194,35 @@ route add default gw "${value}" } -set_network_dns() +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 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 + CONFIG="/etc/resolv.conf" clearconfig for i in ${values}