Skip to content

Commit 212a80c

Browse files
authored
Merge pull request #270 from Icinga:fix/framework_root_folder_lookup
Fix: Framework root folder lookup Fixes `Icinga PowerShell Framework` root folder lookup, in case the module was installed with PowerShell gallery, which creates version folders for each installed version
2 parents 6edd99c + dfda915 commit 212a80c

9 files changed

+21
-11
lines changed

doc/31-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
2929

3030
* [#231](https://github.com/Icinga/icinga-powershell-framework/issues/231) Fixes error while using Icinga Director Self-Service API, in case the host or host API key was deleted inside the Icinga Director and the installation wizard was called with the correct template key, while the old host key was still present inside the Icinga for Windows configuration
3131
* [#232](https://github.com/Icinga/icinga-powershell-framework/pull/232) Fixes wrong encoding while using REST-Api checks experimental feature, and now forces UTF8
32+
* [#237](https://github.com/Icinga/icinga-powershell-framework/issues/237) Fixes `Icinga PowerShell Framework` root folder lookup, in case the module was installed with PowerShell gallery, which creates version folders for each installed version
3233
* [#240](https://github.com/Icinga/icinga-powershell-framework/pull/240) While filtering for certain services with `Get-IcingaServices`, there were some attributes missing from the collection. These are now added resulting in always correct output data.
3334
* [#245](https://github.com/Icinga/icinga-powershell-framework/pull/245) Fixes loading of `.pfx` certificates by properly checking the file type
3435
* [#265](https://github.com/Icinga/icinga-powershell-framework/pull/265) Fixes `Test-Numeric` to now accept negative numeric values and als fixes errors, causing `.` to be allowed multiple times. `ConvertFrom-TimeSpan` now properly prints on negative values if the time provided is positive or negative and also prints microseconds as `us` in case the value is loer than `1ms`

icinga-powershell-framework.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
'Get-IcingaCacheDir',
4949
'Get-IcingaPowerShellConfigDir',
5050
'Get-IcingaFrameworkRootPath',
51+
'Get-IcingaForWindowsRootPath',
5152
'Get-IcingaPowerShellModuleFile',
5253
'Start-IcingaShellAsUser',
5354
'Get-IcingaPowerShellConfig',

icinga-powershell-framework.psm1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,16 @@ function Get-IcingaPowerShellConfigDir()
319319
function Get-IcingaFrameworkRootPath()
320320
{
321321
[string]$Path = $PSScriptRoot;
322-
[int]$Index = $Path.LastIndexOf('\') + 1;
322+
323+
return $PSScriptRoot;
324+
}
325+
326+
function Get-IcingaForWindowsRootPath()
327+
{
328+
[string]$Path = $PSScriptRoot;
329+
[int]$Index = $Path.LastIndexOf('icinga-powershell-framework');
323330
$Path = $Path.Substring(0, $Index);
331+
324332
return $Path;
325333
}
326334

@@ -340,7 +348,7 @@ function Invoke-IcingaCommand()
340348
);
341349

342350
Import-LocalizedData `
343-
-BaseDirectory (Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath 'icinga-powershell-framework') `
351+
-BaseDirectory (Get-IcingaFrameworkRootPath) `
344352
-FileName 'icinga-powershell-framework.psd1' `
345353
-BindingVariable IcingaFrameworkData;
346354

lib/core/framework/Get-IcingaPowerShellModuleArchive.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function Get-IcingaPowerShellModuleArchive()
9191
'Version' = $Tag;
9292
'Directory' = '';
9393
'Archive' = '';
94-
'ModuleRoot' = (Get-IcingaFrameworkRootPath);
94+
'ModuleRoot' = (Get-IcingaForWindowsRootPath);
9595
'Installed' = $FALSE;
9696
};
9797
}
@@ -107,7 +107,7 @@ function Get-IcingaPowerShellModuleArchive()
107107
'Version' = $Tag;
108108
'Directory' = '';
109109
'Archive' = '';
110-
'ModuleRoot' = (Get-IcingaFrameworkRootPath);
110+
'ModuleRoot' = (Get-IcingaForWindowsRootPath);
111111
'Installed' = $FALSE;
112112
};
113113
}
@@ -131,7 +131,7 @@ function Get-IcingaPowerShellModuleArchive()
131131
'Version' = $Tag;
132132
'Directory' = $DownloadDirectory;
133133
'Archive' = $DownloadDestination;
134-
'ModuleRoot' = (Get-IcingaFrameworkRootPath);
134+
'ModuleRoot' = (Get-IcingaForWindowsRootPath);
135135
'Installed' = $TRUE;
136136
};
137137
}

