code drop for windows postscript/postbootscript support. The postscript/postbootscript should be set in node/osimage.postscript/postbootscript and copy to /install/winpostscripts before running nodeset

This commit is contained in:
daniceexi 2013-12-16 02:22:02 -05:00
parent b958093474
commit 32f8a37a22
3 changed files with 216 additions and 2 deletions

View File

@ -523,6 +523,14 @@ sub mkinstall
}
}
#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");
}
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");
@ -560,11 +568,13 @@ sub mkinstall
# generate the auto running command file for windows deployment
open($shandle,">","$installroot/autoinst/$node.cmd");
if ($partcfg) {
print $shandle "set PARTCFG=\"$partcfg\n";
print $shandle "set PARTCFG=\"$partcfg\r\n";
}
if ($installto) {
print $shandle "set INSTALLTO=$installto\n";
print $shandle "set INSTALLTO=$installto\r\n";
}
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";
@ -578,6 +588,24 @@ sub mkinstall
} else {
print $shandle "%instdrv%\\$os\\$arch\\setup /unattend:x:\\unattend.xml /noreboot\r\n";
}
#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";
#print $shandle "i:\\postscripts\
print $shandle 'reg load HKLM\csystem c:\windows\system32\config\system'."\r\n"; #copy installer DUID to system before boot
print $shandle 'reg copy HKLM\system\CurrentControlSet\services\TCPIP6\parameters HKLM\csystem\ControlSet001\services\TCPIP6\parameters /f'."\r\n";

View File

