support for non-root

This commit is contained in:
baiyuan 2014-07-07 01:03:46 -04:00
parent 54a98d30c1
commit 0ad769155e

View File

@ -54,6 +54,7 @@ if ($bootparms{osimageprovmethod} eq 'sysclone') { copySyscloneFiles(); }
exit(0);
sub isRedhat { return (-e '/etc/redhat-release' || -e '/etc/centos-release' || -e '/etc/fedora-release'); }
# Query the db for the kernel, initrd, and kcmdline attributes of the 1st node in the noderange
sub getBootParms {
@ -132,7 +133,17 @@ sub updateGrubOnNodes {
my @output = runcmd('which modifygrub');
my $modifygrub = $output[0];
chomp($modifygrub);
my $cmd = "xdsh $nr -e $modifygrub $vtxt $dtxt -w $WAITTIME -p " . $bootparms->{osimageprovmethod} . ' ' . remoteFilename($bootparms->{kernel}) . ' ' . remoteFilename($bootparms->{initrd}) . ' ';
my @auser = runcmd('whoami');
chop(@auser);
my $cmd;
if($auser[0] eq "root")
{
$cmd = "xdsh $nr -e $modifygrub $vtxt $dtxt -w $WAITTIME -p " . $bootparms->{osimageprovmethod} . ' ' . remoteFilename($bootparms->{kernel}) . ' ' . remoteFilename($bootparms->{initrd}) . ' ';
}
else
{
$cmd = "xdsh $nr -l $auser[0] --sudo -e $modifygrub $vtxt $dtxt -w $WAITTIME -p " . $bootparms->{osimageprovmethod} . ' ' . remoteFilename($bootparms->{kernel}) . ' ' . remoteFilename($bootparms->{initrd}) . ' ';
}
# we need to quote the kernel parms, both here when passing it to xdsh, and on the node
# when xdsh is passing it to modifygrub. The way to get single quotes inside single quotes
# is to quote each of the outer single quotes with double quotes.
@ -216,8 +227,16 @@ sub modifyAutoinstFiles {
foreach my $n (@nodes) {
my $f = "/install/autoinst/$n";
my ($ip, $netmask, $gateway) = getNodeIpInfo($n);
runcmd("sed -i 's/#NODEIPADDR#/$ip/;s/#NODENETMASK#/$netmask/;s/#NODEGATEWAY#/$gateway/' $f");
my @auser = runcmd('whoami');
chop(@auser);
if($auser[0] eq "root")
{
runcmd("sed -i 's/#NODEIPADDR#/$ip/;s/#NODENETMASK#/$netmask/;s/#NODEGATEWAY#/$gateway/' $f");
}
else
{
runcmd("sudo sed -i 's/#NODEIPADDR#/$ip/;s/#NODENETMASK#/$netmask/;s/#NODEGATEWAY#/$gateway/' $f");
}
my $matches = sed($f, $search, $replace, mode=>'insertbefore');
if (!$matches) { die "Error: could not find the right place in $f to insert the sed of the network wait.\n"; }
}