From 7861ebf5653796f190b40a3b0afa04fb2c23e358 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Thu, 19 Aug 2021 09:24:46 +0200 Subject: [PATCH] Adds repo management to mmc --- .../manage/framework/ManageFramework.psm1 | 5 ++ .../repository/ManageIcingaRepo.psm1 | 17 +++++++ .../repository/SetIcingaSnapshotRepo.psm1 | 46 +++++++++++++++++++ .../repository/SetIcingaStableRepo.psm1 | 46 +++++++++++++++++++ lib/core/installer/tools/AddConfigEntry.psm1 | 7 ++- .../installer/tools/ShowInstallerMenu.psm1 | 6 ++- 6 files changed, 123 insertions(+), 4 deletions(-) create mode 100644 lib/core/installer/menu/manage/framework/repository/ManageIcingaRepo.psm1 create mode 100644 lib/core/installer/menu/manage/framework/repository/SetIcingaSnapshotRepo.psm1 create mode 100644 lib/core/installer/menu/manage/framework/repository/SetIcingaStableRepo.psm1 diff --git a/lib/core/installer/menu/manage/framework/ManageFramework.psm1 b/lib/core/installer/menu/manage/framework/ManageFramework.psm1 index 8813980..525d0c5 100644 --- a/lib/core/installer/menu/manage/framework/ManageFramework.psm1 +++ b/lib/core/installer/menu/manage/framework/ManageFramework.psm1 @@ -18,6 +18,11 @@ function Show-IcingaForWindowsManagementConsoleManageFramework() 'Help' = 'Allows you to manage Icinga for Windows background daemons'; 'Disabled' = ($null -eq (Get-Service 'icingapowershell' -ErrorAction SilentlyContinue)); }, + @{ + 'Caption' = 'Manage Icinga Repositories'; + 'Command' = 'Show-IcingaForWindowsManagementConsoleManageIcingaRepositories'; + 'Help' = 'Allows you to manage Icinga for Windows repositories'; + }, @{ 'Caption' = ([string]::Format('Framework Debug Mode: {0}', (& { if ($FrameworkDebug) { 'Enabled' } else { 'Disabled' } } ))); 'Command' = 'Show-IcingaForWindowsManagementConsoleManageFramework'; diff --git a/lib/core/installer/menu/manage/framework/repository/ManageIcingaRepo.psm1 b/lib/core/installer/menu/manage/framework/repository/ManageIcingaRepo.psm1 new file mode 100644 index 0000000..cf9ce18 --- /dev/null +++ b/lib/core/installer/menu/manage/framework/repository/ManageIcingaRepo.psm1 @@ -0,0 +1,17 @@ +function Show-IcingaForWindowsManagementConsoleManageIcingaRepositories() +{ + Show-IcingaForWindowsInstallerMenu ` + -Header 'Manage Icinga for Windows Repositories:' ` + -Entries @( + @{ + 'Caption' = 'Set Icinga Repository "Icinga Stable"'; + 'Command' = 'Show-IcingaForWindowsManagementConsoleSetIcingaStableRepositories'; + 'Help' = 'Allows to set the repository URL for the "Icinga Stable" repository and will override it, if it already exist'; + }, + @{ + 'Caption' = 'Set Icinga Repository "Icinga Snapshot"'; + 'Command' = 'Show-IcingaForWindowsManagementConsoleSetIcingaSnapshotRepositories'; + 'Help' = 'Allows to set the repository URL for the "Icinga Snapshot" repository and will override it, if it already exist'; + } + ); +} diff --git a/lib/core/installer/menu/manage/framework/repository/SetIcingaSnapshotRepo.psm1 b/lib/core/installer/menu/manage/framework/repository/SetIcingaSnapshotRepo.psm1 new file mode 100644 index 0000000..542117a --- /dev/null +++ b/lib/core/installer/menu/manage/framework/repository/SetIcingaSnapshotRepo.psm1 @@ -0,0 +1,46 @@ +function Show-IcingaForWindowsManagementConsoleSetIcingaSnapshotRepositories() +{ + param ( + [array]$Value = @( 'https://packages.icinga.com/IcingaForWindows/snapshot/ifw.repo.json' ), + [string]$DefaultInput = 'c', + [switch]$JumpToSummary = $FALSE, + [switch]$Automated = $FALSE, + [switch]$Advanced = $FALSE + ); + + $CurrentRepositories = Get-IcingaRepositories; + + foreach ($entry in $CurrentRepositories) { + if ($entry.Name -eq 'Icinga Snapshot') { + $Value = $entry.Value.RemotePath; + break; + } + } + + Show-IcingaForWindowsInstallerMenu ` + -Header 'Please enter the URL/Path for the location of your "Icinga Snapshot" Repository:' ` + -Entries @( + @{ + 'Command' = 'Show-IcingaForWindowsManagementConsoleManageIcingaRepositories'; + 'Help' = 'Sets the current repository for Icinga for Windows as "Icinga Snapshot"'; + } + ) ` + -DefaultIndex $DefaultInput ` + -AddConfig ` + -ConfigLimit 1 ` + -DefaultValues $Value ` + -ContinueFirstValue ` + -MandatoryValue ` + -ConfigElement ` + -HiddenConfigElement ` + -Advanced ` + -NoConfigSwap; + + if (Test-IcingaForWindowsManagementConsoleContinue) { + $UserInput = Get-IcingaForWindowsInstallerValuesFromStep -InstallerStep 'Show-IcingaForWindowsManagementConsoleSetIcingaSnapshotRepositories'; + + Add-IcingaRepository -Name 'Icinga Snapshot' -RemotePath $UserInput -Force; + + $global:Icinga.InstallWizard.LastNotice = ([string]::Format('Updated repository "Icinga Snapshot" with URL "{0}"', $UserInput)); + } +} diff --git a/lib/core/installer/menu/manage/framework/repository/SetIcingaStableRepo.psm1 b/lib/core/installer/menu/manage/framework/repository/SetIcingaStableRepo.psm1 new file mode 100644 index 0000000..86908ae --- /dev/null +++ b/lib/core/installer/menu/manage/framework/repository/SetIcingaStableRepo.psm1 @@ -0,0 +1,46 @@ +function Show-IcingaForWindowsManagementConsoleSetIcingaStableRepositories() +{ + param ( + [array]$Value = @( 'https://packages.icinga.com/IcingaForWindows/stable/ifw.repo.json' ), + [string]$DefaultInput = 'c', + [switch]$JumpToSummary = $FALSE, + [switch]$Automated = $FALSE, + [switch]$Advanced = $FALSE + ); + + $CurrentRepositories = Get-IcingaRepositories; + + foreach ($entry in $CurrentRepositories) { + if ($entry.Name -eq 'Icinga Stable') { + $Value = $entry.Value.RemotePath; + break; + } + } + + Show-IcingaForWindowsInstallerMenu ` + -Header 'Please enter the URL/Path for the location of your "Icinga Stable" Repository:' ` + -Entries @( + @{ + 'Command' = 'Show-IcingaForWindowsManagementConsoleManageIcingaRepositories'; + 'Help' = 'Sets the current repository for Icinga for Windows as "Icinga Stable"'; + } + ) ` + -DefaultIndex $DefaultInput ` + -AddConfig ` + -ConfigLimit 1 ` + -DefaultValues $Value ` + -ContinueFirstValue ` + -MandatoryValue ` + -ConfigElement ` + -HiddenConfigElement ` + -Advanced ` + -NoConfigSwap; + + if (Test-IcingaForWindowsManagementConsoleContinue) { + $UserInput = Get-IcingaForWindowsInstallerValuesFromStep -InstallerStep 'Show-IcingaForWindowsManagementConsoleSetIcingaStableRepositories'; + + Add-IcingaRepository -Name 'Icinga Stable' -RemotePath $UserInput -Force; + + $global:Icinga.InstallWizard.LastNotice = ([string]::Format('Updated repository "Icinga Stable" with URL "{0}"', $UserInput)); + } +} diff --git a/lib/core/installer/tools/AddConfigEntry.psm1 b/lib/core/installer/tools/AddConfigEntry.psm1 index 3532b6c..811a779 100644 --- a/lib/core/installer/tools/AddConfigEntry.psm1 +++ b/lib/core/installer/tools/AddConfigEntry.psm1 @@ -8,7 +8,8 @@ function Add-IcingaForWindowsInstallerConfigEntry() [switch]$OverwriteValues = $FALSE, [string]$OverwriteMenu = '', [string]$OverwriteParent = '', - [switch]$Advanced = $FALSE + [switch]$Advanced = $FALSE, + [switch]$NoConfigSwap = $FALSE ); if ([string]::IsNullOrEmpty($OverwriteMenu) -eq $FALSE) { @@ -55,5 +56,7 @@ function Add-IcingaForWindowsInstallerConfigEntry() $global:Icinga.InstallWizard.Config[$Step].Modified = $TRUE; } - Write-IcingaforWindowsManagementConsoleConfigSwap -Config $global:Icinga.InstallWizard.Config; + if ($NoConfigSwap -eq $FALSE) { + Write-IcingaforWindowsManagementConsoleConfigSwap -Config $global:Icinga.InstallWizard.Config; + } } diff --git a/lib/core/installer/tools/ShowInstallerMenu.psm1 b/lib/core/installer/tools/ShowInstallerMenu.psm1 index abcf2d1..f2b4b34 100644 --- a/lib/core/installer/tools/ShowInstallerMenu.psm1 +++ b/lib/core/installer/tools/ShowInstallerMenu.psm1 @@ -18,7 +18,8 @@ function Show-IcingaForWindowsInstallerMenu() [switch]$ReadOnly = $FALSE, [switch]$Automated = $FALSE, [switch]$Advanced = $FALSE, - [switch]$PlainTextOutput = $FALSE + [switch]$PlainTextOutput = $FALSE, + [switch]$NoConfigSwap = $FALSE ); if ((Test-IcingaForWindowsInstallationHeaderPrint) -eq $FALSE -And (Get-IcingaFrameworkDebugMode) -eq $FALSE) { @@ -413,7 +414,8 @@ function Show-IcingaForWindowsInstallerMenu() -Values $StoredValues ` -Hidden:$HiddenConfigElement ` -PasswordInput:$PasswordInput ` - -Advanced:$Advanced; + -Advanced:$Advanced ` + -NoConfigSwap:$NoConfigSwap; } # Reset Help View