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();
|
2011-12-12 19:54:30 +00:00
|
|
|
my $data;
|
|
|
|
# allows our plugins to get the stdin of the cmd that invoked the plugin
|
|
|
|
if ( (($^O =~ /^linux/i) && ($ENV{'SHELL'} =~ /\/ksh$/)) || !defined($ENV{'TERM'}) )
|
|
|
|
{
|
|
|
|
my $rin="";
|
|
|
|
my $rout;
|
|
|
|
vec($rin,fileno(STDIN),1)=1;
|
|
|
|
my $nfound=select($rout=$rin,"","",1);
|
|
|
|
if ($nfound)
|
|
|
|
{
|
|
|
|
while ( <STDIN> ) { $data.=$_; }
|
|
|
|
$cmdref->{stdin}->[0]=$data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (-p STDIN) {
|
|
|
|
while ( <STDIN> ) { $data.=$_; }
|
|
|
|
$cmdref->{stdin}->[0]=$data;
|
|
|
|
}
|
2010-03-21 13:11:47 +00:00
|
|
|
}
|
2011-12-12 19:54:30 +00:00
|
|
|
|
|
|
|
|
2010-05-06 08:47:19 +00:00
|
|
|
Getopt::Long::Configure("posix_default");
|
|
|
|
Getopt::Long::Configure("no_gnu_compat");
|
|
|
|
Getopt::Long::Configure("bundling");
|
|
|
|
|
2011-06-23 05:59:23 +00:00
|
|
|
my $tmp=" ".join(' ', @ARGV);
|
|
|
|
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 {
|
|
|
|
&updatenode_usage();
|
2012-08-22 19:13:27 +00:00
|
|
|
print "The noderange should be the first argument.\n";
|
2010-11-09 16:16:19 +00:00
|
|
|
exit 1;
|
2010-03-21 13:11:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
push (@{$cmdref->{arg}}, @ARGV);
|
2013-01-02 17:18:02 +00:00
|
|
|
# check the syntax
|
2010-03-21 13:11:47 +00:00
|
|
|
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,
|
2013-08-05 13:36:08 +00:00
|
|
|
'g|genmypost' => \$::GENMYPOST,
|
2011-05-13 13:28:04 +00:00
|
|
|
'f|snsync' => \$::SNFILESYNC,
|
2013-01-02 17:18:02 +00:00
|
|
|
'l|user:s' => \$::USER,
|
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,
|
2013-02-28 20:47:12 +00:00
|
|
|
'fanout=i' => \$::fanout,
|
2010-03-21 13:11:47 +00:00
|
|
|
)
|
|
|
|
) {
|
|
|
|
&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;
|
|
|
|
}
|
2013-01-09 18:17:24 +00:00
|
|
|
if (($::USER) && ($::SECURITY))
|
2013-01-02 17:18:02 +00:00
|
|
|
{
|
2013-01-09 18:17:24 +00:00
|
|
|
my $msg = "-l option is not allowed with -k option.";
|
|
|
|
xCAT::MsgUtils->message("E", $msg);
|
|
|
|
exit 1;
|
|
|
|
}
|
2013-03-07 14:27:59 +00:00
|
|
|
if (($::USER) && ($::SNFILESYNC))
|
2013-01-09 18:17:24 +00:00
|
|
|
{
|
2013-03-07 14:27:59 +00:00
|
|
|
my $msg = "-l option is not allowed with -f options.";
|
2013-01-02 17:18:02 +00:00
|
|
|
xCAT::MsgUtils->message("E", $msg);
|
|
|
|
exit 1;
|
|
|
|
}
|
2010-11-09 15:28:03 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
2013-01-02 17:18:02 +00:00
|
|
|
# determine who is running the command on the client and who we will run as
|
|
|
|
# on the node
|
2010-03-21 13:11:47 +00:00
|
|
|
my $current_userid = getpwuid($>);
|
|
|
|
$ENV{DSH_FROM_USERID} = $current_userid;
|
|
|
|
my $to_userid;
|
2013-01-02 17:18:02 +00:00
|
|
|
if ($::USER) # entered -l
|
2010-03-21 13:11:47 +00:00
|
|
|
{
|
|
|
|
$to_userid = $::USER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$to_userid = $current_userid;
|
|
|
|
}
|
|
|
|
$ENV{DSH_TO_USERID} = $to_userid;
|
|
|
|
|
2013-01-02 17:18:02 +00:00
|
|
|
# if -k then we have to get the password
|
2010-03-21 13:11:47 +00:00
|
|
|
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;
|