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.

630 lines
18 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. Rearrange and collect files in preparation for PRS signing.
  28. Usage:
  29. $scriptname: -l:<language> [-d:<Aggregate Path>] [-n:<Build name>] [-undo] [-final]
  30. -l Language.
  31. Default is "usa".
  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. -undo
  37. Undo the signing steps.
  38. Default is doing signing steps.
  39. -final
  40. Sign the finished binary, instead of the internal cats, etc.
  41. -? Display Usage.
  42. Example:
  43. $scriptname -l:ger -d:\\prs
  44. USAGE
  45. exit(1)
  46. }
  47. my ( $lang, $aggDir, $undo, $final );
  48. my ( @tableHash, $rootCatDir, $rootHashDir, $rootBackupDir );
  49. my ( @prodSkus,%skusDirName, @realSignFiles, @workDir );
  50. my ( $dash, $cmdLine );
  51. my ( $name, $buildName, %certLog, %certFileList, %certPath, %certReqID );
  52. exit(1) if( !&GetParams() );
  53. timemsg( "Start [$scriptname]" );
  54. exit(1) if( !&InitVars() );
  55. if( $undo )
  56. {
  57. exit(1) if ( !&CopySignFiles );
  58. exit(1) if ( !&BackupRollbackTestSign );
  59. }
  60. else
  61. {
  62. if( !$final ) {
  63. exit(1) if ( !&BackupRollbackTestSign );
  64. exit(1) if ( !&CopyRealSign );
  65. exit(1) if ( !&FixCatalogs );
  66. }
  67. exit(1) if ( !&CopySignFiles );
  68. }
  69. exit(1) if( !&ErrorCheck );
  70. timemsg( "Complete [$scriptname]\n$dash" );
  71. exit(0);
  72. #-----------------------------------------------------------------------------
  73. sub GetParams
  74. {
  75. parseargs('?' => \&Usage, 'd:' => \$aggDir, 'n:' => \$name, 'undo' => \$undo , 'final' => \$final);
  76. $lang = $ENV{lang};
  77. if( !$aggDir )
  78. {
  79. if( !$undo )
  80. {
  81. $aggDir="$ENV{_NTPOSTBLD}\\..\\build_logs\\prs";
  82. }
  83. else
  84. {
  85. #####Retrieve Build name
  86. if( ! ( $buildName = build_name() ))
  87. {
  88. #errmsg( "[$ENV{_ntpostbld}\\build_logs\\buildname.txt] not found, exit." );
  89. return 0;
  90. }
  91. chomp( $buildName );
  92. #####Define submit log
  93. if( !$final )
  94. {
  95. %certLog =( "prs" => "$ENV{_ntpostbld}\\build_logs\\$buildName\\submit_prs.log",
  96. "fusion" => "$ENV{_ntpostbld}\\build_logs\\$buildName\\submit_fusion.log" );
  97. } else {
  98. %certLog =( "external" => "$ENV{_ntpostbld}\\build_logs\\$buildName\\submit_ext.log" );
  99. }
  100. #####Define Share location
  101. $aggDir = &comlib::ParsePrsSubmitLog( $certLog{prs}, "Aggregation Path - " );
  102. }
  103. }
  104. if( !$name )
  105. {
  106. $name = "sp1";
  107. }
  108. return 1;
  109. }
  110. #-----------------------------------------------------------------------------
  111. sub InitVars
  112. {
  113. #####Defind PRS file aggregation path
  114. %certPath = ();
  115. $certPath{"prs"} = "$aggDir\\prs" if !$final;
  116. $certPath{"fusion"} = "$aggDir\\fusion" if !$final;
  117. $certPath{"external"} = "$aggDir\\pack" if $final;
  118. if( !$buildName )
  119. {
  120. #####Retrieve Build name
  121. if( ! ($buildName = build_name() ))
  122. {
  123. errmsg( "[$ENV{_ntpostbld}\\build_logs\\buildname.txt] not found, exit." );
  124. return 0;
  125. }
  126. chomp( $buildName );
  127. #####Define submit log
  128. system( "md \"$ENV{_ntpostbld}\\build_logs\\$buildName\" ") if( !( -e "$ENV{_ntpostbld}\\build_logs\\$buildName" ) );
  129. if( !$final )
  130. {
  131. %certLog =( "prs" => "$ENV{_ntpostbld}\\build_logs\\$buildName\\submit_prs.log",
  132. "fusion" => "$ENV{_ntpostbld}\\build_logs\\$buildName\\submit_fusion.log" );
  133. } else {
  134. %certLog =( "external" => "$ENV{_ntpostbld}\\build_logs\\$buildName\\submit_ext.log" );
  135. }
  136. }
  137. #####Log to the file for future reference
  138. for my $theCert( keys %certPath)
  139. {
  140. if( !open( OUT, ">$certLog{$theCert}" ) )
  141. {
  142. errmsg( "Fail on opening [$certLog{$theCert}] for write." );
  143. return 0;
  144. }
  145. print OUT "$dash\n";
  146. print OUT "Aggregation Path - $aggDir\n";
  147. print OUT "$dash\n";
  148. close( OUT );
  149. }
  150. ####Define list text files for Prs cert and fusion cert
  151. if( !$final )
  152. {
  153. %certFileList = ( "prs" => "$ENV{RazzleToolPath}\\sp\\prs\\fullprslist\.txt",
  154. "fusion" => "$ENV{RazzleToolPath}\\sp\\prs\\fusionlist\.txt" );
  155. } else {
  156. %certFileList = ( "external" => "$ENV{RazzleToolPath}\\sp\\prs\\finallist\.txt" );
  157. }
  158. for my $theCert ( keys %certFileList )
  159. {
  160. if( !(-e $certFileList{$theCert} ) )
  161. {
  162. errmsg( "[$certFileList{$theCert}] not found, exit." );
  163. return 0;
  164. }
  165. }
  166. #####Misc Init
  167. $dash = '-' x 60;
  168. $rootCatDir = $ENV{_ntpostbld};
  169. $rootHashDir = "$ENV{razzletoolpath}\\sp\\data\\catalog\\$ENV{lang}\\$ENV{_BuildArch}$ENV{_BuildType}";
  170. $rootBackupDir = "$ENV{_ntpostbld}\\congeal_scripts";
  171. #####Set Product Skus
  172. %skusDirName=( "pro" => ".", "per" => "perinf");
  173. if ( $ENV{_BuildArch} =~ /x86/i ) {
  174. @prodSkus=("pro","per");
  175. }
  176. else {
  177. @prodSkus=("pro");
  178. }
  179. # my %validSkus = &cksku::GetSkus( $lang, $ENV{_BuildArch} );
  180. # @prodSkus = keys %validSkus;
  181. #####Set Real Sign Files
  182. @realSignFiles = ( "layout.inf", "dosnet.inf", "txtsetup.sif" );
  183. #####Set Working directories
  184. push( @workDir, "." );
  185. logmsg( "Language ................[$lang]" );
  186. logmsg( "Build Name ..............[$buildName\]" );
  187. logmsg( "PRS Share Name...........[$aggDir]" );
  188. logmsg( "Is Undo signing..........[$undo]" );
  189. for my $theCert ( keys %certFileList )
  190. {
  191. logmsg( "$theCert File Path ......[$certPath{$theCert}]" );
  192. logmsg( "$theCert File List ......[$certFileList{$theCert}]" );
  193. }
  194. logmsg( "Product Skus.............[@prodSkus]" );
  195. logmsg( "Real Sign Files..........[@realSignFiles]" );
  196. logmsg( "Working Directories......[@workDir]" );
  197. logmsg( "Root Catalog Directories.[$rootCatDir]" );
  198. logmsg( "Root Hash Directories....[$rootHashDir]" );
  199. logmsg( "Root Backup Directories..[$rootBackupDir]" );
  200. logmsg( "Log file ................[$ENV{LOGFILE}]" );
  201. logmsg( "Error file ..............[$ENV{ERRFILE}]" );
  202. return 1;
  203. }
  204. #-----------------------------------------------------------------------------
  205. sub BackupRollbackTestSign
  206. {
  207. my ( $catDir, $hashDir, $backupDir );
  208. my ( $rtChk, $srcDir, $destDir, $to, $from );
  209. logmsg( $dash );
  210. if( !$undo )
  211. {
  212. logmsg( "-----Backing up the test sign files-----\n" );
  213. }
  214. else
  215. {
  216. logmsg( "-----Rolling back the test sign files-----\n" );
  217. }
  218. $rtChk = &CheckSigningType;
  219. #####No files need to be backed up
  220. if( $rtChk == 0)
  221. {
  222. logmsg( "Found no test or real sign files. No backups needed." );
  223. return 1;
  224. }
  225. #####mixed type with test and real sign files both exist
  226. if( $rtChk == 3)
  227. {
  228. errmsg( "Found mixed realsign and testsign files, exit." );
  229. return 0;
  230. }
  231. #####All files are real sign
  232. if( $rtChk == 2 && !$undo )
  233. {
  234. logmsg( "Found realsign files in place, skip backing up test sign files" );
  235. return 1;
  236. }
  237. ####Return 1.All files are test sign
  238. if( $rtChk == 1 && $undo )
  239. {
  240. logmsg( "Found Testsign files in place, skip rolling back test sign files" );
  241. return 1;
  242. }
  243. for my $wDir ( @workDir )
  244. {
  245. if( $wDir ne "." )
  246. {
  247. $catDir = "$rootCatDir\\$wDir";
  248. $hashDir = "$rootHashDir\\$wDir";
  249. $backupDir = "$rootBackupDir\\$wDir";
  250. }
  251. else
  252. {
  253. $catDir = $rootCatDir;
  254. $hashDir = $rootHashDir;
  255. $backupDir = $rootBackupDir;
  256. }
  257. for my $skus ( @prodSkus )
  258. {
  259. #####Set Source and Target path
  260. $srcDir = "$catDir\\$skusDirName{ $skus }";
  261. $destDir = "$backupDir\\$skusDirName{ $skus }\\PRSbackups";
  262. #####Flip between do and undo
  263. if( $undo )
  264. {
  265. $from = $destDir;
  266. $to=$srcDir;
  267. }
  268. else
  269. {
  270. $from = $srcDir;
  271. $to = $destDir;
  272. if( -e $to )
  273. {
  274. return 0 if( !&comlib::ExecuteSystem( "rd /s /q $to" ) );
  275. }
  276. return 0 if( !&comlib::ExecuteSystem( "md $to" ) );
  277. }
  278. #####Backup/rollback nt5inf.cat and test sign file
  279. push( @realSignFiles, "nt5inf.cat" );
  280. for my $file( @realSignFiles )
  281. {
  282. next if( !( -e "$from\\$file" ) );
  283. $cmdLine = "copy /Y /V $from\\$file $to\\$file";
  284. return 0 if( !&comlib::ExecuteSystem( $cmdLine ) );
  285. if ( $undo )
  286. {
  287. # In an undo, need to touch the files to make sure they get
  288. # compressed, as they are likely older than the real-sign files
  289. return 0 if ( !&comlib::ExecuteSystem( "touch $to\\$file" ) );
  290. }
  291. }
  292. splice( @realSignFiles, $#realSignFiles, 1);
  293. # #####Backup/rollback nt5inf.hash
  294. # $srcDir = "$hashDir\\$skusDirName{ $skus }";
  295. # if( $undo )
  296. # {
  297. # $from = $destDir;
  298. # $to=$srcDir;
  299. # }
  300. # else
  301. # {
  302. # $from = $srcDir;
  303. # $to = $destDir;
  304. # }
  305. # next if( !( -e "$from\\nt5inf.hash" ) );
  306. # $cmdLine = "copy /Y /V $from\\nt5inf.hash $to\\nt5inf.hash";
  307. # return 0 if( !&comlib::ExecuteSystem( $cmdLine) );
  308. }
  309. }
  310. return 1;
  311. }
  312. #-----------------------------------------------------------------------------
  313. sub CopyRealSign
  314. {
  315. my ( $srcDir, $destDir );
  316. logmsg( $dash );
  317. logmsg( "-----Copying Real Sign Files in place-----\n" );
  318. for my $skus ( @prodSkus )
  319. {
  320. $srcDir = "$ENV{_NtPostBld}\\$skusDirName{ $skus }\\realsign";
  321. $destDir = "$ENV{_NtPostBld}\\$skusDirName{ $skus }";
  322. for my $file( @realSignFiles )
  323. {
  324. next if ( !(-e "$destDir\\$file") );
  325. system( "touch $srcDir\\$file" );
  326. $cmdLine = "copy /y $srcDir\\$file $destDir\\$file";
  327. return 0 if( !&comlib::ExecuteSystem( $cmdLine ) );
  328. }
  329. }
  330. return 1;
  331. }
  332. #-----------------------------------------------------------------------------
  333. sub FixCatalogs
  334. {
  335. logmsg( $dash );
  336. logmsg( "Refresh Catalog file with right hash value.............\n" );
  337. my ( @mFields, $tmp, @hashValue, $newHashStr, $tmpValue );
  338. my ( $catDir, $hashDir, $fileName );
  339. my ( $srcDir, $hashFile, $catFile, $oldHashStr, $hashLine, $newHashStr);
  340. my $oldHash = "$ENV{_NTPOSTBLD}\\build_logs\\oldHash.tmp";
  341. my $newHash = "$ENV{_NTPOSTBLD}\\build_logs\\newHash.tmp";
  342. $tmp = "$ENV{_NTPOSTBLD}\\build_logs\\tmpfile";
  343. for my $wDir ( @workDir )
  344. {
  345. if( $wDir ne "." )
  346. {
  347. $catDir = "$rootCatDir\\$wDir";
  348. $hashDir = "$rootHashDir\\$wDir";
  349. }
  350. else
  351. {
  352. $catDir = $rootCatDir;
  353. $hashDir = $rootHashDir;
  354. }
  355. for my $skus ( @prodSkus )
  356. {
  357. $catFile = "$catDir\\$skusDirName{ $skus }\\nt5inf.cat";
  358. $hashFile = "$hashDir\\$skusDirName{ $skus }\\nt5inf.hash";
  359. next if !-e $catFile;
  360. for my $file( @realSignFiles )
  361. {
  362. &comlib::ExecuteSystem( "del /f $oldHash" ) if ( -e $oldHash );
  363. &comlib::ExecuteSystem( "del /f $newHash" ) if ( -e $newHash );
  364. if( $skus ne "pro" )
  365. {
  366. $fileName = "$ENV{_NtPostBld}\\$skusDirName{ $skus }\\$file";
  367. }
  368. else
  369. {
  370. $fileName = "$ENV{_NtPostBld}\\$file";
  371. }
  372. next if( !( -e $fileName ) );
  373. #####Find old hash value
  374. my $fileName_base = basename($fileName);
  375. return 0 if( !&comlib::ExecuteSystem( "findstr /iC:$fileName_base $hashFile > $oldHash" ) );
  376. my @file= &comlib::ReadFile( $oldHash );
  377. @mFields = split( /\s+/, $file[0]);
  378. $oldHashStr = $mFields[2];
  379. #####Update cat file with Old hash value
  380. if (-e $catFile) {
  381. return 0 if( !&comlib::ExecuteSystem("updcat.exe $catFile -a $fileName >NUL 2>NUL") );
  382. }
  383. #####Update SP cat file with Old hash value
  384. if (-e "$catDir\\$name.cat") {
  385. return 0 if( !&comlib::ExecuteSystem("updcat.exe $catDir\\sp1.cat -a $fileName >NUL 2>NUL") );
  386. }
  387. #####Calculate new hash value & put in the $newhash file
  388. return 0 if( !&comlib::ExecuteSystem( "calchash.exe $fileName >$tmp") );
  389. @file= &comlib::ReadFile( $tmp );
  390. @hashValue = split( /\s+/, $file[0]);
  391. unlink( $tmp );
  392. $newHashStr = "";
  393. for my $tmpValue ( @hashValue ){$newHashStr .= $tmpValue };
  394. if( !open( TMP, ">$newHash" ) )
  395. {
  396. errmsg( "Fail on opening $newHash" );
  397. return 0;
  398. }
  399. print TMP "$fileName - $newHashStr\n";
  400. close ( TMP );
  401. #####Replace old hash with new hash in the hash file
  402. # return 0 if( !&comlib::ExecuteSystem("$ENV{RazzleToolPath}\\postbuildscripts\\hashrep.cmd $newHash $hashFile" ) );
  403. }
  404. #####Sign the Cat file
  405. return 0 if( !&comlib::ExecuteSystem("$ENV{RazzleToolPath}\\ntsign.cmd -n -f $catFile") );
  406. }
  407. }
  408. return 1;
  409. }
  410. #-----------------------------------------------------------------------------
  411. sub CheckSigningType
  412. {
  413. my ( $chkFile );
  414. my ( $chkValue ) =0;
  415. for my $sku ( @prodSkus )
  416. {
  417. for my $file ( @realSignFiles )
  418. {
  419. $chkFile = "$ENV{_ntpostbld}\\$skusDirName{ $sku}\\$file";
  420. next if ( !(-e $chkFile) );
  421. ###Test sign
  422. if( !system ( "findstr /i /l testroot $chkFile >NUL 2>NUL" ) )
  423. {
  424. $chkValue |= 1;
  425. }
  426. else
  427. {
  428. $chkValue |= 2;
  429. }
  430. }
  431. }
  432. return $chkValue;
  433. }
  434. #-----------------------------------------------------------------------------
  435. sub CopySignFiles
  436. {
  437. my ( $src, $dest, $from, $to, $newFileName );
  438. my $name2 = $name;
  439. $name2 = "xp$name2" if $final and $name2 !~ /^q/i;
  440. for my $theCert( keys %certPath)
  441. {
  442. logmsg( $dash );
  443. @tableHash = &comlib::ParsePrsListFile( $lang, $ENV{_buildArch}, $ENV{_buildType}, $certFileList{$theCert} );
  444. if( !$undo )
  445. {
  446. logmsg( "-----Copying files to [$certPath{$theCert}] for $theCert----------\n" );
  447. }
  448. else
  449. {
  450. logmsg( "-----Rolling back files from [$certPath{$theCert}] for $theCert-----\n" );
  451. }
  452. for (my $inx=0; $inx< @tableHash; $inx++)
  453. {
  454. $src = "$ENV{_ntpostbld}\\$tableHash[$inx]->{ Filename }";
  455. $newFileName = "$ENV{_buildArch}$ENV{_buildType}.$lang.$tableHash[$inx]->{ AltName }";
  456. $dest = "$certPath{$theCert}\\$newFileName";
  457. $src =~ s/\%name\%/$name2/ig;
  458. $newFileName =~ s/\%name\%/$name2/ig;
  459. $dest =~ s/\%name\%/$name2/ig;
  460. if( !$undo )
  461. {
  462. $from = $src;
  463. $to = $dest;
  464. }
  465. else
  466. {
  467. $from = $dest;
  468. $to = $src;
  469. }
  470. if( lc $theCert eq "prs" && lc $tableHash[$inx]->{DisplayName} ne "default" && !$undo)
  471. {
  472. &WriteListTxtFile( $tableHash[$inx]->{Filename}, $tableHash[$inx]->{DisplayName} );
  473. }
  474. next if( !( -e $from ) );
  475. if( !&comlib::ExecuteSystem( "copy /y $from $to" ) )
  476. {
  477. errmsg( "Fail on copy $from to $to." );
  478. next;
  479. }
  480. }
  481. if( !&comlib::ExecuteSystem( "touch /c $certPath{$theCert}\\..\\$theCert.$ENV{_buildArch}$ENV{_buildType}.$lang.txt" ) ) {
  482. errmsg( "Unable to mark the copy operation as complete." );
  483. return 0;
  484. }
  485. }
  486. return 1;
  487. }
  488. #-----------------------------------------------------------------------------
  489. sub WriteListTxtFile
  490. {
  491. my ( $pNewFileName, $pDisplayName ) = @_;
  492. my $listFile = "$ENV{temp}\\displayname.$ENV{_BUILDARCH}$ENV{_BUILDTYPE}.txt";
  493. if( -e $listFile )
  494. {
  495. if( !open( LISTFILE, ">>$listFile" ))
  496. {
  497. errmsg( "Fail on open [$listFile] for append." );
  498. return 0;
  499. }
  500. }
  501. else
  502. {
  503. if( !open( LISTFILE, ">$listFile" ))
  504. {
  505. errmsg( "Fail on open [$listFile] for write." );
  506. return 0;
  507. }
  508. }
  509. print LISTFILE "$pNewFileName $pDisplayName\n";
  510. close( LISTFILE );
  511. }
  512. #-----------------------------------------------------------------------------
  513. sub ErrorCheck
  514. {
  515. #####Check error logs
  516. if( -e $ENV{errfile} && !(-z $ENV{errfile}) )
  517. {
  518. $ENV{errfile} =~ /(.*)\.tmp$/;
  519. errmsg( $dash );
  520. errmsg("Please check error at $1");
  521. return 0;
  522. }
  523. return 1;
  524. }
  525. #-----------------------------------------------------------------------------
  526. sub build_name
  527. {
  528. return $name if $name =~ /^q/i;
  529. my $buildPath="$ENV{_ntpostbld}\\congeal_scripts";
  530. my $buildFileName="__qfenum__";
  531. if (-e "$buildPath\\$buildFileName") {
  532. open F,"$buildPath\\$buildFileName" or die "unable to ipen $buildPath\\$buildFileName ";
  533. my $buildNumber=<F>;
  534. if ( $buildNumber=~/^QFEBUILDNUMBER=(\d*)$/ ){
  535. return $1;
  536. }
  537. else{
  538. wrnmsg "$buildPath\\$buildFileName format is not correct. Defaulting to 9999";
  539. return 9999;
  540. }
  541. close F;
  542. }
  543. else {
  544. wrnmsg "$buildPath\\$buildFileName not found. Defaulting to 9999";
  545. return 9999;
  546. }
  547. }
  548. 1;