Skip to content

Commit 054459c

Browse files
authored
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.
2 parents 32c65f5 + 0456da2 commit 054459c

File tree

2 files changed

+59
-23
lines changed

2 files changed

+59
-23
lines changed

doc/31-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
4242
* [#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
4343
* [#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
4444
* [#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
45+
* [#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
4546

4647
## 1.2.0 (2020-08-28)
4748

lib/core/icingaagent/getters/Get-IcingaAgentMSIPackage.psm1

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,73 @@ function Get-IcingaAgentMSIPackage()
1919
$ProgressPreference = "SilentlyContinue";
2020
$Architecture = Get-IcingaAgentArchitecture;
2121
$LastUpdate = $null;
22+
$Version = $Version.ToLower();
2223

2324
if ($Version -eq 'snapshot' -Or $Version -eq 'release') {
24-
$Content = (Invoke-IcingaWebRequest -Uri $Source -UseBasicParsing).RawContent.Split("`r`n");
25-
$UsePackage = $null;
25+
if (Test-Path $Source) {
26+
$Content = Get-ChildItem -Path $Source;
27+
28+
foreach ($entry in $Content) {
29+
$PackageVersion = ($entry.Name.Split('-')[1]).Replace('v', '');
2630

27-
foreach ($line in $Content) {
28-
if ($line -like '*.msi*' -And $line -like "*$Architecture.msi*") {
29-
$MSIPackage = $line.SubString(
30-
$line.IndexOf('Icinga2-'),
31-
$line.IndexOf('.msi') - $line.IndexOf('Icinga2-')
32-
);
33-
$LastUpdate = $line.SubString(
34-
$line.IndexOf('indexcollastmod">') + 17,
35-
$line.Length - $line.IndexOf('indexcollastmod">') - 17
36-
);
37-
$LastUpdate = $LastUpdate.SubString(0, $LastUpdate.IndexOf(' '));
38-
$LastUpdate = $LastUpdate.Replace('-', '');
39-
$MSIPackage = [string]::Format('{0}.msi', $MSIPackage);
4031
if ($Version -eq 'snapshot') {
41-
if ($line -like '*snapshot*') {
42-
$UsePackage = $MSIPackage;
32+
if ($PackageVersion -eq 'snapshot') {
33+
$UseVersion = 'snapshot';
4334
break;
4435
}
45-
} elseif ($Version -eq 'release') {
46-
if ($line -like '*snapshot*' -Or $line -like '*-rc*') {
47-
continue;
36+
continue;
37+
}
38+
39+
if ($PackageVersion -eq 'snapshot') {
40+
continue;
41+
}
42+
43+
if ($null -eq $UseVersion -Or [version]$PackageVersion -ge [version]$UseVersion) {
44+
$UseVersion = $PackageVersion;
45+
}
46+
}
47+
} else {
48+
$Content = (Invoke-IcingaWebRequest -Uri $Source -UseBasicParsing).RawContent.Split("`r`n");
49+
$UsePackage = $null;
50+
$UseVersion = $null;
51+
52+
foreach ($line in $Content) {
53+
if ($line -like '*.msi*' -And $line -like "*$Architecture.msi*") {
54+
$MSIPackage = $line.SubString(
55+
$line.IndexOf('Icinga2-'),
56+
$line.IndexOf('.msi') - $line.IndexOf('Icinga2-')
57+
);
58+
$LastUpdate = $line.SubString(
59+
$line.IndexOf('indexcollastmod">') + 17,
60+
$line.Length - $line.IndexOf('indexcollastmod">') - 17
61+
);
62+
$LastUpdate = $LastUpdate.SubString(0, $LastUpdate.IndexOf(' '));
63+
$LastUpdate = $LastUpdate.Replace('-', '');
64+
$MSIPackage = [string]::Format('{0}.msi', $MSIPackage);
65+
$PackageVersion = ($MSIPackage.Split('-')[1]).Replace('v', '');
66+
67+
if ($Version -eq 'snapshot') {
68+
if ($PackageVersion -eq 'snapshot') {
69+
$UseVersion = 'snapshot';
70+
break;
71+
}
72+
} elseif ($Version -eq 'release') {
73+
if ($line -like '*snapshot*' -Or $line -like '*-rc*') {
74+
continue;
75+
}
76+
77+
if ($null -eq $UseVersion -Or [version]$PackageVersion -ge [version]$UseVersion) {
78+
$UseVersion = $PackageVersion;
79+
}
4880
}
49-
$UsePackage = $MSIPackage;
50-
break;
5181
}
5282
}
5383
}
84+
if ($Version -eq 'snapshot') {
85+
$UsePackage = [string]::Format('Icinga2-{0}-{1}.msi', $UseVersion, $Architecture);
86+
} else {
87+
$UsePackage = [string]::Format('Icinga2-v{0}-{1}.msi', $UseVersion, $Architecture);
88+
}
5489
} else {
5590
$UsePackage = [string]::Format('Icinga2-v{0}-{1}.msi', $Version, $Architecture);
5691
}
@@ -67,7 +102,7 @@ function Get-IcingaAgentMSIPackage()
67102

68103
return @{
69104
'InstallerPath' = $DownloadPath;
70-
'Version' = ($UsePackage).Replace('Icinga2-v', '').Replace([string]::Format('-{0}.msi', $Architecture), '')
105+
'Version' = ($UsePackage).Replace('Icinga2-v', '').Replace('Icinga2-', '').Replace([string]::Format('-{0}.msi', $Architecture), '')
71106
'LastUpdate' = $LastUpdate;
72107
}
73108
}

0 commit comments

Comments
 (0)