Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

312 lines
9.5 KiB

  1. @REM ---------------------------------------------------------------------------
  2. @REM # Script: autoboottest.pl
  3. @REM #
  4. @REM # (c) 2000 Microsoft Corporation. All rights reserved.
  5. @REM #
  6. @REM #
  7. @REM # Version: <2.00> (<02/10/2002>) : tsanders <Remotely install a build on a test machine>
  8. @REM #---------------------------------------------------------------------
  9. @perl -x "%~f0" %*
  10. @goto :EOF
  11. #!perl
  12. #Usage
  13. sub Usage {
  14. print <<USAGE;
  15. \n\
  16. $0 -- Remotely install a build on a test machine
  17. Usage: $0 [-l lang] [-a arch] [-f type] [-n buildnum] [-p PID] [-s source] [-t target] [-u Unattend.txt] [-y sku]
  18. -a architecture
  19. -f type (fre|chk)
  20. -l Language to install
  21. -n Build num to install
  22. -p Product ID
  23. -s installation source
  24. -t target machine
  25. -u unattend.txt location
  26. -y sku select
  27. -? Displays usage
  28. Example:
  29. $0 -l jpn
  30. $0 -l:usa -s:\\\\ntdev\\release\\main\\ger\\latest.tst -t:\\i32bt015 -y:pro
  31. USAGE
  32. exit(1);
  33. }
  34. # Set info
  35. $ENV{script_name} = 'autoboottest.pl';
  36. $VERSION = '2.00';
  37. # Use section
  38. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  39. use lib $ENV{RAZZLETOOLPATH};
  40. use AutoBoottest;
  41. use access;
  42. use WMIFE;
  43. use ParseArgs;
  44. use GetIniSetting;
  45. use cksku;
  46. use Logmsg;
  47. use ParseTable;
  48. use strict;
  49. my $DEBUG = 1;
  50. my $BTDIR = "Boottest";
  51. #-------------------------------------------------------------------------------------
  52. # Main
  53. #-------------------------------------------------------------------------------------
  54. my %BTMList;
  55. my ($Lang, $PID, $BTUser, $BTShare, $BTPass);
  56. my ($Unattend, $DFSSource, $PID);
  57. #Get parameters
  58. Usage() if(! GetSettings() );
  59. if( !GetSecretSettings() ){
  60. errmsg ("Couldn't retrieve secret settings.");
  61. exit(1);
  62. }
  63. if(defined $DEBUG){
  64. for my $key ( keys %BTMList ) {
  65. print "------\n$BTMList{$key}->{Source}\n $BTMList{$key}->{Arc}\n",
  66. "$BTMList{$key}->{Type}\n $BTMList{$key}->{SKU}\n------\n";
  67. }
  68. }
  69. #For each boottestmachine in BTMList execute
  70. for my $BTM ( keys %BTMList )
  71. {
  72. logmsg("Beginning autoboottest on $BTM:\n\tSource: $BTMList{$BTM}->{Source}\n\tArchitechture: $BTMList{$BTM}->{Arc}\n\tType: $BTMList{$BTM}->{Type}\n\tSKU: $BTMList{$BTM}->{SKU}\n");
  73. system("$ENV{RAZZLETOOLPATH}\\setbuildstatus.cmd -s:boot");
  74. #Verify Boottest machine - if not correct skip to next BTM
  75. next if(! AutoBoottest::VerifyBT($BTM) );
  76. #Ensure local build_logs\Boottest dir
  77. `md $ENV{_NTDRIVE}\\$BTDIR` if (! (-e "$ENV{_NTDRIVE}\\$BTDIR"));
  78. #Create User & share
  79. my $tPass;
  80. $BTUser = $BTM."_user" if(!defined $BTUser);
  81. if( ! ($tPass = AutoBoottest::CreateUserShare($BTUser,
  82. $BTM,
  83. $ENV{COMPUTERNAME},
  84. (defined $DFSSource) ? "" : $BTMList{$BTM}->{Source},
  85. "$ENV{_NTDRIVE}\\$BTDIR")
  86. )){
  87. errmsg("CreateUserShare($BTUser, $BTM, $ENV{COMPUTERNAME}, \"($ENV{_NTDRIVE}\\$BTDIR\") failed");
  88. next;
  89. }
  90. $BTPass = $tPass if(!defined $BTPass);
  91. #Generate unattend.txt to BTDIR if not defined, copy to BTDIR else
  92. if(!defined $Unattend)
  93. {
  94. $Unattend = "unattend.$BTM.$Lang.$BTMList{$BTM}->{Arc}" .
  95. ".$BTMList{$BTM}->{SKU}.txt";
  96. if( ! (AutoBoottest::WriteUnattendFile($BTM,
  97. "$ENV{_NTDRIVE}\\$BTDIR\\$Unattend",
  98. $Lang, $PID))) #, $Domainuser, $pass)));
  99. {
  100. errmsg("Couldn't create unattend.txt");
  101. next;
  102. }
  103. }
  104. else{
  105. if( ! AutoBoottest::Copy($Unattend, "$ENV{_NTDRIVE}\\$BTDIR\\"))
  106. {
  107. AutoBoottest::CleanupUserShare($BTUser, $ENV{COMPUTERNAME},
  108. "$ENV{_NTDRIVE}\\$BTMList{$BTM}->{Source}",
  109. "$ENV{_NTDRIVE}\\$BTDIR",
  110. $BTM);
  111. exit(1);
  112. }
  113. }
  114. #Copy tools to $BTMShare
  115. if ( !AutoBoottest::Copy( "$ENV{RazzleToolPath}\\Postbuildscripts\\rx.wsf", "$ENV{_NTDRIVE}\\$BTDIR\\")
  116. ||
  117. !AutoBoottest::Copy( "$ENV{RazzleToolPath}\\$ENV{PROCESSOR_ARCHITECTURE}\\autologon.exe", "$ENV{_NTDRIVE}\\$BTDIR\\")
  118. ||
  119. !AutoBoottest::Copy( "$ENV{RazzleToolPath}\\PostBuildScripts\\*.wsf", "$ENV{_NTDRIVE}\\$BTDIR\\")
  120. )
  121. {
  122. errmsg("Couldn't copy tools");
  123. AutoBoottest::CleanupUserShare($BTUser, $ENV{COMPUTERNAME},
  124. "$ENV{_NTDRIVE}\\$BTMList{$BTM}->{Source}",
  125. "$ENV{_NTDRIVE}\\$BTDIR",
  126. $BTM);
  127. next;
  128. }
  129. #Start remote install1
  130. access::boottest($BTM,
  131. $BTMList{$BTM}->{Source},
  132. $Lang,
  133. $BTMList{$BTM}->{Arc},
  134. $BTMList{$BTM}->{SKU},
  135. "\\\\$ENV{COMPUTERNAME}\\$BTDIR",
  136. $Unattend,
  137. $BTUser,
  138. $BTPass,
  139. (defined $DFSSource) ? 0 : 1);
  140. #Wait on completion of winnt32.exe
  141. if(! AutoBoottest::WaitForProcess($BTM, "winnt32.exe", 60, "", ""))
  142. {
  143. errmsg("Fatal error Winnt32.exe may not have started on $BTM");
  144. }
  145. else{
  146. AutoBoottest::WaitOnProcess($BTM, "winnt32.exe", 600, "", "");
  147. }
  148. AutoBoottest::CleanupUserShare($BTUser, $ENV{COMPUTERNAME},
  149. "$ENV{_NTDRIVE}\\$BTMList{$BTM}->{Source}",
  150. $BTDIR,
  151. $BTM);
  152. }
  153. #-------------------------------------------------------------------------------------
  154. # GetSecretSettings - Get PID
  155. #-------------------------------------------------------------------------------------
  156. sub GetSecretSettings() {
  157. $PID = AutoBoottest::GetPK() if(! defined $PID);
  158. return 0 if("" eq $PID);
  159. return 1;
  160. }
  161. #-------------------------------------------------------------------------------------
  162. # GetSettings - take in commandline - return w/ all vars filled
  163. #-------------------------------------------------------------------------------------
  164. sub GetSettings {
  165. my %skuHash=();
  166. my ( $SKU, $Target, $Source, $src, $srcMachine, @PID, $Arc, $Type, $Unattend) = ();
  167. my ($BldNum, $bnum, $oldlng) = undef;
  168. parseargs('?' => \&Usage, 't:' => \$Target, 'l:' => \$Lang, 'y:' => \$SKU,
  169. 's:' => \$Source, 'a:' => \$Arc, 'f:' => \$Type, 'n:' => \$BldNum,
  170. 'd:' =>\$DEBUG, 'u:'=>\$Unattend, 'p:' => \$PID, 'U:' =>\$BTUser,
  171. 'P:' =>\$BTPass);
  172. #Verify params n such - there will only be 1 lang, so we'll start there
  173. #If source is supplied, then we'll assume a remote installation
  174. #else, we'll assume its a usual postbuild boottest
  175. if(defined $Lang){
  176. $oldlng = $ENV{Lang};
  177. $Lang = $ENV{Lang} = uc($Lang);
  178. }else{
  179. ($ENV{lang} && ($Lang = $ENV{lang})) || ( $Lang = $ENV{Lang} = 'USA' );
  180. }
  181. if(defined $Unattend){
  182. if(! ( -e $Unattend)){
  183. errmsg("Unattend file $Unattend is invalid");
  184. return 0;
  185. }
  186. }
  187. if(defined $BTUser && (! defined $BTPass)){
  188. errmsg("Password must be specified with -P switch");
  189. return 0;
  190. }
  191. #get other info from prodskus.txt
  192. parse_table_file("$ENV{\"RazzleToolPath\"}\\prodskus.txt", \%skuHash );
  193. #if source was defined we'll verify it & target & return
  194. if(defined $Source){
  195. $DFSSource = 1;
  196. errmsg("$Source\\winnt32.exe doesn't exist.") if ( ! (-e "$Source\\winnt32.exe" ));
  197. #Try to determine params if not given on cmd line
  198. (!defined $Arc && $Source =~ /(x86|ia64)/i) ? $Arc = $1 :
  199. errmsg("Architechture could not be determined from $Source - specify with -a switch") if(!defined $Arc);
  200. if(!defined $SKU){
  201. for my $i (split(/;/, $skuHash{$Lang}->{$Arc})){
  202. if($Source =~ /($i)/i){ $SKU = $1; last; }
  203. }
  204. errmsg("SKU could not be determined from $Source - specify with -s switch") if(!defined $SKU);
  205. }
  206. (!defined $Type && $Source =~ /(chk|fre)/i) ? $Type = $1:
  207. errmsg("Type could not be determined from $Source - specify with -t switch");
  208. return 0 if(!defined $Target || !defined $SKU || !defined $Arc || !defined $Type );
  209. $BTMList{$Target}{Source} = "$Source";
  210. $BTMList{$Target}{Arc} = "$Arc";
  211. $BTMList{$Target}{Type} = "$Type";
  212. $BTMList{$Target}{SKU} = "$SKU";
  213. }
  214. else{
  215. #Get arch, sku, & target & put it all together.
  216. for my $a ( (defined $Arc) ? $Arc : $ENV{_BuildArch}){ #keys(%{$skuHash{$Lang}}) ){
  217. next if($a eq "Language");
  218. for my $s ( (defined $SKU) ? $SKU : split(/;/, $skuHash{$Lang}->{$a}) ){
  219. next if($s eq '-');
  220. for my $t ( (defined $Type) ? $Type : ( $Lang =~/usa/i ? ("chk","fre") : ("fre") ) ){
  221. if((my @BTM = split(/\s+/, GetIniSetting::GetSetting( "BootTestMachines",
  222. uc$a.uc$t, uc$s ))) != ())
  223. {
  224. if(!defined($BldNum)){
  225. chomp ($bnum = `getlatestrelease.cmd -l:$Lang -p:$a`);
  226. } else {
  227. chomp ($bnum = `getlatestrelease.cmd -l:$Lang -n:$BldNum -p:$a`);
  228. }
  229. if($bnum =~ /error|none/i){
  230. errmsg("Error getting source for build -- getlatestrelease.cmd -l:$Lang -p:$a returns: $bnum");
  231. next;
  232. }
  233. $BTM[0] = $Target if($Target ne "");
  234. $BTMList{$BTM[0]}{Arc} = $a =~ /x86/ ? "i386" : "ia64";
  235. $BTMList{$BTM[0]}{Type} = $t;
  236. $BTMList{$BTM[0]}{SKU} = $s;
  237. if( -e "$ENV{_NTDRIVE}\\release\\$Lang\\$bnum\\$s\\$BTMList{$BTM[0]}{Arc}\\winnt32\\winnt32.exe" ){
  238. $BTMList{$BTM[0]}{Source} = "\\\\$ENV{COMPUTERNAME}\\release\\$Lang\\$bnum\\$s\\$BTMList{$BTM[0]}{Arc}\\winnt32";
  239. }
  240. elsif(-e "$ENV{_NTDRIVE}\\release\\$Lang\\$bnum\\$s\\$BTMList{$BTM[0]}{Arc}\\winnt32.exe"){
  241. $BTMList{$BTM[0]}{Source} = "\\\\$ENV{COMPUTERNAME}\\release\\$Lang\\$bnum\\$s\\$BTMList{$BTM[0]}{Arc}";
  242. }
  243. else {
  244. errmsg("Error finding winnt32.exe for SKU:$s Arc:$BTMList{$BTM[0]}{Arc} Type:$t");
  245. delete $BTMList{$BTM[0]};
  246. next;
  247. }
  248. }
  249. }
  250. }
  251. }
  252. $ENV{Lang} = $oldlng if(defined($oldlng));
  253. }
  254. (keys %BTMList ) ? return 1 : return 0;
  255. }