2008-06-11 21:24:04 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
package xCAT_plugin::windows;
|
2013-02-07 21:32:19 +00:00
|
|
|
use strict;
|
2008-09-12 22:40:15 +00:00
|
|
|
BEGIN
|
|
|
|
{
|
|
|
|
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
|
|
|
}
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
2008-06-11 21:24:04 +00:00
|
|
|
use Storable qw(dclone);
|
|
|
|
use Sys::Syslog;
|
|
|
|
use File::Temp qw/tempdir/;
|
|
|
|
use xCAT::Table;
|
|
|
|
use xCAT::Utils;
|
2012-08-09 04:07:40 +00:00
|
|
|
use xCAT::TableUtils;
|
2009-09-17 09:53:14 +00:00
|
|
|
use xCAT::SvrUtils;
|
2013-02-07 20:54:55 +00:00
|
|
|
use File::stat;
|
2008-06-20 15:28:41 +00:00
|
|
|
use Socket;
|
2008-06-11 21:24:04 +00:00
|
|
|
use xCAT::MsgUtils;
|
|
|
|
use Data::Dumper;
|
|
|
|
use Getopt::Long;
|
2013-02-05 18:41:50 +00:00
|
|
|
my $globaltftpdir = "/tftpboot";
|
2008-06-11 21:24:04 +00:00
|
|
|
Getopt::Long::Configure("bundling");
|
|
|
|
Getopt::Long::Configure("pass_through");
|
|
|
|
use File::Path;
|
|
|
|
use File::Copy;
|
|
|
|
|
|
|
|
my @cpiopid;
|
|
|
|
|
|
|
|
sub handled_commands
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
copycd => "windows",
|
2013-01-04 21:03:47 +00:00
|
|
|
mkinstall => "nodetype:os=(hyperv.*|win.*|imagex)",
|
2008-09-20 22:26:48 +00:00
|
|
|
mkwinshell => "windows",
|
2008-09-17 18:40:23 +00:00
|
|
|
mkimage => "nodetype:os=imagex",
|
2008-06-11 21:24:04 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub process_request
|
|
|
|
{
|
|
|
|
my $request = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my $doreq = shift;
|
|
|
|
my $distname = undef;
|
|
|
|
my $arch = undef;
|
|
|
|
my $path = undef;
|
2008-06-19 19:53:17 +00:00
|
|
|
my $installroot;
|
2012-08-09 04:07:40 +00:00
|
|
|
$installroot = xCAT::TableUtils->getInstallDir();
|
2013-02-05 18:41:50 +00:00
|
|
|
my $tftpdir = xCAT::TableUtils->get_site_attribute("tftpdir");
|
|
|
|
if ($tftpdir) { $globaltftpdir = $tftpdir; }
|
2008-06-11 21:24:04 +00:00
|
|
|
if ($request->{command}->[0] eq 'copycd')
|
|
|
|
{
|
|
|
|
return copycd($request, $callback, $doreq);
|
|
|
|
}
|
2008-09-20 22:26:48 +00:00
|
|
|
elsif ($request->{command}->[0] eq 'mkwinshell') {
|
|
|
|
return winshell($request,$callback,$doreq);
|
|
|
|
}
|
2008-06-20 15:28:41 +00:00
|
|
|
elsif ($request->{command}->[0] eq 'mkinstall')
|
|
|
|
{
|
|
|
|
return mkinstall($request, $callback, $doreq);
|
|
|
|
}
|
2008-09-17 18:40:23 +00:00
|
|
|
elsif ($request->{command}->[0] eq 'mkimage') {
|
|
|
|
return mkimage($request, $callback, $doreq);
|
|
|
|
}
|
2008-06-11 21:24:04 +00:00
|
|
|
}
|
|
|
|
|
2008-09-17 18:40:23 +00:00
|
|
|
sub mkimage {
|
2008-09-21 17:08:49 +00:00
|
|
|
#NOTES ON IMAGING:
|
|
|
|
#-System must be sysprepped before capture, with /generalize
|
|
|
|
#-EMS settings appear to be lost in the process
|
|
|
|
#-If going to /audit, it's more useful than /oobe.
|
|
|
|
# audit complains about incorrect password on first boot, without any login attempt
|
|
|
|
# audit causes a 'system preparation tool' dialog on first boot that I close
|
2012-08-09 04:07:40 +00:00
|
|
|
my $installroot = xCAT::TableUtils->getInstallDir();
|
2008-09-17 18:40:23 +00:00
|
|
|
my $request = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my $doreq = shift;
|
|
|
|
my @nodes = @{$request->{node}};
|
|
|
|
my $node;
|
|
|
|
my $ostab = xCAT::Table->new('nodetype');
|
|
|
|
my $oshash = $ostab->getNodesAttribs(\@nodes,['profile','arch']);
|
2010-06-23 15:23:06 +00:00
|
|
|
my $vpdtab = xCAT::Table->new('vpd');
|
|
|
|
my $vpdhash = $vpdtab->getNodesAttribs(\@nodes,['uuid']);
|
2008-09-17 18:40:23 +00:00
|
|
|
my $shandle;
|
2010-06-07 14:43:18 +00:00
|
|
|
unless (-d "$installroot/autoinst") {
|
|
|
|
mkpath "$installroot/autoinst";
|
|
|
|
}
|
2013-02-07 21:32:19 +00:00
|
|
|
my $ent;
|
2008-09-17 18:40:23 +00:00
|
|
|
foreach $node (@nodes) {
|
|
|
|
$ent = $oshash->{$node}->[0];
|
|
|
|
unless ($ent->{arch} and $ent->{profile})
|
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
error => ["No profile defined in nodetype for $node"],
|
|
|
|
errorcode => [1]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
next; #No profile
|
|
|
|
}
|
|
|
|
open($shandle,">","$installroot/autoinst/$node.cmd");
|
|
|
|
print $shandle "if exist c:\\xcatimgcred.txt move c:\\xcatimgcred.txt c:\\xcatimgcred.cmd\r\n";
|
|
|
|
print $shandle "if not exist c:\\xcatimgcred.cmd (\r\n";
|
|
|
|
print $shandle " echo ERROR: C:\\xcatimgcred.txt was missing, can't authenticate to server to store image\r\n";
|
|
|
|
print $shandle ")\r\n";
|
|
|
|
print $shandle "call c:\\xcatimgcred.cmd\r\n";
|
|
|
|
print $shandle "del c:\\xcatimgcred.cmd\r\n";
|
|
|
|
print $shandle "x:\r\n";
|
|
|
|
print $shandle "cd \\xcat\r\n";
|
|
|
|
print $shandle "net use /delete i:\r\n";
|
|
|
|
print $shandle 'net use i: %IMGDEST% %PASSWORD% /user:%USER%'."\r\n";
|
|
|
|
print $shandle 'mkdir i:\images'."\r\n";
|
2008-09-18 18:47:20 +00:00
|
|
|
print $shandle 'mkdir i:\images'."\\".$ent->{arch}."\r\n";
|
2008-09-17 18:40:23 +00:00
|
|
|
print $shandle "imagex /capture c: i:\\images\\".$ent->{arch}."\\".$ent->{profile}.".wim ".$ent->{profile}."_".$ent->{arch}."\r\n";
|
|
|
|
print $shandle "IF %PROCESSOR_ARCHITECTURE%==AMD64 GOTO x64\r\n";
|
|
|
|
print $shandle "IF %PROCESSOR_ARCHITECTURE%==x64 GOTO x64\r\n";
|
|
|
|
print $shandle "IF %PROCESSOR_ARCHITECTURE%==x86 GOTO x86\r\n";
|
|
|
|
print $shandle ":x86\r\n";
|
|
|
|
print $shandle "i:\\postscripts\\upflagx86 %XCATD% 3002 next\r\n";
|
|
|
|
print $shandle "GOTO END\r\n";
|
|
|
|
print $shandle ":x64\r\n";
|
|
|
|
print $shandle "i:\\postscripts\\upflagx64 %XCATD% 3002 next\r\n";
|
|
|
|
print $shandle ":END\r\n";
|
|
|
|
print $shandle "pause\r\n";
|
|
|
|
close($shandle);
|
2010-06-23 15:23:06 +00:00
|
|
|
if ($vpdhash->{$node}) {
|
|
|
|
mkwinlinks($node,$ent,$vpdhash->{$node}->[0]->{uuid});
|
|
|
|
} else {
|
|
|
|
mkwinlinks($node,$ent);
|
|
|
|
}
|
2008-09-20 22:26:48 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-21 17:08:49 +00:00
|
|
|
|
2008-09-20 22:26:48 +00:00
|
|
|
sub mkwinlinks {
|
2012-08-09 04:07:40 +00:00
|
|
|
my $installroot = xCAT::TableUtils->getInstallDir(); # for now put this, as it breaks for imagex
|
2008-09-20 22:26:48 +00:00
|
|
|
my $node = shift;
|
|
|
|
my $ent = shift;
|
2010-06-23 15:23:06 +00:00
|
|
|
my $uuid = shift;
|
2008-09-20 22:26:48 +00:00
|
|
|
foreach (getips($node)) {
|
|
|
|
link "$installroot/autoinst/$node.cmd","$installroot/autoinst/$_.cmd";
|
2008-09-17 18:40:23 +00:00
|
|
|
}
|
2012-03-05 18:33:28 +00:00
|
|
|
if ($uuid) {
|
|
|
|
link "$installroot/autoinst/$node.cmd","$installroot/autoinst/$uuid.cmd";
|
|
|
|
#sadly, UUID endiannes is contentious to this day, tolerate a likely mangling
|
|
|
|
#of the UUID
|
2012-03-05 18:33:40 +00:00
|
|
|
$uuid =~ s/^(..)(..)(..)(..)-(..)(..)-(..)(..)-/$4$3$2$1-$6$5-$8$7-/;
|
2012-03-05 18:33:28 +00:00
|
|
|
link "$installroot/autoinst/$node.cmd","$installroot/autoinst/$uuid.cmd";
|
|
|
|
}
|
2008-09-17 18:40:23 +00:00
|
|
|
}
|
2008-09-20 22:26:48 +00:00
|
|
|
|
|
|
|
sub winshell {
|
2012-08-09 04:07:40 +00:00
|
|
|
my $installroot = xCAT::TableUtils->getInstallDir();
|
2008-09-20 22:26:48 +00:00
|
|
|
my $request = shift;
|
|
|
|
my $script = "cmd";
|
|
|
|
my @nodes = @{$request->{node}};
|
|
|
|
my $node;
|
|
|
|
my $ostab = xCAT::Table->new('nodetype');
|
|
|
|
my $oshash = $ostab->getNodesAttribs(\@nodes,['profile','arch']);
|
2010-06-23 15:23:06 +00:00
|
|
|
my $vpdtab = xCAT::Table->new('vpd');
|
|
|
|
my $vpdhash = $vpdtab->getNodesAttribs(\@nodes,['uuid']);
|
2013-02-07 21:32:19 +00:00
|
|
|
my $shandle;
|
2008-09-20 22:26:48 +00:00
|
|
|
foreach $node (@nodes) {
|
|
|
|
open($shandle,">","$installroot/autoinst/$node.cmd");
|
|
|
|
print $shandle $script;
|
|
|
|
close $shandle;
|
2010-06-23 15:23:06 +00:00
|
|
|
if ($vpdhash->{$node}) {
|
|
|
|
mkwinlinks($node,$oshash->{$node}->[0],$vpdhash->{$node}->[0]->{uuid});
|
|
|
|
} else {
|
|
|
|
mkwinlinks($node,$oshash->{$node}->[0]);
|
|
|
|
}
|
2008-09-20 22:26:48 +00:00
|
|
|
my $bptab = xCAT::Table->new('bootparams',-create=>1);
|
|
|
|
$bptab->setNodeAttribs(
|
|
|
|
$node,
|
|
|
|
{
|
|
|
|
kernel => "Boot/pxeboot.0",
|
|
|
|
initrd => "",
|
|
|
|
kcmdline => ""
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub applyimagescript {
|
2008-09-21 17:08:49 +00:00
|
|
|
#Applying will annoy administrator with password change and sysprep tool
|
|
|
|
#in current process
|
|
|
|
#EMS settings loss also bad..
|
|
|
|
#require/use setup.exe for 2k8 to alleviate this?
|
|
|
|
my $arch=shift;
|
|
|
|
my $profile=shift;
|
|
|
|
my $applyscript=<<ENDAPPLY
|
|
|
|
echo select disk 0 > x:/xcat/diskprep.prt
|
|
|
|
echo clean >> x:/xcat/diskprep.prt
|
|
|
|
echo create partition primary >> x:/xcat/diskprep.prt
|
|
|
|
echo format quick >> x:/xcat/diskprep.prt
|
|
|
|
echo active >> x:/xcat/diskprep.prt
|
|
|
|
echo assign >> x:/xcat/diskprep.prt
|
|
|
|
if exist i:/images/$arch/$profile.prt copy i:/images/$arch/$profile.prt x:/xcat/diskprep.prt
|
|
|
|
diskpart /s x:/xcat/diskprep.prt
|
2009-04-29 16:15:14 +00:00
|
|
|
x:/windows/system32/imagex /apply i:/images/$arch/$profile.wim 1 c:
|
2010-06-23 17:48:32 +00:00
|
|
|
reg load HKLM\\csystem c:\\windows\\system32\\config\\system
|
2010-06-23 18:58:09 +00:00
|
|
|
reg copy HKLM\\system\\CurrentControlSet\\services\\TCPIP6\\parameters HKLM\\csystem\\ControlSet001\\services\\TCPIP6\\parameters /f
|
|
|
|
reg copy HKLM\\system\\CurrentControlSet\\services\\TCPIP6\\parameters HKLM\\csystem\\ControlSet002\\services\\TCPIP6\\parameters /f
|
2010-06-23 17:48:32 +00:00
|
|
|
reg unload HKLM\\csystem
|
2008-09-21 17:08:49 +00:00
|
|
|
IF %PROCESSOR_ARCHITECTURE%==AMD64 GOTO x64
|
|
|
|
IF %PROCESSOR_ARCHITECTURE%==x64 GOTO x64
|
|
|
|
IF %PROCESSOR_ARCHITECTURE%==x86 GOTO x86
|
|
|
|
:x86
|
|
|
|
i:/postscripts/upflagx86 %XCATD% 3002 next
|
|
|
|
GOTO END
|
|
|
|
:x64
|
|
|
|
i:/postscripts/upflagx64 %XCATD% 3002 next
|
|
|
|
:END
|
|
|
|
ENDAPPLY
|
2008-09-20 22:26:48 +00:00
|
|
|
}
|
2013-03-25 19:36:20 +00:00
|
|
|
|
|
|
|
sub get_server_certname {
|
|
|
|
my @certdata = `openssl x509 -in /etc/xcat/cert/server-cert.pem -text -noout`;
|
|
|
|
foreach (@certdata) {
|
|
|
|
if (/Subject:/) {
|
|
|
|
s/.*=//;
|
|
|
|
return $_;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-17 18:40:23 +00:00
|
|
|
#Don't sweat os type as for mkimage it is always 'imagex' if it got here
|
2008-06-11 21:24:04 +00:00
|
|
|
sub mkinstall
|
|
|
|
{
|
2008-06-20 15:28:41 +00:00
|
|
|
my $installroot;
|
2012-08-09 04:07:40 +00:00
|
|
|
$installroot = xCAT::TableUtils->getInstallDir();
|
2008-06-11 21:24:04 +00:00
|
|
|
my $request = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my $doreq = shift;
|
|
|
|
my @nodes = @{$request->{node}};
|
2013-02-05 18:41:50 +00:00
|
|
|
my $tftpdir=$globaltftpdir;
|
2008-06-11 21:24:04 +00:00
|
|
|
my $node;
|
|
|
|
my $ostab = xCAT::Table->new('nodetype');
|
|
|
|
my %doneimgs;
|
2008-06-20 15:28:41 +00:00
|
|
|
my $bptab = xCAT::Table->new('bootparams',-create=>1);
|
2008-06-20 21:28:57 +00:00
|
|
|
my $hmtab = xCAT::Table->new('nodehm');
|
2010-06-23 15:23:06 +00:00
|
|
|
my $vpdtab = xCAT::Table->new('vpd');
|
|
|
|
my $vpdhash = $vpdtab->getNodesAttribs(\@nodes,['uuid']);
|
2013-12-03 07:34:05 +00:00
|
|
|
my %img_hash=();
|
|
|
|
my $winimagetab;
|
|
|
|
my $osimagetab;
|
2013-12-10 10:34:09 +00:00
|
|
|
my $winpepathcfg; # the configuration of winpepath for each node. the format is nodename(50)data(150)
|
|
|
|
my $dowinpecfg = 0;
|
2013-12-03 07:34:05 +00:00
|
|
|
|
2013-12-10 10:34:09 +00:00
|
|
|
#unless (-r "$tftpdir/Boot/pxeboot.0" ) {
|
|
|
|
# $callback->(
|
|
|
|
# {error => [ "The Windows netboot image is not created, consult documentation on how to add Windows deployment support to xCAT"],errorcode=>[1]
|
|
|
|
# });
|
|
|
|
# return;
|
|
|
|
#}
|
2013-03-25 19:36:20 +00:00
|
|
|
my $xcatsslname=get_server_certname();
|
|
|
|
unless (-r "$installroot/xcat/ca.pem" and stat("/etc/xcat/cert/ca.pem")->mtime <= stat("$installroot/xcat/ca.pem")->mtime) {
|
|
|
|
mkpath("$installroot/xcat/");
|
|
|
|
copy("/etc/xcat/cert/ca.pem","$installroot/xcat/ca.pem");
|
|
|
|
}
|
2009-03-14 16:14:29 +00:00
|
|
|
require xCAT::Template;
|
2013-12-03 07:34:05 +00:00
|
|
|
|
|
|
|
# get image attributes
|
|
|
|
my $osents = $ostab->getNodesAttribs(\@nodes, ['profile', 'os', 'arch', 'provmethod']);
|
2013-12-10 10:34:09 +00:00
|
|
|
|
|
|
|
# get the proxydhcp configuration
|
|
|
|
if (open (FILE, "</var/lib/xcat/proxydhcp.cfg")) {
|
|
|
|
$winpepathcfg = <FILE>;
|
|
|
|
close(FILE);
|
|
|
|
}
|
|
|
|
|
2008-06-11 21:24:04 +00:00
|
|
|
foreach $node (@nodes)
|
|
|
|
{
|
2013-12-03 07:34:05 +00:00
|
|
|
my $os;
|
|
|
|
my $arch;
|
|
|
|
my $profile;
|
|
|
|
my $tmplfile;
|
|
|
|
my $imagename; # set it if running of 'nodeset osimage=xxx'
|
|
|
|
my $partfile;
|
|
|
|
my $installto;
|
2013-12-10 10:34:09 +00:00
|
|
|
my $winpepath;
|
2013-12-03 07:34:05 +00:00
|
|
|
|
|
|
|
my $ent = $osents->{$node}->[0];
|
|
|
|
if ($ent and $ent->{provmethod} and ($ent->{provmethod} ne 'install') and ($ent->{provmethod} ne 'netboot') and ($ent->{provmethod} ne 'statelite')) {
|
|
|
|
$imagename=$ent->{provmethod};
|
|
|
|
if (!exists($img_hash{$imagename})) {
|
|
|
|
if (!$osimagetab) {
|
|
|
|
$osimagetab=xCAT::Table->new('osimage', -create=>1);
|
|
|
|
}
|
|
|
|
|
|
|
|
my $ref = $osimagetab->getAttribs({imagename => $imagename}, 'osvers', 'osarch', 'profile', 'provmethod');
|
|
|
|
if ($ref) {
|
|
|
|
$img_hash{$imagename}->{osver}=$ref->{'osvers'};
|
|
|
|
$img_hash{$imagename}->{osarch}=$ref->{'osarch'};
|
|
|
|
$img_hash{$imagename}->{profile}=$ref->{'profile'};
|
|
|
|
$img_hash{$imagename}->{provmethod}=$ref->{'provmethod'};
|
|
|
|
if (!$winimagetab) {
|
|
|
|
$winimagetab=xCAT::Table->new('winimage', -create=>1);
|
|
|
|
}
|
2013-12-10 10:34:09 +00:00
|
|
|
my $ref1 = $winimagetab->getAttribs({imagename => $imagename}, 'template', 'installto', 'partitionfile', 'winpepath');
|
2013-12-03 07:34:05 +00:00
|
|
|
if ($ref1) {
|
|
|
|
if ($ref1->{'template'}) {
|
|
|
|
$img_hash{$imagename}->{template}=$ref1->{'template'};
|
|
|
|
}
|
|
|
|
if ($ref1->{'installto'}) {
|
|
|
|
$img_hash{$imagename}->{installto}=$ref1->{'installto'};
|
|
|
|
}
|
|
|
|
if ($ref1->{'partitionfile'}) {
|
|
|
|
$img_hash{$imagename}->{partitionfile}=$ref1->{'partitionfile'};
|
|
|
|
}
|
2013-12-10 10:34:09 +00:00
|
|
|
if ($ref1->{'winpepath'}) {
|
|
|
|
$img_hash{$imagename}->{winpepath}=$ref1->{'winpepath'};
|
|
|
|
}
|
2013-12-03 07:34:05 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$callback->({error => ["The os image $imagename does not exists on the osimage table for $node"], errorcode => [1]});
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my $ph=$img_hash{$imagename};
|
|
|
|
$os = $ph->{osver};
|
|
|
|
$arch = $ph->{osarch};
|
|
|
|
$profile = $ph->{profile};
|
|
|
|
$partfile = $ph->{partitionfile};
|
|
|
|
$tmplfile = $ph->{template};
|
|
|
|
$installto = $ph->{installto};
|
2013-12-10 10:34:09 +00:00
|
|
|
$winpepath = $ph->{winpepath};
|
2013-12-03 07:34:05 +00:00
|
|
|
} else {
|
|
|
|
unless ($ent->{os} and $ent->{arch} and $ent->{profile})
|
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
error => ["No profile defined in nodetype for $node"],
|
|
|
|
errorcode => [1]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
next; #No profile
|
|
|
|
}
|
|
|
|
|
|
|
|
$os = $ent->{os};
|
|
|
|
$arch = $ent->{arch};
|
|
|
|
$profile = $ent->{profile};
|
|
|
|
if ($os eq "imagex") {
|
|
|
|
my $wimfile="$installroot/images/$arch/$profile.wim";
|
|
|
|
unless ( -r $wimfile ) {
|
|
|
|
$callback->({error=>["$wimfile not found, run rimage on a node to capture first"],errorcode=>[1]});
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
my $script=applyimagescript($arch,$profile);
|
|
|
|
my $shandle;
|
|
|
|
open($shandle,">","$installroot/autoinst/$node.cmd");
|
|
|
|
print $shandle $script;
|
|
|
|
close($shandle);
|
|
|
|
if ($vpdhash->{$node}) {
|
|
|
|
mkwinlinks($node,$ent,$vpdhash->{$node}->[0]->{uuid});
|
|
|
|
} else {
|
|
|
|
mkwinlinks($node,$ent);
|
|
|
|
}
|
|
|
|
if ($arch =~ /x86_64/)
|
|
|
|
{
|
|
|
|
$bptab->setNodeAttribs(
|
|
|
|
$node,
|
|
|
|
{
|
|
|
|
kernel => "Boot/pxeboot.0",
|
|
|
|
initrd => "",
|
|
|
|
kcmdline => ""
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} elsif ($arch =~ /x86/) {
|
|
|
|
unless (-r "$tftpdir/Boot/pxeboot32.0") {
|
|
|
|
my $origpxe;
|
|
|
|
my $pxeboot;
|
|
|
|
open($origpxe,"<$tftpdir/Boot/pxeboot.0");
|
|
|
|
open($pxeboot,">$tftpdir/Boot/pxeboot32.0");
|
|
|
|
binmode($origpxe);
|
|
|
|
binmode($pxeboot);
|
|
|
|
my @origpxecontent = <$origpxe>;
|
|
|
|
foreach (@origpxecontent) {
|
|
|
|
s/bootmgr.exe/bootm32.exe/;
|
|
|
|
print $pxeboot $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unless (-r "$tftpdir/bootm32.exe") {
|
|
|
|
my $origmgr;
|
|
|
|
my $bootmgr;
|
|
|
|
open($origmgr,"<$tftpdir/bootmgr.exe");
|
|
|
|
open($bootmgr,">$tftpdir/bootm32.exe");
|
|
|
|
binmode($origmgr);
|
|
|
|
binmode($bootmgr);
|
|
|
|
my @data = <$origmgr>;
|
|
|
|
foreach (@data) {
|
|
|
|
s/(\\.B.o.o.t.\\.B.)C(.)D/${1}3${2}2/; # 16 bit encoding... cheat
|
|
|
|
print $bootmgr $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$bptab->setNodeAttribs(
|
|
|
|
$node,
|
2008-06-11 21:24:04 +00:00
|
|
|
{
|
2013-12-03 07:34:05 +00:00
|
|
|
kernel => "Boot/pxeboot32.0",
|
|
|
|
initrd => "",
|
|
|
|
kcmdline => ""
|
2008-06-11 21:24:04 +00:00
|
|
|
}
|
2013-12-03 07:34:05 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
2008-09-17 18:40:23 +00:00
|
|
|
|
2013-12-03 07:34:05 +00:00
|
|
|
my $custmplpath = "$installroot/custom/install/windows";
|
|
|
|
my $tmplpath = "$::XCATROOT/share/xcat/install/windows";
|
|
|
|
if ($os =~ /^hyperv/) {
|
|
|
|
$custmplpath = "$installroot/custom/install/hyperv";
|
|
|
|
$tmplpath = "$::XCATROOT/share/xcat/install/hyperv";
|
|
|
|
}
|
|
|
|
my $tmplfile=xCAT::SvrUtils::get_tmpl_file_name($custmplpath, $profile, $os, $arch);
|
|
|
|
if (! $tmplfile) { $tmplfile=xCAT::SvrUtils::get_tmpl_file_name($tmplpath, $profile, $os, $arch); }
|
|
|
|
}
|
|
|
|
|
2008-09-12 22:40:15 +00:00
|
|
|
unless ( -r "$tmplfile")
|
2008-06-11 21:24:04 +00:00
|
|
|
{
|
2013-12-03 07:34:05 +00:00
|
|
|
$callback->({error =>["No unattended template exists for " . $ent->{profile}],errorcode => [1]});
|
2008-06-11 21:24:04 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2013-12-10 10:34:09 +00:00
|
|
|
# generate the winpe path configuration file for proxydhcp daemon
|
|
|
|
if ($winpepath) {
|
|
|
|
if ($winpepath =~ /^\//) {
|
|
|
|
$callback->({error =>["The winpepath should be a relative path to /tftpboot/"],errorcode => [1]});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($winpepath !~ /\/$/) {
|
|
|
|
$winpepath .= '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
my $nodename .= pack("a50", $node);
|
|
|
|
my $winpevalue .= pack("a150", $winpepath);
|
|
|
|
if ($winpepathcfg =~ /$nodename$winpevalue/) {
|
|
|
|
; # do nothing
|
|
|
|
} elsif ($winpepathcfg =~ /$nodename/) {
|
|
|
|
$winpepathcfg =~ s/$nodename.{150}/$nodename$winpevalue/;
|
|
|
|
$dowinpecfg = 1;
|
|
|
|
} else {
|
|
|
|
$winpepathcfg .= $nodename;
|
|
|
|
$winpepathcfg .= $winpevalue;
|
|
|
|
$dowinpecfg = 1;
|
|
|
|
}
|
|
|
|
#}
|
|
|
|
|
|
|
|
# copy bootmgr.exe from winpe path, this is shared by different winpes.
|
|
|
|
# if it cannot be shared between winpes, we must figure out a fix
|
|
|
|
if (! -r "$tftpdir/bootmgr.exe") {
|
|
|
|
copy("$tftpdir/$winpepath/Boot/bootmgr.exe", "$tftpdir/bootmgr.exe");
|
|
|
|
}
|
|
|
|
|
2008-06-11 21:24:04 +00:00
|
|
|
#Call the Template class to do substitution to produce an unattend.xml file in the autoinst dir
|
|
|
|
my $tmperr;
|
2013-12-03 07:34:05 +00:00
|
|
|
my @utilfiles = (
|
|
|
|
"fixupunattend.vbs",
|
|
|
|
"detectefi.exe",
|
|
|
|
"xCAT.psd1",
|
|
|
|
"xCAT.psm1",
|
|
|
|
"xCAT.format.ps1xml",
|
|
|
|
"nextdestiny.ps1",
|
|
|
|
);
|
|
|
|
foreach my $utilfile (@utilfiles) {
|
|
|
|
unless (-r "$installroot/utils/windows/$utilfile" and stat("$::XCATROOT/share/xcat/netboot/windows/$utilfile")->mtime <= stat("$installroot/utils/windows/$utilfile")->mtime) {
|
|
|
|
mkpath("$installroot/utils/windows/");
|
|
|
|
copy("$::XCATROOT/share/xcat/netboot/windows/$utilfile","$installroot/utils/windows/$utilfile");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (-r "$tmplfile") {
|
|
|
|
$tmperr = xCAT::Template->subvars(
|
2008-09-12 22:40:15 +00:00
|
|
|
$tmplfile,
|
2013-02-07 20:54:55 +00:00
|
|
|
"$installroot/autoinst/$node.xml",
|
2010-08-06 14:22:28 +00:00
|
|
|
$node,
|
2013-12-03 07:34:05 +00:00
|
|
|
0);
|
2008-06-11 21:24:04 +00:00
|
|
|
}
|
2008-09-12 22:40:15 +00:00
|
|
|
|
2013-12-03 07:34:05 +00:00
|
|
|
if ($tmperr) {
|
|
|
|
$callback->({node => [{name => [$node], error => [$tmperr], errorcode => [1]}]});
|
2008-06-11 21:24:04 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# create the node-specific post script DEPRECATED, don't do
|
|
|
|
#mkpath "/install/postscripts/";
|
2013-12-10 10:34:09 +00:00
|
|
|
if (! -r "$tftpdir/$winpepath/Boot/pxeboot.0" ) {
|
2008-06-19 19:53:17 +00:00
|
|
|
$callback->(
|
|
|
|
{error => [ "The Windows netboot image is not created, consult documentation on how to add Windows deployment support to xCAT"],errorcode=>[1]
|
|
|
|
});
|
2013-12-10 10:34:09 +00:00
|
|
|
return;
|
2008-06-19 19:53:17 +00:00
|
|
|
} elsif (-r $installroot."/$os/$arch/sources/install.wim") {
|
2008-06-11 21:24:04 +00:00
|
|
|
if ($arch =~ /x86/)
|
|
|
|
{
|
|
|
|
$bptab->setNodeAttribs(
|
|
|
|
$node,
|
|
|
|
{
|
2013-12-10 10:34:09 +00:00
|
|
|
kernel => "$winpepath"."Boot/pxeboot.0",
|
2008-06-11 21:24:04 +00:00
|
|
|
initrd => "",
|
2008-06-19 19:53:17 +00:00
|
|
|
kcmdline => ""
|
2008-06-11 21:24:04 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
error => [
|
2008-06-20 15:28:41 +00:00
|
|
|
"Failed to detect copycd configured install source at /$installroot/$os/$arch/sources/install.wim"
|
2008-06-11 21:24:04 +00:00
|
|
|
],
|
|
|
|
errorcode => [1]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2008-06-20 15:28:41 +00:00
|
|
|
my $shandle;
|
2008-06-20 21:28:57 +00:00
|
|
|
my $sspeed;
|
|
|
|
my $sport;
|
|
|
|
if ($hmtab) {
|
|
|
|
my $sent = $hmtab->getNodeAttribs($node,"serialport","serialspeed");
|
|
|
|
if ($sent and defined($sent->{serialport}) and $sent->{serialspeed}) {
|
|
|
|
$sport = $sent->{serialport};
|
|
|
|
$sspeed = $sent->{serialspeed};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-16 07:22:02 +00:00
|
|
|
#copy precreated mypostscript from /tftpboot/mypostscript to /install/mypostscript
|
|
|
|
if (-r "$tftpdir/mypostscripts/mypostscript.$node") {
|
|
|
|
if (! -d "$installroot/mypostscripts") {
|
|
|
|
mkpath ("$installroot/mypostscripts");
|
|
|
|
}
|
|
|
|
copy ("$tftpdir/mypostscripts/mypostscript.$node", "$installroot/mypostscripts/mypostscript.$node");
|
|
|
|
}
|
|
|
|
|
2013-12-03 07:34:05 +00:00
|
|
|
if (-f "$::XCATROOT/share/xcat/netboot/detectefi.exe" and not -f "$installroot/utils/detectefi.exe") {
|
|
|
|
mkpath("$installroot/utils/");
|
|
|
|
copy("$::XCATROOT/share/xcat/netboot/detectefi.exe","$installroot/utils/detectefi.exe");
|
|
|
|
}
|
|
|
|
|
|
|
|
my $partcfg;
|
|
|
|
if ($partfile) {
|
|
|
|
if (-r $partfile) {
|
|
|
|
$partcfg = "[BIOS]";
|
|
|
|
if (open (PFILE, "<$partfile")) {
|
|
|
|
while (<PFILE>) {
|
|
|
|
s/\s*$//g;
|
|
|
|
s/^\s*//g;
|
|
|
|
if (/^\[bios\](.*)/i) {
|
|
|
|
$partcfg .= $1;
|
|
|
|
} elsif (/^\[uefi\](.*)/i) {
|
|
|
|
$partcfg .= "[UEFI]$1";
|
2013-12-10 10:34:09 +00:00
|
|
|
} elsif (/^\[installto\](.*)/i) {
|
|
|
|
$installto = $1;
|
2013-12-03 07:34:05 +00:00
|
|
|
} else {
|
|
|
|
$partcfg .= $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$callback->({data =>["Cannot open partition configuration file: $partfile."]});
|
|
|
|
}
|
|
|
|
}
|
2008-06-20 21:28:57 +00:00
|
|
|
|
2013-12-03 07:34:05 +00:00
|
|
|
if ($installto && ($installto !~ /^[\d:]+$/)) {
|
|
|
|
$callback->({error =>["The format of installto is not correct: installto."]});
|
|
|
|
$installto = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
# generate the auto running command file for windows deployment
|
2011-09-22 18:02:54 +00:00
|
|
|
open($shandle,">","$installroot/autoinst/$node.cmd");
|
2013-12-03 07:34:05 +00:00
|
|
|
if ($partcfg) {
|
2013-12-16 07:22:02 +00:00
|
|
|
print $shandle "set PARTCFG=\"$partcfg\r\n";
|
2013-12-03 07:34:05 +00:00
|
|
|
}
|
|
|
|
if ($installto) {
|
2013-12-16 07:22:02 +00:00
|
|
|
print $shandle "set INSTALLTO=$installto\r\n";
|
2013-12-03 07:34:05 +00:00
|
|
|
}
|
2013-12-16 07:22:02 +00:00
|
|
|
|
|
|
|
|
2013-12-03 07:34:05 +00:00
|
|
|
print $shandle 'for /f "tokens=2 delims= " %%i in ('."'net use ^| find ".'"install"'."') do set instdrv=%%i\r\n";
|
|
|
|
print $shandle "%instdrv%\\utils\\windows\\fixupunattend.vbs %instdrv%\\autoinst\\$node.xml x:\\unattend.xml\r\n";
|
|
|
|
|
|
|
|
#### test part
|
|
|
|
#print $shandle "start /max cmd\r\n";
|
|
|
|
#print $shandle "pause\r\n";
|
|
|
|
|
2008-06-20 21:28:57 +00:00
|
|
|
if ($sspeed) {
|
|
|
|
$sport++;
|
2013-02-08 20:11:15 +00:00
|
|
|
print $shandle "%instdrv%\\$os\\$arch\\setup /unattend:x:\\unattend.xml /emsport:COM$sport /emsbaudrate:$sspeed /noreboot\r\n";
|
2008-06-20 21:28:57 +00:00
|
|
|
} else {
|
2013-02-08 20:11:15 +00:00
|
|
|
print $shandle "%instdrv%\\$os\\$arch\\setup /unattend:x:\\unattend.xml /noreboot\r\n";
|
2008-06-20 21:28:57 +00:00
|
|
|
}
|
2013-12-16 07:22:02 +00:00
|
|
|
|
|
|
|
#check the existence of necessary files
|
|
|
|
print $shandle "IF NOT EXIST %instdrv%\\mypostscripts\\mypostscript.$node GOTO:SKIPPOST\r\n";
|
|
|
|
print $shandle "IF NOT EXIST %instdrv%\\winpostscripts\\xcatwinpost.vbs GOTO:SKIPPOST\r\n";
|
|
|
|
print $shandle "IF NOT EXIST %instdrv%\\winpostscripts\\runpost.vbs GOTO:SKIPPOST\r\n";
|
|
|
|
#crate c:\xcatpost
|
|
|
|
print $shandle "mkdir c:\\xcatpost\r\n";
|
|
|
|
#generate c:\xcatpost\xcatenv to pass env variables for later using
|
|
|
|
print $shandle "set NODENAME=$node\r\n";
|
|
|
|
print $shandle "echo NODENAME=$node>>c:\\xcatpost\\xcatenv\r\n";
|
|
|
|
#copy postscripts to c:\xcatpost
|
|
|
|
print $shandle "copy %instdrv%\\winpostscripts\\* c:\\xcatpost\\\r\n";
|
|
|
|
print $shandle "copy %instdrv%\\mypostscripts\\mypostscript.$node c:\\xcatpost\\\r\n";
|
|
|
|
print $shandle ":SKIPPOST\r\n";
|
|
|
|
#### test part
|
|
|
|
#print $shandle "start /max cmd\r\n";
|
|
|
|
#print $shandle "pause\r\n";
|
|
|
|
|
2008-06-20 21:28:57 +00:00
|
|
|
#print $shandle "i:\\postscripts\
|
2010-06-23 17:48:32 +00:00
|
|
|
print $shandle 'reg load HKLM\csystem c:\windows\system32\config\system'."\r\n"; #copy installer DUID to system before boot
|
2010-06-23 19:16:19 +00:00
|
|
|
print $shandle 'reg copy HKLM\system\CurrentControlSet\services\TCPIP6\parameters HKLM\csystem\ControlSet001\services\TCPIP6\parameters /f'."\r\n";
|
|
|
|
print $shandle 'reg copy HKLM\system\CurrentControlSet\services\TCPIP6\parameters HKLM\csystem\ControlSet002\services\TCPIP6\parameters /f'."\r\n";
|
2010-06-23 17:48:32 +00:00
|
|
|
print $shandle 'reg unload HKLM\csystem'."\r\n";
|
2013-05-10 14:52:44 +00:00
|
|
|
print $shandle "If EXIST %instdrv%\\winpostscripts GOTO wps\r\n";
|
|
|
|
print $shandle "goto up\r\n";
|
|
|
|
print $shandle ":wps\r\n";
|
|
|
|
print $shandle "mkdir c:\\xcatpost\r\n";
|
|
|
|
print $shandle "xcopy %instdrv%\\winpostscripts c:\\xcatpost\r\n";
|
|
|
|
print $shandle ":up\r\n";
|
2013-03-23 17:23:20 +00:00
|
|
|
print $shandle "If EXIST X:\\Windows\\system32\\WindowsPowerShell GOTO PSH\r\n";
|
2008-06-20 21:28:57 +00:00
|
|
|
print $shandle "IF %PROCESSOR_ARCHITECTURE%==AMD64 GOTO x64\r\n";
|
|
|
|
print $shandle "IF %PROCESSOR_ARCHITECTURE%==x64 GOTO x64\r\n";
|
|
|
|
print $shandle "IF %PROCESSOR_ARCHITECTURE%==x86 GOTO x86\r\n";
|
|
|
|
print $shandle ":x86\r\n";
|
2013-02-08 20:11:15 +00:00
|
|
|
print $shandle "%instdrv%\\postscripts\\upflagx86 %XCATD% 3002 next\r\n";
|
2008-06-20 21:28:57 +00:00
|
|
|
print $shandle "GOTO END\r\n";
|
|
|
|
print $shandle ":x64\r\n";
|
2013-02-08 20:11:15 +00:00
|
|
|
print $shandle "%instdrv%\\postscripts\\upflagx64 %XCATD% 3002 next\r\n";
|
2013-03-23 17:23:20 +00:00
|
|
|
print $shandle "GOTO END\r\n";
|
2013-03-25 19:36:31 +00:00
|
|
|
print $shandle ":PSH\r\n";
|
|
|
|
print $shandle "set mastername=$xcatsslname\r\n";
|
|
|
|
print $shandle "set master=%XCATD%\r\n";
|
2013-03-23 17:23:20 +00:00
|
|
|
print $shandle "mkdir x:\\windows\\system32\\WindowsPowerShell\\v1.0\\Modules\\xCAT\r\n";
|
|
|
|
print $shandle "copy %instdrv%\\utils\\windows\\xCAT.* x:\\windows\\system32\\WindowsPowerShell\\v1.0\\Modules\\xCAT\r\n";
|
|
|
|
print $shandle "powershell set-executionpolicy bypass CurrentUser\r\n";
|
|
|
|
print $shandle "powershell %instdrv%\\utils\\windows\\nextdestiny.ps1\r\n";
|
2008-06-20 21:28:57 +00:00
|
|
|
print $shandle ":END\r\n";
|
2008-06-20 15:28:41 +00:00
|
|
|
close($shandle);
|
2010-06-23 15:23:06 +00:00
|
|
|
if ($vpdhash->{$node}) {
|
|
|
|
mkwinlinks($node,undef,$vpdhash->{$node}->[0]->{uuid});
|
|
|
|
} else {
|
|
|
|
mkwinlinks($node,undef);
|
|
|
|
}
|
2013-02-05 18:41:50 +00:00
|
|
|
#since we are manipulating the 'filename' more precisely, no longer any reason to make per node BCD links
|
|
|
|
# foreach (getips($node)) { #This should be deprecated, probably
|
|
|
|
# unlink "$tftpdir/Boot/BCD.$_";
|
|
|
|
# if ($arch =~ /64/) {
|
|
|
|
# link "$tftpdir/Boot/BCD.64","$tftpdir/Boot/BCD.$_";
|
|
|
|
# } else {
|
|
|
|
# link "$tftpdir/Boot/BCD.32","$tftpdir/Boot/BCD.$_";
|
|
|
|
# }
|
|
|
|
# }
|
2008-06-11 21:24:04 +00:00
|
|
|
}
|
2013-12-10 10:34:09 +00:00
|
|
|
|
|
|
|
# generate the winpe path configuration file for proxydhcp daemon
|
|
|
|
if ($dowinpecfg) {
|
2014-01-10 14:15:50 +00:00
|
|
|
unless (-d "/var/lib/xcat/") {
|
|
|
|
mkpath "/var/lib/xcat/";
|
|
|
|
}
|
|
|
|
if (open (FILE, ">/var/lib/xcat/proxydhcp.cfg")) {
|
|
|
|
print FILE $winpepathcfg;
|
|
|
|
close (FILE);
|
|
|
|
if (open (PDPID, "</var/run/xcat/proxydhcp-xcat.pid")) {
|
|
|
|
my $pdpid = <PDPID>;
|
|
|
|
kill 10, $pdpid;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$callback->({error=>["Cannot open /var/lib/xcat/proxydhcp.cfg for update."],errorcode=>[1]});
|
2013-12-10 10:34:09 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-11 21:24:04 +00:00
|
|
|
}
|
2008-06-20 15:28:41 +00:00
|
|
|
sub getips { #TODO: all the possible ip addresses
|
|
|
|
my $node = shift;
|
2010-06-01 19:21:52 +00:00
|
|
|
my $ipn = inet_aton($node); #would use proper method, but trying to deprecate this anyhow
|
|
|
|
unless ($ipn) { return (); }
|
|
|
|
#THIS CURRENTLY WOULD BREAK WITH IPV6 anyway...
|
|
|
|
my $ip = inet_ntoa($ipn);
|
2008-06-20 15:28:41 +00:00
|
|
|
return ($ip);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-11 21:24:04 +00:00
|
|
|
|
|
|
|
sub copycd
|
|
|
|
{
|
|
|
|
my $request = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my $doreq = shift;
|
|
|
|
my $distname = "";
|
2012-11-06 03:20:33 +00:00
|
|
|
my $arch;
|
|
|
|
my $path;
|
|
|
|
my $mntpath=undef;
|
|
|
|
my $inspection=undef;
|
2012-11-08 07:02:56 +00:00
|
|
|
my $noosimage=undef;
|
2012-11-06 03:20:33 +00:00
|
|
|
|
2008-06-11 21:24:04 +00:00
|
|
|
my $installroot;
|
|
|
|
$installroot = "/install";
|
2012-05-23 06:29:34 +00:00
|
|
|
#my $sitetab = xCAT::Table->new('site');
|
|
|
|
#if ($sitetab)
|
|
|
|
#{
|
|
|
|
#(my $ref) = $sitetab->getAttribs({key => installdir}, value);
|
2012-08-09 04:07:40 +00:00
|
|
|
my @entries = xCAT::TableUtils->get_site_attribute("installdir");
|
2012-05-23 06:29:34 +00:00
|
|
|
my $t_entry = $entries[0];
|
|
|
|
if ( defined($t_entry) )
|
2008-06-11 21:24:04 +00:00
|
|
|
{
|
2012-05-23 06:29:34 +00:00
|
|
|
$installroot = $t_entry;
|
2008-06-11 21:24:04 +00:00
|
|
|
}
|
2012-05-23 06:29:34 +00:00
|
|
|
#}
|
2008-06-11 21:24:04 +00:00
|
|
|
|
|
|
|
@ARGV = @{$request->{arg}};
|
|
|
|
GetOptions(
|
|
|
|
'n=s' => \$distname,
|
|
|
|
'a=s' => \$arch,
|
2012-11-06 03:20:33 +00:00
|
|
|
'p=s' => \$path,
|
|
|
|
'm=s' => \$mntpath,
|
2012-11-08 07:02:56 +00:00
|
|
|
'i' => \$inspection,
|
|
|
|
'o' => \$noosimage,
|
2008-06-11 21:24:04 +00:00
|
|
|
);
|
2012-11-06 03:20:33 +00:00
|
|
|
unless ($mntpath)
|
2008-06-11 21:24:04 +00:00
|
|
|
{
|
|
|
|
|
2012-11-06 03:20:33 +00:00
|
|
|
#this plugin needs $mntpath...
|
2008-06-11 21:24:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-01-04 21:03:47 +00:00
|
|
|
if ($distname and $distname !~ /^win.*/ and $distname !~ /^hyperv.*/)
|
2008-06-11 21:24:04 +00:00
|
|
|
{
|
|
|
|
#If they say to call it something other than win<something>, give up?
|
|
|
|
return;
|
|
|
|
}
|
2013-02-07 21:32:19 +00:00
|
|
|
my $darch;
|
2012-11-06 03:20:33 +00:00
|
|
|
if (-d $mntpath . "/sources/6.0.6000.16386_amd64" and -r $mntpath . "/sources/install.wim")
|
2008-06-11 21:24:04 +00:00
|
|
|
{
|
2013-02-07 21:32:19 +00:00
|
|
|
$darch = "x86_64";
|
2008-06-11 21:24:04 +00:00
|
|
|
unless ($distname) {
|
|
|
|
$distname = "win2k8";
|
|
|
|
}
|
|
|
|
}
|
2009-11-09 20:35:43 +00:00
|
|
|
# add support for Win7
|
2012-11-06 03:20:33 +00:00
|
|
|
if(-r $mntpath . "/sources/idwbinfo.txt"){
|
|
|
|
open(DBNAME, $mntpath . "/sources/idwbinfo.txt");
|
2009-11-09 20:35:43 +00:00
|
|
|
while(<DBNAME>){
|
|
|
|
if(/BuildArch=amd64/){
|
|
|
|
$darch = "x86_64";
|
2012-11-21 16:56:37 +00:00
|
|
|
} elsif (/BuildBranch=win7_rtm/){
|
2009-11-09 20:35:43 +00:00
|
|
|
$distname = "win7";
|
2012-11-21 16:56:37 +00:00
|
|
|
} elsif (/BuildBranch=win8_rtm/){
|
2012-11-21 17:38:07 +00:00
|
|
|
if (-r $mntpath . "/sources/background_cli.bmp") {
|
|
|
|
$distname = "win8";
|
|
|
|
} elsif (-r $mntpath . "/sources/background_svr.bmp") {
|
2012-11-21 17:52:27 +00:00
|
|
|
if (-r $mntpath . "/sources/EI.CFG") {
|
|
|
|
my $eicfg;
|
|
|
|
open($eicfg,"<", $mntpath . "/sources/EI.CFG");
|
|
|
|
my $eiline = <$eicfg>;
|
|
|
|
$eiline = <$eicfg>;
|
|
|
|
if ($eiline =~ /Hyper/) {
|
2013-01-04 21:03:47 +00:00
|
|
|
$distname = "hyperv2012";
|
2012-11-21 17:52:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
unless ($distname) {
|
|
|
|
$distname = "win2012";
|
|
|
|
}
|
2012-11-21 17:38:07 +00:00
|
|
|
}
|
2009-11-09 20:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
close(DBNAME);
|
|
|
|
}
|
2012-11-06 03:20:33 +00:00
|
|
|
if (-r $mntpath . "/sources/install_Windows Server 2008 R2 SERVERENTERPRISE.clg") {
|
2010-01-14 20:32:51 +00:00
|
|
|
$distname = "win2k8r2";
|
|
|
|
}
|
2008-06-11 21:24:04 +00:00
|
|
|
unless ($distname)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($darch)
|
|
|
|
{
|
|
|
|
unless ($arch)
|
|
|
|
{
|
|
|
|
$arch = $darch;
|
|
|
|
}
|
|
|
|
if ($arch and $arch ne $darch)
|
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
error =>
|
|
|
|
["Requested Windows architecture $arch, but media is $darch"],
|
|
|
|
errorcode => [1]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-11-06 03:20:33 +00:00
|
|
|
|
|
|
|
if($inspection)
|
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
info =>
|
|
|
|
"DISTNAME:$distname\n"."ARCH:$arch\n"
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-11 21:24:04 +00:00
|
|
|
%{$request} = (); #clear request we've got it.
|
|
|
|
|
2012-11-06 03:20:33 +00:00
|
|
|
my $defaultpath="$installroot/$distname/$arch";
|
|
|
|
unless($path)
|
|
|
|
{
|
|
|
|
$path=$defaultpath;
|
|
|
|
}
|
2013-04-02 19:19:30 +00:00
|
|
|
my $osdistroname=$distname."-".$arch;
|
|
|
|
if ($::XCATSITEVALS{osimagerequired}){
|
|
|
|
my ($nohaveimages,$errstr) = xCAT::SvrUtils->update_tables_with_templates($distname, $arch,$path,$osdistroname,checkonly=>1);
|
|
|
|
if ($nohaveimages) {
|
2013-04-03 20:57:18 +00:00
|
|
|
$callback->({error => "No Templates found to support $distname($arch)",errorcode=>2});
|
2013-04-02 19:19:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-11-06 03:20:33 +00:00
|
|
|
|
2008-06-11 21:24:04 +00:00
|
|
|
$callback->(
|
2012-11-06 03:20:33 +00:00
|
|
|
{data => "Copying media to $path"});
|
2008-06-11 21:24:04 +00:00
|
|
|
my $omask = umask 0022;
|
2012-11-06 03:20:33 +00:00
|
|
|
if(-l $path)
|
|
|
|
{
|
|
|
|
unlink($path);
|
|
|
|
}
|
|
|
|
mkpath("$path");
|
2008-06-11 21:24:04 +00:00
|
|
|
umask $omask;
|
2012-11-06 03:20:33 +00:00
|
|
|
|
2008-06-11 21:24:04 +00:00
|
|
|
my $rc;
|
|
|
|
$SIG{INT} = $SIG{TERM} = sub {
|
|
|
|
foreach(@cpiopid){
|
|
|
|
kill 2, $_;
|
|
|
|
}
|
2012-11-06 03:20:33 +00:00
|
|
|
if ($mntpath) {
|
2008-08-11 18:36:10 +00:00
|
|
|
chdir("/");
|
2012-11-06 03:20:33 +00:00
|
|
|
system("umount $mntpath");
|
2008-06-11 21:24:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
my $kid;
|
2012-11-06 03:20:33 +00:00
|
|
|
chdir $mntpath;
|
2008-06-11 21:24:04 +00:00
|
|
|
my $numFiles = `find . -print | wc -l`;
|
|
|
|
my $child = open($kid,"|-");
|
|
|
|
unless (defined $child) {
|
|
|
|
$callback->({error=>"Media copy operation fork failure"});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($child) {
|
|
|
|
push @cpiopid,$child;
|
|
|
|
my @finddata = `find .`;
|
|
|
|
for (@finddata) {
|
|
|
|
print $kid $_;
|
|
|
|
}
|
|
|
|
close($kid);
|
|
|
|
$rc = $?;
|
|
|
|
} else {
|
2012-11-06 03:20:33 +00:00
|
|
|
my $c = "nice -n 20 cpio -vdump $path";
|
2008-06-11 21:24:04 +00:00
|
|
|
my $k2 = open(PIPE, "$c 2>&1 |") ||
|
|
|
|
$callback->({error => "Media copy operation fork failure"});
|
|
|
|
push @cpiopid, $k2;
|
|
|
|
my $copied = 0;
|
|
|
|
my ($percent, $fout);
|
|
|
|
while(<PIPE>){
|
|
|
|
next if /^cpio:/;
|
|
|
|
$percent = $copied / $numFiles;
|
|
|
|
$fout = sprintf "%0.2f%%", $percent * 100;
|
|
|
|
$callback->({sinfo => "$fout"});
|
|
|
|
++$copied;
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
}
|
2012-11-06 03:20:33 +00:00
|
|
|
chmod 0755, "$path";
|
|
|
|
unless($path =~ /^($defaultpath)/)
|
|
|
|
{
|
|
|
|
mkpath($defaultpath);
|
|
|
|
if(-d $defaultpath)
|
|
|
|
{
|
|
|
|
rmtree($defaultpath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unlink($defaultpath);
|
|
|
|
}
|
|
|
|
|
|
|
|
my $hassymlink = eval { symlink("",""); 1 };
|
|
|
|
if ($hassymlink) {
|
|
|
|
symlink($path,$defaultpath);
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
link($path,$defaultpath);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-11 21:24:04 +00:00
|
|
|
if ($rc != 0)
|
|
|
|
{
|
|
|
|
$callback->({error => "Media copy operation failed, status $rc"});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$callback->({data => "Media copy operation successful"});
|
2012-11-06 03:20:33 +00:00
|
|
|
my @ret=xCAT::SvrUtils->update_osdistro_table($distname,$arch,$path,$osdistroname);
|
|
|
|
if ($ret[0] != 0) {
|
|
|
|
$callback->({data => "Error when updating the osdistro tables: " . $ret[1]});
|
|
|
|
}
|
2012-11-08 07:02:56 +00:00
|
|
|
|
|
|
|
unless($noosimage){
|
|
|
|
my @ret=xCAT::SvrUtils->update_tables_with_templates($distname, $arch,$path,$osdistroname);
|
|
|
|
if ($ret[0] != 0) {
|
|
|
|
$callback->({data => "Error when updating the osimage tables: " . $ret[1]});
|
|
|
|
}
|
2009-09-19 17:03:14 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-11 21:24:04 +00:00
|
|
|
}
|
|
|
|
|
2009-09-17 09:53:14 +00:00
|
|
|
#sub get_tmpl_file_name {
|
|
|
|
# my $base=shift;
|
|
|
|
# my $profile=shift;
|
|
|
|
# my $os=shift;
|
|
|
|
# my $arch=shift;
|
|
|
|
# if (-r "$base/$profile.$os.$arch.tmpl") {
|
|
|
|
# return "$base/$profile.$os.$arch.tmpl";
|
|
|
|
# }
|
|
|
|
# elsif (-r "$base/$profile.$arch.tmpl") {
|
|
|
|
# return "$base/$profile.$arch.tmpl";
|
|
|
|
# }
|
|
|
|
# elsif (-r "$base/$profile.$os.tmpl") {
|
|
|
|
# return "$base/$profile.$os.tmpl";
|
|
|
|
# }
|
|
|
|
# elsif (-r "$base/$profile.tmpl") {
|
|
|
|
# return "$base/$profile.tmpl";
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# return "";
|
|
|
|
#}
|
2008-06-11 21:24:04 +00:00
|
|
|
1;
|
2008-09-12 22:40:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|