2009-09-10 11:37:24 +00:00
|
|
|
#!/usr/bin/env perl
|
2007-10-26 22:44:33 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
2007-12-11 19:15:28 +00:00
|
|
|
BEGIN
|
|
|
|
{
|
2008-10-17 16:04:13 +00:00
|
|
|
$::XCATROOT =
|
|
|
|
$ENV{'XCATROOT'} ? $ENV{'XCATROOT'}
|
|
|
|
: -d '/opt/xcat' ? '/opt/xcat'
|
|
|
|
: '/usr';
|
2007-12-11 19:15:28 +00:00
|
|
|
}
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
2008-07-18 12:03:49 +00:00
|
|
|
use strict;
|
2007-10-26 22:44:33 +00:00
|
|
|
use File::Basename;
|
2008-10-17 16:04:13 +00:00
|
|
|
use Cwd;
|
2009-12-04 14:47:53 +00:00
|
|
|
use Socket;
|
2008-10-17 16:04:13 +00:00
|
|
|
|
2008-02-18 15:57:25 +00:00
|
|
|
#use Data::Dumper;
|
2007-10-26 22:44:33 +00:00
|
|
|
use Getopt::Long;
|
2008-04-05 14:53:35 +00:00
|
|
|
require xCAT::MsgUtils;
|
|
|
|
require xCAT::DSHCLI;
|
2008-06-10 17:25:36 +00:00
|
|
|
use xCAT::Utils;
|
2011-10-17 13:35:00 +00:00
|
|
|
use xCAT::RemoteShellExp;
|
2008-04-17 12:46:39 +00:00
|
|
|
require xCAT::Client;
|
2007-10-26 22:44:33 +00:00
|
|
|
my $bname = basename($0);
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head1 xdsh/xdcp
|
|
|
|
|
|
|
|
This program is the client interface for xdsh/xdcp.
|
|
|
|
|
|
|
|
|
|
|
|
xdsh/xdcp command
|
2007-12-12 13:19:58 +00:00
|
|
|
|
|
|
|
This is the interface to for xdsh/xdsp
|
|
|
|
The command can run in client/server mode (default) or in bypass mode
|
2008-02-18 15:57:25 +00:00
|
|
|
where it does not use the xcat daemon xcatd.
|
2007-12-12 13:19:58 +00:00
|
|
|
Bypass mode is useful, when executing the command on the Management Server
|
2008-02-18 15:57:25 +00:00
|
|
|
and in particular if you want to run as a non-root id.
|
2007-12-12 13:19:58 +00:00
|
|
|
Call parse_args to verify mode (client/server or bypass)
|
2008-02-18 15:57:25 +00:00
|
|
|
and whether to use Env Variables
|
2007-10-26 22:44:33 +00:00
|
|
|
Build hash and submit request
|
2007-12-12 13:19:58 +00:00
|
|
|
See man page for options
|
|
|
|
|
2007-10-26 22:44:33 +00:00
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Main
|
|
|
|
|
|
|
|
# report unsupported dsh exports
|
|
|
|
&check_invalid_exports;
|
|
|
|
|
|
|
|
my $cmdref;
|
2007-12-12 13:19:58 +00:00
|
|
|
my $arg;
|
2008-04-07 19:24:28 +00:00
|
|
|
my @SaveARGV = @ARGV;
|
2008-10-17 16:04:13 +00:00
|
|
|
$cmdref->{cwd}->[0] = cwd();
|
2007-10-26 22:44:33 +00:00
|
|
|
$cmdref->{command}->[0] = $bname; # save my command name
|
2008-07-22 14:22:02 +00:00
|
|
|
|
2008-10-17 16:04:13 +00:00
|
|
|
my $arg = @SaveARGV[0];
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-04-07 19:24:28 +00:00
|
|
|
if ($arg =~ /^-/) # no noderange
|
|
|
|
{
|
2008-10-17 16:04:13 +00:00
|
|
|
|
|
|
|
# check for help, bypass, other client flags
|
|
|
|
if ($bname eq "xdsh")
|
|
|
|
{
|
|
|
|
&parse_args_xdsh;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ # xdcp
|
|
|
|
&parse_args_xdcp;
|
|
|
|
}
|
|
|
|
if ($::ROOTIMG != 1)
|
|
|
|
{ # if not running against rootimg then noderange required
|
|
|
|
xCAT::MsgUtils->message("I",
|
|
|
|
"Node range not specified, see $bname man page for syntax.\n");
|
|
|
|
exit 1;
|
|
|
|
}
|
2008-04-07 19:24:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$cmdref->{noderange}->[0] = $arg; # save noderange
|
2008-10-17 16:04:13 +00:00
|
|
|
my $tmp = shift(@SaveARGV); # take if off the argument list
|
|
|
|
if (!($cmdref->{noderange}->[0]))
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message("I",
|
|
|
|
"Node range not specified, see man page for syntax.\n");
|
|
|
|
exit 1;
|
2008-07-18 12:03:49 +00:00
|
|
|
}
|
2008-04-07 19:24:28 +00:00
|
|
|
@ARGV = @SaveARGV; # noderange removed for parsing
|
2008-10-17 16:04:13 +00:00
|
|
|
if ($bname eq "xdsh")
|
|
|
|
{
|
2009-12-04 14:47:53 +00:00
|
|
|
&parse_args_xdsh($cmdref->{noderange}->[0]);
|
2008-10-17 16:04:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ # xdcp
|
|
|
|
&parse_args_xdcp;
|
|
|
|
}
|
2007-12-12 13:19:58 +00:00
|
|
|
}
|
2008-04-05 14:53:35 +00:00
|
|
|
|
2010-02-05 03:16:04 +00:00
|
|
|
foreach my $sarg (@SaveARGV)
|
2008-04-07 19:24:28 +00:00
|
|
|
{
|
2010-02-25 14:57:19 +00:00
|
|
|
if (($bname eq "xdcp") && ($sarg !~ /^-/) && ( $sarg !~ /^\//))
|
2010-02-05 03:16:04 +00:00
|
|
|
{
|
|
|
|
$sarg = xCAT::Utils->full_path($sarg);
|
|
|
|
}
|
|
|
|
push(@{$cmdref->{arg}}, $sarg);
|
2008-04-07 19:24:28 +00:00
|
|
|
}
|
2008-10-17 16:04:13 +00:00
|
|
|
|
2007-12-12 13:19:58 +00:00
|
|
|
# add environment variables, if they have not already been assigned with
|
|
|
|
# command line flags
|
|
|
|
if (!($::NODE_RSH))
|
|
|
|
{
|
|
|
|
if ($ENV{'DSH_NODE_RSH'})
|
|
|
|
{
|
|
|
|
push(@{$cmdref->{env}}, "DSH_NODE_RSH=$ENV{'DSH_NODE_RSH'}");
|
|
|
|
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2008-10-17 16:04:13 +00:00
|
|
|
if (!($::NODE_RCP))
|
|
|
|
{
|
|
|
|
if ($ENV{'DSH_NODE_RCP'})
|
|
|
|
{
|
|
|
|
push(@{$cmdref->{env}}, "DSH_NODE_RCP=$ENV{'DSH_NODE_RCP'}");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2007-12-12 13:19:58 +00:00
|
|
|
if (!($::NODE_OPTS))
|
2007-10-26 22:44:33 +00:00
|
|
|
{
|
2007-12-12 13:19:58 +00:00
|
|
|
if ($ENV{'DSH_NODE_OPTS'})
|
|
|
|
{
|
|
|
|
push(@{$cmdref->{env}}, "DSH_NODE_OPTS=$ENV{'DSH_NODE_OPTS'}");
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2007-12-12 13:19:58 +00:00
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2007-12-12 13:19:58 +00:00
|
|
|
if (!($::FANOUT))
|
2007-10-26 22:44:33 +00:00
|
|
|
{
|
2007-12-12 13:19:58 +00:00
|
|
|
if ($ENV{'DSH_FANOUT'})
|
|
|
|
{
|
|
|
|
push(@{$cmdref->{env}}, "DSH_FANOUT=$ENV{'DSH_FANOUT'}");
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2007-12-12 13:19:58 +00:00
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2007-12-12 13:19:58 +00:00
|
|
|
if (!($::TIMEOUT))
|
2007-10-26 22:44:33 +00:00
|
|
|
{
|
2007-12-12 13:19:58 +00:00
|
|
|
if ($ENV{'DSH_TIMEOUT'})
|
2007-10-26 22:44:33 +00:00
|
|
|
{
|
2007-12-12 13:19:58 +00:00
|
|
|
push(@{$cmdref->{env}}, "DSH_TIMEOUT=$ENV{'DSH_TIMEOUT'}");
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2009-02-04 17:18:44 +00:00
|
|
|
if ($ENV{'DSH_REMOTE_PASSWORD'})
|
|
|
|
{
|
|
|
|
push(@{$cmdref->{env}}, "DSH_REMOTE_PASSWORD=$ENV{'DSH_REMOTE_PASSWORD'}");
|
|
|
|
}
|
2009-02-06 12:52:36 +00:00
|
|
|
|
|
|
|
if ($ENV{'DSH_FROM_USERID'})
|
2009-02-04 17:18:44 +00:00
|
|
|
{
|
2009-02-06 12:52:36 +00:00
|
|
|
push(@{$cmdref->{env}}, "DSH_FROM_USERID=$ENV{'DSH_FROM_USERID'}");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($ENV{'DSH_TO_USERID'})
|
|
|
|
{
|
|
|
|
push(@{$cmdref->{env}}, "DSH_TO_USERID=$ENV{'DSH_TO_USERID'}");
|
2009-02-04 17:18:44 +00:00
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2009-02-06 13:18:31 +00:00
|
|
|
if ($ENV{'DEVICETYPE'})
|
|
|
|
{
|
|
|
|
push(@{$cmdref->{env}}, "DEVICETYPE=$ENV{'DEVICETYPE'}");
|
|
|
|
}
|
|
|
|
|
2009-05-25 12:27:48 +00:00
|
|
|
if ($ENV{'DSH_RSYNC_FILE'})
|
|
|
|
{
|
|
|
|
push(@{$cmdref->{env}}, "DSH_RSYNC_FILE=$ENV{'DSH_RSYNC_FILE'}");
|
|
|
|
}
|
2009-05-19 14:59:17 +00:00
|
|
|
if ($ENV{'RSYNCSN'})
|
|
|
|
{
|
|
|
|
push(@{$cmdref->{env}}, "RSYNCSN=$ENV{'RSYNCSN'}");
|
|
|
|
}
|
2009-07-22 13:35:33 +00:00
|
|
|
if ($ENV{'RSYNCSNONLY'})
|
|
|
|
{
|
|
|
|
push(@{$cmdref->{env}}, "RSYNCSNONLY=$ENV{'RSYNCSNONLY'}");
|
|
|
|
}
|
2009-09-23 11:43:11 +00:00
|
|
|
if ($ENV{'DCP_PULL'})
|
|
|
|
{
|
|
|
|
push(@{$cmdref->{env}}, "DCP_PULL=$ENV{'DCP_PULL'}");
|
|
|
|
}
|
2010-05-14 16:21:42 +00:00
|
|
|
if ($ENV{'DSHEXECUTE'})
|
|
|
|
{
|
|
|
|
push(@{$cmdref->{env}}, "DSHEXECUTE=$ENV{'DSHEXECUTE'}");
|
|
|
|
}
|
2009-05-19 14:59:17 +00:00
|
|
|
|
2008-10-17 16:04:13 +00:00
|
|
|
xCAT::Client::submit_request($cmdref, \&xCAT::Client::handle_response);
|
2008-02-18 15:57:25 +00:00
|
|
|
exit $xCAT::Client::EXITCODE;
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 parse_args_xdsh
|
2008-02-18 15:57:25 +00:00
|
|
|
|
2007-10-26 22:44:33 +00:00
|
|
|
Parses for dsh input
|
|
|
|
Check if the command ask for help and display usage
|
2007-12-12 13:19:58 +00:00
|
|
|
Need to check only for the -X flag
|
2008-02-18 15:57:25 +00:00
|
|
|
Need to check -B flag to determine mode
|
2007-12-12 13:19:58 +00:00
|
|
|
|
2007-10-26 22:44:33 +00:00
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub parse_args_xdsh
|
|
|
|
{
|
2009-12-04 14:47:53 +00:00
|
|
|
my $snodes = shift;
|
2007-10-26 22:44:33 +00:00
|
|
|
Getopt::Long::Configure("posix_default");
|
|
|
|
Getopt::Long::Configure("no_gnu_compat");
|
|
|
|
Getopt::Long::Configure("bundling");
|
2007-12-12 13:19:58 +00:00
|
|
|
my %options = ();
|
2007-10-26 22:44:33 +00:00
|
|
|
if (
|
|
|
|
!GetOptions(
|
2009-02-04 17:18:44 +00:00
|
|
|
'e|execute' => \$options{'execute'},
|
|
|
|
'f|fanout=i' => \$options{'fanout'},
|
|
|
|
'h|help' => \$options{'help'},
|
|
|
|
'l|user=s' => \$options{'user'},
|
|
|
|
'm|monitor' => \$options{'monitor'},
|
|
|
|
'o|node-options=s' => \$options{'node-options'},
|
|
|
|
'q|show-config' => \$options{'show-config'},
|
|
|
|
'r|node-rsh=s' => \$options{'node-rsh'},
|
|
|
|
'i|rootimg=s' => \$options{'rootimg'},
|
|
|
|
's|stream' => \$options{'streaming'},
|
|
|
|
't|timeout=i' => \$options{'timeout'},
|
|
|
|
'v|verify' => \$options{'verify'},
|
|
|
|
'z|exit-status' => \$options{'exit-status'},
|
2007-12-12 13:19:58 +00:00
|
|
|
'B|bypass' => \$options{'bypass'},
|
2009-12-04 14:47:53 +00:00
|
|
|
'c|cleanup' => \$options{'cleanup'},
|
2007-12-12 13:19:58 +00:00
|
|
|
'E|environment=s' => \$options{'environment'},
|
|
|
|
'I|ignore-sig|ignoresig=s' => \$options{'ignore-signal'},
|
2007-12-20 19:03:27 +00:00
|
|
|
'K|keysetup' => \$options{'ssh-setup'},
|
2007-12-12 13:19:58 +00:00
|
|
|
'L|no-locale' => \$options{'no-locale'},
|
|
|
|
'Q|silent' => \$options{'silent'},
|
|
|
|
'S|syntax=s' => \$options{'syntax'},
|
|
|
|
'T|trace' => \$options{'trace'},
|
|
|
|
'V|version' => \$options{'version'},
|
|
|
|
|
2009-02-04 17:18:44 +00:00
|
|
|
'devicetype=s' => \$options{'devicetype'},
|
2007-12-12 13:19:58 +00:00
|
|
|
'command-name|commandName=s' => \$options{'command-name'},
|
|
|
|
'command-description|commandDescription=s' =>
|
|
|
|
\$options{'command-description'},
|
|
|
|
'X:s' => \$options{'ignore_env'}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
2007-12-12 13:19:58 +00:00
|
|
|
|
|
|
|
xCAT::DSHCLI->usage_dsh;
|
2007-10-26 22:44:33 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
2007-12-12 13:19:58 +00:00
|
|
|
if ($options{'help'})
|
2007-10-26 22:44:33 +00:00
|
|
|
{
|
2007-12-12 13:19:58 +00:00
|
|
|
xCAT::DSHCLI->usage_dsh;
|
2007-10-26 22:44:33 +00:00
|
|
|
exit 0;
|
|
|
|
}
|
2009-12-04 14:47:53 +00:00
|
|
|
|
|
|
|
# cleanup the service node temp directory and exit
|
|
|
|
# if default to not prompt, if user specified prompt
|
|
|
|
if (($options{'cleanup'}) && (!$snodes))
|
|
|
|
{
|
|
|
|
my $msg = "Service node range must be supplied on the -c command.";
|
|
|
|
xCAT::MsgUtils->message("E", $msg);
|
|
|
|
exit 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
if ($options{'cleanup'})
|
|
|
|
{
|
|
|
|
|
|
|
|
# get the directory on the servicenode to put the files in
|
|
|
|
my $defaultsyndir = "/var/xcat/syncfiles";
|
|
|
|
my @syndir = xCAT::Utils->get_site_attribute("SNsyncfiledir");
|
|
|
|
my $synfiledir;
|
|
|
|
if ($syndir[0])
|
|
|
|
{
|
|
|
|
$synfiledir = $syndir[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$synfiledir = "/var/xcat/syncfiles"; # default
|
|
|
|
}
|
|
|
|
if ($defaultsyndir ne $synfiledir)
|
|
|
|
{
|
|
|
|
my $answer;
|
|
|
|
my $msg =
|
|
|
|
"Do you wish to erase $synfiledir and all subdirectories?\n Enter Y or N.";
|
|
|
|
xCAT::MsgUtils->message('I', "$msg");
|
|
|
|
`stty -echo`;
|
|
|
|
chop($answer = <STDIN>);
|
|
|
|
`stty echo`;
|
|
|
|
$answer =~ tr/a-z/A-Z/; # convert to upper
|
|
|
|
if ($answer ne "Y")
|
|
|
|
{
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
my $cmd = "xdsh $snodes -v rm -rf $synfiledir/*";
|
|
|
|
xCAT::Utils->runcmd($cmd, 0);
|
|
|
|
if ($::RUNCMD_RC != 0)
|
|
|
|
{ # error
|
|
|
|
my $msg = "Error from $cmd: to cleanup servicenodes sync directory";
|
|
|
|
xCAT::MsgUtils->message("E", $msg);
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
}
|
2008-10-17 16:04:13 +00:00
|
|
|
if ($options{'bypass'})
|
|
|
|
{
|
2009-12-04 14:47:53 +00:00
|
|
|
$ENV{XCATBYPASS} = "yes"; # bypass xcatd
|
2008-10-17 16:04:13 +00:00
|
|
|
}
|
2009-05-18 14:41:21 +00:00
|
|
|
if ($options{'show-config'})
|
|
|
|
{
|
|
|
|
xCAT::DSHCLI->show_dsh_config;
|
|
|
|
exit 0;
|
|
|
|
}
|
2010-05-14 16:21:42 +00:00
|
|
|
# -if -e flag, execute script have to do special processing for hierarchy
|
|
|
|
# in the plugin
|
|
|
|
if ($options{'execute'})
|
|
|
|
{
|
|
|
|
$ENV{'DSHEXECUTE'} = join ' ', @ARGV; # execute script
|
|
|
|
}
|
2009-04-03 15:44:09 +00:00
|
|
|
|
|
|
|
# find out who is the current user running xdsh
|
|
|
|
#my $current_userid = getlogin(); # does not work for su
|
|
|
|
my $current_userid = getpwuid($>);
|
|
|
|
|
|
|
|
$ENV{DSH_FROM_USERID} = $current_userid;
|
|
|
|
|
|
|
|
# find out who we are going to log on to the node as
|
|
|
|
|
|
|
|
my $to_userid;
|
2009-05-19 14:59:17 +00:00
|
|
|
if ($options{'user'}) # if -l option
|
2009-04-03 15:44:09 +00:00
|
|
|
{
|
|
|
|
$to_userid = $options{'user'};
|
|
|
|
}
|
|
|
|
else
|
2007-12-12 13:19:58 +00:00
|
|
|
{
|
2009-04-03 15:44:09 +00:00
|
|
|
$to_userid = $current_userid;
|
|
|
|
}
|
|
|
|
$ENV{DSH_TO_USERID} = $to_userid;
|
2009-04-03 18:37:57 +00:00
|
|
|
|
2011-10-10 16:45:13 +00:00
|
|
|
# if devicetype=Mellanox, xdsh does not setup ssh, rspconfig does
|
|
|
|
my $devicepath = $options{'devicetype'};
|
|
|
|
$devicepath =~ s/::/\//g;
|
|
|
|
if (($options{'ssh-setup'}) && ($devicepath =~ /Mellanox/i)) {
|
|
|
|
my $msg =
|
|
|
|
"You do not use xdsh -K to setup the Mellanox switch ssh keys. Use rspconfig. See man page for rspconfig option sshcfg={enable|disable}.";
|
|
|
|
xCAT::MsgUtils->message("E", $msg);
|
|
|
|
exit 2;
|
|
|
|
}
|
2009-04-03 18:37:57 +00:00
|
|
|
# only allow -K with -l if --devicetype defined
|
2009-05-18 14:41:21 +00:00
|
|
|
if ( (($options{'user'}) && ($options{'ssh-setup'}))
|
|
|
|
&& (!($options{'devicetype'})))
|
|
|
|
{
|
|
|
|
my $msg =
|
2011-10-10 16:45:13 +00:00
|
|
|
"The -K and -l flag may only be used if --devicetype is specified.";
|
2009-05-18 14:41:21 +00:00
|
|
|
xCAT::MsgUtils->message("E", $msg);
|
|
|
|
exit 2;
|
2009-04-03 18:06:04 +00:00
|
|
|
}
|
2009-05-18 14:41:21 +00:00
|
|
|
if ($options{'ssh-setup'}) # if going to setup ssh keys
|
2009-04-03 18:06:04 +00:00
|
|
|
{
|
2010-02-15 14:40:31 +00:00
|
|
|
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 must abort the key exchange";
|
|
|
|
xCAT::MsgUtils->message("E", $msg);
|
|
|
|
exit 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ # password entered pass to the server
|
|
|
|
$ENV{DSH_REMOTE_PASSWORD} = $userpw;
|
2009-04-03 15:44:09 +00:00
|
|
|
|
2010-02-15 14:40:31 +00:00
|
|
|
}
|
2009-02-04 17:18:44 +00:00
|
|
|
}
|
2009-05-18 14:41:21 +00:00
|
|
|
|
2009-04-03 20:00:06 +00:00
|
|
|
# Get the home directory
|
|
|
|
my $home = xCAT::Utils->getHomeDir($current_userid);
|
|
|
|
$ENV{'DSH_FROM_USERID_HOME'} = $home;
|
2010-03-16 16:59:48 +00:00
|
|
|
#
|
|
|
|
# create /.ssh dir if needed
|
|
|
|
#
|
|
|
|
my $sshdir = "$home/.ssh";
|
|
|
|
if (!-d $sshdir)
|
|
|
|
{
|
|
|
|
my $cmd = "/bin/mkdir -m 700 -p $sshdir";
|
|
|
|
my $outref = xCAT::Utils->runcmd("$cmd", 0);
|
|
|
|
if ($::RUNCMD_RC != 0)
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message('E', "Could not create $sshdir directory.");
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 14:41:21 +00:00
|
|
|
|
2009-04-03 20:00:06 +00:00
|
|
|
# add config file with strict host checking no
|
|
|
|
my $cmd = "echo \"StrictHostKeyChecking no\" >> $home/.ssh/config";
|
|
|
|
xCAT::Utils->runcmd($cmd, 0);
|
|
|
|
if ($::RUNCMD_RC != 0)
|
|
|
|
{ # error
|
2009-05-18 14:41:21 +00:00
|
|
|
$msg = "Error from $cmd\n";
|
|
|
|
xCAT::MsgUtils->message("E", $msg);
|
2009-04-03 20:00:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my $cmd = "chmod 0600 $home/.ssh/config";
|
|
|
|
xCAT::Utils->runcmd($cmd, 0);
|
|
|
|
if ($::RUNCMD_RC != 0)
|
|
|
|
{ # error
|
2009-05-18 14:41:21 +00:00
|
|
|
$msg = "Error from $cmd\n";
|
|
|
|
xCAT::MsgUtils->message("E", $msg);
|
2009-04-03 20:00:06 +00:00
|
|
|
}
|
2009-04-03 15:44:09 +00:00
|
|
|
|
|
|
|
# if current_userid is not "root", we need to generate the keys
|
|
|
|
# here before becoming root while running under xcatd
|
|
|
|
#
|
|
|
|
if ($current_userid ne "root")
|
|
|
|
{
|
2011-10-17 13:35:00 +00:00
|
|
|
$::REMOTE_SHELL = "/usr/bin/ssh";
|
|
|
|
my $callback = \&xCAT::Client::handle_response;
|
|
|
|
# generates new keys for non-root id, if they do not already exist
|
|
|
|
my $rc=
|
|
|
|
xCAT::RemoteShellExp->remoteshellexp("k",$callback,$::REMOTE_SHELL);
|
|
|
|
if ($rc != 0) {
|
|
|
|
$msg = "remoteshellexp failed generating keys.";
|
|
|
|
xCAT::MsgUtils->message("E", $msg);
|
|
|
|
}
|
2009-04-03 15:44:09 +00:00
|
|
|
|
2009-04-03 18:37:57 +00:00
|
|
|
|
2009-04-03 15:44:09 +00:00
|
|
|
}
|
|
|
|
} # end setup of ssh
|
2007-12-12 13:19:58 +00:00
|
|
|
if ($options{'version'})
|
|
|
|
{
|
2008-06-10 17:25:36 +00:00
|
|
|
my $version = xCAT::Utils->Version();
|
2008-10-02 14:27:40 +00:00
|
|
|
$version .= "\n";
|
2009-02-06 12:52:36 +00:00
|
|
|
xCAT::MsgUtils->message("N", $version);
|
2007-12-12 13:19:58 +00:00
|
|
|
exit 0;
|
|
|
|
}
|
2008-10-17 16:04:13 +00:00
|
|
|
if ($options{'rootimg'})
|
|
|
|
{
|
|
|
|
$::ROOTIMG = 1;
|
|
|
|
}
|
|
|
|
if ($options{'node-rsh'}) # if set on command line, use it
|
2007-12-12 13:19:58 +00:00
|
|
|
{
|
|
|
|
$::NODE_RSH = 1;
|
|
|
|
}
|
2008-10-17 16:04:13 +00:00
|
|
|
if ($options{'node-opts'}) # if set on command line, use it
|
2007-12-12 13:19:58 +00:00
|
|
|
{
|
|
|
|
$::NODE_OPTS = 1;
|
|
|
|
}
|
2008-10-17 16:04:13 +00:00
|
|
|
if ($options{'fanout'}) # if set on command line, use it
|
2007-12-12 13:19:58 +00:00
|
|
|
{
|
|
|
|
$::FANOUT = 1;
|
|
|
|
}
|
2008-10-17 16:04:13 +00:00
|
|
|
if ($options{'timeout'}) # if set on command line, use it
|
2007-12-12 13:19:58 +00:00
|
|
|
{
|
|
|
|
$::TIMEOUT = 1;
|
|
|
|
}
|
|
|
|
if (defined $options{'ignore_env'})
|
|
|
|
{
|
|
|
|
xCAT::DSHCLI->ignoreEnv($options{'ignore_env'});
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 parse_args_xdcp
|
2008-02-18 15:57:25 +00:00
|
|
|
|
2007-10-26 22:44:33 +00:00
|
|
|
Parses for dcp input
|
|
|
|
Check if the command ask for help and display usage
|
2007-12-12 13:19:58 +00:00
|
|
|
Need to check -X flag to determine how to set Environment Variables
|
2008-02-18 15:57:25 +00:00
|
|
|
Need to check -B flag to determine mode
|
2007-12-12 13:19:58 +00:00
|
|
|
|
2007-10-26 22:44:33 +00:00
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub parse_args_xdcp
|
|
|
|
{
|
|
|
|
|
2007-12-12 13:19:58 +00:00
|
|
|
my %options = ();
|
2007-10-26 22:44:33 +00:00
|
|
|
Getopt::Long::Configure("posix_default");
|
|
|
|
Getopt::Long::Configure("no_gnu_compat");
|
|
|
|
Getopt::Long::Configure("bundling");
|
|
|
|
|
|
|
|
if (
|
|
|
|
!GetOptions(
|
2007-12-12 13:19:58 +00:00
|
|
|
'f|fanout=i' => \$options{'fanout'},
|
2009-05-18 14:41:21 +00:00
|
|
|
'F|File=s' => \$options{'File'},
|
2007-12-12 13:19:58 +00:00
|
|
|
'h|help' => \$options{'help'},
|
2009-05-18 14:41:21 +00:00
|
|
|
'i|rootimg=s' => \$options{'rootimg'},
|
2007-12-12 13:19:58 +00:00
|
|
|
'l|user=s' => \$options{'user'},
|
|
|
|
'n|nodes=s' => \$options{'nodes'},
|
|
|
|
'o|node-options=s' => \$options{'node-options'},
|
|
|
|
'q|show-config' => \$options{'show-config'},
|
|
|
|
'p|preserve' => \$options{'preserve'},
|
|
|
|
'r|c|node-rcp=s' => \$options{'node-rcp'},
|
2009-07-22 13:35:33 +00:00
|
|
|
's' => \$options{'rsyncSN'},
|
2007-12-12 13:19:58 +00:00
|
|
|
't|timeout=i' => \$options{'timeout'},
|
|
|
|
'v|verify' => \$options{'verify'},
|
|
|
|
'B|bypass' => \$options{'bypass'},
|
|
|
|
'Q|silent' => \$options{'silent'},
|
|
|
|
'P|pull' => \$options{'pull'},
|
|
|
|
'R|recursive' => \$options{'recursive'},
|
|
|
|
'T|trace' => \$options{'trace'},
|
|
|
|
'V|version' => \$options{'version'},
|
|
|
|
'X:s' => \$options{'ignore_env'}
|
2007-10-26 22:44:33 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
2007-12-12 13:19:58 +00:00
|
|
|
xCAT::DSHCLI->usage_dcp;
|
2007-10-26 22:44:33 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
2007-12-12 13:19:58 +00:00
|
|
|
if ($options{'help'})
|
2007-10-26 22:44:33 +00:00
|
|
|
{
|
2007-12-12 13:19:58 +00:00
|
|
|
xCAT::DSHCLI->usage_dcp;
|
2007-10-26 22:44:33 +00:00
|
|
|
exit 0;
|
|
|
|
}
|
2009-05-18 14:41:21 +00:00
|
|
|
if ($options{'show-config'})
|
|
|
|
{
|
|
|
|
xCAT::DSHCLI->show_dsh_config;
|
|
|
|
exit 0;
|
|
|
|
}
|
2010-02-15 14:40:31 +00:00
|
|
|
if (defined($options{File}) && ($options{File} !~ /^\//))
|
|
|
|
{ #relative path
|
2010-02-05 03:16:04 +00:00
|
|
|
$options{File} = xCAT::Utils->full_path($options{File});
|
|
|
|
}
|
2010-02-15 14:40:31 +00:00
|
|
|
if (defined($options{rootimg}) && ($options{rootimg} !~ /^\//))
|
|
|
|
{ #relative path
|
2010-02-05 03:16:04 +00:00
|
|
|
$options{rootimg} = xCAT::Utils->full_path($options{rootimg});
|
|
|
|
}
|
2009-06-25 18:16:23 +00:00
|
|
|
|
2009-07-22 13:35:33 +00:00
|
|
|
# rsync only to the service node
|
|
|
|
if ($options{'rsyncSN'})
|
|
|
|
{
|
|
|
|
$ENV{'RSYNCSNONLY'} = "yes"; # rsync file to SN
|
|
|
|
}
|
|
|
|
|
2009-12-04 14:47:53 +00:00
|
|
|
# if Pull function hierarchy must be handled special in plugin
|
2009-09-23 11:43:11 +00:00
|
|
|
if ($options{'pull'})
|
|
|
|
{
|
|
|
|
$ENV{'DCP_PULL'} = "yes";
|
|
|
|
}
|
|
|
|
|
2009-06-25 18:16:23 +00:00
|
|
|
# if rsyncing to a node, not the root image
|
|
|
|
# then must sync to service node first, if using hierarchy
|
|
|
|
# These env variable are used in xdsh.pm preprocessing
|
|
|
|
if ((!($options{'rootimg'})) && ($options{'File'}))
|
2009-05-19 14:59:17 +00:00
|
|
|
{
|
2009-12-04 14:47:53 +00:00
|
|
|
$ENV{'RSYNCSN'} = "yes"; #rsync file to SN, if exist
|
2009-05-19 14:59:17 +00:00
|
|
|
}
|
2009-06-25 18:16:23 +00:00
|
|
|
|
2009-05-25 12:27:48 +00:00
|
|
|
if ($options{'File'})
|
|
|
|
{
|
2009-06-25 18:16:23 +00:00
|
|
|
$ENV{'DSH_RSYNC_FILE'} = $options{'File'}; # rsync file
|
2009-05-25 12:27:48 +00:00
|
|
|
}
|
2007-12-12 13:19:58 +00:00
|
|
|
if ($options{'version'})
|
|
|
|
{
|
2008-07-07 18:38:47 +00:00
|
|
|
my $version = xCAT::Utils->Version();
|
2008-10-02 14:27:40 +00:00
|
|
|
$version .= "\n";
|
2008-07-07 18:38:47 +00:00
|
|
|
xCAT::MsgUtils->message("I", $version);
|
2007-12-12 13:19:58 +00:00
|
|
|
exit 0;
|
|
|
|
}
|
2009-06-09 14:37:27 +00:00
|
|
|
if ($options{'rootimg'})
|
|
|
|
{
|
|
|
|
$::ROOTIMG = 1;
|
|
|
|
}
|
2009-05-18 14:41:21 +00:00
|
|
|
if (($options{'rootimg'}) && (!($options{'File'})))
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message("E",
|
2009-05-19 14:59:17 +00:00
|
|
|
"To use -i flag you must supply the -F flag\n.");
|
2009-05-18 14:41:21 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
2008-10-17 16:04:13 +00:00
|
|
|
if ($options{'node-rcp'}) # if set on command line, use it
|
|
|
|
{
|
|
|
|
$::NODE_RCP = 1;
|
|
|
|
}
|
2007-12-12 13:19:58 +00:00
|
|
|
|
2008-10-17 16:04:13 +00:00
|
|
|
if ($options{'bypass'})
|
2007-12-12 13:19:58 +00:00
|
|
|
{
|
|
|
|
$ENV{XCATBYPASS} = "yes"; # bypass xcatd
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 check_invalid_exports
|
|
|
|
Check for unsupported dsh exports and warns
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub check_invalid_exports
|
|
|
|
|
|
|
|
{
|
|
|
|
##
|
|
|
|
# Check for unsupported Environment Variables
|
|
|
|
# DSH_DEVICE_LIST, DSH_DEVICE_OPTS, DSH_DEVICE_RCP,DSH_DEVICE_RSH,
|
|
|
|
# DSH_NODEGROUP_PATH
|
2007-12-12 13:19:58 +00:00
|
|
|
# For support Env Variables tell them to use the command line flag
|
2007-10-26 22:44:33 +00:00
|
|
|
##
|
2009-12-04 14:47:53 +00:00
|
|
|
|
|
|
|
if ($ENV{'DSH_CONTEXT'})
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message("I",
|
|
|
|
"DSH_CONTEXT is set but is not supported. It will be ignored.\n");
|
|
|
|
}
|
2008-10-17 16:04:13 +00:00
|
|
|
if ($ENV{'DSH_LIST'}) # if file of nodes input
|
2008-01-28 14:47:17 +00:00
|
|
|
{
|
2008-10-17 16:04:13 +00:00
|
|
|
xCAT::MsgUtils->message("I",
|
|
|
|
"DSH_LIST is set but is not supported. It will be ignored.\n");
|
2008-01-28 14:47:17 +00:00
|
|
|
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
if ($ENV{'DSH_NODE_LIST'})
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message(
|
2007-12-12 13:19:58 +00:00
|
|
|
"I",
|
|
|
|
"DSH_NODE_LIST is set but is not supported. It will be ignored.\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if ($ENV{'WCOLL'})
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message("I",
|
|
|
|
"WCOLL is set but is not supported. It will be ignored.\n");
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
if ($ENV{'DSH_DEVICE_LIST'})
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message(
|
|
|
|
"I",
|
|
|
|
"DSH_DEVICE_LIST is set but is not supported. It will be ignored.\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if ($ENV{'DSH_DEVICE_OPTS'})
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message(
|
|
|
|
"I",
|
|
|
|
"DSH_DEVICE_OPTS is set but is not supported. It will be ignored.\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if ($ENV{'DSH_DEVICE_RCP'})
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message(
|
|
|
|
"I",
|
|
|
|
"DSH_DEVICE_RCP is set but is not supported. It will be ignored.\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if ($ENV{'DSH_DEVICE_RSH'})
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message(
|
|
|
|
"I",
|
|
|
|
"DSH_DEVICE_RSH is set but is not supported. It will be ignored.\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if ($ENV{'DSH_NODEGROUP_PATH'})
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message(
|
|
|
|
"I",
|
|
|
|
"DSH_NODEGROUP_PATH is set but is not supported. It will be ignored.\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if ($ENV{'RSYNC_RSH'})
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message("I",
|
|
|
|
" RSYNC_RSH is set but is not supported. It will be ignored.\n");
|
|
|
|
}
|
2007-12-12 13:19:58 +00:00
|
|
|
if ($ENV{'DSH_REPORT'})
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message("I",
|
|
|
|
" DSH_REPORT is set but is not supported. It will be ignored.\n");
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|