@ -0,0 +1,64 @@
Dim myshell, filesys
Dim args, pname, pargs, cmdname
Dim logname, loghandler, fline, output
'Ingore the error box to avoid the stop of postscript running
On Error Resume Next
'WScript.echo "get in runpost"
logname = "c:\xcatpost\xcat.log"
'Initialize the shell and fs objects
Set myshell = WScript.createObject("WScript.Shell")
Set filesys = CreateObject("Scripting.FileSystemObject")
'Open the log file for writting
Set loghandler = filesys.OpenTextFile(logname, 8, True)
' Get script name and arguments
Set args = WScript.Arguments
If args.Count <= 0 Then
loghandler.Close
WScript.Quit
ElseIf args.Count = 1 Then
pname = args(0)
pargs = ""
ElseIf args.Count > 1 Then
pname = args(0)
For i = 1 to args.Count - 1
pargs = pargs & " " & args(i)
Next
End If
If Not filesys.FileExists("c:\xcatpost\" & pname) Then
loghandler.WriteLine "Cannot find file: c:\xcatpost\" & pname
loghandler.Close
WScript.Quit
End If
cmdname = "cmd /c "
if Right(pname, 4) = ".bat" Or Right(pname, 4) = ".cmd" Then
cmdname = cmdname & "call "
End If
cmdname = cmdname & " c:\xcatpost\" & pname & " " & pargs
loghandler.WriteLine "=========================================="
loghandler.WriteLine now
loghandler.WriteLine "Run script: " & pname & " " & pargs
'Run command
'WScript.echo cmdname
Set output = myshell.Exec(cmdname)
' Handle the output from the script
Do While Not output.StdOut.AtEndOfStream
fline = output.StdOut.ReadLine()
loghandler.WriteLine fline
Loop
loghandler.WriteLine "The return code is: " & output.ExitCode
loghandler.WriteLine ""
loghandler.Close

View File

@ -0,0 +1,122 @@
'This script is used to run postscripts for Windows compute node
Dim filesys, myshell
Dim nodename, origpostscript, mypostscript, mypostbootscript
Dim output, tmpstr, startpoint
Dim fileread, filewrite, filewritepost, filewritepostboot, fline
Dim flagwp, flagwpb
Dim logname,loghandler
'Ingore the error box to avoid the stop of postscript running
On Error Resume Next
logname = "c:\xcatpost\xcat.log"
'Initialize the shell and fs objects
Set myshell = WScript.createObject("WScript.Shell")
Set filesys = CreateObject("Scripting.FileSystemObject")
'Open the log file for writting
Set loghandler = filesys.OpenTextFile(logname, 8, True)
loghandler.WriteLine "=========================================="
loghandler.WriteLine now
loghandler.WriteLine "Get in xcatwinpost.vbs"
'Read envrironment variables from c:\xcatpost\xcatenv
Set fileread = filesys.OpenTextFile("c:\xcatpost\xcatenv",1)
Do Until fileread.AtEndOfStream
fline = fileread.ReadLine
strpoint = InStr(fline, "NODENAME=")
If strpoint Then
nodename = Mid(fline, strpoint+9)
End If
Loop
loghandler.WriteLine "The nodename is: " & nodename
'Get the postscripts from xCAT management
origpostscript = "c:\xcatpost\mypostscript." & nodename
mypostscript = "c:\xcatpost\mypostscript.cmd"
mypostbootscript = "c:\xcatpost\mypostbootscript.cmd"
' Debug
'WScript.echo "orig mypostscript"& origpostscript
'Check the existence of mypostscript file
If NOT filesys.FileExists(origpostscript) Then
loghandler.WriteLine "Cannot find the original mypostscript: " & origpostscript
loghandler.Close
'WScript.echo "QUIT"
WScript.quit [1]
End If
'Create mypostscript and mypostbootscript from original postscript which was copied from xCAT MN
Set fileread = filesys.OpenTextFile(origpostscript, 1)
Set filewritepost = filesys.OpenTextFile(mypostscript, 2, True)
Set filewritepostboot = filesys.OpenTextFile(mypostbootscript, 2, True)
flagwp = 0
flagwpb = 0
Do Until fileread.AtEndOfStream
fline = fileread.ReadLine
If InStr(fline, "|") Then
' Ignore the char |
' Do nothing
ElseIf InStr(fline, "osimage-postscripts-start-here") Or InStr(fline, "node-postscripts-start-here") Then
flagwp = 1
ElseIf InStr(fline, "osimage-postscripts-end-here") Or InStr(fline, "node-postscripts-end-here") Then
flagwp = 0
ElseIf InStr(fline, "osimage-postbootscripts-start-here") Or InStr(fline, "node-postbootscripts-start-here") Then
flagwpb = 1
ElseIf InStr(fline, "osimage-postbootscripts-end-here") Or InStr(fline, "node-postbootscripts-end-here") Then
flagwpb = 0
ElseIf InStr(fline, "=") Then
' Set the environment variables
tmpstr = "Set "&fline
' Ignore the char '
tmpstr = Replace(tmpstr, "'", "")
filewritepost.WriteLine tmpstr
filewritepostboot.WriteLine tmpstr
ElseIf flagwp Then
' Run script with runpost.vbs
fline = "c:\xcatpost\runpost.vbs " & fline
filewritepost.WriteLine fline
ElseIf flagwpb Then
' Run script with runpost.vbs
fline = "c:\xcatpost\runpost.vbs " & fline
filewritepostboot.WriteLine fline
End If
Loop
fileread.Close
filewritepost.Close
filewritepostboot.Close
loghandler.WriteLine "mypostscript and mypostbootscript have been created"
'Generate the setup computed file which is used to initiate the running of postbootscripts
If NOT filesys.FolderExists("C:\Windows\Setup\Scripts\") Then
filesys.CreateFolder("C:\Windows\Setup\Scripts\")
End If
'Open it with appending mode
set filewrite = filesys.OpenTextFile("C:\Windows\Setup\Scripts\SetupComplete.cmd", 8, True)
filewrite.WriteLine "cmd /c call " & mypostbootscript
filewrite.Close
loghandler.WriteLine "C:\Windows\Setup\Scripts\SetupComplete.cmd has been created."
loghandler.WriteLine "To run mypostscript"
loghandler.WriteLine ""
loghandler.Close
' Run mypostscript
Set myshell = WScript.createObject("WScript.Shell")
myshell.Run "cmd /c " & mypostscript, 0, True
'Do While Not output.StdOut.AtEndOfStream
' fline = output.StdOut.ReadLine()
' WScript.echo fline
'Loop