# $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 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 "set network.iface [iface] [networking] [ip] [netmask] [broadcast] [network]" 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" } set_network_iface() { local iface="$1" local networking="$2" local ip="$3" local netmask="$4" local broadcast="$5" local network="$6" local CONFIG [[ -z ${iface} ]] && help_network_iface && return 1 [[ -z ${networking} ]] && help_network_iface && return 1 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) addconfig 'NETWORKING="static"' addconfig "IP=\"${ip}\"" addconfig "NETMASK=\"${netmask}\"" addconfig "BROADCAST=\"${broadcast}\"" addconfig "NETWORK=\"${network}\"" ;; 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.*") ]] then set_system_service restart network "${iface}" else set_system_service start network "${iface}" fi } help_network_gateway() { 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:') echo "${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 dns local i dns=$(grep nameserver /etc/resolv.conf | sed 's:.*[[:space:]]\(.*\):\1:g') for i in ${dns} do echo "${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} do addconfig "nameserver ${i}" done }