From dfda9154e1fd038082a883c3c13f96726c08490c Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Mon, 31 May 2021 17:02:46 +0200 Subject: [PATCH] Fix Framework root folder lookup --- doc/31-Changelog.md | 1 + icinga-powershell-framework.psd1 | 1 + icinga-powershell-framework.psm1 | 12 ++++++++++-- .../framework/Get-IcingaPowerShellModuleArchive.psm1 | 6 +++--- .../framework/Publish-IcingaPluginConfiguration.psm1 | 2 +- lib/core/framework/Uninstall-IcingaForWindows.psm1 | 4 ++-- .../Uninstall-IcingaFrameworkComponent.psm1 | 2 +- ...wsManagementConsoleRegisterBackgroundDaemons.psm1 | 2 +- lib/core/tools/Write-IcingaConsoleHeader.psm1 | 2 +- 9 files changed, 21 insertions(+), 11 deletions(-) diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index a05050c..09c8d6a 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -29,6 +29,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#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 * [#232](https://github.com/Icinga/icinga-powershell-framework/pull/232) Fixes wrong encoding while using REST-Api checks experimental feature, and now forces UTF8 +* [#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 * [#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. * [#245](https://github.com/Icinga/icinga-powershell-framework/pull/245) Fixes loading of `.pfx` certificates by properly checking the file type * [#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` diff --git a/icinga-powershell-framework.psd1 b/icinga-powershell-framework.psd1 index bfcfe24..43a59a1 100644 --- a/icinga-powershell-framework.psd1 +++ b/icinga-powershell-framework.psd1 @@ -48,6 +48,7 @@ 'Get-IcingaCacheDir', 'Get-IcingaPowerShellConfigDir', 'Get-IcingaFrameworkRootPath', + 'Get-IcingaForWindowsRootPath', 'Get-IcingaPowerShellModuleFile', 'Start-IcingaShellAsUser', 'Get-IcingaPowerShellConfig', diff --git a/icinga-powershell-framework.psm1 b/icinga-powershell-framework.psm1 index 0f81452..502fd31 100644 --- a/icinga-powershell-framework.psm1 +++ b/icinga-powershell-framework.psm1 @@ -319,8 +319,16 @@ function Get-IcingaPowerShellConfigDir() function Get-IcingaFrameworkRootPath() { [string]$Path = $PSScriptRoot; - [int]$Index = $Path.LastIndexOf('\') + 1; + + return $PSScriptRoot; +} + +function Get-IcingaForWindowsRootPath() +{ + [string]$Path = $PSScriptRoot; + [int]$Index = $Path.LastIndexOf('icinga-powershell-framework'); $Path = $Path.Substring(0, $Index); + return $Path; } @@ -340,7 +348,7 @@ function Invoke-IcingaCommand() ); Import-LocalizedData ` - -BaseDirectory (Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath 'icinga-powershell-framework') ` + -BaseDirectory (Get-IcingaFrameworkRootPath) ` -FileName 'icinga-powershell-framework.psd1' ` -BindingVariable IcingaFrameworkData; diff --git a/lib/core/framework/Get-IcingaPowerShellModuleArchive.psm1 b/lib/core/framework/Get-IcingaPowerShellModuleArchive.psm1 index 1f43ebd..b67db76 100644 --- a/lib/core/framework/Get-IcingaPowerShellModuleArchive.psm1 +++ b/lib/core/framework/Get-IcingaPowerShellModuleArchive.psm1 @@ -91,7 +91,7 @@ function Get-IcingaPowerShellModuleArchive() 'Version' = $Tag; 'Directory' = ''; 'Archive' = ''; - 'ModuleRoot' = (Get-IcingaFrameworkRootPath); + 'ModuleRoot' = (Get-IcingaForWindowsRootPath); 'Installed' = $FALSE; }; } @@ -107,7 +107,7 @@ function Get-IcingaPowerShellModuleArchive() 'Version' = $Tag; 'Directory' = ''; 'Archive' = ''; - 'ModuleRoot' = (Get-IcingaFrameworkRootPath); + 'ModuleRoot' = (Get-IcingaForWindowsRootPath); 'Installed' = $FALSE; }; } @@ -131,7 +131,7 @@ function Get-IcingaPowerShellModuleArchive() 'Version' = $Tag; 'Directory' = $DownloadDirectory; 'Archive' = $DownloadDestination; - 'ModuleRoot' = (Get-IcingaFrameworkRootPath); + 'ModuleRoot' = (Get-IcingaForWindowsRootPath); 'Installed' = $TRUE; }; } diff --git a/lib/core/framework/Publish-IcingaPluginConfiguration.psm1 b/lib/core/framework/Publish-IcingaPluginConfiguration.psm1 index 49c107b..2966a7e 100644 --- a/lib/core/framework/Publish-IcingaPluginConfiguration.psm1 +++ b/lib/core/framework/Publish-IcingaPluginConfiguration.psm1 @@ -45,7 +45,7 @@ function Publish-IcingaPluginConfiguration() } if ([string]::IsNullOrEmpty($ComponentPath)) { - $ComponentPath = Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath ([string]::Format('icinga-powershell-{0}', $ComponentName)); + $ComponentPath = Join-Path -Path (Get-IcingaForWindowsRootPath) -ChildPath ([string]::Format('icinga-powershell-{0}', $ComponentName)); } if ((Test-Path $ComponentPath) -eq $FALSE) { diff --git a/lib/core/framework/Uninstall-IcingaForWindows.psm1 b/lib/core/framework/Uninstall-IcingaForWindows.psm1 index a1b77f0..bf544fc 100644 --- a/lib/core/framework/Uninstall-IcingaForWindows.psm1 +++ b/lib/core/framework/Uninstall-IcingaForWindows.psm1 @@ -40,8 +40,8 @@ function Uninstall-IcingaForWindows() $CurrentLocation = Get-Location; - if ($CurrentLocation -eq (Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath 'icinga-powershell-framework')) { - Set-Location -Path (Get-IcingaFrameworkRootPath); + if ($CurrentLocation -eq (Get-IcingaFrameworkRootPath)) { + Set-Location -Path (Get-IcingaForWindowsRootPath); } Write-IcingaConsoleNotice 'Uninstalling Icinga for Windows from this host'; diff --git a/lib/core/framework/Uninstall-IcingaFrameworkComponent.psm1 b/lib/core/framework/Uninstall-IcingaFrameworkComponent.psm1 index e88540f..f514a8f 100644 --- a/lib/core/framework/Uninstall-IcingaFrameworkComponent.psm1 +++ b/lib/core/framework/Uninstall-IcingaFrameworkComponent.psm1 @@ -24,7 +24,7 @@ function Uninstall-IcingaFrameworkComponent() [string]$Name = '' ); - $ModuleBase = Get-IcingaFrameworkRootPath; + $ModuleBase = Get-IcingaForWindowsRootPath; $UninstallComponent = [string]::Format('icinga-powershell-{0}', $Name); $UninstallPath = Join-Path -Path $ModuleBase -ChildPath $UninstallComponent; diff --git a/lib/core/installer/menu/manage/framework/backgrounddaemons/Show-IcingaForWindowsManagementConsoleRegisterBackgroundDaemons.psm1 b/lib/core/installer/menu/manage/framework/backgrounddaemons/Show-IcingaForWindowsManagementConsoleRegisterBackgroundDaemons.psm1 index ab296f0..308188d 100644 --- a/lib/core/installer/menu/manage/framework/backgrounddaemons/Show-IcingaForWindowsManagementConsoleRegisterBackgroundDaemons.psm1 +++ b/lib/core/installer/menu/manage/framework/backgrounddaemons/Show-IcingaForWindowsManagementConsoleRegisterBackgroundDaemons.psm1 @@ -24,7 +24,7 @@ function Show-IcingaForWindowsManagementConsoleRegisterBackgroundDaemons() $ModuleInfo = $null; - Import-LocalizedData -BaseDirectory (Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath $module.Name) -FileName ([string]::Format('{0}.psd1', $module.Name)) -BindingVariable ModuleInfo -ErrorAction SilentlyContinue; + Import-LocalizedData -BaseDirectory (Join-Path -Path (Get-IcingaForWindowsRootPath) -ChildPath $module.Name) -FileName ([string]::Format('{0}.psd1', $module.Name)) -BindingVariable ModuleInfo -ErrorAction SilentlyContinue; 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))) { continue; diff --git a/lib/core/tools/Write-IcingaConsoleHeader.psm1 b/lib/core/tools/Write-IcingaConsoleHeader.psm1 index 782b467..c91644c 100644 --- a/lib/core/tools/Write-IcingaConsoleHeader.psm1 +++ b/lib/core/tools/Write-IcingaConsoleHeader.psm1 @@ -10,7 +10,7 @@ function Write-IcingaConsoleHeader() [array]$TableHeader = @(); Import-LocalizedData ` - -BaseDirectory (Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath 'icinga-powershell-framework') ` + -BaseDirectory (Get-IcingaFrameworkRootPath) ` -FileName 'icinga-powershell-framework.psd1' ` -BindingVariable IcingaFrameworkData;