From aff955d3ed0a9c88584ff0100232f9ef4bcd6f252786c101713ed3ebd46c6f4e Mon Sep 17 00:00:00 2001 From: Olaf Hering Date: Fri, 23 Nov 2012 15:01:29 +0000 Subject: [PATCH] - update hv_set_ifconfig further to work with our ifcfg [bnc#790469] OBS-URL: https://build.opensuse.org/package/show/Virtualization/hyper-v?expand=0&rev=45 --- hyper-v.changes | 5 + hyper-v.tools.hv.hv_set_ifconfig.sh | 141 ++++++++++++++++++++++++---- 2 files changed, 127 insertions(+), 19 deletions(-) diff --git a/hyper-v.changes b/hyper-v.changes index 6db6e5f..2e66669 100644 --- a/hyper-v.changes +++ b/hyper-v.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Fri Nov 23 15:58:28 CET 2012 - ohering@suse.de + +- update hv_set_ifconfig further to work with our ifcfg [bnc#790469] + ------------------------------------------------------------------- Thu Nov 22 18:14:12 CET 2012 - ohering@suse.de diff --git a/hyper-v.tools.hv.hv_set_ifconfig.sh b/hyper-v.tools.hv.hv_set_ifconfig.sh index 3860957..46ef9c2 100644 --- a/hyper-v.tools.hv.hv_set_ifconfig.sh +++ b/hyper-v.tools.hv.hv_set_ifconfig.sh @@ -41,43 +41,146 @@ then : expect configuration datafile as first argument exit 1 fi -# +# send subshell output to syslog ( +f=/etc/sysconfig/network/scripts/functions +if test -f ${f} +then + . ${f} +else + echo "MISSING ${f}" + exit 1 +fi +# remove known config variables from environment +unset HWADDR unset DHCP unset IF_NAME +unset ${!IPADDR*} +unset ${!NETMASK*} +unset ${!GATEWAY*} +unset ${!IPV6ADDR*} +unset ${!IPV6NETMASK*} +unset ${!IPV6_DEFAULTGW*} +unset ${!DNS*} . "$1" +# if test -z "${IF_NAME}" then echo "Missing IF_NAME= in ${cfg}" exit 1 fi # -t=`mktemp` -if test -z "${t}" -then - exit 1 -fi - +t_ifcfg=`mktemp` +t_ifroute=`mktemp` _exit() { - rm -f "${t}" + rm -f "${t_ifcfg}" "${t_ifroute}" } trap _exit EXIT # -cat >> "${t}" <<_EOF_ -# contents from $0 $* -`cat "${cfg}"` -# -# additional options: -STARTMODE=auto -_EOF_ - -if test "${DHCP}" = "yes" +if test -z "${t_ifcfg}" || test -z "${t_ifroute}" then - echo "BOOTPROTO=dhcp" >> ${t}; + exit 1 +fi +# +# Create ifcfg-* file +( + echo "STARTMODE=auto" + # + if test -n "${HWADDR}" + then + : # ignore HWADDR, it just repeats the existing MAC value + fi + # + if test "${DHCP}" = "yes" + then + echo "BOOTPROTO=dhcp" + fi + # + # loop through all ipv4 adresses + for var in ${!IPADDR*} + do + index=${var#IPADDR} + pfx= + # find corresponding NETMASK variable + eval nm=\$NETMASK${index} + # if specified, calculate prefix + if test -n "${nm}" + then + pfx=`mask2pfxlen "${nm}" 2>/dev/null` + fi + # construct actual value + eval val=\$IPADDR${index} + # append prefix to value + if test -n "${pfx}" + then + val="${val}/${pfx}" + fi + # write config variable + echo "IPADDR${index}='${val}'" + done + # loop through all ipv6 adresses + for var in ${!IPV6ADDR*} + do + index=${var#IPV6ADDR} + pfx= + # find corresponding IPV6NETMASK variable + eval nm=\$IPV6NETMASK${index} + # if specified, calculate prefix + if test -n "${nm}" + then + pfx=`mask2pfxlen "${nm}" 2>/dev/null` + fi + # construct actual value + eval val=\$IPV6ADDR${index} + # append prefix to value + if test -n "${pfx}" + then + val="${val}/${pfx}" + fi + # write config variable + echo "IPV6ADDR${index}='${val}'" + done + +) >> "${t_ifcfg}" + +# Create ifroute-* file +( + if test -n "${GATEWAY}" + then + echo "default $GATEWAY - $IF_NAME" + fi + if test -n "${IPV6_DEFAULTGW}" + then + echo "default $IPV6_DEFAULTGW - $IF_NAME" + fi +) >> "${t_ifroute}" +# Only a single default gateway is supported +unset GATEWAY IPV6_DEFAULTGW +if test -n "${!GATEWAY*}${!IPV6_DEFAULTGW*}" +then + echo "WARNING: multiple gateways not supported: ${!GATEWAY*} ${!IPV6_DEFAULTGW*}" fi +# collect DNS info +_DNS_= +for var in ${!DNS*} +do + eval val=\$${var} + if test -n "${_DNS_}" + then + _DNS_="${_DNS_} ${val}" + else + _DNS_=${val} + fi +done +# echo "$0: working on network interface ifcfg-${IF_NAME}" -cp -b ${t} "/etc/sysconfig/network/ifcfg-${IF_NAME}" +cp -fb ${t_ifcfg} "/etc/sysconfig/network/ifcfg-${IF_NAME}" +cp -fb ${t_ifroute} "/etc/sysconfig/network/ifroute-${IF_NAME}" +if test -n "${_DNS_}" && test -w /etc/sysconfig/network/config +then + sed -i "s@^NETCONFIG_DNS_STATIC_SERVERS=.*@NETCONFIG_DNS_STATIC_SERVERS='$_DNS_'@" /etc/sysconfig/network/config +fi ifdown "${IF_NAME}" -o hotplug ifup "${IF_NAME}" -o hotplug ) 2>&1 | logger -t "${0##*/}[$PPID / $$]"