2009-03-25 15:09:23 +00:00
|
|
|
#!/usr/bin/env perl -w
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
#####################################################
|
|
|
|
#
|
|
|
|
# xCAT script resource for NIM (AIX nodes)
|
|
|
|
#
|
|
|
|
#####################################################
|
|
|
|
|
2010-04-21 19:03:49 +00:00
|
|
|
# if AIX - make sure we include perl 5.8.2 in INC path.
|
|
|
|
# Needed to find perl dependencies shipped in deps tarball.
|
|
|
|
if ($^O =~ /^aix/i) {
|
|
|
|
use lib "/usr/opt/perl5/lib/5.8.2/aix-thread-multi";
|
|
|
|
use lib "/usr/opt/perl5/lib/5.8.2";
|
|
|
|
use lib "/usr/opt/perl5/lib/site_perl/5.8.2/aix-thread-multi";
|
|
|
|
use lib "/usr/opt/perl5/lib/site_perl/5.8.2";
|
|
|
|
}
|
|
|
|
|
2009-03-25 15:09:23 +00:00
|
|
|
use File::Path;
|
2010-04-21 19:03:49 +00:00
|
|
|
use IO::Socket;
|
|
|
|
my $useSocketSSL=eval { require IO::Socket::SSL; };
|
|
|
|
use Getopt::Long;
|
|
|
|
use XML::Simple;
|
2009-03-25 15:09:23 +00:00
|
|
|
|
|
|
|
# since we don't have syslog set up yet we'll
|
|
|
|
# just save msgs in a local log file
|
|
|
|
$logdir = "/var/log/xcat";
|
|
|
|
|
|
|
|
if (!-d $logdir) {
|
|
|
|
mkpath($logdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
$::sdate = `/bin/date`;
|
|
|
|
chomp $::sdate;
|
|
|
|
my $logfile = $logdir . "/xcat.log";
|
|
|
|
|
|
|
|
# this log should not contain much so it might be ok to let it grow?
|
|
|
|
# at least we'll have the errors preserved
|
|
|
|
open(LOGFILE,">>",$logfile);
|
|
|
|
$::LOG_FILE = \*LOGFILE;
|
|
|
|
|
|
|
|
# get hostname
|
|
|
|
$::shorthost = `hostname -s`;
|
|
|
|
chomp $::shorthost;
|
|
|
|
|
|
|
|
my $servnode;
|
|
|
|
# get the name of my service node/NIM master from the /etc/niminfo file
|
|
|
|
if (-f "/etc/niminfo") {
|
2010-06-03 14:15:21 +00:00
|
|
|
$cmd = "/bin/cat /etc/niminfo | /bin/grep 'NIM_MASTER_HOSTNAME'";
|
2009-03-25 15:09:23 +00:00
|
|
|
&runcmd($cmd);
|
|
|
|
my $SNline = $::outref;
|
|
|
|
my $junk;
|
|
|
|
($junk, $servnode) = split(/=/, $SNline);
|
|
|
|
|
|
|
|
# save the servnode from niminfo in xcatinfo
|
|
|
|
my $xcatinfo="/etc/xcatinfo";
|
|
|
|
open(XCATINFO,">",$xcatinfo);
|
|
|
|
print XCATINFO "XCATSERVER=$servnode\n";
|
|
|
|
close(XCATINFO);
|
|
|
|
} else {
|
2010-06-03 14:15:21 +00:00
|
|
|
print "$::sdate xcataixscript: Could not find /etc/niminfo file.\n";
|
2009-03-25 15:09:23 +00:00
|
|
|
print $::LOG_FILE "$::sdate xcataixscript: Could not find /etc/niminfo file.\n";
|
|
|
|
}
|
|
|
|
$servnode =~ s/^\s*//;
|
|
|
|
chomp $servnode;
|
|
|
|
|
|
|
|
# create the xcatpost dir
|
2010-06-03 14:15:21 +00:00
|
|
|
my $cmd = "/bin/mkdir -m 755 -p /xcatpost";
|
2009-03-25 15:09:23 +00:00
|
|
|
if (&runcmd($cmd) != 0) {
|
2010-06-03 14:15:21 +00:00
|
|
|
print "$::sdate xcataixscript: Could not make the /xcatpost directory.\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixscript: Could not make the /xcatpost directory.\n";
|
2009-03-25 15:09:23 +00:00
|
|
|
}
|
|
|
|
|
2010-06-03 14:15:21 +00:00
|
|
|
# Set a temporary root password
|
|
|
|
# - the user-provided root passwd will be set by xcataixpost
|
|
|
|
my $pwcmd = qq~/bin/echo "root:xcatroot" | /bin/chpasswd -c >/dev/null 2>&1~;
|
|
|
|
if (&runcmd($pwcmd) != 0) {
|
|
|
|
print "$::sdate xcataixscript: Could not set password.\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixscript: Could not set password.\n";
|
2010-04-21 19:03:49 +00:00
|
|
|
}
|
|
|
|
|
2010-06-03 14:15:21 +00:00
|
|
|
# need fix to support INSTALLDIR !!!!!
|
|
|
|
# socket doesn't work at this point of install so need another
|
|
|
|
# way to get INSTALLDIR value!!!
|
2010-04-21 19:03:49 +00:00
|
|
|
my $installdir;
|
|
|
|
if (!$installdir) {
|
|
|
|
$installdir="/install";
|
|
|
|
}
|
|
|
|
|
|
|
|
# get the contents of the $installdir/postscripts dir on the server
|
2009-03-25 15:09:23 +00:00
|
|
|
# - mount dir from server and copy files
|
2010-06-17 07:38:54 +00:00
|
|
|
# IPv6, should only use NFS version 4 mount
|
|
|
|
my $mcmd;
|
|
|
|
my $snipcmd = "host $servnode";
|
2011-10-24 11:25:16 +00:00
|
|
|
if (((&runcmd($snipcmd) == 0) && ($::outref =~ /:/)) || ($ENV{'USENFSV4ONAIX'} && ($ENV{'USENFSV4ONAIX'} =~ /1|Yes|yes|YES|Y|y/)))
|
2010-06-17 07:38:54 +00:00
|
|
|
{
|
|
|
|
$mcmd = "mkdir -p /xcatmnt; mount -o nolock -o vers=4 $servnode:$installdir/postscripts /xcatmnt";
|
|
|
|
} else {
|
|
|
|
$mcmd = "mkdir -p /xcatmnt; mount -o nolock $servnode:$installdir/postscripts /xcatmnt";
|
|
|
|
}
|
2009-03-25 15:09:23 +00:00
|
|
|
if (&runcmd($mcmd) != 0) {
|
2010-06-03 14:15:21 +00:00
|
|
|
print "$::sdate xcataixscript: Could not mount $installdir/postscripts from $servnode.\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixscript: Could not mount $installdir/postscripts from $servnode.\n";
|
2009-03-25 15:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my $cpcmd;
|
|
|
|
if ((@ARGV==0) || ($ARGV[0] != 2)) {
|
2010-06-03 14:15:21 +00:00
|
|
|
$cpcmd = "/bin/cp -r /xcatmnt/* /xcatpost >/dev/null 2>&1";
|
2009-03-25 15:09:23 +00:00
|
|
|
} else {
|
|
|
|
# when argv[1]=2, there is only one postscript file,
|
|
|
|
# user wants only download it to save time
|
2010-06-03 14:15:21 +00:00
|
|
|
$cpcmd= "/bin/cp /xcatmnt/$ARGV[1] /xcatpost >/dev/null 2>&1";
|
2009-03-25 15:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (&runcmd($cpcmd) != 0) {
|
2010-06-03 14:15:21 +00:00
|
|
|
print "$::sdate xcataixscript: Could not copy postscripts to /xcatpost.\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixscript: Could not copy postscripts to /xcatpost.\n";
|
2009-03-25 15:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# make sure all are executable
|
2010-06-03 14:15:21 +00:00
|
|
|
my $chcmd = "/bin/chmod +x /xcatpost/*";
|
2009-03-25 15:09:23 +00:00
|
|
|
if (&runcmd($chcmd) != 0) {
|
2010-06-03 14:15:21 +00:00
|
|
|
print "$::sdate xcataixscript: Could not change /xcatpost file permissions.\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixscript: Could not change /xcatpost file permissions.\n";
|
2009-03-25 15:09:23 +00:00
|
|
|
}
|
|
|
|
|
2010-06-03 14:15:21 +00:00
|
|
|
my $ucmd = "/usr/sbin/umount /xcatmnt; /bin/rmdir /xcatmnt";
|
2009-03-25 15:09:23 +00:00
|
|
|
if (&runcmd($ucmd) != 0) {
|
2010-06-03 14:15:21 +00:00
|
|
|
print "$::sdate xcataixscript: Could not unmount $installdir.\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixscript: Could not unmount $installdir/postscripts.\n";
|
2009-03-25 15:09:23 +00:00
|
|
|
}
|
|
|
|
|
2010-06-03 14:15:21 +00:00
|
|
|
# add xcat to /etc/inittab???
|
2009-03-25 15:09:23 +00:00
|
|
|
# see if it is already there
|
|
|
|
my $lsicmd = "/usr/sbin/lsitab xcat > /dev/null 2>&1";
|
|
|
|
if (&runcmd($lsicmd) != 0) {
|
|
|
|
# ok - create the entry
|
2010-06-03 14:15:21 +00:00
|
|
|
my $mkitab_cmd = '/usr/sbin/mkitab "xcat:2:wait:/xcatpost/xcataixpost > /dev/console 2>&1"';
|
2009-03-25 15:09:23 +00:00
|
|
|
if (&runcmd($mkitab_cmd) != 0) {
|
2010-06-03 14:15:21 +00:00
|
|
|
print "$::sdate xcataixscript: Could not add xcataixpost to /etc/inittab.\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixscript: Could not add xcataixpost to /etc/inittab.\n";
|
2009-03-25 15:09:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close($::LOG_FILE);
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
#####################################################
|
|
|
|
#
|
|
|
|
# run the command
|
|
|
|
#
|
|
|
|
#####################################################
|
|
|
|
sub runcmd
|
|
|
|
{
|
|
|
|
my ($cmd) = @_;
|
|
|
|
my $rc=0;
|
|
|
|
$cmd .= ' 2>&1' ;
|
|
|
|
$::outref = `$cmd`;
|
|
|
|
if ($?)
|
|
|
|
{
|
|
|
|
$rc = $? >> 8;
|
|
|
|
if ($rc > 0)
|
|
|
|
{
|
2010-06-03 14:15:21 +00:00
|
|
|
print "$::sdate xcataixscript: $::outref\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixscript: $::outref\n";
|
2009-03-25 15:09:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $rc;
|
|
|
|
}
|