diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index 8c1a18c6..74ecfe0c 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -42,6 +42,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#152](https://github.com/Icinga/icinga-powershell-framework/issues/152) Fixes incorrect rendering for empty arrays which used `$null` incorrectly instead of `@()` and fixed ValidateSet which now also supports arrays as data type * [#159](https://github.com/Icinga/icinga-powershell-framework/pull/159) Fixes crash during update of the Icinga Framework, caused by the newly introduced experimental feature for code caching * [#165](https://github.com/Icinga/icinga-powershell-framework/pull/165) Fixes fetching for Icinga Agent certificate for REST-Api daemon on upper/lower case hostname mismatch +* [#166](https://github.com/Icinga/icinga-powershell-framework/pull/166) Fixes fetching of Icinga Agent MSI packages by correctly comparing versions to ensure we always use the latest version and fixes `release` usage for local/network drive sources ## 1.2.0 (2020-08-28) diff --git a/lib/core/icingaagent/getters/Get-IcingaAgentMSIPackage.psm1 b/lib/core/icingaagent/getters/Get-IcingaAgentMSIPackage.psm1 index 709f1b39..b6450e07 100644 --- a/lib/core/icingaagent/getters/Get-IcingaAgentMSIPackage.psm1 +++ b/lib/core/icingaagent/getters/Get-IcingaAgentMSIPackage.psm1 @@ -19,38 +19,73 @@ function Get-IcingaAgentMSIPackage() $ProgressPreference = "SilentlyContinue"; $Architecture = Get-IcingaAgentArchitecture; $LastUpdate = $null; + $Version = $Version.ToLower(); if ($Version -eq 'snapshot' -Or $Version -eq 'release') { - $Content = (Invoke-IcingaWebRequest -Uri $Source -UseBasicParsing).RawContent.Split("`r`n"); - $UsePackage = $null; + if (Test-Path $Source) { + $Content = Get-ChildItem -Path $Source; + + foreach ($entry in $Content) { + $PackageVersion = ($entry.Name.Split('-')[1]).Replace('v', ''); - foreach ($line in $Content) { - if ($line -like '*.msi*' -And $line -like "*$Architecture.msi*") { - $MSIPackage = $line.SubString( - $line.IndexOf('Icinga2-'), - $line.IndexOf('.msi') - $line.IndexOf('Icinga2-') - ); - $LastUpdate = $line.SubString( - $line.IndexOf('indexcollastmod">') + 17, - $line.Length - $line.IndexOf('indexcollastmod">') - 17 - ); - $LastUpdate = $LastUpdate.SubString(0, $LastUpdate.IndexOf(' ')); - $LastUpdate = $LastUpdate.Replace('-', ''); - $MSIPackage = [string]::Format('{0}.msi', $MSIPackage); if ($Version -eq 'snapshot') { - if ($line -like '*snapshot*') { - $UsePackage = $MSIPackage; + if ($PackageVersion -eq 'snapshot') { + $UseVersion = 'snapshot'; break; } - } elseif ($Version -eq 'release') { - if ($line -like '*snapshot*' -Or $line -like '*-rc*') { - continue; + continue; + } + + if ($PackageVersion -eq 'snapshot') { + continue; + } + + if ($null -eq $UseVersion -Or [version]$PackageVersion -ge [version]$UseVersion) { + $UseVersion = $PackageVersion; + } + } + } else { + $Content = (Invoke-IcingaWebRequest -Uri $Source -UseBasicParsing).RawContent.Split("`r`n"); + $UsePackage = $null; + $UseVersion = $null; + + foreach ($line in $Content) { + if ($line -like '*.msi*' -And $line -like "*$Architecture.msi*") { + $MSIPackage = $line.SubString( + $line.IndexOf('Icinga2-'), + $line.IndexOf('.msi') - $line.IndexOf('Icinga2-') + ); + $LastUpdate = $line.SubString( + $line.IndexOf('indexcollastmod">') + 17, + $line.Length - $line.IndexOf('indexcollastmod">') - 17 + ); + $LastUpdate = $LastUpdate.SubString(0, $LastUpdate.IndexOf(' ')); + $LastUpdate = $LastUpdate.Replace('-', ''); + $MSIPackage = [string]::Format('{0}.msi', $MSIPackage); + $PackageVersion = ($MSIPackage.Split('-')[1]).Replace('v', ''); + + if ($Version -eq 'snapshot') { + if ($PackageVersion -eq 'snapshot') { + $UseVersion = 'snapshot'; + break; + } + } elseif ($Version -eq 'release') { + if ($line -like '*snapshot*' -Or $line -like '*-rc*') { + continue; + } + + if ($null -eq $UseVersion -Or [version]$PackageVersion -ge [version]$UseVersion) { + $UseVersion = $PackageVersion; + } } - $UsePackage = $MSIPackage; - break; } } } + if ($Version -eq 'snapshot') { + $UsePackage = [string]::Format('Icinga2-{0}-{1}.msi', $UseVersion, $Architecture); + } else { + $UsePackage = [string]::Format('Icinga2-v{0}-{1}.msi', $UseVersion, $Architecture); + } } else { $UsePackage = [string]::Format('Icinga2-v{0}-{1}.msi', $Version, $Architecture); } @@ -67,7 +102,7 @@ function Get-IcingaAgentMSIPackage() return @{ 'InstallerPath' = $DownloadPath; - 'Version' = ($UsePackage).Replace('Icinga2-v', '').Replace([string]::Format('-{0}.msi', $Architecture), '') + 'Version' = ($UsePackage).Replace('Icinga2-v', '').Replace('Icinga2-', '').Replace([string]::Format('-{0}.msi', $Architecture), '') 'LastUpdate' = $LastUpdate; } }