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.

410 lines
11 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM
  4. REM staledfs.cmd
  5. REM List and/or purge the stale DFS links for \\ntdev\release.
  6. REM
  7. REM Copyright (c) Microsoft Corporation. All rights reserved.
  8. REM Version: < 1.0 > 09/06/2001 Suemiao Rossignol
  9. REM Version: < 2.0 > 07/17/2002 Jorge Peraza
  10. REM ------------------------------------------------------------------
  11. perl -x "%~f0" %*
  12. goto :EOF
  13. #!perl
  14. use strict;
  15. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  16. use lib $ENV{RAZZLETOOLPATH};
  17. use PbuildEnv;
  18. use Logmsg;
  19. use ParseArgs;
  20. use File::Basename;
  21. use BuildName;
  22. use GetIniSetting;
  23. use hashtext;
  24. use comlib;
  25. use LockProc;
  26. require $ENV{'sdxroot'} . '\TOOLS\sendmsg.pl';
  27. my $scriptname = basename( $0 );
  28. sub Usage {
  29. print<<USAGE;
  30. List and/or purge the stale DFS link(s) for nt releases.
  31. Usage:
  32. $scriptname: -l:<language> [-b:<branch>] [-purge|-mail:<mailto>] [-a]
  33. -l Language.
  34. Default is "usa".
  35. -n Build Number.
  36. -b Branch.
  37. Default is "main".
  38. -purge Option to purge stale link(s).
  39. Default is listing stale link(s) only.
  40. -a All languages (USA servers)
  41. -ae All languages (EU servers)
  42. -mail Send mails.
  43. -? Display Usage.
  44. Example:
  45. $scriptname
  46. $scriptname -b:idw
  47. $scriptname -l:ger
  48. USAGE
  49. exit(1)
  50. }
  51. my ( $buildNo, $branch, $isPurge,$isPurgeds, $isSendMail,,@lSendMail, $isPowerLess );
  52. my ( $dfsRoot, $lockObj, %dfsMap );
  53. my ( $dash, $dot, $totcnt, $totdwn , @staleList, @mailList, @mailDwList, @downList);
  54. my ( @lLangs, $isAllLangs, $isAllELangs, $lLang, $sTie);
  55. GetParams();
  56. Init();
  57. if(Run()==0)
  58. {
  59. #Set error level to 1
  60. exit(1);
  61. }
  62. exit(0);
  63. #-----------------------------------------------------------------------------
  64. sub Init
  65. {
  66. splice(@staleList, 0);
  67. splice(@mailList, 0);
  68. splice(@mailDwList, 0);
  69. splice(@downList, 0);
  70. $totcnt=0;
  71. $totdwn=0;
  72. logmsg( "Lauguage(s) .....[@lLangs]" );
  73. logmsg( "Build Number.....[$buildNo]" );
  74. logmsg( "Branch...........[$branch]" );
  75. logmsg( "Temp Log file ...[$ENV{LOGFILE}]" );
  76. logmsg( "Temp Error file .[$ENV{ERRFILE}]" );
  77. }
  78. sub Run
  79. {
  80. if( !TieDFS($sTie))
  81. {
  82. return 0;
  83. #next;
  84. }
  85. foreach $lLang (@lLangs)
  86. {
  87. $ENV{lang} = $lLang;
  88. $sTie = $ENV{lang};
  89. if( !&ListStaleLinks() )
  90. {
  91. next;
  92. }
  93. if( $isPurge )
  94. {
  95. return 0 if( !&PurgeDFSLinks );
  96. }
  97. }
  98. if( $isSendMail )
  99. {
  100. if(($totcnt+$totdwn)!=0)
  101. {
  102. return 0 if( !&SendMail() );
  103. }
  104. }
  105. return 1;
  106. }
  107. sub GetParams
  108. {
  109. my $sSendMail;
  110. parseargs('?' => \&Usage, 'n:' => \$buildNo, 'b:' => \$branch, 'mail:' =>\$sSendMail, 'a' => \$isAllLangs, 'ae' => \$isAllELangs,
  111. 'purge' => \$isPurge, 'purgeds' => \$isPurgeds, 'p' =>\$isPowerLess );
  112. $branch = "main" if( !$branch );
  113. if($sSendMail)
  114. {
  115. $isSendMail = 1;
  116. @lSendMail = split("#",$sSendMail);
  117. }
  118. if( $isAllLangs )
  119. {
  120. @lLangs = getLanguages();
  121. $sTie = "USA";
  122. }
  123. if( $isAllELangs )
  124. {
  125. @lLangs = getLanguages();
  126. $sTie = "ES";
  127. }
  128. else
  129. {
  130. push (@lLangs,$ENV{lang});
  131. $sTie = $ENV{lang};
  132. }
  133. }
  134. #-----------------------------------------------------------------------------
  135. sub TieDFS
  136. {
  137. my $sLang;
  138. $sLang = shift;
  139. ##### Tie DFS view to hash object
  140. return 0 if( !&comlib::TieDfsView($sLang, $branch, \%dfsMap ));
  141. $dfsRoot = ( tied %dfsMap )->GetDfsRoot();
  142. return 1;
  143. }
  144. sub findServ
  145. {
  146. my $sNew = shift;
  147. #Find the sNew Server in the list passed as parameter to the function
  148. if(grep(($_ eq $sNew),@_))
  149. {
  150. return 1;
  151. }
  152. return 0;
  153. }
  154. #-----------------------------------------------------------------------------
  155. sub ListStaleLinks
  156. {
  157. my (@mList, $outstr, $outstrM);
  158. return 0 if( !( tied %dfsMap )->ParseShare($sTie,"",$branch,"","","",\@mList) );
  159. logmsg( $dash );
  160. for my $theShare ( @mList )
  161. {
  162. # continue when the share exists in the release server
  163. $theShare =~ /^(\\\\[^\\]+)(\\[^\\]+)(.*)$/;
  164. my $server = $1;
  165. my $curShare = "$1$2";
  166. next if( -e $curShare );
  167. next if( $buildNo && $curShare !~ /$buildNo/ );
  168. # parse the server
  169. my $msg;
  170. # print the link-share pair
  171. for my $theLink( @{$dfsMap{ $theShare }} )
  172. {
  173. next if( $theLink !~ /$ENV{lang}/i );
  174. my $link = "$dfsRoot\\$theLink";
  175. if( system( "net view $server >nul 2>nul" ))
  176. {
  177. $msg = " *** [$server] is current down";
  178. $totdwn++;
  179. push( @downList, "$link $theShare" );
  180. $outstr = sprintf("\nDFS Link: %s\nShare: %s%s\n", $link, $theShare, $msg);
  181. $outstrM = sprintf("<br><font face=\"Arial\" size=\"2\"><font color=\"#000080\"><strong>DFS Link:</strong></font></font><a href=\"file:%s\">%s</a><br><font face=\"Arial\" size=\"2\"><font color=\"#000080\"><strong>Missing Share: </strong></font></font><a href=\"file:%s\">%s</a></font>", $link, $link, $theShare,$theShare);
  182. if( $isSendMail )
  183. {
  184. if(!findServ($server,@mailDwList))
  185. {
  186. push( @mailDwList, $server );
  187. }
  188. }
  189. }
  190. else
  191. {
  192. if( system( "dir $theShare >nul 2>nul" ))
  193. {
  194. $msg = "Missing Share";
  195. }
  196. else
  197. {
  198. $msg = "Missing DFS Link";
  199. }
  200. $totcnt++;
  201. push( @staleList, "$link $theShare" );
  202. $outstr = sprintf("\nDFS Link: %s\nShare: %s ** %s\n", $link, $theShare, $msg);
  203. $outstrM = sprintf("<br><font face=\"Arial\" color=\"#ff0000\" size=\"2\"><strong>%s</strong></font><br><font face=\"Arial\" size=\"2\"><font color=\"#000080\"><strong>DFS Link:</strong></font></font><a href=\"file:%s\">%s</a><br><font face=\"Arial\" size=\"2\"><font color=\"#000080\"><strong>Share: </strong></font></font><a href=\"file:%s\">%s</a></font>", $msg,$link, $link, $theShare,$theShare);
  204. if( $isSendMail )
  205. {
  206. push( @mailList, $outstrM );
  207. }
  208. }
  209. logmsg( $outstr );
  210. }
  211. }
  212. logmsg( "Total [$totcnt] stale dfs link for [$ENV{lang}]." );
  213. logmsg( "Total [$totdwn] down servers for [$ENV{lang}]." );
  214. if( !$isPurge && $totcnt )
  215. {
  216. logmsg( "Run [staledfs.cmd -l:$ENV{lang} -purge] to purge the above stale links" );
  217. }
  218. logmsg( $dash );
  219. return 1;
  220. }
  221. #-----------------------------------------------------------------------------
  222. sub PurgeDFSLinks
  223. {
  224. logmsg( $dash );
  225. if( !($totcnt + $totdwn) )
  226. {
  227. logmsg( "No stale links found. Exit" );
  228. return 1;
  229. }
  230. ##### Apply Semaphore lock
  231. return 0 if ( !&comlib::LockProcess( $sTie, $branch, \$lockObj ) );
  232. ##### Interaction through the stale lists
  233. my $choice = (-1);
  234. while( $choice > 3 || $choice < 1 )
  235. {
  236. printf("\n$dot\n$dot\nDo you want to Un-map the above %d link(s) (1)Yes for all (2)Yes for selection (3)Quit? ", $totcnt);
  237. chomp( $choice=<STDIN> );
  238. if( $choice == 1 )
  239. {
  240. print "\n$dot\n$dot\nConfirm un-map all the above link(s). (1)Yes. (2)No. ";
  241. chomp( $choice=<STDIN> );
  242. last if( $choice == 1);
  243. $choice = (-1);
  244. }
  245. }
  246. if( $choice == 3 ){ $lockObj->Unlock(); return 1; }
  247. my $cnt=0;
  248. my @sharePath=();
  249. push @staleList, @downList;
  250. foreach ( @staleList )
  251. {
  252. my @tmp = split( /\s/, $_);
  253. my $theLink = $tmp[0];
  254. my $theShare = $tmp[1];
  255. my $cmdLine = "dfscmd /remove $theLink $theShare";
  256. if( $choice != 1 )
  257. {
  258. my $outstr = sprintf("$dash\n-(%03d)-\n%s\n%s",(++$cnt), $theLink, $theShare );
  259. logmsg( $outstr );
  260. my $choice2 = (-1);
  261. while( $choice2 > 3 || $choice2 < 1 )
  262. {
  263. print "$dot\nDo you want to Un-map the above link (1)Yes (2)Skip (3)Quit? " ;
  264. chomp( $choice2=<STDIN> );
  265. }
  266. if ( $choice2 == 3){ $lockObj->Unlock(); return 1; }
  267. next if( $choice2 == 2);
  268. }
  269. if( $isPowerLess )
  270. {
  271. logmsg( $cmdLine );
  272. }
  273. else
  274. {
  275. &comlib::ExecuteSystem( $cmdLine );
  276. }
  277. }
  278. $lockObj->Unlock();
  279. return 1;
  280. }
  281. #-----------------------------------------------------------------------------
  282. sub SendMail
  283. {
  284. my ( $mailFrom, $mailMsg ,$mailSubject);
  285. if(!($isAllLangs||$isAllELangs))
  286. {
  287. $mailSubject = $totcnt+$totdwn . " Stale DFS Links found for \"$branch - $ENV{lang}\"";
  288. }
  289. else
  290. {
  291. $mailSubject = $totcnt+$totdwn . " Stale DFS Links found for \"$branch\"";
  292. }
  293. my $mailFrom = "ntbldi";
  294. if( $ENV{lang} =~ /usa/i || $ENV{lang} =~ /ger/i || $ENV{lang} =~ /jpn/i
  295. || $ENV{lang} =~ /fr/i )
  296. {
  297. $mailFrom = "y-ntbld";
  298. }
  299. $mailMsg = "<html><head></head><body><p><font face=\"Arial\" size=\"2\"><font color=\"#000080\">The DFS </font><a href=\"file:$dfsRoot\"><font color=\"#000080\">$dfsRoot</font></a><font color=\"#000080\"> was examined and found to have stale links and/or release servers that were unreachable. This will cause people to be unable to access the builds listed below.</font></span></font></p><p><font face=\"Arial\" color=\"#ff0000\" size=\"2\"><strong>A builder needs to investigate and correct these issues ASAP!</strong></span></font></p>";
  300. if(!($isAllLangs||$isAllELangs))
  301. {
  302. $mailMsg .= "<br/><font face=\"Arial\" color=\"#800000\" size=\"2\"><strong><u>Servers Down:</u></strong></font> <br> <font face=\"Arial\" color=\"#000080\" size=\"2\">$totdwn DFS links for $branch $ENV{lang} point to servers that are down.</font><br/><blockquote><p>";
  303. }
  304. else
  305. {
  306. $mailMsg .= "<br/><font face=\"Arial\" color=\"#800000\" size=\"2\"><strong><u>Servers Down</u></strong></font> <br> <font face=\"Arial\" color=\"#000080\" size=\"2\">$totdwn DFS links for $branch point to servers that are down.</font><br/><blockquote><p>";
  307. }
  308. $mailMsg .= "<a href=\"file:$_\">$_<a><br>" for ( @mailDwList );
  309. if(!($isAllLangs||$isAllELangs))
  310. {
  311. $mailMsg .= "</blockquote></p><br/><font face=\"Arial\" color=\"#800000\" size=\"2\"><strong><u>Stale Links</u></strong></font> <br> <font face=\"Arial\" color=\"#000080\" size=\"2\">$totcnt DFS links for $branch $ENV{lang}</font><br/><blockquote><p>";
  312. }
  313. else
  314. {
  315. $mailMsg .= "</blockquote></p><br/><font face=\"Arial\" color=\"#800000\" size=\"2\"><strong><u>Stale Links</u></strong></font> <br> <font face=\"Arial\" color=\"#000080\" size=\"2\">$totcnt DFS links for $branch</font> <br/><blockquote><p>";
  316. }
  317. $mailMsg .= "$_<br/>" for ( @mailList );
  318. $mailMsg .= "<br>Run staledfs.cmd -l:[lang] -purge, to purge the above stale links<br>";
  319. $mailMsg .= "</blockquote></p><address><br>This email was automatically generated by staledfs.cmd<br><br></address>";
  320. $mailMsg .= "<br><font face=\"Arial\" color=\"#000080\" size=\"2\">Thanks!</font><br>";
  321. $mailMsg .= "<font SIZE=\"2\" COLOR=\"#000080\"><i><b><u><p>Windows International Build Team</u> : </b></i></font><br><a HREF=\"http://ntbld/intl\"><font SIZE=\"2\" COLOR=\"#0000ff\"><u><i><b>http://ntbld/intl</b></i></u></font></a></p><font SIZE=\"2\" COLOR=\"#0000ff\"><p>NT Build Lab 26N/2233 - x34613</p></font>";
  322. if( sendmsg ('-v', $mailFrom, $mailSubject, $mailMsg,"content:text/html",@lSendMail))
  323. {
  324. print "WARNING: sendmsg failed!\n";
  325. return 0;
  326. }
  327. return 1;
  328. }
  329. #-----------------------------------------------------------------------------
  330. sub getLanguages
  331. {
  332. my $hLang;
  333. my @lHlist;
  334. my @lList;
  335. HashText::Read_Text_Hash(1,$ENV{"RazzleToolPath"} . "\\codes.txt",\@lHlist);
  336. foreach $hLang (@lHlist)
  337. {
  338. push(@lList,$hLang->{Lang});
  339. }
  340. return @lList;
  341. }
  342. 1;