# $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() { local val if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] then val=$(hostname) else val=$(< @@SYSCONFDIR@@/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="@@SYSCONFDIR@@/hostname" clearconfig addconfig "${value}" hostname "${value}" # update hosts file CONFIG="@@SYSCONFDIR@@/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}@@CONFDDIR@@ -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}@@CONFDDIR@@${iface}; echo ) | while read line do rvecho -n ";${line}" done rvecho done } set_network_iface() { local iface="$1" local networking="$2" local ip="$3" local netmask="$4" 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 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="@@CONFDDIR@@/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"' ;; esac if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]] then if [[ ! -z $(ip addr | grep "${iface}.*UP.*") ]] then set_system_service restart network "${iface}" else set_system_service start network "${iface}" fi else case ${networking} in static) ifconfig "${iface}" "${ip}" netmask "${netmask}" broadcast "${broadcast}" ;; dhcp) source @@CONFDDIR@@/network [[ ! -z $(pidof ${dhcp_prog}) ]] && killall ${DEFAULT_DHCP_PROG} ${DEFAULT_DHCP_PROG} ${DEFAULT_DHCP_START} "${iface}" ;; esac 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:') rvecho "${gw}" } set_network_gateway() { local value="$1" local CONFIG local i [[ -z ${value} ]] && help_network_gateway && return 1 CONFIG="@@CONFDDIR@@/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 @@SYSCONFDIR@@/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="@@SYSCONFDIR@@/resolv.conf" clearconfig for i in ${values} do addconfig "nameserver ${i}" done }