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.

420 lines
12 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM
  4. REM catsign.cmd
  5. REM creates and signs windows catalog files
  6. REM
  7. REM Copyright (c) Microsoft Corporation. All rights reserved.
  8. REM
  9. REM ------------------------------------------------------------------
  10. if defined _CPCMAGIC goto CPCBegin
  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 ParseArgs;
  19. sub Usage { print<<USAGE; exit(1) }
  20. catsign [-l <language>]
  21. Creates nt5.cat, nt5inf.cat, ntprint.cat
  22. Directory for all of the output
  23. %_NTPostBld%
  24. Binaries directory (where ntprint.inf, dosnet.inf exist)
  25. %_NTPostBld%
  26. Directory for binplacing the CAT files
  27. %_NTPostBld%
  28. Note: If none of these are set (catsign is run w/o args), these will
  29. all default to %bindir%%binroot% (just like bindsys.cmd)
  30. [NoList] Don't recreate the lists
  31. [NoCDF] Don't recreate the CDFs
  32. [NoCAT] Don't create the CATS
  33. [NoSign] Don't sign with the test signature
  34. [NoTime] Don't timestamp the test signature
  35. [NoBin] Don't binplace the CAT files
  36. USAGE
  37. parseargs('?' => \&Usage);
  38. # *** NEXT FEW LINES ARE TEMPLATE ***
  39. $ENV{"_CPCMAGIC"}++;exit(system($0)>>8);
  40. __END__
  41. :CPCBegin
  42. set _CPCMAGIC=
  43. setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
  44. REM *** BEGIN YOUR CMD SCRIPT BELOW ***
  45. if defined verbose echo on
  46. REM ------------------------------------------------
  47. REM Set default Variables for script:
  48. REM ------------------------------------------------
  49. REM Initialize exitcode
  50. set exitcode=0
  51. set perl=perl
  52. REM Set inflist. This is the list of subdirectories containing inf files.
  53. set inflist=.
  54. perl %RazzleToolPath%\cksku.pm -t:per -l:%lang%
  55. if %errorlevel% EQU 0 (
  56. set inflist=!inflist! perinf
  57. )
  58. perl %RazzleToolPath%\cksku.pm -t:bla -l:%lang%
  59. if %errorlevel% EQU 0 (
  60. set inflist=%inflist% blainf
  61. )
  62. perl %RazzleToolPath%\cksku.pm -t:sbs -l:%lang%
  63. if %errorlevel% EQU 0 (
  64. set inflist=%inflist% sbsinf
  65. )
  66. perl %RazzleToolPath%\cksku.pm -t:srv -l:%lang%
  67. if %errorlevel% EQU 0 (
  68. set inflist=!inflist! srvinf
  69. )
  70. perl %RazzleToolPath%\cksku.pm -t:ads -l:%lang%
  71. if %errorlevel% EQU 0 (
  72. set inflist=!inflist! entinf
  73. )
  74. perl %RazzleToolPath%\cksku.pm -t:dtc -l:%lang%
  75. if %errorlevel% EQU 0 (
  76. set inflist=!inflist! dtcinf
  77. )
  78. set excludes=%RazzleToolPath%\PostBuildScripts\exclude.lst
  79. set nt5p=ntprint
  80. REM Setup the directory for the output
  81. set CatDir=%tmp%
  82. set catlists=%tmp%\lists
  83. set catfiles=%tmp%\cats
  84. set catCDFs=%tmp%\CDFs
  85. set IncLists=%tmp%\IncLists
  86. set signedCATs=%tmp%\testsig
  87. set tempdir=%tmp%\temp
  88. set CDFTMP=%tmp%\CDFs\tmp
  89. REM ----------------------------------------------------------
  90. REM Prepare a place for the output files
  91. REM ----------------------------------------------------------
  92. if NOT exist %catdir% md %catdir%
  93. if NOT exist %catlists% md %catlists%
  94. if NOT exist %catfiles% md %catfiles%
  95. if NOT exist %catCDFs% md %catCDFs%
  96. if NOT exist %signedCATs% md %signedCATs%
  97. if NOT exist %tempdir% md %tempdir%
  98. REM ----------------------------------------------------------
  99. REM Handle special cases
  100. REM ----------------------------------------------------------
  101. REM This needs to be included before international can adopt
  102. goto SkipSpec
  103. if exist %alt_path%\desktop.in_ (
  104. call ExecuteCmd.cmd "copy %alt_path%\desktop.in_ %tempdir%\desktop.ini"
  105. )
  106. if exist %_NTPostBld%\desktop.in_ (
  107. call ExecuteCmd.cmd "copy %_NTPostBld%\desktop.in_ %tempdir%\desktop.ini"
  108. )
  109. if /i NOT exist %_NTPostBld%\dump\catalogs md %_NTPostBld%\dump\catalogs
  110. REM Make winnt.exe show up as signed
  111. copy %_NTPostBld%\winnt.exe %_NTPostBld%\dump\catalogs
  112. REM Make relnotes.htm show up as signed
  113. if exist %alt_path%\relnotes.htm (
  114. call ExecuteCmd.cmd "copy %alt_path%\relnotes.htm %_NTPostBld%\dump\catalogs"
  115. ) else (
  116. call ExecuteCmd.cmd "copy %_NTPostBld%\relnotes.htm %_NTPostBld%\dump\catalogs"
  117. )
  118. REM Make the selfreg infs show up as signed
  119. if exist %alt_path%\dump\selfreg* (
  120. call ExecuteCmd.cmd "copy %alt_path%\dump\selfreg* %_NTPostBld%\dump\catalogs"
  121. ) else (
  122. call ExecuteCmd.cmd "copy %_NTPostBld%\dump\selfreg* %_NTPostBld%\dump\catalogs"
  123. )
  124. REM Make sure these files exist
  125. for %%i in (%_NTPostBld%\dump\catalogs\winnt.exe %_NTPostBld%\dump\catalogs\relnotes.htm %_NTPostBld%\dump\catalogs\selfreg*) do (
  126. if /i NOT exist %%i (
  127. call errmsg.cmd "%%i not found"
  128. set exitcode=1
  129. )
  130. )
  131. :SkipSpec
  132. REM ----------------------------------------------------------
  133. REM Create CDFs
  134. REM ----------------------------------------------------------
  135. call logmsg.cmd "Creating nt5 and nt5inf catalog inputs ..."
  136. REM pushd to make output better
  137. REM BUGBUG This is now in pbuild.dat, but we need a way to do it from here too when not called
  138. REM from postbuild, so that catsign can be run independently
  139. pushd %RazzleToolPath%\postbuildscripts
  140. call ExecuteCmd.cmd "CdData.cmd -c -l:%lang%"
  141. popd
  142. REM Figure out if we are in incremental mode
  143. set IncMode=
  144. if exist %CatCDFs%\nt5.icr set IncMode=1
  145. if exist %CatCDFs%\nt5inf.icr set IncMode=1
  146. if exist %CatCDFs%\%nt5p%.icr set IncMode=1
  147. if exist %CatCDFs%\perinf\nt5inf.icr set IncMode=1
  148. if exist %CatCDFs%\blainf\nt5inf.icr set IncMode=1
  149. if exist %CatCDFs%\sbsinf\nt5inf.icr set IncMode=1
  150. if exist %CatCDFs%\srvinf\nt5inf.icr set IncMode=1
  151. if exist %CatCDFs%\entinf\nt5inf.icr set IncMode=1
  152. if exist %CatCDFs%\dtcinf\nt5inf.icr set IncMode=1
  153. REM Sanity Check - if incremental there shouldn't be any non-incremental cdfs
  154. if defined IncMode (
  155. if exist %CatCDFs%\nt5.CDF (
  156. call logmsg.cmd "Both incremental and non-incremental cdfs exist. Defaulting to non-incremental."
  157. set IncMode=
  158. ) else (
  159. for %%a in (nt5.cat nt5inf.cat) do (
  160. if not exist %_NTPOSTBLD%\%%a (
  161. call logmsg.cmd "Incremental mode but no cat's to update. Defaulting to non-incremental."
  162. set IncMode=
  163. )
  164. )
  165. )
  166. if not defined IncMode (
  167. REM we need to generate the cdfs because at this point we only have the
  168. REM icr's assumedly. cddata.cmd -x will ignore the bindiff changes.
  169. call ExecuteCmd.cmd "%RazzleToolPath%\PostBuildScripts\cddata.cmd -x -c -f -l:%lang%"
  170. )
  171. )
  172. REM Make sure these CDFs have been created
  173. set CDFNotFound=
  174. echo Incremental = !IncMode!
  175. if NOT defined IncMode (
  176. for %%i in (%nt5p%.CDF nt5.CDF) do (
  177. if /i NOT exist %catCDFs%\%%i (
  178. set CDFNotFound=1
  179. set exitcode=1
  180. )
  181. )
  182. for %%i in (%inflist%) do (
  183. for %%j in (nt5inf.CDF) do (
  184. if /i NOT exist %catCDFs%\%%i\%%j (
  185. set CDFNotFound=1
  186. set exitcode=1
  187. )
  188. )
  189. )
  190. ) else (
  191. REM Look for incremental CDFs also
  192. for %%i in (%nt5p%.icr nt5.icr) do (
  193. if /i NOT exist %catCDFs%\%%i (
  194. set CDFNotFound=1
  195. set exitcode=1
  196. )
  197. )
  198. for %%i in (%inflist%) do (
  199. for %%j in (nt5inf.icr) do (
  200. if /i NOT exist %catCDFs%\%%i\%%j (
  201. set CDFNotFound=1
  202. set exitcode=1
  203. )
  204. )
  205. )
  206. )
  207. if defined CDFNotFound call errmsg.cmd "CDFs are missing - catsign failed"
  208. REM -------------------------------------------------
  209. REM Create the catalog files
  210. REM -------------------------------------------------
  211. if defined IncMode (
  212. call logmsg.cmd /t "Catsign running in incremental mode ..."
  213. goto IncCatGen
  214. )
  215. :CreateCATs
  216. if /i "%NoCATs%" == "Yes" goto EndCreateCATs
  217. echo Waiting for catalog generation to complete ...
  218. set CatTemp=%tmp%\cattemp
  219. if NOT exist %CatTemp% md %CatTemp%
  220. if exist %CatTemp%\*.tmp del %CatTemp%\*.tmp
  221. for %%a in (ntprintcat.cmd nt5cat.cmd nt5infcat.cmd) do call :CatGen %%a
  222. goto EndCatGen
  223. :CatGen
  224. call ExecuteCmd.cmd "start "PB_%1" /MIN cmd /c %RazzleToolPath%\postbuildscripts\%1 -l:%lang%"
  225. goto :EOF
  226. :EndCatGen
  227. REM BUGBUG This needs to be fixed by writing temp files here, but
  228. REM this outta do for now.
  229. sleep 30
  230. :CatTempLoop
  231. sleep 5
  232. if EXIST %CatTemp%\*.tmp goto CatTempLoop
  233. goto EndIncCatGen
  234. :IncCatGen
  235. REM Get rid of empty cdfs by looking for null files
  236. for %%a in (%CatCDFs%\%nt5p%.icr %CatCDFs%\nt5.icr) do (
  237. if %%~za NEQ 0 set IncCdfs=!IncCdfs! %%~na
  238. )
  239. for %%a in (%InfList%) do (
  240. for %%b in (%CatCDFs%\%%a\nt5inf.icr) do (
  241. if %%~zb NEQ 0 set IncCdfs=!IncCdfs! %%a\%%~nb
  242. )
  243. )
  244. echo Incremental List = %IncCdfs%
  245. REM Now call updcat
  246. for %%a in (%IncCdfs%) do (
  247. if exist %tmp%\FHash.tmp del /f %tmp%\FHash.tmp
  248. if exist %tmp%\NHash.tmp del /f %tmp%\NHash.tmp
  249. perl -ane "if ($F[1] eq '-') { $h{$F[0]} = $F[2] } else { print qq($F[0] - $h{$F[0]}\n) }" %_NTPostBld%\congeal_scripts\%%a.hash>%tmp%\FHash.tmp %CatCDFs%\%%a.icr
  250. for /f "tokens=1,3" %%b in (%tmp%\FHash.tmp) do (
  251. updcat.exe %_NTPostBld%\%%a.cat -r "%%c" %%b
  252. if errorlevel 1 call executecmd.cmd "updcat.exe %_NTPostBld%\%%a.cat -a %%b"
  253. for /f "delims=" %%d in ('calchash.exe %%b') do (
  254. set ThisHash=%%d
  255. set ThisHash=!ThisHash: =!
  256. echo %%b - !ThisHash!>>%TMP%\NHash.tmp
  257. )
  258. )
  259. call ExecuteCmd.cmd "%RazzleToolPath%\PostBuildScripts\hashrep.cmd %TMP%\NHash.tmp %_NTPostBld%\congeal_scripts\%%a.hash"
  260. REM Sign the catalogs
  261. call ntsign %_NTPostBld%\%%a.cat -l %lang%
  262. if errorlevel 1 (
  263. call errmsg.cmd "Signing %%a.cat failed."
  264. set exitcode=1
  265. )
  266. )
  267. goto EndTestSign
  268. :EndIncCatGen
  269. REM Make sure these CATs have been created
  270. for %%i in (%nt5p%.CAT nt5.CAT) do (
  271. if /i NOT exist %catfiles%\%%i (
  272. call errmsg.cmd "%catfiles%\%%i not found%
  273. set exitcode=1
  274. )
  275. )
  276. for %%i in (%inflist%) do (
  277. for %%j in (nt5inf.CAT) do (
  278. if /i NOT exist %catfiles%\%%i\%%j (
  279. call errmsg.cmd "%catfiles%\%%i\%%j not found"
  280. set exitcode=1
  281. )
  282. )
  283. )
  284. :EndCreateCATs
  285. REM -------------------------------------------------
  286. REM Create the catalog files with the test signature
  287. REM -------------------------------------------------
  288. :TestSign
  289. call ExecuteCmd.cmd "copy %catfiles%\%nt5p%.CAT %signedCATs%"
  290. call ExecuteCmd.cmd "ntsign.cmd %signedCATs%\%nt5p%.CAT -l %lang%"
  291. call ExecuteCmd.cmd "copy %catfiles%\nt5.CAT %signedCATs%"
  292. call ExecuteCmd.cmd "ntsign.cmd %signedCATs%\nt5.CAT -l %lang%"
  293. for %%a in (%inflist%) do (
  294. if NOT exist %signedCATs%\%%a (
  295. md %signedCATs%\%%a
  296. )
  297. call ExecuteCmd.cmd "copy %catfiles%\%%a\nt5inf.CAT %signedCATs%\%%a"
  298. call ExecuteCmd.cmd "ntsign.cmd %signedCATs%\%%a\nt5inf.CAT -l %lang%"
  299. )
  300. :EndTestSign
  301. REM ---------------------------
  302. REM Binplace the catalog files
  303. REM ---------------------------
  304. :BinPlace
  305. if defined IncMode goto :EOF
  306. if /i "%NoBin%" == "Yes" goto EndBinPlace
  307. call logmsg.cmd "Binplacing %nt5p%.CAT, nt5.CAT, nt5inf.CAT"
  308. copy %signedCATs%\%nt5p%.CAT %_NTPostBld%
  309. copy %signedCATs%\nt5.CAT %_NTPostBld%
  310. for %%a in (%inflist%) do (
  311. call logmsg.cmd "Binplacing %%a\nt5inf.CAT"
  312. if not exist %_NTPostBld%\%%a md %_NTPostBld%\%%a
  313. copy %signedCATs%\%%a\nt5inf.CAT %_NTPostBld%\%%a
  314. )
  315. REM Make sure these CATs have been binplaced
  316. for %%i in (%nt5p%.CAT nt5.CAT) do (
  317. if /i NOT exist %_NTPostBld%\%%i (
  318. call errmsg.cmd "%_NTPostBld%\%%i not found%
  319. set exitcode=1
  320. )
  321. )
  322. for %%i in (%inflist%) do (
  323. for %%j in (nt5inf.CAT) do (
  324. if /i NOT exist %_NTPostBld%\%%i\%%j (
  325. call errmsg.cmd "%_NTPostBld%\%%i\%%j not found"
  326. set exitcode=1
  327. )
  328. )
  329. )
  330. if NOT "%OFFICIAL_BUILD_MACHINE%"=="1" goto :EOF
  331. :Test_Binplace
  332. REM --------------------------------------------
  333. REM Binplace the CDF files for testing purposes
  334. REM --------------------------------------------
  335. REM Set the directory for binplacing the binaries
  336. set cdf_out=%_NTPostBld%\cdf
  337. copy %catCDFs%\%nt5p%.CDF %cdf_out%
  338. copy %catCDFs%\%nt5p%.log %cdf_out%
  339. copy %catCDFs%\nt5.CDF %cdf_out%
  340. copy %catCDFs%\nt5.log %cdf_out%
  341. for %%a in (%inflist%) do (
  342. set flat_name=%%a
  343. set !flat_name:\=_!
  344. copy %catCDFs%\%%a\nt5inf.CDF %cdf_out%\nt5inf.!flat_name!.cdf
  345. copy %catCDFs%\nt5inf.!flat_name!.log %cdf_out%
  346. )