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.

190 lines
6.5 KiB

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. if DEFINED _echo echo on
  4. if DEFINED verbose echo on
  5. REM BootInit.cmd is a script that runs once on a boot test machine to set up
  6. REM for future boot tests. It presupposes that there is a safe build and another
  7. REM partition for the test build
  8. REM Provide usage.
  9. for %%a in (./ .- .) do if ".%1." == "%%a?." goto Usage
  10. REM Find out which drive is the test drive
  11. :GetDrive
  12. set TestDrives=
  13. set /p TestDrives="Enter the drive letter for your test build (e.g., d:) "
  14. for %%a in (%TestDrives%) do (
  15. set TestDrive=%%a
  16. if /i NOT "!TestDrive:~0,2!" == "!TestDrive!" (
  17. echo Drive letter should be one letter followed by a colon, try again.
  18. goto GetDrive
  19. )
  20. if /i NOT "!TestDrive:~1,1!" == ":" (
  21. echo Drive letter should be one letter followed by a colon, try again.
  22. goto GetDrive
  23. )
  24. )
  25. :GetPlatform
  26. set /p ProcArc="Enter the processor architecture of this machine (x86|amd64|ia64) "
  27. if /i NOT "!ProcArc!" == "x86" (
  28. if /i NOT "!ProcArc!" == "amd64" (
  29. if /i NOT "!ProcArc!" == "ia64" (echo You did not enter a valid architecture && goto :GetPlatform)
  30. )
  31. )
  32. :GetProductID
  33. set /p ProductID="Enter the Product ID for this machine (xxxxx-xxxxx-xxxxx-xxxxx-xxxxx) "
  34. :GetBootTestUserAndPassword
  35. set /p BT_User="Enter the user that will be used during boot tests (Eg, NTDEV\winbld) "
  36. set /p BT_Password="Enter the password for this user "
  37. REM Now check for a label
  38. :CheckLabel
  39. for /f %%a in ('vol !TestDrive! ^|findstr /ilc:"has no label"') do if "!ErrorLevel!" == "0" goto EndLabel
  40. REM Remove the label from this drive
  41. REM First make a temporary "answer" file
  42. if exist %tmp%\nixlabel.txt del /f %tmp%\nixlabel.txt
  43. echo.>%tmp%\nixlabel.txt
  44. echo y>>%tmp%\nixlabel.txt
  45. REM Now remove the label
  46. label !TestDrive!<%tmp%\nixlabel.txt
  47. REM Check the label is removed
  48. goto CheckLabel
  49. :EndLabel
  50. REM Clean up
  51. if exist %tmp%\nixlabel.cmd del /f %tmp%\nixlabel.cmd
  52. REM Save off good boot.ini
  53. if /i "!ProcArc!" == "amd64" set Intel=1
  54. if /i "!ProcArc!" == "ia64" set Intel=1
  55. if /i "!ProcArc!" == "x86" set Intel=1
  56. if /i "!ProcArc!" == "amd64" set BootFile=boot.ini
  57. if /i "!ProcArc!" == "ia64" set BootFile=boot.nvr
  58. if /i "!ProcArc!" == "x86" set BootFile=boot.ini
  59. if /i "!Intel!" == "1" set /p IniChk="Your !BootFile! should contain only the safe build at this point. If this is not the case fix it, then press enter to continue."
  60. attrib -s -h -r c:\!BootFile!
  61. attrib -s -h -r c:\!BootFile!.sav
  62. copy c:\!BootFile! c:\!BootFile!.sav
  63. attrib +s +h +r c:\!BootFile!
  64. attrib +s +h +r c:\!BootFile!.sav
  65. REM Copy remote.exe to the boot test machine
  66. REM BUGBUG This path may change
  67. echo .
  68. copy \\ntdev\release\main\usa\latest.tst\!ProcArc!fre\bin\idw\remote.exe !Windir!\system32
  69. if NOT exist !Windir!\system32\remote.exe (
  70. echo copy from \\ntdev\release\main\usa\latest.tst\!ProcArc!fre\bin\idw\remote.exe failed
  71. set /p RemoteLoc="Enter a full path to a direcetory with a valid copy of remote.exe. E.g., \\mymachine\d$\winnt\idw. You need the free version built for your processor architecture. "
  72. copy !RemoteLoc!\remote.exe !Windir!\system32
  73. if NOT exist !Windir!\system32\remote.exe (echo copy from !RemoteLoc! failed - aborting && goto end)
  74. )
  75. if not exist %systemdrive%\simple_perl md %systemdrive%\simple_perl
  76. set PerlRoot=%systemdrive%\simple_perl
  77. for %%f in (%0) do (
  78. set perlsource=%%~dpf\..\perl\bin
  79. copy !perlsource!\*.exe %PerlRoot%
  80. copy !perlsource!\*.dll %PerlRoot%
  81. )
  82. if NOT exist %PerlRoot%\perl.exe (
  83. echo copy from !perlsource!\perl.exe failed
  84. set /p PerlSource="Enter a full path to a directory with a valid copy of perl.exe. E.g., \\mymachine\d$\nt\tools\perl\bin. You need the free version built for your processor architecture. "
  85. copy !PerlSource!\*.exe %PerlRoot%
  86. copy !PerlSource!\*.dll %PerlRoot%
  87. if NOT exist %PerlRoot%\perl.exe (echo copy from !PerlSource! failed - aborting && goto end)
  88. )
  89. set ParseSystemVariable=%PerlRoot%\ParseSys.pl
  90. echo. > %ParseSystemVariable%
  91. echo open(F1, "<$ARGV[0]"); >>%ParseSystemVariable%
  92. echo open(F2, ">$ARGV[1]"); >>%ParseSystemVariable%
  93. echo while(^<F1^>) { >>%ParseSystemVariable%
  94. echo # Parse System Variable >>%ParseSystemVariable%
  95. echo s/\$\{(\w+)\}/$ENV{$1}/g; >>%ParseSystemVariable%
  96. echo print F2 $_; >>%ParseSystemVariable%
  97. echo } >>%ParseSystemVariable%
  98. echo close(F1); >>%ParseSystemVariable%
  99. echo close(F2); >>%ParseSystemVariable%
  100. set BootTestDriveVarName=BootTestDrive
  101. set FindOldestDrive=%PerlRoot%\FindOldestDrive.pl
  102. echo. > %FindOldestDrive%
  103. echo # Search oldest share >>%FindOldestDrive%
  104. echo $t = "\\tools"; >>%FindOldestDrive%
  105. echo $_ = (sort { >>%FindOldestDrive%
  106. echo ((lstat $a . $t)[9] + 0 ^<=^> >>%FindOldestDrive%
  107. echo (lstat $b . $t)[9] + 0) } >>%FindOldestDrive%
  108. echo qw(%TestDrives%))[0]; >>%FindOldestDrive%
  109. echo s/\s*//g; >>%FindOldestDrive%
  110. echo print "set %BootTestDriveVarName%=$_"; >>%FindOldestDrive%
  111. set ExecutePerl=%PerlRoot%\ExecutePerl.cmd
  112. echo. > %ExecutePerl%
  113. echo @for /f "delims=" %%%%c in ('%PerlRoot%\perl.exe %%*') do %%%%c>>%ExecutePerl%
  114. REM Put a script to start remote.exe in the start up menu
  115. REM NOTE: It is intentional that the three set commands leave no trailing spaces between them and the following commands!
  116. set MyCommand=cmd /k %ExecutePerl% %FindOldestDrive% ^& title remote /C %computername% ^"BootTestRemote^" ^& @set P_roductID=%ProductID%^& @set BT_U=!BT_User!^& @set BT_P=!BT_Password!
  117. set BootTestRemote="!ALLUSERSPROFILE!\Start Menu\Programs\Startup\BootTestRemote.cmd"
  118. echo start !Windir!\system32\remote.exe /s "%MyCommand%" BootTestRemote> %BootTestRemote%
  119. REM Clean all environment variable we set in this script
  120. set MyCommand=
  121. set BootTestRemote=
  122. set ExecutePerl=
  123. set FindOldestDrive=
  124. set ParseSystemVariable=
  125. set PerlSource=
  126. set PerlRoot=
  127. set RemoteLoc=
  128. set IniChk=
  129. set Intel=
  130. set BootFile=
  131. set ProcArc=
  132. set TestDrive=
  133. set TestDrives=
  134. set ProductID=
  135. set BT_User=
  136. set BT_Password=
  137. REM Fire up the remote
  138. call "!ALLUSERSPROFILE!\Start Menu\Programs\Startup\BootTestRemote.cmd"
  139. echo It is recommended that you log out and back in to make sure the remote was correctly placed in the start up menu.
  140. goto end
  141. :Usage
  142. echo.
  143. echo BootInit.cmd - Used for initializing a boot test machine the very first time.
  144. echo Installs remote.exe and calls it from the startup menu
  145. echo and removes the test volume label.
  146. echo.
  147. :end
  148. endlocal