1
0

sign.bat 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. :: ############################################################################
  2. ::
  3. :: FILE: sign.bat
  4. ::
  5. :: DESCRIPTION: Signing and Hashing script for Salt builds on Windows.
  6. :: Requires an official Code Signing Certificate and drivers
  7. :: installed to sign the files. Generates hashes in MD5 and
  8. :: SHA256 in a file of the same name with a `.md5` or
  9. :: `.sha256` extension.
  10. ::
  11. :: NOTE: This script is used internally by SaltStack to sign and
  12. :: hash Windows Installer builds and uses resources not
  13. :: available to the community, such as SaltStack's Code
  14. :: Signing Certificate. It is placed here for version
  15. :: control.
  16. ::
  17. :: COPYRIGHT: (c) 2012-2018 by the SaltStack Team
  18. ::
  19. :: LICENSE: Apache 2.0
  20. :: ORGANIZATION: SaltStack, Inc (saltstack.com)
  21. :: CREATED: 2017
  22. ::
  23. :: ############################################################################
  24. ::
  25. :: USAGE: The script must be located in a directory that has the installer
  26. :: files in a subfolder named with the major version, ie: `2018.3`.
  27. :: Insert the key fob that contains the code signing certificate. Run
  28. :: the script passing the full version: `.\sign.bat 2018.3.1`.
  29. ::
  30. :: The script will sign the installers and generate the corresponding
  31. :: hash files. These can then be uploaded to the salt repo.
  32. ::
  33. :: The files must be in the following format:
  34. :: <Series>\Salt-Minion-<Version>-<Python Version>-<System Architecture>-Setup.exe
  35. :: So, for a Salt Minion installer for 2018.3.1 on AMD64 for Python 3
  36. :: file would be placed in a subdirectory named `2018.3` and the file
  37. :: would be named: `Salt-Minion-2018.3.1-Py3-AMD64-Setup.exe`. This
  38. :: is how the file is created by the NSI Script anyway.
  39. ::
  40. :: ############################################################################
  41. @ echo off
  42. if [%1]==[] (
  43. echo You must pass a version
  44. goto quit
  45. ) else (
  46. set "Version=%~1"
  47. )
  48. for /F "tokens=1,2 delims=." %%a in ("%Version%") do (set Series=%%a.%%b)
  49. :: See if the Series Directory exists (uses new versioning)
  50. if not exist .\%Series%\ (
  51. echo - Series %Series% was not found, trying new naming convention
  52. for /F "tokens=1,2 delims=." %%a in ("%Version%") do (set Series=%%a)
  53. )
  54. if not exist .\%Series%\ (
  55. echo - Series %Series% is not valid
  56. exit 1
  57. )
  58. :: If it ends in a '.' trim it
  59. if "%Series:~-1%"=="." (
  60. set Series=%Series:~0,-1%
  61. )
  62. :: Sign Installer Files
  63. echo ===========================================================================
  64. echo Signing...
  65. echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  66. signtool.exe sign /a /t http://timestamp.digicert.com ^
  67. "%Series%\Salt-Minion-%Version%-AMD64-Setup.exe" ^
  68. "%Series%\Salt-Minion-%Version%-x86-Setup.exe" ^
  69. "%Series%\Salt-%Version%-AMD64-Setup.exe" ^
  70. "%Series%\Salt-%Version%-x86-Setup.exe" ^
  71. "%Series%\Salt-%Version%-Py2-AMD64-Setup.exe" ^
  72. "%Series%\Salt-%Version%-Py2-x86-Setup.exe" ^
  73. "%Series%\Salt-%Version%-Py3-AMD64-Setup.exe" ^
  74. "%Series%\Salt-%Version%-Py3-x86-Setup.exe" ^
  75. "%Series%\Salt-Minion-%Version%-Py2-AMD64-Setup.exe" ^
  76. "%Series%\Salt-Minion-%Version%-Py2-x86-Setup.exe" ^
  77. "%Series%\Salt-Minion-%Version%-Py3-AMD64-Setup.exe" ^
  78. "%Series%\Salt-Minion-%Version%-Py3-x86-Setup.exe"
  79. echo %ERRORLEVEL%
  80. echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  81. echo Signing Complete
  82. echo ===========================================================================
  83. :: Create Hash files
  84. echo ===========================================================================
  85. echo Creating Hashes...
  86. echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  87. set "file_name=Salt-Minion-%Version%-AMD64-Setup.exe"
  88. set "file=.\%Series%\%file_name%"
  89. if exist "%file%" (
  90. echo - %file_name%
  91. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\"" -NoNewLine
  92. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"" -NoNewLine)
  93. set "file_name=Salt-Minion-%Version%-x86-Setup.exe"
  94. set "file=.\%Series%\%file_name%"
  95. if exist "%file%" (
  96. echo - %file_name%
  97. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\"" -NoNewLine
  98. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"" -NoNewLine)
  99. set "file_name=Salt-%Version%-AMD64-Setup.exe"
  100. set "file=.\%Series%\%file_name%"
  101. if exist "%file%" (
  102. echo - %file_name%
  103. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\"" -NoNewLine
  104. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"" -NoNewLine)
  105. set "file_name=Salt-%Version%-x86-Setup.exe"
  106. set "file=.\%Series%\%file_name%"
  107. if exist "%file%" (
  108. echo - %file_name%
  109. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\"" -NoNewLine
  110. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"" -NoNewLine)
  111. set "file_name=Salt-%Version%-Py2-AMD64-Setup.exe"
  112. set "file=.\%Series%\%file_name%"
  113. if exist "%file%" (
  114. echo - %file_name%
  115. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\"" -NoNewLine
  116. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"" -NoNewLine)
  117. set "file_name=Salt-%Version%-Py2-x86-Setup.exe"
  118. set "file=.\%Series%\%file_name%"
  119. if exist "%file%" (
  120. echo - %file_name%
  121. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\"" -NoNewLine
  122. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"" -NoNewLine)
  123. set "file_name=Salt-%Version%-Py3-AMD64-Setup.exe"
  124. set "file=.\%Series%\%file_name%"
  125. if exist "%file%" (
  126. echo - %file_name%
  127. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\"" -NoNewLine
  128. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"" -NoNewLine)
  129. set "file_name=Salt-%Version%-Py3-x86-Setup.exe"
  130. set "file=.\%Series%\%file_name%"
  131. if exist "%file%" (
  132. echo - %file_name%
  133. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\"" -NoNewLine
  134. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"" -NoNewLine)
  135. set "file_name=Salt-Minion-%Version%-Py2-AMD64-Setup.exe"
  136. set "file=.\%Series%\%file_name%"
  137. if exist "%file%" (
  138. echo - %file_name%
  139. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\"" -NoNewLine
  140. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"" -NoNewLine)
  141. set "file_name=Salt-Minion-%Version%-Py2-x86-Setup.exe"
  142. set "file=.\%Series%\%file_name%"
  143. if exist "%file%" (
  144. echo - %file_name%
  145. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\"" -NoNewLine
  146. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"" -NoNewLine)
  147. set "file_name=Salt-Minion-%Version%-Py3-AMD64-Setup.exe"
  148. set "file=.\%Series%\%file_name%"
  149. if exist "%file%" (
  150. echo - %file_name%
  151. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\"" -NoNewLine
  152. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"" -NoNewLine)
  153. set "file_name=Salt-Minion-%Version%-Py3-x86-Setup.exe"
  154. set "file=.\%Series%\%file_name%"
  155. if exist "%file%" (
  156. echo - %file_name%
  157. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\"" -NoNewLine
  158. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"" -NoNewLine)
  159. echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  160. echo Hashing Complete
  161. echo ===========================================================================
  162. :quit