From 516b4172056e6304f8ea52ba6887546817f565634f0d1661c0864028fd47ade8 Mon Sep 17 00:00:00 2001
From: Olaf Hering <ohering@suse.com>
Date: Fri, 26 Oct 2012 15:14:16 +0000
Subject: [PATCH] - update hv_set_ifconfig to work with our ifcfg

OBS-URL: https://build.opensuse.org/package/show/Virtualization/hyper-v?expand=0&rev=34
---
 hyper-v.changes                     |  5 +++
 hyper-v.tools.hv.hv_set_ifconfig.sh | 67 ++++++++++++++++++-----------
 2 files changed, 46 insertions(+), 26 deletions(-)

diff --git a/hyper-v.changes b/hyper-v.changes
index eee0e75..592d6d8 100644
--- a/hyper-v.changes
+++ b/hyper-v.changes
@@ -1,3 +1,8 @@
+-------------------------------------------------------------------
+Fri Oct 26 17:13:40 CEST 2012 - ohering@suse.de
+
+- update hv_set_ifconfig to work with our ifcfg
+
 -------------------------------------------------------------------
 Sat Oct 13 11:40:30 CEST 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 bcfd731..1be68df 100644
--- a/hyper-v.tools.hv.hv_set_ifconfig.sh
+++ b/hyper-v.tools.hv.hv_set_ifconfig.sh
@@ -1,7 +1,4 @@
 #!/bin/bash
-
-# This example script activates an interface based on the specified
-# configuration.
 #
 # In the interest of keeping the KVP daemon code free of distro specific
 # information; the kvp daemon code invokes this external script to configure
@@ -10,13 +7,6 @@
 # The only argument to this script is the configuration file that is to
 # be used to configure the interface.
 #
-# Each Distro is expected to implement this script in a distro specific
-# fashion. For instance on Distros that ship with Network Manager enabled,
-# this script can be based on the Network Manager APIs for configuring the
-# interface.
-#
-# This example script is based on a RHEL environment.
-#
 # Here is the format of the ip configuration file:
 #
 # HWADDR=macaddr
@@ -45,24 +35,49 @@
 # is expected to return the configuration that is set via the SET
 # call.
 #
-
-
-
-echo "IPV6INIT=yes" >> $1
-echo "NM_CONTROLLED=no" >> $1
-echo "PEERDNS=yes" >> $1
-echo "ONBOOT=yes" >> $1
-
-dhcp=$(grep "DHCP" $1 2>/dev/null)
-if [ "$dhcp" != "" ];
+cfg=$1
+if ! test -f "${cfg}"
 then
-echo "BOOTPROTO=dhcp" >> $1;
+	: expect configuration datafile as first argument
+	exit 1
+fi
+#
+(
+unset DHCP
+unset IF_NAME
+. "$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
 
-cp $1 /etc/sysconfig/network-scripts/
+_exit() {
+	rm -f "${t}"
+}
+trap _exit EXIT
+#
+cat >> "${t}" <<_EOF_
+# contents from $0 $*
+`cat "${cfg}"`
+#
+# additional options:
+STARTMODE=auto
+_EOF_
 
+if test "${DHCP}" = "yes"
+then
+	echo "BOOTPROTO=dhcp" >> ${t};
+fi
 
-interface=$(echo $1 | awk -F - '{ print $2 }')
-
-/sbin/ifdown $interface 2>/dev/null
-/sbin/ifup $interfac 2>/dev/null
+echo "$0: working on network interface ifcfg-${IF_NAME}"
+cp -b ${t} /etc/sysconfig/network/ifcfg-${IF_NAME}
+ifdown ${IF_NAME} -o hotplug
+ifup ${IF_NAME} -o hotplug
+) 2>&1 | logger -t "${0##*/}[$PPID / $$]"