2008-06-11 18:42:59 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
#(C)IBM Corp
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head1 aixremoteshell
|
|
|
|
|
|
|
|
This sets up the remote shell for rooton the AIX node,such that root can
|
|
|
|
login using with no password. The default is /bin/rsh and
|
2008-06-12 18:43:37 +00:00
|
|
|
/bin/rcp but can be overriden by setting the useSSHonAIX attribute in the
|
|
|
|
site table to yes, in which case we will use ssh/scp.
|
2008-06-11 18:42:59 +00:00
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#
|
2008-06-12 18:43:37 +00:00
|
|
|
# If USESSHONAIX does not exist or is no or 0 then
|
2008-06-11 18:42:59 +00:00
|
|
|
# setup .rhosts on the node
|
|
|
|
# else (ssh)
|
|
|
|
# setup the ssh keys on the node
|
|
|
|
# end
|
|
|
|
|
|
|
|
# MAIN
|
|
|
|
use strict;
|
|
|
|
my $rc = 0;
|
|
|
|
|
|
|
|
# Override from site table
|
2008-06-12 18:43:37 +00:00
|
|
|
my $usesshonaix = $ENV{'USESSHONAIX'};
|
2008-06-19 16:49:54 +00:00
|
|
|
my $master = $ENV{'MASTER'};
|
|
|
|
my $node = $ENV{'NODE'};
|
2008-06-11 18:42:59 +00:00
|
|
|
my $msg;
|
|
|
|
my $home;
|
|
|
|
my $cmd;
|
|
|
|
my $username = "root";
|
|
|
|
my @root = split ':', (`/bin/grep ^$username /etc/passwd 2>&1`);
|
|
|
|
$home = $root[5];
|
2008-06-19 16:49:54 +00:00
|
|
|
# root home directory must be root system
|
|
|
|
$rc = &runcmd("chown root $home");
|
|
|
|
if ($rc != 0)
|
|
|
|
{
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
$rc = &runcmd("chgrp system $home");
|
|
|
|
if ($rc != 0)
|
|
|
|
{
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
if ($home eq "\/")
|
|
|
|
{
|
|
|
|
$home = "";
|
|
|
|
}
|
2008-06-11 18:42:59 +00:00
|
|
|
|
2008-06-12 18:43:37 +00:00
|
|
|
$usesshonaix =~ tr/a-z/A-Z/; # convert to upper
|
2008-06-19 16:49:54 +00:00
|
|
|
if ((!defined($usesshonaix)) || ($usesshonaix eq "0") || ($usesshonaix eq "NO"))
|
2008-06-12 18:43:37 +00:00
|
|
|
{ # setting up rsh
|
|
|
|
# setup .rhosts if not already setup
|
2008-06-11 18:42:59 +00:00
|
|
|
$cmd = "/bin/grep \"^$master root\" $home/.rhosts";
|
|
|
|
`$cmd 2>&1`;
|
|
|
|
my $rc = $? >> 8;
|
|
|
|
if ($rc)
|
2008-06-12 18:43:37 +00:00
|
|
|
{ # if not found, then add entry in .rhosts
|
2008-06-11 18:42:59 +00:00
|
|
|
&runcmd("/bin/echo $master root >> $home/.rhosts");
|
|
|
|
chmod 0600, "$home/.rhosts";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
2008-06-12 18:43:37 +00:00
|
|
|
{ # setting up ssh
|
2008-06-11 18:42:59 +00:00
|
|
|
my $sshdconfig = "/etc/ssh/sshd_config";
|
|
|
|
my $sshconfig = "/etc/ssh/ssh_config";
|
|
|
|
if (-e $sshdconfig)
|
2008-06-12 18:43:37 +00:00
|
|
|
{ # ssh installed
|
2008-06-19 16:49:54 +00:00
|
|
|
my $tmp="$sshdconfig.ORIG";
|
|
|
|
if (!(-e "$sshdconfig.ORIG"))
|
|
|
|
{
|
|
|
|
&runcmd("cp $sshdconfig $sshdconfig.ORIG");
|
|
|
|
}
|
2008-06-11 18:42:59 +00:00
|
|
|
&runcmd("echo \"KeyRegenerationInterval 0\" >>$sshdconfig");
|
|
|
|
&runcmd("echo \"X11Forwarding yes\" >>$sshdconfig");
|
|
|
|
&runcmd("echo \"MaxStartups 1024\" >>$sshdconfig");
|
|
|
|
&runcmd("echo \"PasswordAuthentication no\" >>$sshdconfig");
|
2008-06-19 16:49:54 +00:00
|
|
|
if (!(-e "$sshconfig.ORIG"))
|
|
|
|
{
|
|
|
|
&runcmd("cp $sshconfig $sshconfig.ORIG");
|
|
|
|
}
|
2008-06-11 18:42:59 +00:00
|
|
|
&runcmd("echo \"StrictHostKeyChecking no\" >>$sshconfig");
|
|
|
|
}
|
|
|
|
else
|
2008-06-19 16:49:54 +00:00
|
|
|
{ # ssh not installed
|
2008-06-11 18:42:59 +00:00
|
|
|
my $msg = "Failed to setup ssh on $node, ssh not installed. \n";
|
|
|
|
`logger -t xcat $msg`;
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
if (-e "/xcatpost/_ssh")
|
2008-06-19 16:49:54 +00:00
|
|
|
{ # ssh public key available
|
2008-06-11 18:42:59 +00:00
|
|
|
$rc = &runcmd("mkdir -p $home/.ssh");
|
|
|
|
if ($rc == 0)
|
|
|
|
{
|
2008-06-19 16:49:54 +00:00
|
|
|
$rc = &runcmd("cp -fp /xcatpost/_ssh/* $home/.ssh");
|
|
|
|
if ($rc == 0)
|
|
|
|
{
|
|
|
|
#$rc = &runcmd("scp -p $master:$home/.ssh/id_* $home/.ssh");
|
|
|
|
$rc = &runcmd("chmod 0700 $home/.ssh");
|
|
|
|
$rc = &runcmd("chmod 0600 $home/.ssh/*");
|
|
|
|
}
|
2008-06-11 18:42:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2008-06-19 16:49:54 +00:00
|
|
|
{ # ssh keys not available
|
2008-06-11 18:42:59 +00:00
|
|
|
my $msg = "Failed to setup ssh on $node, ssh keys not available. \n";
|
|
|
|
`logger -t xcat $msg`;
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exit $rc;
|
|
|
|
|
|
|
|
#
|
|
|
|
# run the command
|
|
|
|
#
|
|
|
|
sub runcmd
|
|
|
|
{
|
|
|
|
my ($cmd) = @_;
|
|
|
|
my $rc = 0;
|
|
|
|
$cmd .= ' 2>&1';
|
|
|
|
my $outref = [];
|
|
|
|
@$outref = `$cmd`;
|
|
|
|
if ($?)
|
|
|
|
{
|
|
|
|
$rc = $? >> 8;
|
|
|
|
if ($rc > 0)
|
|
|
|
{
|
|
|
|
my $msg = "$cmd returned rc=$rc @$outref\n";
|
|
|
|
`logger -t xcat $msg`;
|
2008-06-19 16:49:54 +00:00
|
|
|
print $msg;
|
2008-06-11 18:42:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $rc;
|
|
|
|
}
|
|
|
|
|