Source code of Windows XP (NT5)
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.

345 lines
9.7 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM
  4. REM movefiles.cmd
  5. REM Rearrange and collect files in preparation for PRS signing.
  6. REM
  7. REM Copyright (c) Microsoft Corporation. All rights reserved.
  8. REM Version: < 1.0 > 04/09/2001 Suemiao Rossignol
  9. REM ------------------------------------------------------------------
  10. perl -x "%~f0" %*
  11. goto :EOF
  12. #!perl
  13. use strict;
  14. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  15. use lib $ENV{RAZZLETOOLPATH};
  16. use PbuildEnv;
  17. use Logmsg;
  18. use ParseArgs;
  19. use File::Basename;
  20. use GetIniSetting;
  21. use comlib;
  22. #use HashText;
  23. use cksku;
  24. my $scriptname = basename( $0 );
  25. sub Usage {
  26. print<<USAGE;
  27. Submit PRS signing requests and wait until they finish.
  28. Usage:
  29. $scriptname: -p:<Dest Path> [-d:<Aggregate Path>] [-n:<Build name>]
  30. -p Destination path.
  31. A path to copy the signed files to when done.
  32. -d Aggregate path.
  33. A path to conglomerate PRS files at before submitting to the prslab.
  34. -n Build name.
  35. The name of the service pack or QFE being built.
  36. -? Display Usage.
  37. Example:
  38. $scriptname -l:ger -d:\\prs
  39. USAGE
  40. exit(1)
  41. }
  42. my ( $aggDir, $destDir );
  43. my ( @tableHash );
  44. my ( @prodSkus,%skusDirName, @realSignFiles, @workDir );
  45. my ( $dash, $cmdLine );
  46. my ( $name, $buildName, %certLog, %certFileList, %certPath, %certReqID );
  47. exit(1) if( !&GetParams() );
  48. timemsg( "Start [$scriptname]" );
  49. exit(1) if( !&InitVars() );
  50. exit(1) if( !&SubmitReq );
  51. exit(1) if( &PollReq != 8 );
  52. exit(1) if( !&ErrorCheck );
  53. timemsg( "Complete [$scriptname]\n$dash" );
  54. exit(0);
  55. #-----------------------------------------------------------------------------
  56. sub GetParams
  57. {
  58. parseargs('?' => \&Usage, 'p:' => \$destDir, 'd:' => \$aggDir, 'n:' => \$name );
  59. if( !$aggDir )
  60. {
  61. $aggDir="$ENV{_NTPOSTBLD}\\..\\build_logs\\prs";
  62. }
  63. if( !$name )
  64. {
  65. $name = "sp1";
  66. }
  67. return 1;
  68. }
  69. #-----------------------------------------------------------------------------
  70. sub InitVars
  71. {
  72. #####Defind PRS file aggregation path
  73. %certPath = ( );
  74. if ( -e "$aggDir\\prs" ) {
  75. $certPath{"prs"} = "$aggDir\\prs";
  76. } else {
  77. if ( !&comlib::ExecuteSystem( "touch /c $aggDir\\prs.txt" ) )
  78. {
  79. errmsg("Unable to mark signing for prs as skipped.");
  80. return 0;
  81. }
  82. }
  83. if ( -e "$aggDir\\fusion" ) {
  84. $certPath{"fusion"} = "$aggDir\\fusion";
  85. } else {
  86. if ( !&comlib::ExecuteSystem( "touch /c $aggDir\\fusion.txt" ) )
  87. {
  88. errmsg("Unable to mark signing for fusion as skipped.");
  89. return 0;
  90. }
  91. }
  92. if ( -e "$aggDir\\pack" ) {
  93. $certPath{"external"} = "$aggDir\\pack";
  94. } else {
  95. if ( !&comlib::ExecuteSystem( "touch /c $aggDir\\external.txt" ) )
  96. {
  97. errmsg("Unable to mark signing for external as skipped.");
  98. return 0;
  99. }
  100. }
  101. #####Retrieve Build name
  102. if( ! ($buildName = build_name() ))
  103. {
  104. errmsg( "[$ENV{_ntpostbld}\\build_logs\\buildname.txt] not found, exit." );
  105. return 0;
  106. }
  107. chomp( $buildName );
  108. #####Define submit log
  109. system( "md \"$ENV{_ntpostbld}\\build_logs\\$buildName\" ") if( !( -e "$ENV{_ntpostbld}\\build_logs\\$buildName" ) );
  110. %certLog =( "prs" => "$ENV{_ntpostbld}\\build_logs\\$buildName\\submit_prs.log",
  111. "fusion" => "$ENV{_ntpostbld}\\build_logs\\$buildName\\submit_fusion.log",
  112. "external" => "$ENV{_ntpostbld}\\build_logs\\$buildName\\submit_ext.log" );
  113. #####Misc Init
  114. $dash = '-' x 60;
  115. #####Set Product Skus
  116. %skusDirName=( "pro" => ".", "per" => "perinf");
  117. if ( $ENV{_BuildArch} =~ /x86/i ) {
  118. @prodSkus=("pro","per");
  119. }
  120. else {
  121. @prodSkus=("pro");
  122. }
  123. #####Set Working directories
  124. push( @workDir, "." );
  125. logmsg( "Build Name ..............[$buildName\]" );
  126. logmsg( "PRS Share Name...........[$aggDir]" );
  127. logmsg( "Dest Dir Name............[$destDir]" );
  128. logmsg( "Product Skus.............[@prodSkus]" );
  129. logmsg( "Working Directories......[@workDir]" );
  130. logmsg( "Log file ................[$ENV{LOGFILE}]" );
  131. logmsg( "Error file ..............[$ENV{ERRFILE}]" );
  132. return 1;
  133. }
  134. #-----------------------------------------------------------------------------
  135. sub SubmitReq
  136. {
  137. my ( $cmdLine );
  138. logmsg( $dash );
  139. logmsg( "Submitting the signing request....." );
  140. for my $theCert( keys %certPath)
  141. {
  142. my $tmpCertType = $theCert;
  143. $tmpCertType = "buildlab" if ( $tmpCertType eq "prs" );
  144. my $dispname = "";
  145. if (lc $theCert eq "external") {
  146. if ($name =~ /^q/i) {
  147. $dispname = "-displayname:\"Windows XP QFE (".(uc$name).")\"";
  148. } else {
  149. $dispname = "-displayname:\"Windows XP Service Pack 1\"";
  150. }
  151. }
  152. $cmdLine = "$ENV{RAZZLETOOLPATH}\\sp\\prs\\submit.cmd $certPath{$theCert} -cert:$tmpCertType $dispname >> $certLog{$theCert}";
  153. if( !&comlib::ExecuteSystem( $cmdLine ) )
  154. {
  155. errmsg( "Error on submitting files for $theCert" );
  156. return 0;
  157. }
  158. if( !( $certReqID{$theCert} = &comlib::ParsePrsSubmitLog( $certLog{$theCert}, "Request was successfully submitted. ID #" ) ) )
  159. {
  160. errmsg( "Failed to parse [$certLog{$theCert}]");
  161. return 0;
  162. }
  163. logmsg( "$theCert - $certReqID{$theCert}" );
  164. }
  165. return 1;
  166. }
  167. #-----------------------------------------------------------------------------
  168. sub PollReq
  169. {
  170. use Win32::OLE qw(in);
  171. my %status = ( 1 => 'Pre-Activation',
  172. 2 => 'Waiting for Sign-Off',
  173. 3 => 'Waiting for Virus Check',
  174. 5 => 'Waiting for Digital Signature',
  175. 6 => 'Waiting for Time Stamp',
  176. 7 => 'Waiting to be posted to signed server',
  177. 8 => 'Complete. Posted to Signed Server',
  178. 30 => 'Problem Occurred (contact signhelp to reactivate request)',
  179. 60 => 'Failed: Signer Rejected Job',
  180. 64 => 'Could not strong name sign one or more files',
  181. 65 => 'Failed: Automatic Handoff Failed',
  182. 66 => 'Failed: Virus Found',
  183. 67 => 'Failed: Couldn�t Digitally Sign One or More Files',
  184. 68 => 'Failed: Couldn�t Time Stamp One or More Files',
  185. 69 => 'Failed: Job Inactive Too Long',
  186. 70 => 'Administratively Failed',
  187. 71 => 'Waiting for manual review',
  188. 72 => 'On Hold For Phone Verification' );
  189. logmsg( $dash );
  190. logmsg( "-----Polling the request status-----" );
  191. my $request;
  192. if( ! ($request = Win32::OLE->new('SecureCodeSign.CodeSign')) )
  193. {
  194. errmsg( "Failed to instantiate request object ". Win32::OLE->LastError() );
  195. return 0;
  196. }
  197. if( !$request->Init( "production" ) )
  198. {
  199. errmsg( "Failed to Connect to server and validate permission" );
  200. return 0;
  201. }
  202. for my $theCert( sort keys %certReqID)
  203. {
  204. logmsg( $dash );
  205. logmsg ( "Polling ID# [$certReqID{$theCert}] for [$theCert]....." );
  206. while( 1 )
  207. {
  208. if ( !$request->UpdateStatus($certReqID{$theCert}) )
  209. {
  210. errmsg( "Failed determining request status: ". Win32::OLE->LastError() );
  211. return 0;
  212. }
  213. timemsg( $request->Status ." - " .$status{$request->Status} );
  214. if( $request->Status == 8)
  215. {
  216. logmsg( $dash );
  217. return 0 if !&GetFiles($theCert);
  218. last;
  219. }
  220. sleep( 60 );
  221. }
  222. }
  223. return $request->status;
  224. }
  225. #-----------------------------------------------------------------------------
  226. sub MailSignhelp
  227. {
  228. my ( $pSubject ) = @_;
  229. require $ENV{'sdxroot'} . '\TOOLS\sendmsg.pl';
  230. my $mailFrom = "ntbld";
  231. my $mailMsg = "Please investigate.\n Thanks!\n\n";
  232. $mailMsg .= "Windows US Build Team : http://ntbld/\n";
  233. $mailMsg .= "NT Build Lab 26N/2219 - x66817\n";
  234. my @mailTO = ( "signhelp" );
  235. if( sendmsg ('-v', $mailFrom, $pSubject, $mailMsg, @mailTO))
  236. {
  237. print "WARNING: sendmsg failed!\n";
  238. return 0;
  239. }
  240. return 1;
  241. }
  242. #-----------------------------------------------------------------------------
  243. sub GetFiles
  244. {
  245. my ( $theCert ) = @_;
  246. my $reqID = $certReqID{$theCert};
  247. my $src = "\\\\prslab\\signed2\\$ENV{username}$reqID";
  248. my $dst = $certPath{$theCert};
  249. $dst =~ s/\Q$aggDir\E/$destDir/i;
  250. &comlib::ExecuteSystem( "md $dst" ) if ( !( -d $dst ) );
  251. if ( !&comlib::ExecuteSystem( "xcopy /eify $src $dst" ) )
  252. {
  253. errmsg("Unable to retrieve signed files from $dst to $src.");
  254. return 0;
  255. }
  256. if ( !&comlib::ExecuteSystem( "touch /c $certPath{$theCert}\\..\\$theCert.txt" ) )
  257. {
  258. errmsg("Unable to mark signing for $theCert as complete.");
  259. return 0;
  260. }
  261. return 1;
  262. }
  263. #-----------------------------------------------------------------------------
  264. sub ErrorCheck
  265. {
  266. #####Check error logs
  267. if( -e $ENV{errfile} && !(-z $ENV{errfile}) )
  268. {
  269. $ENV{errfile} =~ /(.*)\.tmp$/;
  270. errmsg( $dash );
  271. errmsg("Please check error at $1");
  272. return 0;
  273. }
  274. return 1;
  275. }
  276. #-----------------------------------------------------------------------------
  277. sub build_name
  278. {
  279. return $name if $name =~ /^q/i;
  280. my $buildPath="$ENV{_ntpostbld}\\congeal_scripts";
  281. my $buildFileName="__qfenum__";
  282. if (-e "$buildPath\\$buildFileName") {
  283. open F,"$buildPath\\$buildFileName" or die "unable to ipen $buildPath\\$buildFileName ";
  284. my $buildNumber=<F>;
  285. if ( $buildNumber=~/^QFEBUILDNUMBER=(\d*)$/ ){
  286. return $1;
  287. }
  288. else{
  289. wrnmsg "$buildPath\\$buildFileName format is not correct. Defaulting to 9999";
  290. return 9999;
  291. }
  292. close F;
  293. }
  294. else {
  295. wrnmsg "$buildPath\\$buildFileName not found. Defaulting to 9999";
  296. return 9999;
  297. }
  298. }
  299. 1;