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.

714 lines
22 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM <<srvrel.cmd>>
  4. REM copy the build From Build Machine to Release Servers.
  5. REM
  6. REM Copyright (c) Microsoft Corporation. All rights reserved.
  7. REM Version: < 1.0 > 02/02/2001 Suemiao Rossignol
  8. REM ------------------------------------------------------------------
  9. perl -x "%~f0" %*
  10. goto :EOF
  11. #!perl
  12. use strict;
  13. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  14. use lib $ENV{RAZZLETOOLPATH};
  15. use Logmsg;
  16. use ParseArgs;
  17. use File::Basename;
  18. use BuildName;
  19. use GetIniSetting;
  20. use comlib;
  21. use cksku;
  22. use WaitProc;
  23. my $scriptname = basename( $0 );
  24. sub Usage {
  25. print<<USAGE;
  26. Propagate builds to release servers.
  27. Usage:
  28. $scriptname: -l:<language> [-b:<BuildName>][-r:<SourceServer>][-xcopy ][-s][-p]
  29. -l Language.
  30. Default is "usa".
  31. -b Build Name.
  32. Default is defined in
  33. <ReleaseShare>\\<buildName>\\build_logs\\buildname.txt for language usa.
  34. <ReleaseShare>\\<lang>\\<buildName>\\build_logs\\buildname.txt for language none usa.
  35. -r Alternate source server other than build machine.
  36. Replace build machine if this is defined.
  37. -xcopy Use xcopy as a copy command.
  38. Default is compdir.
  39. -s Incorporate virus scan.
  40. -p Powerless.
  41. Display key variables only.
  42. -? Display Usage.
  43. Example:
  44. $scriptname -b:2415.x86fre.main.001222-1745 -xcopy
  45. $scriptname -l:ger -p
  46. USAGE
  47. exit(1)
  48. }
  49. my ( $lang, $buildName, $srcServer, $useXcopy, $virusScan, $powerLess );
  50. my ( $buildArch, $buildType );
  51. my ( @buildMachines, $buildMachineReleaseShareName, $pullResDir );
  52. my ( $releaseShareName, $releaseResDir, @releaseAccess, $releaseDrive );
  53. my ( $latestReleaseShareName, $freeSpaceReq, $numBuildToKeep);
  54. my ( @mConglomerators, $isConglomerator,$symFarm, $statusFile);
  55. my ( %groupShareName, %groupShareRootDir );
  56. my ( %validSkus, @validSkus, $copyCmd, $scanProg, $retryCount );
  57. &GetParams();
  58. if( !&InitVars() ){ exit(1);}
  59. if( !$powerLess && !&VerifyDiskSpace ){ exit(1); }
  60. if( !$powerLess && !&DeletePublicShare){ exit(1); }
  61. if( !$powerLess && !&PurgeOldCdimage ){ exit(1); }
  62. my $curRetry=0;
  63. while( $curRetry <= $retryCount )
  64. {
  65. timemsg( "Auto retry count [$curRetry]." ) if( $curRetry);
  66. if( !&LoopPullServers )
  67. {
  68. ++$curRetry;
  69. next;
  70. }
  71. if( !$powerLess && !&CreatePublicShare){ exit(1); }
  72. timemsg( "Complete [$scriptname]" );
  73. exit(0);
  74. }
  75. exit(1);
  76. #-----------------------------------------------------------------------------
  77. sub GetParams
  78. {
  79. parseargs('?' => \&Usage, 'b:' => \$buildName,'l:' =>\$ENV{lang}, 'r:' => \$srcServer,
  80. 'xcopy' =>\$useXcopy, 's' => \$virusScan, 'p' =>\$powerLess );
  81. $ENV{lang} = "usa" if( !$ENV{lang} );
  82. $lang = $ENV{lang};
  83. $copyCmd = "compdir" if( !$useXcopy );
  84. }
  85. #-----------------------------------------------------------------------------
  86. sub InitVars
  87. {
  88. my( @iniRequest, $iniBuildMachine, $sTemp);
  89. my( $buildBranch, $buildNo, $iniFile, $releaseShareRootDir);
  90. my( @releaseServers );
  91. #####Set build name, Number, Branch, Archtecture, Type and ini file
  92. if( !$buildName )
  93. {
  94. if( ! ($buildName = build_name() ))
  95. {
  96. my ($cmdLine ) = "$ENV{RazzleToolPath}\\postbuildscripts\\getlatestrelease.cmd -l:$lang";
  97. return 0 if( !chomp(($buildName= `$cmdLine`)) );
  98. }
  99. }
  100. #####Set LogFile & ErrFile
  101. $ENV{temp} = "$ENV{temp}\\$lang\\$buildName";
  102. system( "md $ENV{temp}" ) if( !(-e $ENV{temp} ) );
  103. $ENV{LOGFILE} = "$ENV{temp}\\srvrel.log";
  104. $ENV{ERRFILE} = "$ENV{temp}\\srvrel.err";
  105. if(-e $ENV{LOGFILE} )
  106. {
  107. system( "copy $ENV{LOGFILE} $ENV{LOGFILE}.old");
  108. system( "del $ENV{LOGFILE}" );
  109. }
  110. if(-e $ENV{ERRFILE} )
  111. {
  112. system( "copy $ENV{ERRFILE} $ENV{ERRFILE}.old") ;
  113. system( "del $ENV{ERRFILE}" );
  114. }
  115. timemsg( "Start [$scriptname]" );
  116. $buildNo = build_number($buildName);
  117. $buildBranch = build_branch($buildName);
  118. $buildArch = build_arch($buildName);
  119. $buildType = build_type($buildName);
  120. $iniFile = "$buildBranch.$lang.ini";
  121. #####Set release servers
  122. @iniRequest = ( "ReleaseServers::$buildArch$buildType" );
  123. my( $iniRelServers ) = &GetIniSetting::GetSetting( @iniRequest );
  124. if( !$iniRelServers )
  125. {
  126. errmsg( "no [ReleaseServers] defined in [$iniFile], exit." );
  127. return 0;
  128. }
  129. @releaseServers = split( /\s+/, $iniRelServers );
  130. #####Set build machine
  131. if( $srcServer )
  132. {
  133. $iniBuildMachine = $srcServer;
  134. }
  135. else
  136. {
  137. @iniRequest = ( "BuildMachines::$buildArch$buildType");
  138. $iniBuildMachine = &GetIniSetting::GetSetting( @iniRequest );
  139. if( !$iniBuildMachine )
  140. {
  141. errmsg( "No [BuildMachines] defined in [$iniFile], exit." );
  142. return 0;
  143. }
  144. }
  145. @buildMachines = split( /\s+/, $iniBuildMachine );
  146. for my $bldMachine ( @buildMachines )
  147. {
  148. if( !&comlib::ExecuteSystem( "net view $bldMachine >nul 2>nul ") )
  149. {
  150. errmsg( "Failed to see [$bldMachine] via net view, exit. ");
  151. return 0;
  152. }
  153. }
  154. #####Set release Share Drive
  155. @iniRequest = ("ReleaseDrive::$ENV{computername}");
  156. $releaseDrive = &GetIniSetting::GetSettingEx( $buildBranch,$lang,@iniRequest );
  157. if ( !$releaseDrive )
  158. {
  159. $ENV{_ntdrive} =~ /(.*)\:/;
  160. $releaseDrive = $1;
  161. }
  162. #####Set <ReleaseShareName> & <ReleaseShareRootDir> & <RreleaseResDir>
  163. $buildMachineReleaseShareName = &comlib::GetReleaseShareName( $buildBranch, $lang );
  164. #####Set $releaseShareName hard code to release for srvrel specific
  165. $releaseShareName="release";
  166. $releaseShareRootDir = &comlib::ParseNetShare( "release", "Path" );
  167. if( !$releaseShareRootDir )
  168. {
  169. $releaseShareRootDir = "$releaseDrive:\\$releaseShareName";
  170. }
  171. $releaseResDir = "$releaseShareRootDir\\$lang\\$buildName";
  172. #####Set latest share name
  173. $latestReleaseShareName = "$buildName.$lang";
  174. #####Set Push Dir
  175. $statusFile = "$ENV{temp}\\SrvRelFailed.txt";
  176. &comlib::ExecuteSystem( "md $releaseResDir" ) if( !( -e $releaseResDir ) );
  177. &comlib::ExecuteSystem( "md $releaseResDir\\build_logs" ) if( !( -e "$releaseResDir\\build_logs" ) );
  178. wrnmsg( "Found [$statusFile], check if same process in progress, exit")if( -e $statusFile );
  179. #####Set access user to the release share
  180. @iniRequest = ( "ReleaseAccess" );
  181. for my $access( @iniRequest )
  182. {
  183. my $iniAccess = &GetIniSetting::GetSetting( $access );
  184. @releaseAccess = split ( /\s+/, $iniAccess );
  185. last if( @releaseAccess );
  186. }
  187. @releaseAccess = ("$ENV{userDomain}\\$ENV{UserName}") if ( !@releaseAccess );
  188. #####Set free space required & number builds to keep for the release machine
  189. @iniRequest = ("ReleaseServerFreeSpace\:\:$ENV{computername}");
  190. $freeSpaceReq = &GetIniSetting::GetSetting( @iniRequest );
  191. $freeSpaceReq = 10 if ( !$freeSpaceReq);
  192. @iniRequest = ("ReleaseServerBuildsToKeep\:\:$ENV{computername}\:\:$buildArch$buildType");
  193. $numBuildToKeep = &GetIniSetting::GetSettingEx( $buildBranch,$lang, @iniRequest );
  194. $numBuildToKeep = 2 if( !$numBuildToKeep );
  195. #####Set conglomerators
  196. @iniRequest = ( "ConglomerationServers" );
  197. my( $iniAggServers ) = &GetIniSetting::GetSetting( @iniRequest );
  198. if( !$iniAggServers )
  199. {
  200. logmsg( "no [ConglomerationServers] defined in $iniFile." );
  201. $isConglomerator = 0;
  202. }
  203. else
  204. {
  205. @mConglomerators = split( /\s+/, $iniAggServers );
  206. $isConglomerator = 1;
  207. $isConglomerator = 0 if (!grep /^$ENV{computername}$/i, @mConglomerators);
  208. }
  209. #####Set Symbol Servers
  210. $symFarm = &GetIniSetting::GetSettingEx( $buildBranch,$lang,"SymFarm" );
  211. #####Share name and Share root dir for each group item
  212. %groupShareRootDir = ( "lang" => "$releaseShareRootDir\\$lang\\$buildNo.$buildBranch",
  213. "build" => "$releaseShareRootDir\\misc\\$buildNo.$buildBranch" );
  214. %groupShareName = ( "lang" => "$buildNo.$buildBranch.$lang",
  215. "build" => "$buildNo.$buildBranch.misc" );
  216. #####Define Valid Skus for the given languages and Architecture
  217. %validSkus = &cksku::GetSkus( $lang, $buildArch );
  218. @validSkus = keys %validSkus;
  219. #####Verify if virus scan is applied in ini file
  220. #####when it is undefined from comman line
  221. if( !$virusScan )
  222. {
  223. @iniRequest = ("VirusScan::$ENV{computername}");
  224. $virusScan = &GetIniSetting::GetSetting( @iniRequest );
  225. if ( $virusScan eq "true" ){ $virusScan = 1; } else { $virusScan = 0; }
  226. }
  227. #####Find the location of virus scan executable
  228. if( $virusScan )
  229. {
  230. my $tmp = "\\.\\tmp.txt";
  231. if( system( "where inocmd32.exe > $tmp" ) )
  232. {
  233. wrnmsg( "inocmd32.exe is not installed in this machine, skip virus scan.");
  234. $virusScan = 0;
  235. }
  236. my @tmp = &comlib::ReadFile( $tmp );
  237. $scanProg = $tmp[0];
  238. }
  239. #####Define Auto-retry count used when fails on releasing
  240. @iniRequest = ("AutoRetryReleaseCount::$ENV{computername}");
  241. $retryCount=0 if( !($retryCount = &GetIniSetting::GetSetting( @iniRequest ) ) );
  242. logmsg( "TEMP Dir .................[$ENV{temp}]" );
  243. logmsg( "Log file ................[$ENV{LOGFILE}]" );
  244. logmsg( "Error file ..............[$ENV{ERRFILE}]" );
  245. logmsg( "Lauguage ................[$lang]" );
  246. logmsg( "Copy command .............[$copyCmd]" );
  247. logmsg( "Is Virus Scan ............[$virusScan]" );
  248. logmsg( "Virus Scan File...........[$scanProg]" );
  249. logmsg( "Build name ...............[$buildName]" );
  250. logmsg( "Valid Skus ...............[@validSkus]" );
  251. logmsg( "ini file ................[$iniFile]" );
  252. logmsg( "Build Machine ............[$iniBuildMachine]" );
  253. logmsg( "Alternate Source server...[$srcServer]" );
  254. logmsg( "This computer ............[$ENV{computername}]" );
  255. logmsg( "Release Servers ..........[$iniRelServers]");
  256. logmsg( "Conglomerators ...........[$iniAggServers]" );
  257. logmsg( "Release Drive ............[$releaseDrive]" );
  258. logmsg( "Release share Resource ...[$releaseResDir]" );
  259. logmsg( "Latest release Share name [$latestReleaseShareName]" );
  260. logmsg( "Release Access ...........[@releaseAccess]" );
  261. logmsg( "Free space required ......[$freeSpaceReq G]" );
  262. logmsg( "Number builds to keep ....[$numBuildToKeep]" );
  263. logmsg( "Is Conglomerator..........[$isConglomerator]" );
  264. if( $isConglomerator )
  265. {
  266. for my $key ( sort keys %groupShareName )
  267. {
  268. logmsg( "Conglomeration share name:Path [$groupShareName{$key}:$groupShareRootDir{$key}]" );
  269. }
  270. }
  271. logmsg( "Symbol Server.............[$symFarm]" );
  272. logmsg( "Status File ..............[$statusFile]" );
  273. logmsg( "Auto Retry count .........[$retryCount]" );
  274. return 1;
  275. }
  276. #-----------------------------------------------------------------------------
  277. sub LoopPullServers
  278. {
  279. #####Set Pull Dir
  280. my $anyPullRes=0;
  281. for ( my $inx =0; $inx< @buildMachines; $inx++ )
  282. {
  283. if( $srcServer )
  284. {
  285. $pullResDir = "\\\\$buildMachines[$inx]\\$releaseShareName\\$lang\\$buildName";
  286. }
  287. else
  288. {
  289. if( lc($lang) eq "usa")
  290. {
  291. $pullResDir = "\\\\$buildMachines[$inx]\\$buildMachineReleaseShareName\\$buildName";
  292. }
  293. else
  294. {
  295. $pullResDir = "\\\\$buildMachines[$inx]\\$buildMachineReleaseShareName\\$lang\\$buildName";
  296. }
  297. }
  298. if( system ( "dir $pullResDir>nul 2>nul" ) )
  299. {
  300. wrnmsg( "[$pullResDir] not exists in [$buildMachines[$inx]]." );
  301. next;
  302. }
  303. $anyPullRes = 1;
  304. logmsg( "Pull Path ................[$pullResDir]" );
  305. return 0 if( !$powerLess && !&RemoteRelease );
  306. }
  307. if( !$anyPullRes )
  308. {
  309. errmsg( "[$buildName] not found in [@buildMachines] for [$lang]" );
  310. return 0;
  311. }
  312. return 1;
  313. }
  314. #-----------------------------------------------------------------------------
  315. sub RemoteRelease
  316. {
  317. my ( $cmdLine, $cmdLine2, $evtList, @copyList );
  318. if( !( open FILE, ">$statusFile" ) ) {
  319. errmsg("Could not open [$statusFile] file for writing: $!");
  320. return 0;
  321. }
  322. print FILE "NOT RAISEABLE\n";
  323. close FILE;
  324. #####Collect all the dirs to be copied
  325. my @excludeDir = keys %validSkus;
  326. push( @excludeDir, "build_logs" );
  327. push( @excludeDir, "Resources" );
  328. push( @excludeDir, "symbols.pri" ) if( $symFarm );
  329. my $tmpFile = "$ENV{TEMP}\\tmpFile";
  330. &comlib::ExecuteSystem( "dir /b /ad $pullResDir > $tmpFile" );
  331. @copyList = &comlib::ReadFile( $tmpFile );
  332. unlink( $tmpFile );
  333. for ( my $i = 0; $i < @copyList; $i++)
  334. {
  335. for my $theExclude ( @excludeDir )
  336. {
  337. if( lc($copyList[$i]) eq lc($theExclude) )
  338. {
  339. splice( @copyList, $i, 1);
  340. $i--;
  341. last;
  342. }
  343. }
  344. }
  345. unshift( @copyList, "." );
  346. push( @copyList, "build_logs" );
  347. #####Start up copy executiion
  348. my $maxProc = $ENV{number_of_processors} * 2;
  349. my @cmdAry=();
  350. my $copyOpts;
  351. my $virusScanOpts;
  352. my $extCmd;
  353. #####Allpy non-recursive flag for '.' dir
  354. $virusScanOpts = "-NOS";
  355. if( lc($copyCmd) eq "xcopy" )
  356. {
  357. $copyOpts = "/dhikr";
  358. }
  359. else
  360. {
  361. $copyOpts = "/eknstr";
  362. }
  363. $extCmd = "& $scanProg $virusScanOpts -LIS:$ENV{temp}\\root.scan -ARC $releaseResDir\\." if( $virusScan);
  364. $cmdLine = "$copyCmd $copyOpts $pullResDir\\$copyList[0] $releaseResDir\\$copyList[0]$extCmd";
  365. push( @cmdAry, $cmdLine );
  366. #####Apply recursive flag for none '.' dirs
  367. $virusScanOpts ="";
  368. if( lc($copyCmd) eq "xcopy" )
  369. {
  370. $copyOpts = "/dhikre";
  371. }
  372. else
  373. {
  374. $copyOpts = "/eknst";
  375. }
  376. for( my $inx=1; $inx < @copyList; $inx++)
  377. {
  378. $extCmd = "& $scanProg $virusScanOpts -LIS:$ENV{temp}\\$copyList[$inx].scan -ARC $releaseResDir\\$copyList[$inx]" if( $virusScan);
  379. $cmdLine = "$copyCmd $copyOpts $pullResDir\\$copyList[$inx] $releaseResDir\\$copyList[$inx]$extCmd";
  380. push( @cmdAry, $cmdLine );
  381. }
  382. return 0 if( !&WaitProc::wait_proc( $maxProc, @cmdAry ) );
  383. if( $srcServer )
  384. {
  385. if( !$powerLess && !system( "dir $releaseResDir\\build_logs\\*qly" ) )
  386. {
  387. &comlib::ExecuteSystem( "del $releaseResDir\\build_logs\\*qly" );
  388. }
  389. }
  390. #####Copy conglomerators again to different pathes if this is conglomerator
  391. if( $isConglomerator ){ return 0 if ( !&MiscCopy ); }
  392. #####Call cdimage & filechk
  393. return 0 if (!&PostCopy);
  394. #####Summery of Virus Scan
  395. &VirusScanSummary if( $virusScan );
  396. #####Check error logs
  397. if( -e $ENV{errfile} && !(-z $ENV{errfile}) )
  398. {
  399. logmsg("Please check error at $ENV{errfile}");
  400. return 0;
  401. }
  402. unlink $statusFile if( -e $statusFile );
  403. logmsg("srvrel Copy Successfully");
  404. return 1;
  405. }
  406. #-----------------------------------------------------------------------------
  407. sub MiscCopy
  408. {
  409. my ( $cmdLine, $copyFlag );
  410. for my $theGroup ( keys %groupShareName )
  411. {
  412. &comlib::ExecuteSystem("md $groupShareRootDir{$theGroup}" )if( !( -e $groupShareRootDir{$theGroup}) );
  413. if( system( "net share $groupShareName{$theGroup} >nul 2>nul" ) )
  414. {
  415. $cmdLine = "rmtshare \\\\$ENV{computerName}\\$groupShareName{$theGroup}=$groupShareRootDir{$theGroup}";
  416. $cmdLine .= " /grant $ENV{USERDOMAIN}\\$ENV{USERNAME}:read";
  417. #####Raiseall.pl should grant access to these shares in the main build lab
  418. if ( !$ENV{MAIN_BUILD_LAB_MACHINE} )
  419. {
  420. for my $ID ( @releaseAccess )
  421. {
  422. $cmdLine .= " /grant $ID:read";
  423. }
  424. }
  425. &comlib::ExecuteSystem( $cmdLine );
  426. }
  427. my @hashTable = &comlib::ParseTable( $theGroup, $lang, $buildArch, $buildType );
  428. for my $line( @hashTable )
  429. {
  430. my $from = "$releaseResDir\\$line->{SourceDir}";
  431. my $to = "$groupShareRootDir{$theGroup}\\$line->{DestDir}";
  432. if( uc($line->{DestDir}) eq "IFS" || uc($line->{DestDir}) eq "HAL" || uc($line->{DestDir}) eq "PDK")
  433. {
  434. $copyFlag = "/yei";
  435. }
  436. else
  437. {
  438. $copyFlag = "/ydei";
  439. }
  440. my $tmpfile = &comlib::CreateExcludeFile( $line->{ExcludeDir} );
  441. &comlib::ExecuteSystem( "xcopy $copyFlag /EXCLUDE:$tmpfile $from $to" );
  442. }
  443. }
  444. return 1;
  445. }
  446. #-----------------------------------------------------------------------------
  447. sub PostCopy
  448. {
  449. if( @validSkus )
  450. {
  451. #####Call cdimage
  452. local $ENV{_ntpostbld}=$releaseResDir;
  453. local $ENV{_ntpostbld_bak}=$ENV{_ntpostbld};
  454. local $ENV{_BuildArch}=$buildArch;
  455. local $ENV{_BuildType}=$buildType;
  456. $ENV{dont_modify_ntpostbld} =1;
  457. if( lc($buildArch) eq "x86" )
  458. {
  459. $ENV{x86}=1;
  460. $ENV{386}=1;
  461. $ENV{ia64}="";
  462. $ENV{amd64}="";
  463. }
  464. elsif ( lc($buildArch) eq "amd64" )
  465. {
  466. $ENV{x86}="";
  467. $ENV{386}="";
  468. $ENV{ia64}="";
  469. $ENV{amd64}=1;
  470. }
  471. elsif ( lc($buildArch) eq "ia64" )
  472. {
  473. $ENV{x86}="";
  474. $ENV{386}="";
  475. $ENV{ia64}=1;
  476. $ENV{amd64}="";
  477. }
  478. logmsg( "set %_ntpostbld% = [$ENV{_ntpostbld}]");
  479. logmsg( "set %_ntpostbld_bak% = [$ENV{_ntpostbld_bak}]");
  480. logmsg( "Set x86 = [$ENV{x86}]" );
  481. logmsg( "Set 386 = [$ENV{386}]" );
  482. logmsg( "Set ia64 = [$ENV{ia64}]" );
  483. logmsg( "Set amd64 = [$ENV{amd64}]" );
  484. logmsg( "Set dont_modify_ntpostbld = [$ENV{dont_modify_ntpostbld}]" );
  485. return 0 if (!&comlib::ExecuteSystem( "$ENV{RazzleToolPath}\\postbuildscripts\\cdimage.cmd -l:$lang -d:release" ) );
  486. return 0 if (!&comlib::ExecuteSystem( "$ENV{RazzleToolPath}\\postbuildscripts\\makeprocd2 -l:$lang -d:release" ) );
  487. #####Call filechk
  488. return 0 if( !&comlib::ExecuteSystem( "perl $ENV{RazzleToolPath}\\postbuildscripts\\filechk.pl -l:$lang") );
  489. return 0 if( !&comlib::ExecuteSystem( "$ENV{RazzleToolPath}\\postbuildscripts\\HashBuild.cmd srvrelhash -l:$lang"));
  490. }
  491. else
  492. {
  493. logmsg( "Skip cdimage.cmd and filechk.pl for MUI release" );
  494. }
  495. return 1;
  496. }
  497. #-----------------------------------------------------------------------------
  498. sub DeletePublicShare
  499. {
  500. #####use system for not logging the error message if the share is does not exist.
  501. if( !system( "net share $latestReleaseShareName >nul 2>nul") )
  502. {
  503. return 0 if( !&comlib::ExecuteSystem( "net share $latestReleaseShareName /d /y" ) );
  504. }
  505. return 1;
  506. }
  507. #-----------------------------------------------------------------------------
  508. sub CreatePublicShare
  509. {
  510. my ( $cmdLine );
  511. if( system( "net share $latestReleaseShareName >nul 2>nul") )
  512. {
  513. $cmdLine = "rmtshare \\\\$ENV{computerName}\\$latestReleaseShareName=$releaseResDir";
  514. $cmdLine .= " /grant $ENV{USERDOMAIN}\\$ENV{USERNAME}:read";
  515. #####Raiseall.pl should grant access to these shares in the main build lab
  516. if ( !$ENV{MAIN_BUILD_LAB_MACHINE} )
  517. {
  518. for my $ID ( @releaseAccess )
  519. {
  520. $cmdLine .= " /grant $ID:read";
  521. }
  522. }
  523. return 0 if( !&comlib::ExecuteSystem( $cmdLine ) );
  524. }
  525. return 1;
  526. }
  527. #-----------------------------------------------------------------------------
  528. sub VerifyDiskSpace
  529. {
  530. my ($availDiskSpace, $retry, $reqSpace ) = (0, 0, 1000000000);
  531. my $tmpFile = "$ENV{_ntdrive}\\freeSize";
  532. my @freeSize;
  533. $reqSpace *= $freeSpaceReq;
  534. while( $retry < 2)
  535. {
  536. system( "cd /d $releaseDrive:\&freedisk>$tmpFile&cd /d $ENV{_ntdrive}" );
  537. @freeSize = &comlib::ReadFile( $tmpFile );
  538. unlink( $tmpFile );
  539. if( ($freeSize[0] - $reqSpace) > 0 )
  540. {
  541. logmsg( "Available disk space [$freeSize[0]], delete builds is not required." );
  542. return 1;
  543. }
  544. my ( $cmdLine ) = "$ENV{RazzleToolPath}\\postbuildscripts\\deletebuild.cmd AUTO \/l $lang \/a $buildArch$buildType \/f $freeSpaceReq \/k $numBuildToKeep";
  545. return 1 if( &comlib::ExecuteSystem( $cmdLine ) );
  546. ++$retry;
  547. }
  548. return 0;
  549. }
  550. #-----------------------------------------------------------------------------
  551. sub PurgeOldCdimage
  552. {
  553. for my $theDir ( @validSkus )
  554. {
  555. my $curDir = "$releaseResDir\\$theDir";
  556. if( -e $curDir )
  557. {
  558. logmsg( "Purging old cdimage [$curDir]" );
  559. &comlib::ExecuteSystem( "rd /s /q $curDir" );
  560. }
  561. }
  562. return 1;
  563. }
  564. #-----------------------------------------------------------------------------
  565. sub VirusScanSummary
  566. {
  567. #####Open/read directory where is the location of virus scan output file
  568. if( !opendir( LOGDIR, $ENV{temp} ) )
  569. {
  570. errmsg( "Fail to open directory [$ENV{temp}] for read.");
  571. return 0;
  572. }
  573. my @allFiles = readdir( LOGDIR );
  574. closedir(LOGDIR);
  575. ####Loop through all the virus scan output file to have summary
  576. my $totFileScanned=0;
  577. my $totVirusFound=0;
  578. my $totInfectedFiles=0;
  579. my @allLines;
  580. my @errorFiles=();
  581. for my $theFile ( @allFiles )
  582. {
  583. next if( $theFile !~ /(.+)(.scan)/ );
  584. @allLines = &comlib::ReadFile( "$ENV{temp}\\$theFile" );
  585. for my $theLine ( @allLines )
  586. {
  587. if( $theLine =~ /(Total Files Scanned:)\s+(\d+)/ )
  588. {
  589. $totFileScanned += $2;
  590. next;
  591. }
  592. if( $theLine =~ /(Total Viruses Found:)\s+(\d+)/ )
  593. {
  594. $totVirusFound += $2;
  595. push( @errorFiles, $theFile ) if( $2 );
  596. next;
  597. }
  598. if( $theLine =~ /(Total Infected Files Found:)\s+(\d+)/ )
  599. {
  600. $totInfectedFiles += $2;
  601. push( @errorFiles, $theFile ) if( $2) ;
  602. next;
  603. }
  604. }
  605. }
  606. my $msgStr;
  607. $msgStr = sprintf( "%-27.27s[%6d]", "Total Files Scanned:", $totFileScanned );
  608. logmsg( $msgStr );
  609. $msgStr = sprintf( "%-27.27s[%6d]", "Total Viruses Found:", $totVirusFound );
  610. logmsg( $msgStr );
  611. $msgStr = sprintf( "%-27.27s[%6d]", "Total Infected Files Found:", $totInfectedFiles );
  612. logmsg( $msgStr );
  613. if( $totVirusFound || $totInfectedFiles )
  614. {
  615. errmsg( "Found Virus, please check the following files:[@errorFiles]" );
  616. return 0;
  617. }
  618. return 1;
  619. }
  620. #-----------------------------------------------------------------------------
  621. 1;