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;
|
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;
|
2009-09-17 09:53:14 +00:00
|
|
|
use xCAT::SvrUtils;
|
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;
|
|
|
|
Getopt::Long::Configure("bundling");
|
|
|
|
Getopt::Long::Configure("pass_through");
|
|
|
|
use File::Path;
|
|
|
|
use File::Copy;
|
|
|
|
|
|
|
|
my @cpiopid;
|
|
|
|
|
|
|
|
sub handled_commands
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
copycd => "windows",
|
2008-09-17 18:40:23 +00:00
|
|
|
mkinstall => "nodetype:os=(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;
|
|
|
|
$installroot = "/install";
|
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
|
2008-09-17 18:40:23 +00:00
|
|
|
my $installroot = "/install";
|
|
|
|
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']);
|
|
|
|
my $shandle;
|
|
|
|
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);
|
2008-09-20 22:26:48 +00:00
|
|
|
mkwinlinks($node,$ent);
|
|
|
|
}
|
|
|
|
}
|
2008-09-21 17:08:49 +00:00
|
|
|
|
2008-09-20 22:26:48 +00:00
|
|
|
sub mkwinlinks {
|
2010-04-16 15:59:20 +00:00
|
|
|
my $installroot = "/install"; # for now put this, as it breaks for imagex
|
2008-09-20 22:26:48 +00:00
|
|
|
my $node = shift;
|
|
|
|
my $ent = shift;
|
|
|
|
foreach (getips($node)) {
|
|
|
|
link "$installroot/autoinst/$node.cmd","$installroot/autoinst/$_.cmd";
|
2008-09-17 18:40:23 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-20 22:26:48 +00:00
|
|
|
|
|
|
|
sub winshell {
|
|
|
|
my $installroot = "/install";
|
|
|
|
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']);
|
|
|
|
foreach $node (@nodes) {
|
|
|
|
open($shandle,">","$installroot/autoinst/$node.cmd");
|
|
|
|
print $shandle $script;
|
|
|
|
close $shandle;
|
|
|
|
mkwinlinks($node,$oshash->{$node}->[0]);
|
|
|
|
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:
|
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
|
|
|
}
|
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;
|
|
|
|
$installroot = "/install";
|
2008-06-11 21:24:04 +00:00
|
|
|
my $request = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my $doreq = shift;
|
|
|
|
my @nodes = @{$request->{node}};
|
2008-09-17 18:40:23 +00:00
|
|
|
my $tftpdir="/tftpboot";
|
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');
|
2008-09-17 18:40:23 +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;
|
|
|
|
}
|
2009-03-14 16:14:29 +00:00
|
|
|
require xCAT::Template;
|
2008-06-11 21:24:04 +00:00
|
|
|
foreach $node (@nodes)
|
|
|
|
{
|
|
|
|
my $osinst;
|
|
|
|
my $ent = $ostab->getNodeAttribs($node, ['profile', 'os', 'arch']);
|
|
|
|
unless ($ent->{os} and $ent->{arch} and $ent->{profile})
|
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
error => ["No profile defined in nodetype for $node"],
|
|
|
|
errorcode => [1]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
next; #No profile
|
|
|
|
}
|
|
|
|
my $os = $ent->{os};
|
|
|
|
my $arch = $ent->{arch};
|
|
|
|
my $profile = $ent->{profile};
|
2008-09-17 18:40:23 +00:00
|
|
|
if ($os eq "imagex") {
|
2008-09-21 17:08:49 +00:00
|
|
|
unless ( -r "$installroot/images/$arch/$profile.wim" ) {
|
2008-09-17 18:40:23 +00:00
|
|
|
$callback->({error=>["$installroot/images/$profile.$arch.wim not found, run rimage on a node to capture first"],errorcode=>[1]});
|
|
|
|
next;
|
|
|
|
}
|
2008-09-21 17:08:49 +00:00
|
|
|
my $script=applyimagescript($arch,$profile);
|
|
|
|
my $shandle;
|
|
|
|
open($shandle,">","$installroot/autoinst/$node.cmd");
|
|
|
|
print $shandle $script;
|
|
|
|
close($shandle);
|
|
|
|
mkwinlinks($node,$ent);
|
2010-05-21 18:34:17 +00:00
|
|
|
if ($arch =~ /x86_64/)
|
2008-09-21 17:08:49 +00:00
|
|
|
{
|
|
|
|
$bptab->setNodeAttribs(
|
|
|
|
$node,
|
|
|
|
{
|
|
|
|
kernel => "Boot/pxeboot.0",
|
|
|
|
initrd => "",
|
|
|
|
kcmdline => ""
|
|
|
|
}
|
|
|
|
);
|
2010-05-21 18:34:17 +00:00
|
|
|
} 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);
|
|
|
|
foreach (@data) {
|
|
|
|
s/(\\.B.o.o.t.\\.B.)C(.)D/${1}3${2}2/; # 16 bit encoding... cheat
|
|
|
|
print $bootmgr $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$bptab->setNodeAttribs(
|
|
|
|
$node,
|
|
|
|
{
|
|
|
|
kernel => "Boot/pxeboot32.0",
|
|
|
|
initrd => "",
|
|
|
|
kcmdline => ""
|
|
|
|
}
|
|
|
|
);
|
2008-09-21 17:08:49 +00:00
|
|
|
}
|
2008-09-17 18:40:23 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2009-09-17 09:53:14 +00:00
|
|
|
my $tmplfile=xCAT::SvrUtils::get_tmpl_file_name("$installroot/custom/install/windows", $profile, $os, $arch);
|
|
|
|
if (! $tmplfile) { $tmplfile=xCAT::SvrUtils::get_tmpl_file_name("$::XCATROOT/share/xcat/install/windows", $profile, $os, $arch); }
|
2008-09-12 22:40:15 +00:00
|
|
|
unless ( -r "$tmplfile")
|
2008-06-11 21:24:04 +00:00
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
error =>
|
2008-06-19 19:53:17 +00:00
|
|
|
["No unattended template exists for " . $ent->{profile}],
|
2008-06-11 21:24:04 +00:00
|
|
|
errorcode => [1]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
#Call the Template class to do substitution to produce an unattend.xml file in the autoinst dir
|
|
|
|
my $tmperr;
|
2008-09-12 22:40:15 +00:00
|
|
|
if (-r "$tmplfile")
|
2008-06-11 21:24:04 +00:00
|
|
|
{
|
|
|
|
$tmperr =
|
|
|
|
xCAT::Template->subvars(
|
2008-09-12 22:40:15 +00:00
|
|
|
$tmplfile,
|
2008-06-11 21:24:04 +00:00
|
|
|
"/install/autoinst/$node",
|
|
|
|
$node
|
|
|
|
);
|
|
|
|
}
|
2008-09-12 22:40:15 +00:00
|
|
|
|
2008-06-11 21:24:04 +00:00
|
|
|
if ($tmperr)
|
|
|
|
{
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
node => [
|
|
|
|
{
|
|
|
|
name => [$node],
|
|
|
|
error => [$tmperr],
|
|
|
|
errorcode => [1]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# create the node-specific post script DEPRECATED, don't do
|
|
|
|
#mkpath "/install/postscripts/";
|
|
|
|
#xCAT::Postage->writescript($node, "/install/postscripts/".$node, "install", $callback);
|
2008-06-19 19:53:17 +00:00
|
|
|
if (! -r "/tftpboot/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]
|
|
|
|
});
|
|
|
|
} elsif (-r $installroot."/$os/$arch/sources/install.wim") {
|
2008-06-11 21:24:04 +00:00
|
|
|
|
|
|
|
if ($arch =~ /x86/)
|
|
|
|
{
|
|
|
|
$bptab->setNodeAttribs(
|
|
|
|
$node,
|
|
|
|
{
|
2008-06-19 19:53:17 +00:00
|
|
|
kernel => "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};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-20 15:28:41 +00:00
|
|
|
open($shandle,">","$installroot/autoinst/$node.cmd");
|
2008-06-20 21:28:57 +00:00
|
|
|
if ($sspeed) {
|
|
|
|
$sport++;
|
|
|
|
print $shandle "i:\\$os\\$arch\\setup /unattend:i:\\autoinst\\$node /emsport:COM$sport /emsbaudrate:$sspeed /noreboot\r\n";
|
|
|
|
} else {
|
|
|
|
print $shandle "i:\\$os\\$arch\\setup /unattend:i:\\autoinst\\$node /noreboot\r\n";
|
|
|
|
}
|
|
|
|
#print $shandle "i:\\postscripts\
|
|
|
|
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";
|
2008-06-20 15:28:41 +00:00
|
|
|
close($shandle);
|
|
|
|
foreach (getips($node)) {
|
2008-06-20 21:28:57 +00:00
|
|
|
link "$installroot/autoinst/$node.cmd","$installroot/autoinst/$_.cmd";
|
2008-06-20 15:28:41 +00:00
|
|
|
unlink "/tftpboot/Boot/BCD.$_";
|
|
|
|
if ($arch =~ /64/) {
|
|
|
|
link "/tftpboot/Boot/BCD.64","/tftpboot/Boot/BCD.$_";
|
|
|
|
} else {
|
|
|
|
link "/tftpboot/Boot/BCD.32","/tftpboot/Boot/BCD.$_";
|
|
|
|
}
|
|
|
|
}
|
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 = "";
|
|
|
|
my $installroot;
|
|
|
|
$installroot = "/install";
|
|
|
|
my $sitetab = xCAT::Table->new('site');
|
|
|
|
if ($sitetab)
|
|
|
|
{
|
|
|
|
(my $ref) = $sitetab->getAttribs({key => installdir}, value);
|
|
|
|
if ($ref and $ref->{value})
|
|
|
|
{
|
|
|
|
$installroot = $ref->{value};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ARGV = @{$request->{arg}};
|
|
|
|
GetOptions(
|
|
|
|
'n=s' => \$distname,
|
|
|
|
'a=s' => \$arch,
|
|
|
|
'p=s' => \$path
|
|
|
|
);
|
|
|
|
unless ($path)
|
|
|
|
{
|
|
|
|
|
|
|
|
#this plugin needs $path...
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($distname and $distname !~ /^win.*/)
|
|
|
|
{
|
|
|
|
|
|
|
|
#If they say to call it something other than win<something>, give up?
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (-d $path . "/sources/6.0.6000.16386_amd64" and -r $path . "/sources/install.wim")
|
|
|
|
{
|
|
|
|
$darch = x86_64;
|
|
|
|
unless ($distname) {
|
|
|
|
$distname = "win2k8";
|
|
|
|
}
|
|
|
|
}
|
2009-11-09 20:35:43 +00:00
|
|
|
# add support for Win7
|
|
|
|
if(-r $path . "/sources/idwbinfo.txt"){
|
|
|
|
open(DBNAME, $path . "/sources/idwbinfo.txt");
|
|
|
|
while(<DBNAME>){
|
|
|
|
if(/BuildArch=amd64/){
|
|
|
|
$darch = "x86_64";
|
|
|
|
}
|
|
|
|
if(/BuildBranch=win7_rtm/){
|
|
|
|
$distname = "win7";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(DBNAME);
|
|
|
|
}
|
2010-01-14 20:32:51 +00:00
|
|
|
if (-r $path . "/sources/install_Windows Server 2008 R2 SERVERENTERPRISE.clg") {
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
%{$request} = (); #clear request we've got it.
|
|
|
|
|
|
|
|
$callback->(
|
|
|
|
{data => "Copying media to $installroot/$distname/$arch/$discnumber"});
|
|
|
|
my $omask = umask 0022;
|
|
|
|
mkpath("$installroot/$distname/$arch");
|
|
|
|
umask $omask;
|
|
|
|
my $rc;
|
|
|
|
$SIG{INT} = $SIG{TERM} = sub {
|
|
|
|
foreach(@cpiopid){
|
|
|
|
kill 2, $_;
|
|
|
|
}
|
|
|
|
if ($::CDMOUNTPATH) {
|
2008-08-11 18:36:10 +00:00
|
|
|
chdir("/");
|
2008-06-11 21:24:04 +00:00
|
|
|
system("umount $::CDMOUNTPATH");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
my $kid;
|
|
|
|
chdir $path;
|
|
|
|
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 {
|
|
|
|
my $c = "nice -n 20 cpio -vdump $installroot/$distname/$arch";
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
chmod 0755, "$installroot/$distname/$arch";
|
|
|
|
if ($rc != 0)
|
|
|
|
{
|
|
|
|
$callback->({error => "Media copy operation failed, status $rc"});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$callback->({data => "Media copy operation successful"});
|
2009-09-19 17:03:14 +00:00
|
|
|
my @ret=xCAT::SvrUtils->update_tables_with_templates($distname, $arch);
|
|
|
|
if ($ret[0] != 0) {
|
|
|
|
$callback->({data => "Error when updating the osimage tables: " . $ret[1]});
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|