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.

285 lines
8.9 KiB

  1. @REM -----------------------------------------------------------------
  2. @REM
  3. @REM samsigen.cmd - travisn
  4. @REM
  5. @REM Generate sasetup.msi from sasetup_.msi
  6. @REM 1) create data.cab for client bins and stream that in
  7. @REM 2) stream in custom actions
  8. @REM 3) Update file table with new version and size info (for this build)
  9. @REM 4) Update product version
  10. @REM
  11. @REM Assumes i386 build env (we don't build sasetup MSI for any other archs)
  12. @REM
  13. @REM Copyright (c) Microsoft Corporation. All rights reserved.
  14. @REM
  15. @REM -----------------------------------------------------------------
  16. @if defined _CPCMAGIC goto CPCBegin
  17. @perl -x "%~f0" %*
  18. @goto :EOF
  19. #!perl
  20. use strict;
  21. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  22. use lib $ENV{RAZZLETOOLPATH};
  23. use PbuildEnv;
  24. use ParseArgs;
  25. sub Usage { print<<USAGE; exit(1) }
  26. samsigen.cmd [-p]
  27. -p => called from PRS signing
  28. USAGE
  29. parseargs('?' => \&Usage, 'p' =>\$ENV{PRS});
  30. # *** TEMPLATE CODE ***
  31. $ENV{"_CPCMAGIC"}++;exit(system($0)>>8);
  32. __END__
  33. @:CPCBegin
  34. @set _CPCMAGIC=
  35. @if not defined DEBUG echo off
  36. REM (need this switch for the BuildNum stuff below to work)
  37. setlocal ENABLEDELAYEDEXPANSION
  38. set SAKITDIR=%_NTPOSTBLD%\sacomponents
  39. set MSIIDTDIR=%SAKITDIR%\idt
  40. set MSINAME=%SAKITDIR%\sasetup.msi
  41. set TEMPLATEMSI=%SAKITDIR%\sasetup_.msi
  42. set TEMPCABDIR=%_NTPOSTBLD%\satmpCab
  43. set CABNAME=Data.Cab
  44. set TEMPCABFILE=%SAKITDIR%\%CABNAME%
  45. set CUSTOMACTION=%SAKITDIR%\vbssetup
  46. REM make tempdirs
  47. if exist %TEMPCABDIR% (
  48. rmdir /q /s %TEMPCABDIR%
  49. if errorlevel 1 call errmsg.cmd "err deleting tmpcab dir"& goto errend
  50. )
  51. if exist %MSIIDTDIR% (
  52. rmdir /q /s %MSIIDTDIR%
  53. if errorlevel 1 call errmsg.cmd "err deleting idtdir dir"& goto errend
  54. )
  55. mkdir %TEMPCABDIR%
  56. if errorlevel 1 call errmsg.cmd "err creating tmpcab dir"& goto errend
  57. mkdir %MSIIDTDIR%
  58. if errorlevel 1 call errmsg.cmd "err creating %MSIIDTDIR% dir"& goto errend
  59. REM Copy the template MSI to create the final MSI
  60. if exist %MSINAME% del %MSINAME%
  61. copy %TEMPLATEMSI% %MSINAME%
  62. if errorlevel 1 call errmsg.cmd "err copying template msi sasetup_.msi to sasetup.msi" & goto errend
  63. REM Update the MSI version number in the Property and Upgrade tables
  64. call :SetVersion %MSINAME% %MSIIDTDIR%
  65. REM Copy the Terminal Services ActiveX control to the SAComponents directory so it will be built with sasetup.msi
  66. copy %_NTPOSTBLD%\msrdp.cab %SAKITDIR%
  67. if errorlevel 1 goto errend
  68. REM rename files
  69. %SAKITDIR%\PrepareCabFiles.exe %SAKITDIR% %TEMPCABDIR%
  70. if errorlevel 1 call errmsg.cmd "err preparing files to create sakit cab."& goto errend
  71. REM Sign the files that will go in the cab,
  72. REM unless this is the PRS-signed build when they've already been signed
  73. if NOT "%PRS%" == "1" (
  74. Call deltacat.cmd %TEMPCABDIR%
  75. if errorlevel 1 call errmsg.cmd "err signing files for the cab file"& goto errend
  76. move %TEMPCABDIR%\delta.cat %_NtPostBld%\sasetup.cat
  77. if errorlevel 1 call errmsg.cmd "err moving sasetup.cat"& goto errend
  78. move %TEMPCABDIR%\delta.cdf %_NtPostBld%\sasetup.cdf
  79. if errorlevel 1 call errmsg.cmd "err moving sasetup.cdf"& goto errend
  80. )
  81. REM now generate the cab file
  82. if exist %TEMPCABFILE% (
  83. del %TEMPCABFILE%
  84. )
  85. REM Sequence of files MUST match Sequence field of MSI File table (see Sequence property in File table)
  86. REM The sequence is corrected in the call to wifilver.vbs below
  87. cabarc -s 6144 -i 1 n %TEMPCABFILE% %TEMPCABDIR%\*.*
  88. if errorlevel 1 (
  89. call errmsg.cmd "cabarc failed to generate %TEMPCABFILE%"
  90. goto errend
  91. )
  92. REM *****************************************************
  93. REM * Stream in the client binaries (in cab form) *
  94. REM *****************************************************
  95. REM Make sure the msi doesn't already contain a CAB file
  96. cscript.exe %SAKITDIR%\wistream.vbs %MSINAME% /D %CABNAME%
  97. REM Stream in the new data.cab
  98. cscript.exe %SAKITDIR%\wistream.vbs %MSINAME% %TEMPCABFILE%
  99. if errorlevel 1 (
  100. call errmsg.cmd "wistream failed to stream in %TEMPCABFILE%"
  101. goto errend
  102. )
  103. del %TEMPCABFILE%
  104. REM *****************************************************
  105. REM * Stream in the custom actions *
  106. REM * NOTE: This assumes an entry is already in the *
  107. REM * binary table. New entries are not created. *
  108. REM * The binary data is overwritten. *
  109. REM *****************************************************
  110. cscript.exe %SAKITDIR%\wistream.vbs %MSINAME% %CUSTOMACTION%\SASetupCA.dll Binary.New_Binary1
  111. if errorlevel 1 (
  112. call errmsg.cmd "wistream failed to stream in SASetupCA.dll"
  113. goto errend
  114. )
  115. cscript.exe %SAKITDIR%\wistream.vbs %MSINAME% %CUSTOMACTION%\configServices.vbs Binary.New_Binary2
  116. if errorlevel 1 (
  117. call errmsg.cmd "wistream failed to stream in configServices.vbs"
  118. goto errend
  119. )
  120. cscript.exe %SAKITDIR%\wistream.vbs %MSINAME% %CUSTOMACTION%\createwebsite.vbs Binary.New_Binary3
  121. if errorlevel 1 (
  122. call errmsg.cmd "wistream failed to stream in createwebsite.vbs"
  123. goto errend
  124. )
  125. cscript.exe %SAKITDIR%\wistream.vbs %MSINAME% %CUSTOMACTION%\mof.vbs Binary.New_Binary5
  126. if errorlevel 1 (
  127. call errmsg.cmd "wistream failed to stream in mof.vbs"
  128. goto errend
  129. )
  130. REM *****************************************************
  131. REM * Update the filetable with file size and ver info *
  132. REM * assumes the source files are in the same directory*
  133. REM *****************************************************
  134. call cscript.exe %SAKITDIR%\wifilver.vbs /U %MSINAME% %TEMPCABDIR%
  135. if errorlevel 1 (
  136. call errmsg.cmd "wifilver failed"
  137. goto errend
  138. )
  139. rmdir /q /s %TEMPCABDIR%
  140. if errorlevel 1 call errmsg.cmd "err deleting tmpcab dir"& goto errend
  141. REM *****************************************************
  142. REM * Copy the final version of sasetup.msi to the *
  143. REM * release folder *
  144. REM *****************************************************
  145. move %MSINAME% %_NTPOSTBLD%
  146. if errorlevel 1 (
  147. call errmsg.cmd "Failed to copy sasetup.msi to release location"
  148. goto errend
  149. )
  150. call logmsg.cmd "samsigen.cmd completed successfully!"
  151. call logmsg.cmd "To install, run %_NTPOSTBLD%\sasetup.msi"
  152. REM we're done
  153. endlocal
  154. goto end
  155. REM ******************SUBS START HERE********************
  156. REM *****************************************************
  157. REM * Update version sub *
  158. REM * (updates version in the property table *
  159. REM *****************************************************
  160. :SetVersion
  161. REM
  162. REM Update the version in the Property table
  163. REM and update the version in the Upgrade Table
  164. REM
  165. REM %1 is the msi file
  166. REM %2 is the msiidt directory
  167. set ntverp=%_NTBINDIR%\public\sdk\inc\ntverp.h
  168. if NOT EXIST %ntverp% (echo Can't find ntverp.h.&goto :ErrEnd)
  169. for /f "tokens=3 delims=, " %%i in ('findstr /c:"#define VER_PRODUCTMAJORVERSION " %ntverp%') do (
  170. set /a ProductMajor="%%i"
  171. set BuildNum=%%i
  172. )
  173. for /f "tokens=3 delims=, " %%i in ('findstr /c:"#define VER_PRODUCTMINORVERSION " %ntverp%') do (
  174. set /a ProductMinor="%%i"
  175. set BuildNum=!BuildNum!.%%i
  176. )
  177. for /f "tokens=6" %%i in ('findstr /c:"#define VER_PRODUCTBUILD " %ntverp%') do (
  178. set /a ProductBuild="%%i"
  179. set BuildNum=!BuildNum!.%%i
  180. )
  181. for /f "tokens=3" %%i in ('findstr /c:"#define VER_PRODUCTBUILD_QFE " %ntverp%') do (
  182. set /a ProductQfe="%%i"
  183. set BuildNum=!BuildNum!.%%i
  184. )
  185. call logmsg.cmd "Updating the sasetup.msi ProductVersion to !BuildNum! in prop table"
  186. call cscript.exe %SAKITDIR%\wiexport.vbs %1 %2 Property
  187. copy %2\Property.idt %2\Property.idt.old > nul
  188. del /f %2\Property.idt
  189. for /f "tokens=1,2 delims= " %%a in (%2\Property.idt.old) do (
  190. if /i "%%a" == "ProductVersion" (
  191. echo %%a !BuildNum!>>%2\Property.idt
  192. ) else (
  193. echo %%a %%b>>%2\Property.idt
  194. )
  195. )
  196. REM Set the property that says if this is an x86 or a 64-bit package
  197. if /i "%CurArch%" == "i386" (
  198. echo Install32 ^1>>%2\Property.idt
  199. )
  200. if /i "%CurArch%" == "ia64" (
  201. echo Install64 ^1>>%2\Property.idt
  202. )
  203. call cscript.exe %SAKITDIR%\wiimport.vbs //nologo %1 %2 Property.idt
  204. REM call logmsg.cmd "Finished updating the ProductVersion in the property table"
  205. call logmsg.cmd "Setting the version in the Upgrade table"
  206. call cscript.exe %SAKITDIR%\wiexport.vbs //nologo %1 %2 Upgrade
  207. copy %2\Upgrade.idt %2\Upgrade.idt.old > nul
  208. del /f %2\Upgrade.idt
  209. REM
  210. REM Put the header to the file
  211. REM Echo the first three lines to the file
  212. set /a count=1
  213. for /f "tokens=*" %%a in (%2\upgrade.idt.old) do (
  214. if !count! LEQ 3 echo %%a>>%2\Upgrade.idt
  215. set /a count=!count!+1
  216. )
  217. for /f "skip=3 tokens=1,2,3,4 delims= " %%a in (%2\Upgrade.idt.old) do (
  218. echo %%a !BuildNum! %%c %%d>>%2\Upgrade.idt
  219. )
  220. call cscript.exe %SAKITDIR%\wiimport.vbs //nologo %1 %2 Upgrade.idt
  221. call logmsg.cmd "Finished updating the version in the upgrade table"
  222. goto :EOF
  223. :errend
  224. goto :EOF
  225. :end
  226. seterror.exe 0
  227. goto :EOF