]> granicus.if.org Git - icinga2/commitdiff
Chocolatey: Add build script for package bugfix/chocolatey
authorMichael Insel <michael@insel.email>
Fri, 11 Oct 2019 16:42:48 +0000 (18:42 +0200)
committerMichael Insel <michael@insel.email>
Fri, 11 Oct 2019 16:42:48 +0000 (18:42 +0200)
choco/CMakeLists.txt
choco/chocolateyInstall.ps1.template.cmake [moved from choco/chocolateyInstall.ps1.cmake with 79% similarity, mode: 0644]
tools/win32/build-choco.ps1 [new file with mode: 0644]

index d7b90bb471541e8b2874f1a215c71866778d5080..fb147a15cf291d32c704a83f994d164245f659a5 100644 (file)
@@ -1,14 +1,6 @@
 # Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+
 
 if(WIN32)
-  find_program(CHOCO_BINARY choco)
-
   configure_file(icinga2.nuspec.cmake icinga2.nuspec)
-  configure_file(chocolateyInstall.ps1.cmake chocolateyInstall.ps1)
-
-  add_custom_target(choco-pkg ALL
-    COMMAND choco pack
-    COMMAND ${CMAKE_COMMAND} -E rename ${CMAKE_CURRENT_BINARY_DIR}/icinga2.${ICINGA2_VERSION_SAFE}.nupkg ${CMAKE_CURRENT_BINARY_DIR}/icinga2.nupkg
-    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/icinga2.nuspec ${CMAKE_CURRENT_BINARY_DIR}/chocolateyInstall.ps1 chocolateyUninstall.ps1
-  )
+  configure_file(chocolateyInstall.ps1.template.cmake chocolateyInstall.ps1.template)
 endif()
old mode 100755 (executable)
new mode 100644 (file)
similarity index 79%
rename from choco/chocolateyInstall.ps1.cmake
rename to choco/chocolateyInstall.ps1.template.cmake
index 26fe239..424a737
@@ -1,20 +1,20 @@
-$packageName= 'icinga2'\r
-$toolsDir   = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)"\r
-$url = 'https://packages.icinga.com/windows/Icinga2-v${CHOCO_VERSION_SHORT}-x86.msi'\r
-$url64 = 'https://packages.icinga.com/windows/Icinga2-v${CHOCO_VERSION_SHORT}-x86_64.msi'\r
-\r
-$packageArgs = @{\r
-  packageName   = $packageName\r
-  fileType      = 'msi'\r
-  url           = $url\r
-  url64bit      = $url64\r
-  silentArgs    = "/qn /norestart"\r
-  validExitCodes= @(0)\r
-  softwareName  = 'Icinga 2*'\r
-  checksum      = '' # TODO: Add checksum\r
-  checksumType  = 'sha256'\r
-  checksum64    = '' # TODO: Add checksum\r
-  checksumType64= 'sha256'\r
-}\r
-\r
+$packageName= 'icinga2'
+$toolsDir   = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)"
+$url = 'https://packages.icinga.com/windows/Icinga2-v${CHOCO_VERSION_SHORT}-x86.msi'
+$url64 = 'https://packages.icinga.com/windows/Icinga2-v${CHOCO_VERSION_SHORT}-x86_64.msi'
+
+$packageArgs = @{
+  packageName   = $packageName
+  fileType      = 'msi'
+  url           = $url
+  url64bit      = $url64
+  silentArgs    = "/qn /norestart"
+  validExitCodes= @(0)
+  softwareName  = 'Icinga 2*'
+  checksum      = '%CHOCO_32BIT_CHECKSUM%'
+  checksumType  = 'sha256'
+  checksum64    = '%CHOCO_64BIT_CHECKSUM%'
+  checksumType64= 'sha256'
+}
+
 Install-ChocolateyPackage @packageArgs
\ No newline at end of file
diff --git a/tools/win32/build-choco.ps1 b/tools/win32/build-choco.ps1
new file mode 100644 (file)
index 0000000..24fa5f4
--- /dev/null
@@ -0,0 +1,42 @@
+Set-PsDebug -Trace 1
+
+if(-not (Test-Path "$($env:ProgramData)\chocolatey\choco.exe")) {
+       throw "Could not find Choco executable. Abort."
+}
+
+if (-not (Test-Path env:ICINGA2_BUILDPATH)) {
+  $env:ICINGA2_BUILDPATH = '.\debug'
+}
+
+if(-not (Test-Path "$($env:ICINGA2_BUILDPATH)\choco\chocolateyInstall.ps1.template")) {
+       throw "Could not find Chocolatey install script template. Abort."
+}
+
+$chocoInstallScriptTemplatePath = "$($env:ICINGA2_BUILDPATH)\choco\chocolateyInstall.ps1.template"
+$chocoInstallScript = Get-Content $chocoInstallScriptTemplatePath
+
+if(-not (Test-Path "$($env:ICINGA2_BUILDPATH)\*-x86.msi")) {
+       throw "Could not find Icinga 2 32 bit MSI package. Abort."
+}
+
+$hashMSIpackage32 =  Get-FileHash "$($env:ICINGA2_BUILDPATH)\*-x86.msi"
+Write-Output "File Hash for 32 bit MSI package: $($hashMSIpackage32.Hash)."
+
+if(-not (Test-Path "$($env:ICINGA2_BUILDPATH)\*-x86_64.msi")) {
+       throw "Could not find Icinga 2 64 bit MSI package. Abort."
+}
+
+$hashMSIpackage64 =  Get-FileHash "$($env:ICINGA2_BUILDPATH)\*-x86_64.msi"
+Write-Output "File Hash for 32 bit MSI package: $($hashMSIpackage64.Hash)"
+
+$chocoInstallScript = $chocoInstallScript.Replace("%CHOCO_32BIT_CHECKSUM%", "$($hashMSIpackage32.Hash)")
+$chocoInstallScript = $chocoInstallScript.Replace("%CHOCO_64BIT_CHECKSUM%", "$($hashMSIpackage64.Hash)")
+Write-Output $chocoInstallScript
+
+Set-Content -Path "$($env:ICINGA2_BUILDPATH)\choco\chocolateyInstall.ps1" -Value $chocoInstallScript
+
+cd "$($env:ICINGA2_BUILDPATH)\choco"
+& "$($env:ProgramData)\chocolatey\choco.exe" "pack"
+cd "..\.."
+
+Move-Item -Path "$($env:ICINGA2_BUILDPATH)\choco\*.nupkg" -Destination "$($env:ICINGA2_BUILDPATH)"
\ No newline at end of file