lib/core/framework/Publish-IcingaPluginConfiguration.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function Publish-IcingaPluginConfiguration()
4545
}
4646

4747
if ([string]::IsNullOrEmpty($ComponentPath)) {
48-
$ComponentPath = Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath ([string]::Format('icinga-powershell-{0}', $ComponentName));
48+
$ComponentPath = Join-Path -Path (Get-IcingaForWindowsRootPath) -ChildPath ([string]::Format('icinga-powershell-{0}', $ComponentName));
4949
}
5050

5151
if ((Test-Path $ComponentPath) -eq $FALSE) {

lib/core/framework/Uninstall-IcingaForWindows.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ function Uninstall-IcingaForWindows()
4040

4141
$CurrentLocation = Get-Location;
4242

43-
if ($CurrentLocation -eq (Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath 'icinga-powershell-framework')) {
44-
Set-Location -Path (Get-IcingaFrameworkRootPath);
43+
if ($CurrentLocation -eq (Get-IcingaFrameworkRootPath)) {
44+
Set-Location -Path (Get-IcingaForWindowsRootPath);
4545
}
4646

4747
Write-IcingaConsoleNotice 'Uninstalling Icinga for Windows from this host';

lib/core/framework/Uninstall-IcingaFrameworkComponent.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function Uninstall-IcingaFrameworkComponent()
2424
[string]$Name = ''
2525
);
2626

27-
$ModuleBase = Get-IcingaFrameworkRootPath;
27+
$ModuleBase = Get-IcingaForWindowsRootPath;
2828
$UninstallComponent = [string]::Format('icinga-powershell-{0}', $Name);
2929
$UninstallPath = Join-Path -Path $ModuleBase -ChildPath $UninstallComponent;
3030

lib/core/installer/menu/manage/framework/backgrounddaemons/Show-IcingaForWindowsManagementConsoleRegisterBackgroundDaemons.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function Show-IcingaForWindowsManagementConsoleRegisterBackgroundDaemons()
2424

2525
$ModuleInfo = $null;
2626

27-
Import-LocalizedData -BaseDirectory (Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath $module.Name) -FileName ([string]::Format('{0}.psd1', $module.Name)) -BindingVariable ModuleInfo -ErrorAction SilentlyContinue;
27+
Import-LocalizedData -BaseDirectory (Join-Path -Path (Get-IcingaForWindowsRootPath) -ChildPath $module.Name) -FileName ([string]::Format('{0}.psd1', $module.Name)) -BindingVariable ModuleInfo -ErrorAction SilentlyContinue;
2828

2929
if ($null -eq $ModuleInfo -Or $null -eq $ModuleInfo.PrivateData -Or $null -eq $ModuleInfo.PrivateData.Type -Or ([string]::IsNullOrEmpty($ModuleInfo.PrivateData.Type)) -Or $ModuleInfo.PrivateData.Type -ne 'daemon' -Or $null -eq $ModuleInfo.PrivateData.Function -Or ([string]::IsNullOrEmpty($ModuleInfo.PrivateData.Function))) {
3030
continue;

lib/core/tools/Write-IcingaConsoleHeader.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function Write-IcingaConsoleHeader()
1010
[array]$TableHeader = @();
1111

1212
Import-LocalizedData `
13-
-BaseDirectory (Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath 'icinga-powershell-framework') `
13+
-BaseDirectory (Get-IcingaFrameworkRootPath) `
1414
-FileName 'icinga-powershell-framework.psd1' `
1515
-BindingVariable IcingaFrameworkData;
1616

0 commit comments

Comments
 (0)