Merge pull request #166 from Icinga:fix/agent_version_fetching_and_local_sources

Fix: Fixes release fetching of Agent with correct comparison and proper support for local sources

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.
This commit is contained in:
Lord Hepipud 2020-11-24 16:46:13 +01:00 committed by GitHub
commit 054459cbce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 24 deletions

View file

@ -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 * [#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 * [#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 * [#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) ## 1.2.0 (2020-08-28)

View file

@ -19,10 +19,35 @@ function Get-IcingaAgentMSIPackage()
$ProgressPreference = "SilentlyContinue"; $ProgressPreference = "SilentlyContinue";
$Architecture = Get-IcingaAgentArchitecture; $Architecture = Get-IcingaAgentArchitecture;
$LastUpdate = $null; $LastUpdate = $null;
$Version = $Version.ToLower();
if ($Version -eq 'snapshot' -Or $Version -eq 'release') { if ($Version -eq 'snapshot' -Or $Version -eq 'release') {
if (Test-Path $Source) {
$Content = Get-ChildItem -Path $Source;
foreach ($entry in $Content) {
$PackageVersion = ($entry.Name.Split('-')[1]).Replace('v', '');
if ($Version -eq 'snapshot') {
if ($PackageVersion -eq 'snapshot') {
$UseVersion = 'snapshot';
break;
}
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"); $Content = (Invoke-IcingaWebRequest -Uri $Source -UseBasicParsing).RawContent.Split("`r`n");
$UsePackage = $null; $UsePackage = $null;
$UseVersion = $null;
foreach ($line in $Content) { foreach ($line in $Content) {
if ($line -like '*.msi*' -And $line -like "*$Architecture.msi*") { if ($line -like '*.msi*' -And $line -like "*$Architecture.msi*") {
@ -37,20 +62,30 @@ function Get-IcingaAgentMSIPackage()
$LastUpdate = $LastUpdate.SubString(0, $LastUpdate.IndexOf(' ')); $LastUpdate = $LastUpdate.SubString(0, $LastUpdate.IndexOf(' '));
$LastUpdate = $LastUpdate.Replace('-', ''); $LastUpdate = $LastUpdate.Replace('-', '');
$MSIPackage = [string]::Format('{0}.msi', $MSIPackage); $MSIPackage = [string]::Format('{0}.msi', $MSIPackage);
$PackageVersion = ($MSIPackage.Split('-')[1]).Replace('v', '');
if ($Version -eq 'snapshot') { if ($Version -eq 'snapshot') {
if ($line -like '*snapshot*') { if ($PackageVersion -eq 'snapshot') {
$UsePackage = $MSIPackage; $UseVersion = 'snapshot';
break; break;
} }
} elseif ($Version -eq 'release') { } elseif ($Version -eq 'release') {
if ($line -like '*snapshot*' -Or $line -like '*-rc*') { if ($line -like '*snapshot*' -Or $line -like '*-rc*') {
continue; continue;
} }
$UsePackage = $MSIPackage;
break; if ($null -eq $UseVersion -Or [version]$PackageVersion -ge [version]$UseVersion) {
$UseVersion = $PackageVersion;
} }
} }
} }
}
}
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 { } else {
$UsePackage = [string]::Format('Icinga2-v{0}-{1}.msi', $Version, $Architecture); $UsePackage = [string]::Format('Icinga2-v{0}-{1}.msi', $Version, $Architecture);
} }
@ -67,7 +102,7 @@ function Get-IcingaAgentMSIPackage()
return @{ return @{
'InstallerPath' = $DownloadPath; '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; 'LastUpdate' = $LastUpdate;
} }
} }