diff --git a/xCAT/postscripts/aixremoteshell b/xCAT/postscripts/aixremoteshell new file mode 100644 index 000000000..6ae2a1531 --- /dev/null +++ b/xCAT/postscripts/aixremoteshell @@ -0,0 +1,121 @@ +#!/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 + /bin/rcp but can be overriden by setting the rsh and rcp attribute in the + site table to another remote shell such as /bin/ssh /bin/scp. +=cut + +#----------------------------------------------------------------------------- + +# +# If rsh=rsh then +# setup .rhosts on the node +# else (ssh) +# setup the ssh keys on the node +# end + +# MAIN +use strict; +my $rc = 0; + +# AIX default +my $remoteshell = "/bin/rsh"; +my $remotecopy = "/bin/rcp"; + +# Override from site table +$remoteshell = $ENV{'RSH'}; +$remotecopy = $ENV{'RCP'}; +my $master = $ENV{'MASTER'}; +my $node = $ENV{'NODE'}; +my $msg; +my $home; +my $cmd; +my $username = "root"; +my @root = split ':', (`/bin/grep ^$username /etc/passwd 2>&1`); +$home = $root[5]; + +if (grep /rsh/, $remoteshell) +{ # setting up rsh + # setup .rhosts if not already setup + $cmd = "/bin/grep \"^$master root\" $home/.rhosts"; + `$cmd 2>&1`; + my $rc = $? >> 8; + if ($rc) + { # if not found, then add entry in .rhosts + &runcmd("/bin/echo $master root >> $home/.rhosts"); + chmod 0600, "$home/.rhosts"; + } + +} +else +{ # setting up ssh + my $sshdconfig = "/etc/ssh/sshd_config"; + my $sshconfig = "/etc/ssh/ssh_config"; + if (-e $sshdconfig) + { # ssh installed + &runcmd("cp $sshdconfig $sshdconfig.ORIG"); + &runcmd("echo \"KeyRegenerationInterval 0\" >>$sshdconfig"); + &runcmd("echo \"X11Forwarding yes\" >>$sshdconfig"); + &runcmd("echo \"MaxStartups 1024\" >>$sshdconfig"); + &runcmd("echo \"PasswordAuthentication no\" >>$sshdconfig"); + &runcmd("cp $sshconfig $sshconfig.ORIG"); + &runcmd("echo \"StrictHostKeyChecking no\" >>$sshconfig"); + } + else + { # ssh not installed + my $msg = "Failed to setup ssh on $node, ssh not installed. \n"; + `logger -t xcat $msg`; + exit 1; + } + if (-e "/xcatpost/_ssh") + { # ssh public key available + $rc = &runcmd("mkdir -p $home/.ssh"); + if ($rc == 0) + { + &runcmd("cp -fp /xcatpost/_ssh/* $home/.ssh"); + chmod 0700, "$home/.ssh"; + chmod 0600, "$home/.ssh/*"; + } + } + else + { # ssh keys not available + my $msg = "Failed to setup ssh on $node, ssh keys not available. \n"; + `logger -t xcat $msg`; + exit 1; + } + $rc = &runcmd("scp -p $master:$home/.ssh/id_* $home/.ssh"); + chmod 0600, "$home/.ssh/*"; +} +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`; + } + } + return $rc; +} +