2010-03-21 13:11:47 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; }
|
|
|
|
|
|
|
|
use Getopt::Long;
|
|
|
|
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
|
|
|
use Cwd;
|
|
|
|
use File::Basename;
|
|
|
|
use xCAT::Client;
|
|
|
|
use xCAT::MsgUtils;
|
|
|
|
use xCAT::Usage;
|
2011-05-13 13:28:04 +00:00
|
|
|
use strict;
|
2010-03-21 13:11:47 +00:00
|
|
|
|
|
|
|
sub updatenode_usage
|
|
|
|
{
|
|
|
|
my $usage_string = xCAT::Usage->getUsage("updatenode");
|
|
|
|
print "$usage_string\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $bname = basename($0);
|
|
|
|
my $cmdref;
|
|
|
|
$cmdref->{command}->[0] = $bname;
|
|
|
|
$cmdref->{cwd}->[0] = cwd();
|
|
|
|
|
|
|
|
if (-p STDIN) {
|
|
|
|
my $data;
|
|
|
|
while ( <STDIN> ) { $data.=$_; }
|
|
|
|
$cmdref->{stdin}->[0]=$data;
|
|
|
|
}
|
2010-05-06 08:47:19 +00:00
|
|
|
Getopt::Long::Configure("posix_default");
|
|
|
|
Getopt::Long::Configure("no_gnu_compat");
|
|
|
|
Getopt::Long::Configure("bundling");
|
2010-11-09 15:28:03 +00:00
|
|
|
#GetOptions('h|help' => \$::HELP,
|
|
|
|
# 'v|version' => \$::VERSION);
|
2010-05-06 08:47:19 +00:00
|
|
|
# display the usage if -h or --help is specified
|
|
|
|
|
2010-11-09 16:16:19 +00:00
|
|
|
my $tmp=join(' ', @ARGV);
|
2011-06-16 09:31:39 +00:00
|
|
|
if (!($tmp =~ /--help|-h$|-v$|--version/)) {
|
2010-11-09 16:16:19 +00:00
|
|
|
my $arg=shift(@ARGV);
|
|
|
|
# Set the noderange
|
|
|
|
if ($arg !~ /^-/) {
|
|
|
|
my @tempnr = ();
|
|
|
|
foreach my $nr (split(/,/, $arg)) {
|
|
|
|
if ($nr =~ /^\^(.*)$/) {
|
|
|
|
my $nrf = $1;
|
|
|
|
if ($nrf !~ /^\//) { #relative path
|
|
|
|
$nrf = Cwd::abs_path($nrf);
|
|
|
|
}
|
|
|
|
$nrf = "\^" . $nrf;
|
|
|
|
push @tempnr, $nrf;
|
|
|
|
} else {
|
|
|
|
push @tempnr, $nr;
|
|
|
|
}
|
2010-03-21 13:11:47 +00:00
|
|
|
}
|
2010-11-09 16:16:19 +00:00
|
|
|
$arg = join(',',@tempnr);
|
|
|
|
$cmdref->{noderange}->[0]=$arg;
|
|
|
|
} else {
|
|
|
|
print "The noderange should be the first argument.\n";
|
|
|
|
&updatenode_usage();
|
|
|
|
exit 1;
|
2010-03-21 13:11:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
push (@{$cmdref->{arg}}, @ARGV);
|
|
|
|
|
|
|
|
# if trying to update security, get the password
|
|
|
|
# to access the target node firstly
|
|
|
|
if (
|
|
|
|
!GetOptions(
|
2010-10-05 19:09:24 +00:00
|
|
|
'A|updateallsw' => \$::ALLSW,
|
2010-03-21 13:11:47 +00:00
|
|
|
'c|cmdlineonly' => \$::CMDLINE,
|
2010-10-05 19:09:24 +00:00
|
|
|
'd=s' => \$::ALTSRC,
|
2010-03-21 13:11:47 +00:00
|
|
|
'h|help' => \$::HELP,
|
|
|
|
'v|version' => \$::VERSION,
|
|
|
|
'V|verbose' => \$::VERBOSE,
|
|
|
|
'F|sync' => \$::FILESYNC,
|
2011-05-13 13:28:04 +00:00
|
|
|
'f|snsync' => \$::SNFILESYNC,
|
2010-03-21 13:11:47 +00:00
|
|
|
'S|sw' => \$::SWMAINTENANCE,
|
|
|
|
's|sn' => \$::SETSERVER,
|
|
|
|
'P|scripts:s' => \$::RERUNPS,
|
2010-03-24 12:05:58 +00:00
|
|
|
'k|security' => \$::SECURITY,
|
2010-07-16 20:12:50 +00:00
|
|
|
'o|os:s' => \$::OS,
|
2010-03-21 13:11:47 +00:00
|
|
|
'user=s' => \$::USER,
|
|
|
|
'devicetype=s' => \$::DEVICETYPE,
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
&updatenode_usage();
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
2010-11-09 15:28:03 +00:00
|
|
|
if ($::HELP)
|
|
|
|
{
|
2011-05-13 13:28:04 +00:00
|
|
|
&updatenode_usage();
|
2010-11-09 15:28:03 +00:00
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
# display the version statement if -v or --verison is specified
|
|
|
|
if ($::VERSION)
|
|
|
|
{
|
|
|
|
my $version = xCAT::Utils->Version();
|
|
|
|
print "$version\n";
|
|
|
|
exit 0;
|
|
|
|
}
|
2011-05-13 13:28:04 +00:00
|
|
|
if (($::FILESYNC) && ($::SNFILESYNC)){ # only one
|
|
|
|
my $msg = "Choose either -f to sync the service nodes, or -F to sync the nodes not both.";
|
|
|
|
xCAT::MsgUtils->message("E", $msg);
|
|
|
|
exit 1;
|
|
|
|
}
|
2010-11-09 15:28:03 +00:00
|
|
|
|
2010-11-09 16:16:19 +00:00
|
|
|
|
2010-03-21 13:11:47 +00:00
|
|
|
my $current_userid = getpwuid($>);
|
|
|
|
$ENV{DSH_FROM_USERID} = $current_userid;
|
|
|
|
my $to_userid;
|
|
|
|
if ($::USER)
|
|
|
|
{
|
|
|
|
$to_userid = $::USER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$to_userid = $current_userid;
|
|
|
|
}
|
|
|
|
$ENV{DSH_TO_USERID} = $to_userid;
|
|
|
|
|
|
|
|
if ($::SECURITY) {
|
|
|
|
my $msg;
|
|
|
|
if (!($ENV{'DSH_REMOTE_PASSWORD'}))
|
|
|
|
{ # if not already set
|
|
|
|
# prompt for the password for the userid on the node that will be setup
|
|
|
|
my $userpw;
|
|
|
|
$msg =
|
|
|
|
"Enter the password for the userid: $to_userid on the node where the ssh keys \nwill be updated:\n";
|
|
|
|
xCAT::MsgUtils->message("I", $msg);
|
|
|
|
system("stty -echo"); # turn off keyboard
|
|
|
|
chop($userpw = <STDIN>);
|
|
|
|
system("stty echo"); # turn on keyboard
|
|
|
|
|
|
|
|
if ($userpw eq "")
|
|
|
|
{ # did not enter a password
|
|
|
|
$msg = "Did not enter a password will abort the security update.";
|
|
|
|
xCAT::MsgUtils->message("E", $msg);
|
|
|
|
exit 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ # password entered pass to the server
|
|
|
|
$ENV{DSH_REMOTE_PASSWORD} = $userpw;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (keys %ENV) {
|
2010-09-28 02:35:12 +00:00
|
|
|
if (/^DSH_/ || /^XCAT/) {
|
|
|
|
push @{$cmdref->{environment}}, "$_=$ENV{$_}";
|
|
|
|
}
|
2010-03-21 13:11:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
xCAT::Client::submit_request($cmdref,\&xCAT::Client::handle_response);
|
|
|
|
exit $xCAT::Client::EXITCODE;
|