From f0a8697c626b53e7b7aa48e9cbbb58d2c280f9a0 Mon Sep 17 00:00:00 2001
From: baiyuan <bybai@cn.ibm.com>
Date: Mon, 7 Jul 2014 01:01:21 -0400
Subject: [PATCH] support for non-root user

---
 xCAT-SoftLayer/bin/modifygrub | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/xCAT-SoftLayer/bin/modifygrub b/xCAT-SoftLayer/bin/modifygrub
index a1769e8e9..3b567b423 100755
--- a/xCAT-SoftLayer/bin/modifygrub
+++ b/xCAT-SoftLayer/bin/modifygrub
@@ -59,8 +59,13 @@ sub addKernelParms {
 
 	# replace <nodename> with the nodename
 	my $nodename = $ENV{NODE};			# this env var is set by xdsh
+        if (!$nodename){
+             my $tmpstr=$args->{kernelparms};
+             my @strhost=split(' ',$tmpstr);
+             my @tempname=split('=',$strhost[7]);
+             $nodename=$tempname[1];
+        }
 	$args->{kernelparms} =~ s/<nodename>/$nodename/g;
-
 	# get node ip and add it to the kernel parms
 	my ($nic, $ip, $netmask, $network, $broadcast, $gateway, $mac) = getNodeIpInfo($args);
 	if (!$ip) { die "Error: could not find the NIC that would connect to the xCAT mgmt node's IP (".$args->{mnip}.").\n"; }
@@ -83,6 +88,7 @@ sub addKernelParms {
 	else {			# scripted install
 		#todo: the parameters for kickstart are likely different
 		$args->{kernelparms} .= " $bootif hostip=$ip netmask=$netmask gateway=$gateway dns=$mnip hostname=$nodename netdevice=$nic netwait=$WAITTIME textmode=1";
+              # print Dumper($args->{kernelparms})
 	}
 }
 
@@ -94,7 +100,7 @@ sub getNodeIpInfo {
 	verbose("using IP prefix $ipprefix");
 
 	# parse ip addr show output, looking for ipprefix, to determine nic, ip, mac
-	my @output = runcmd("ip addr show");
+	my @output = runcmd("/sbin/ip addr show");
 	my ($nic, $mac, $ipandmask);
 	foreach my $line (@output) {
 		my ($nictmp, $mactmp, $iptmp);
@@ -148,7 +154,7 @@ sub getNodeIpInfo {
 
 	# finally, find the gateway
 	my $gateway;
-	my @output = runcmd("ip route");
+	my @output = runcmd("/sbin/ip route");
 	# we are looking for a line like: 10.0.0.0/8 via 10.54.51.1 dev bond0
 	my @networks = grep(m/ via .* $nic\s*$/, @output);
 	if (scalar(@networks)) { ($gateway) = $networks[0]=~m/ via\s+(\S+)/; }