1
0

sign.bat 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. :: Sign Installer Files
  50. echo ===========================================================================
  51. echo Signing...
  52. echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  53. signtool.exe sign /t http://timestamp.digicert.com ^
  54. "%Series%\Salt-Minion-%Version%-AMD64-Setup.exe" ^
  55. "%Series%\Salt-Minion-%Version%-x86-Setup.exe" ^
  56. "%Series%\Salt-%Version%-AMD64-Setup.exe" ^
  57. "%Series%\Salt-%Version%-x86-Setup.exe" ^
  58. "%Series%\Salt-%Version%-Py2-AMD64-Setup.exe" ^
  59. "%Series%\Salt-%Version%-Py2-x86-Setup.exe" ^
  60. "%Series%\Salt-%Version%-Py3-AMD64-Setup.exe" ^
  61. "%Series%\Salt-%Version%-Py3-x86-Setup.exe" ^
  62. "%Series%\Salt-Minion-%Version%-Py2-AMD64-Setup.exe" ^
  63. "%Series%\Salt-Minion-%Version%-Py2-x86-Setup.exe" ^
  64. "%Series%\Salt-Minion-%Version%-Py3-AMD64-Setup.exe" ^
  65. "%Series%\Salt-Minion-%Version%-Py3-x86-Setup.exe"
  66. echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  67. echo Signing Complete
  68. echo ===========================================================================
  69. :: Create Hash files
  70. echo ===========================================================================
  71. echo Creating Hashes...
  72. echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. set "file_name=Salt-Minion-%Version%-AMD64-Setup.exe"
  74. set "file=.\%Series%\%file_name%"
  75. if exist "%file%" (
  76. echo - %file_name%
  77. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\""
  78. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"")
  79. set "file_name=Salt-Minion-%Version%-x86-Setup.exe"
  80. set "file=.\%Series%\%file_name%"
  81. if exist "%file%" (
  82. echo - %file_name%
  83. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\""
  84. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"")
  85. set "file_name=Salt-%Version%-AMD64-Setup.exe"
  86. set "file=.\%Series%\%file_name%"
  87. if exist "%file%" (
  88. echo - %file_name%
  89. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\""
  90. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"")
  91. set "file_name=Salt-%Version%-x86-Setup.exe"
  92. set "file=.\%Series%\%file_name%"
  93. if exist "%file%" (
  94. echo - %file_name%
  95. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\""
  96. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"")
  97. set "file_name=Salt-%Version%-Py2-AMD64-Setup.exe"
  98. set "file=.\%Series%\%file_name%"
  99. if exist "%file%" (
  100. echo - %file_name%
  101. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\""
  102. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"")
  103. set "file_name=Salt-%Version%-Py2-x86-Setup.exe"
  104. set "file=.\%Series%\%file_name%"
  105. if exist "%file%" (
  106. echo - %file_name%
  107. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\""
  108. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"")
  109. set "file_name=Salt-%Version%-Py3-AMD64-Setup.exe"
  110. set "file=.\%Series%\%file_name%"
  111. if exist "%file%" (
  112. echo - %file_name%
  113. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\""
  114. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"")
  115. set "file_name=Salt-%Version%-Py3-x86-Setup.exe"
  116. set "file=.\%Series%\%file_name%"
  117. if exist "%file%" (
  118. echo - %file_name%
  119. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\""
  120. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"")
  121. set "file_name=Salt-Minion-%Version%-Py2-AMD64-Setup.exe"
  122. set "file=.\%Series%\%file_name%"
  123. if exist "%file%" (
  124. echo - %file_name%
  125. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\""
  126. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"")
  127. set "file_name=Salt-Minion-%Version%-Py2-x86-Setup.exe"
  128. set "file=.\%Series%\%file_name%"
  129. if exist "%file%" (
  130. echo - %file_name%
  131. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\""
  132. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"")
  133. set "file_name=Salt-Minion-%Version%-Py3-AMD64-Setup.exe"
  134. set "file=.\%Series%\%file_name%"
  135. if exist "%file%" (
  136. echo - %file_name%
  137. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\""
  138. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"")
  139. set "file_name=Salt-Minion-%Version%-Py3-x86-Setup.exe"
  140. set "file=.\%Series%\%file_name%"
  141. if exist "%file%" (
  142. echo - %file_name%
  143. powershell -c "$hash = (Get-FileHash -Algorithm MD5 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.md5\""
  144. powershell -c "$hash = (Get-FileHash -Algorithm SHA256 \"%file%\").Hash; Out-File -InputObject $hash\" %file_name%\" -FilePath \"%file%.sha256\"")
  145. echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  146. echo Hashing Complete
  147. echo ===========================================================================
  148. :quit