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.

291 lines
7.1 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM
  4. REM <<template_script.cmd>>
  5. REM <<purpose of this script>>
  6. REM
  7. REM Copyright (c) Microsoft Corporation. All rights reserved.
  8. REM
  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 ParseArgs;
  18. use Logmsg;
  19. use ParseTable;
  20. #
  21. # Global vars
  22. #
  23. # Command line parameters
  24. my ($qfenum, $quality, $arch, $debug);
  25. # Shares text file
  26. my $f_spshares = "$ENV{RAZZLETOOLPATH}\\sp\\spshares.txt";
  27. # Shares hash
  28. my @ah_shares;
  29. # Error return
  30. my $errorcode;
  31. sub Usage { print<<USAGE; exit(1) }
  32. sharesp.cmd -n:qfenum -q:quality -a:arch -d:debug [-l:lang] [-?]
  33. -n:qfenum Service pack number ie. 1000
  34. -q:quality bvt, tst, del
  35. -a:arch x86, ia64
  36. -d:debug fre, chk
  37. -l:lang Language
  38. USAGE
  39. parseargs('?' => \&Usage,
  40. 'n:' => \$qfenum,
  41. 'q:' => \$quality,
  42. 'a:' => \$arch,
  43. 'd:' => \$debug
  44. );
  45. #
  46. # Main
  47. #
  48. &main();
  49. #
  50. # Main entry point. Runs all functions.
  51. #
  52. sub main
  53. {
  54. #Only run if offical build machine
  55. unless ( $errorcode = &IsOfficial() )
  56. {
  57. logmsg ( "This script only runs on OFFICIAL_BUILD_MACHINE's." );
  58. logmsg ( "Exiting..." );
  59. return;
  60. }
  61. #Load and parse shares data file
  62. unless ( @ah_shares = &ParseSharesData( ($ENV{"RazzleToolPath"} . "\\sp\\spshares.txt"), \@ah_shares) )
  63. {
  64. logmsg ( "Could not parse spshares.txt." );
  65. logmsg ( "Exiting..." );
  66. return;
  67. }
  68. # Sub variables in hash
  69. unless ( @ah_shares = &FilterHash( $qfenum, $arch, $debug, $ENV{LANG}, \@ah_shares ) )
  70. {
  71. logmsg ( "Could not filter shares hash." );
  72. logmsg ( "Exiting..." );
  73. return;
  74. }
  75. #Share out the shares
  76. unless ( &NetShare( $quality, \@ah_shares ) )
  77. {
  78. logmsg ( "Could not create local shares." );
  79. logmsg ( "Exiting..." );
  80. return;
  81. }
  82. }
  83. #
  84. # Function: Check if local machine is OFFICIAL
  85. #
  86. # return: 1 if true; undef if false
  87. #
  88. sub IsOfficial
  89. {
  90. if ( exists ($ENV{OFFICIAL_BUILD_MACHINE}) )
  91. {
  92. return 1;
  93. }
  94. return;
  95. }
  96. #
  97. # Function: Read spshares.txt and return a hash
  98. #
  99. # return: %
  100. #
  101. sub ParseSharesData
  102. {
  103. my ($input_file, $ah_shares) = @_;
  104. my (@ah_shares);
  105. logmsg ("#### Parsing spshares.txt ####");
  106. ParseTable::parse_table_file($input_file, \@ah_shares);
  107. return @ah_shares;
  108. }
  109. #
  110. # Function: Sub variables in hash for real values.
  111. #
  112. # return: %
  113. #
  114. sub FilterHash
  115. {
  116. my ($qfenum, $arch, $debug, $lang, $ah_shares) = @_;
  117. logmsg ("#### Parse shares table w/variables ####");
  118. # Log filter values
  119. logmsg ("Qfenum: $qfenum");
  120. logmsg ("Architecure: $arch");
  121. logmsg ("Debug: $debug");
  122. logmsg ("Lang: $lang");
  123. my $share;
  124. my @ah_shares = @$ah_shares;
  125. for $share (@ah_shares)
  126. {
  127. # Make share name variable substitutions
  128. $share->{ShareName} =~ s/<qfenum>/$qfenum/ig;
  129. $share->{ShareName} =~ s/<arch>/$arch/ig;
  130. $share->{ShareName} =~ s/<debug>/$debug/ig;
  131. $share->{ShareName} =~ s/<lang>/$lang/ig;
  132. # Make share path variable substitutions
  133. $share->{SharePath} =~ s/<_NTDRIVE>/$ENV{_NTDRIVE}/ig;
  134. $share->{SharePath} =~ s/<qfenum>/$qfenum/ig;
  135. $share->{SharePath} =~ s/<arch>/$arch/ig;
  136. $share->{SharePath} =~ s/<debug>/$debug/ig;
  137. $share->{SharePath} =~ s/<lang>/$lang/ig;
  138. # Make share group variable substitutions
  139. $share->{ShareGroup} =~ s/<userdomain>/$ENV{USERDOMAIN}/ig;
  140. $share->{ShareGroup} =~ s/<username>/$ENV{USERNAME}/ig;
  141. $share->{ShareGroup} =~ s/^/ \/GRANT /ig;
  142. $share->{ShareGroup} =~ s/;/ \/GRANT /ig;
  143. }
  144. return @ah_shares = @$ah_shares;
  145. }
  146. #
  147. # Function: Create the shares using rmtshare.exe
  148. #
  149. # return:
  150. #
  151. sub NetShare
  152. {
  153. my ($quality, $ah_shares) = @_;
  154. # Use default share setting if quality is undefined
  155. if ($quality !~ m/(tst|bvt|all|del)/i )
  156. {
  157. return;
  158. }
  159. # Local vars
  160. my $share;
  161. my @ah_shares = @$ah_shares;
  162. my $cmdLine;
  163. my @cmdOutput;
  164. logmsg ("#### Creating the shares ####");
  165. for $share ( @ah_shares )
  166. {
  167. if ( $quality =~ /del/i )
  168. {
  169. #Remove shares for "quality" condition
  170. logmsg ("Remove the share if it exists...");
  171. $cmdLine = "rmtshare \\\\$ENV{COMPUTERNAME}";
  172. $cmdLine .= "\\$share->{ShareName}";
  173. $cmdLine .= " /DELETE";
  174. logmsg ("Running: $cmdLine");
  175. @cmdOutput = `$cmdLine`;
  176. logmsg ("@cmdOutput");
  177. }
  178. if ( $share->{Condition} =~ $quality )
  179. {
  180. #Remove shares for "quality" condition
  181. logmsg ("Remove the share if it exists...");
  182. $cmdLine = "rmtshare \\\\$ENV{COMPUTERNAME}";
  183. $cmdLine .= "\\$share->{ShareName}";
  184. $cmdLine .= " /DELETE";
  185. logmsg ("Running: $cmdLine");
  186. @cmdOutput = `$cmdLine`;
  187. logmsg ("@cmdOutput");
  188. } elsif ( $share->{Condition} =~ m/all/i )
  189. {
  190. # Remove shares for "All" condition
  191. logmsg ("Remove the share if it exists...");
  192. $cmdLine = "rmtshare \\\\$ENV{COMPUTERNAME}";
  193. $cmdLine .= "\\$share->{ShareName}";
  194. $cmdLine .= " /DELETE";
  195. logmsg ("Running: $cmdLine");
  196. @cmdOutput = `$cmdLine`;
  197. logmsg ("@cmdOutput");
  198. }
  199. }
  200. for $share ( @ah_shares )
  201. {
  202. if ( $share->{Condition} =~ $quality )
  203. {
  204. #Create shares for "quality" condition
  205. logmsg ("Create the new share...");
  206. $cmdLine = "rmtshare \\\\$ENV{COMPUTERNAME}";
  207. $cmdLine .= "\\$share->{ShareName}=";
  208. $cmdLine .= "$share->{SharePath}";
  209. $cmdLine .= " $share->{ShareGroup}";
  210. #Create shares for owner
  211. $cmdLine .= " /GRANT $ENV{USERDOMAIN}\\$ENV{USERNAME}:READ";
  212. logmsg ("Running: $cmdLine");
  213. @cmdOutput = `$cmdLine`;
  214. logmsg ("@cmdOutput");
  215. } elsif ( $share->{Condition} =~ m/all/i )
  216. {
  217. # Create shares for "All" condition
  218. logmsg ("Create the new share...");
  219. $cmdLine = "rmtshare \\\\$ENV{COMPUTERNAME}";
  220. $cmdLine .= "\\$share->{ShareName}=";
  221. $cmdLine .= "$share->{SharePath}";
  222. $cmdLine .= " $share->{ShareGroup}";
  223. logmsg ("Running: $cmdLine");
  224. @cmdOutput = `$cmdLine`;
  225. logmsg ("@cmdOutput");
  226. }
  227. }
  228. return 1;
  229. }
  230. sub DumpHash
  231. {
  232. my ($ah_shares) = @_;
  233. my $share;
  234. my @ah_shares = @$ah_shares;
  235. logmsg ("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
  236. for $share (@ah_shares)
  237. {
  238. logmsg ("***************************************");
  239. logmsg ("ShareName: $share->{ShareName}");
  240. logmsg ("SharePath: $share->{SharePath}");
  241. logmsg ("ShareGroup: $share->{ShareGroup}");
  242. logmsg ("Condition: $share->{Condition}");
  243. }
  244. logmsg ("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
  245. return 1;
  246. }