Improves setup wizard usability and fixes Director overriding

This commit is contained in:
Lord Hepipud 2019-11-03 09:46:27 +01:00
parent 9d8a790e63
commit 0dafbb6e07
2 changed files with 221 additions and 124 deletions

View file

@ -2,22 +2,20 @@ function Start-IcingaAgentDirectorWizard()
{ {
param( param(
[string]$DirectorUrl, [string]$DirectorUrl,
[string]$SelfServiceAPIKey, [string]$SelfServiceAPIKey = $null,
$OverrideDirectorVars = $null, $OverrideDirectorVars = $null,
$InstallFrameworkService = $null,
$ServiceDirectory = $null,
$ServiceBin = $null,
[bool]$RunInstaller = $FALSE [bool]$RunInstaller = $FALSE
); );
[hashtable]$DirectorOverrideArgs = @{}
if ([string]::IsNullOrEmpty($DirectorUrl)) { if ([string]::IsNullOrEmpty($DirectorUrl)) {
$DirectorUrl = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify the Url pointing to your Icinga Director' -Default 'v').answer; $DirectorUrl = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify the Url pointing to your Icinga Director' -Default 'v').answer;
} }
[bool]$HostKnown = $FALSE; [bool]$HostKnown = $FALSE;
[string]$TemplateKey = $SelfServiceAPIKey; [string]$TemplateKey = $SelfServiceAPIKey;
if ($null -eq $OverrideDirectorVars) { if ($null -eq $OverrideDirectorVars -And $RunInstaller -eq $FALSE) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to manually override arguments provided by the Director API?' -Default 'n').result -eq 0) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to manually override arguments provided by the Director API?' -Default 'n').result -eq 0) {
$OverrideDirectorVars = $TRUE; $OverrideDirectorVars = $TRUE;
} else{ } else{
@ -43,9 +41,13 @@ function Start-IcingaAgentDirectorWizard()
$Arguments = Get-IcingaDirectorSelfServiceConfig -DirectorUrl $DirectorUrl -ApiKey $SelfServiceAPIKey; $Arguments = Get-IcingaDirectorSelfServiceConfig -DirectorUrl $DirectorUrl -ApiKey $SelfServiceAPIKey;
$Arguments = Convert-IcingaDirectorSelfServiceArguments -JsonInput $Arguments; $Arguments = Convert-IcingaDirectorSelfServiceArguments -JsonInput $Arguments;
if ($OverrideDirectorVars -eq $TRUE) { if ($OverrideDirectorVars -eq $TRUE -And -Not $RunInstaller) {
$NewArguments = Start-IcingaDirectorAPIArgumentOverride -Arguments $Arguments; $DirectorOverrideArgs = Start-IcingaDirectorAPIArgumentOverride -Arguments $Arguments;
$Arguments = $NewArguments; foreach ($entry in $DirectorOverrideArgs.Keys) {
if ($Arguments.ContainsKey($entry)) {
$Arguments[$entry] = $DirectorOverrideArgs[$entry];
}
}
} }
if ($HostKnown -eq $FALSE) { if ($HostKnown -eq $FALSE) {
@ -62,48 +64,29 @@ function Start-IcingaAgentDirectorWizard()
$Arguments = Get-IcingaDirectorSelfServiceConfig -DirectorUrl $DirectorUrl -ApiKey $SelfServiceAPIKey; $Arguments = Get-IcingaDirectorSelfServiceConfig -DirectorUrl $DirectorUrl -ApiKey $SelfServiceAPIKey;
$Arguments = Convert-IcingaDirectorSelfServiceArguments -JsonInput $Arguments; $Arguments = Convert-IcingaDirectorSelfServiceArguments -JsonInput $Arguments;
if ($OverrideDirectorVars -eq $TRUE) { if ($OverrideDirectorVars -eq $TRUE -And -Not $RunInstaller) {
$NewArguments = Start-IcingaDirectorAPIArgumentOverride -Arguments $Arguments; $DirectorOverrideArgs = Start-IcingaDirectorAPIArgumentOverride -Arguments $Arguments;
$Arguments = $NewArguments; foreach ($entry in $DirectorOverrideArgs.Keys) {
if ($Arguments.ContainsKey($entry)) {
$Arguments[$entry] = $DirectorOverrideArgs[$entry];
}
}
} }
} }
$Arguments.Add( $DirectorOverrideArgs.Add(
'UseDirectorSelfService', $TRUE
);
$Arguments.Add(
'OverrideDirectorVars', $FALSE
);
$Arguments.Add(
'DirectorUrl', $DirectorUrl 'DirectorUrl', $DirectorUrl
); );
$Arguments.Add( if ([string]::IsNullOrEmpty($TemplateKey) -eq $FALSE) {
'SelfServiceAPIKey', $TemplateKey $DirectorOverrideArgs.Add(
); 'SelfServiceAPIKey', $TemplateKey
$Arguments.Add( );
'SkipDirectorQuestion', $TRUE
);
$Arguments.Add(
'InstallFrameworkService', $InstallFrameworkService
);
$Arguments.Add(
'ServiceDirectory', $ServiceDirectory
);
$Arguments.Add(
'ServiceBin', $ServiceBin
);
$Arguments.Add(
'ProvidedArgs', $Arguments
);
if ($RunInstaller) {
Start-IcingaAgentInstallWizard @Arguments;
return;
} }
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'The Director wizard is complete. Do you want to start the installation now?' -Default 'y').result -eq 1) { return @{
Start-IcingaAgentInstallWizard @Arguments; 'Arguments' = $Arguments;
} 'Overrides' = $DirectorOverrideArgs;
};
} }
function Start-IcingaDirectorAPIArgumentOverride() function Start-IcingaDirectorAPIArgumentOverride()
@ -118,7 +101,28 @@ function Start-IcingaDirectorAPIArgumentOverride()
foreach ($entry in $Arguments.Keys) { foreach ($entry in $Arguments.Keys) {
$value = (Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Please enter the new value for the argument "{0}"', $entry)) -Default 'v' -DefaultInput $Arguments[$entry]).answer; $value = (Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Please enter the new value for the argument "{0}"', $entry)) -Default 'v' -DefaultInput $Arguments[$entry]).answer;
$NewArguments.Add($entry, $value); if ($Arguments[$entry] -is [array]) {
if ([string]::IsNullOrEmpty($value) -eq $FALSE) {
[array]$tmpArray = $value.Split(',');
if ($null -ne (Compare-Object -ReferenceObject $Arguments[$entry] -DifferenceObject $tmpArray)) {
$NewArguments.Add(
$entry,
([string]::Join(',', $tmpArray))
);
}
}
continue;
} elseif ($Arguments[$entry] -is [bool]) {
if ($value -eq 'true' -or $value -eq 'y' -or $value -eq '1' -or $value -eq 'yes' -or $value -eq 1) {
$value = 1;
} else {
$value = 0;
}
}
if ($Arguments[$entry] -ne $value) {
$NewArguments.Add($entry, $value);
}
} }
return $NewArguments; return $NewArguments;

View file

@ -2,15 +2,15 @@ function Start-IcingaAgentInstallWizard()
{ {
param( param(
[string]$Hostname, [string]$Hostname,
[switch]$AutoUseFQDN = $FALSE, $AutoUseFQDN,
[switch]$AutoUseHostname = $FALSE, $AutoUseHostname,
[switch]$LowerCase = $FALSE, $LowerCase,
[switch]$UpperCase = $FALSE, $UpperCase,
$AddDirectorGlobal = $null, $AddDirectorGlobal = $null,
$AddGlobalTemplates = $null, $AddGlobalTemplates = $null,
[string]$PackageSource, [string]$PackageSource,
[string]$AgentVersion, [string]$AgentVersion,
[switch]$AllowVersionChanges = $FALSE, $AllowVersionChanges,
$UpdateAgent = $null, $UpdateAgent = $null,
$AcceptConnections = $null, $AcceptConnections = $null,
[array]$Endpoints = @(), [array]$Endpoints = @(),
@ -20,7 +20,8 @@ function Start-IcingaAgentInstallWizard()
[string]$CAEndpoint, [string]$CAEndpoint,
$CAPort = $null, $CAPort = $null,
[string]$Ticket, [string]$Ticket,
[string]$CAFile, [string]$CAFile = $null,
$EmptyCA = $null,
[switch]$RunInstaller, [switch]$RunInstaller,
[switch]$Reconfigure, [switch]$Reconfigure,
[string]$ServiceUser, [string]$ServiceUser,
@ -32,9 +33,8 @@ function Start-IcingaAgentInstallWizard()
$UseDirectorSelfService = $null, $UseDirectorSelfService = $null,
[bool]$SkipDirectorQuestion = $FALSE, [bool]$SkipDirectorQuestion = $FALSE,
[string]$DirectorUrl, [string]$DirectorUrl,
[string]$SelfServiceAPIKey, [string]$SelfServiceAPIKey = $null,
$OverrideDirectorVars = $null, $OverrideDirectorVars = $null
[hashtable]$ProvidedArgs = @{}
); );
[array]$InstallerArguments = @(); [array]$InstallerArguments = @();
@ -50,34 +50,98 @@ function Start-IcingaAgentInstallWizard()
} }
} }
if ($UseDirectorSelfService) { if ($UseDirectorSelfService) {
$InstallerArguments += '-UseDirectorSelfService 1'; $InstallerArguments += '-UseDirectorSelfService 1';
Start-IcingaAgentDirectorWizard ` $DirectorArgs = Start-IcingaAgentDirectorWizard `
-DirectorUrl $DirectorUrl ` -DirectorUrl $DirectorUrl `
-SelfServiceAPIKey $SelfServiceAPIKey ` -SelfServiceAPIKey $SelfServiceAPIKey `
-OverrideDirectorVars $OverrideDirectorVars ` -OverrideDirectorVars $OverrideDirectorVars `
-InstallFrameworkService $InstallFrameworkService `
-ServiceDirectory $ServiceDirectory `
-ServiceBin $ServiceBin `
-RunInstaller $RunInstaller; -RunInstaller $RunInstaller;
return;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'DirectorUrl' -Value $DirectorUrl -InstallerArguments $InstallerArguments;
$DirectorUrl = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'SelfServiceAPIKey' -Value $SelfServiceAPIKey -InstallerArguments $InstallerArguments -Default $null;
if ([string]::IsNullOrEmpty($Result.Value) -eq $FALSE) {
Write-Host 'Setting self service arg'
$SelfServiceAPIKey = $Result.Value;
$InstallerArguments = $Result.Args;
}
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'PackageSource' -Value $PackageSource -InstallerArguments $InstallerArguments;
$PackageSource = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'AgentVersion' -Value $AgentVersion -InstallerArguments $InstallerArguments;
$AgentVersion = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'CAPort' -Value $CAPort -InstallerArguments $InstallerArguments;
$CAPort = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'AllowVersionChanges' -Value $AllowVersionChanges -InstallerArguments $InstallerArguments;
$AllowVersionChanges = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'GlobalZones' -Value $GlobalZones -InstallerArguments $InstallerArguments;
$GlobalZones = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'ParentZone' -Value $ParentZone -InstallerArguments $InstallerArguments;
$ParentZone = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'CAEndpoint' -Value $CAEndpoint -InstallerArguments $InstallerArguments;
$CAEndpoint = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'Endpoints' -Value $Endpoints -InstallerArguments $InstallerArguments;
$Endpoints = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'AddFirewallRule' -Value $AddFirewallRule -InstallerArguments $InstallerArguments;
$AddFirewallRule = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'AcceptConnections' -Value $AcceptConnections -InstallerArguments $InstallerArguments;
$AcceptConnections = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'ServiceUser' -Value $ServiceUser -InstallerArguments $InstallerArguments;
$ServiceUser = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'UpdateAgent' -Value $UpdateAgent -InstallerArguments $InstallerArguments;
$UpdateAgent = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'AddDirectorGlobal' -Value $AddDirectorGlobal -InstallerArguments $InstallerArguments;
$AddDirectorGlobal = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'AddGlobalTemplates' -Value $AddGlobalTemplates -InstallerArguments $InstallerArguments;
$AddGlobalTemplates = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'LowerCase' -Value $LowerCase -Default $FALSE -InstallerArguments $InstallerArguments;
$LowerCase = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'UpperCase' -Value $UpperCase -Default $FALSE -InstallerArguments $InstallerArguments;
$UpperCase = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'AutoUseFQDN' -Value $AutoUseFQDN -Default $FALSE -InstallerArguments $InstallerArguments;
$AutoUseFQDN = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'AutoUseHostname' -Value $AutoUseHostname -Default $FALSE -InstallerArguments $InstallerArguments;
$AutoUseHostname = $Result.Value;
$InstallerArguments = $Result.Args;
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'EndpointConnections' -Value $EndpointConnections -InstallerArguments $InstallerArguments;
$EndpointConnections = $Result.Value;
$InstallerArguments = $Result.Args;
} }
} }
if ([string]::IsNullOrEmpty($Hostname) -And $AutoUseFQDN -eq $FALSE -And $AutoUseHostname -eq $FALSE) { if ([string]::IsNullOrEmpty($Hostname) -And $AutoUseFQDN -eq $FALSE -And $AutoUseHostname -eq $FALSE) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to manually specify a hostname?' -Default 'n').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to manually specify a hostname?' -Default 'n').result -eq 1) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to automatically fetch the hostname with its FQDN?' -Default 'y').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to automatically fetch the hostname with its FQDN?' -Default 'y').result -eq 1) {
$InstallerArguments += '-AutoUseFQDN'; $InstallerArguments += '-AutoUseFQDN 1';
$AutoUseFQDN = $TRUE; $AutoUseFQDN = $TRUE;
} else { } else {
$InstallerArguments += '-AutoUseHostname'; $InstallerArguments += '-AutoUseHostname 1';
$AutoUseHostname = $TRUE; $AutoUseHostname = $TRUE;
} }
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to modify the hostname to only include lower case characters?' -Default 'y').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to modify the hostname to only include lower case characters?' -Default 'y').result -eq 1) {
$InstallerArguments += '-LowerCase'; $InstallerArguments += '-LowerCase 1';
$LowerCase = $TRUE; $LowerCase = $TRUE;
} else { } else {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to modify the hostname to only include upper case characters?' -Default 'n').result -eq 0) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to modify the hostname to only include upper case characters?' -Default 'n').result -eq 0) {
$InstallerArguments += '-UpperCase'; $InstallerArguments += '-UpperCase 1';
$UpperCase = $TRUE; $UpperCase = $TRUE;
} }
} }
@ -130,7 +194,7 @@ function Start-IcingaAgentInstallWizard()
$AgentVersion = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify the version you wish to install ("latest", "snapshot", or a version like "2.11.0")' -Default 'v').answer; $AgentVersion = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify the version you wish to install ("latest", "snapshot", or a version like "2.11.0")' -Default 'v').answer;
$AllowVersionChanges = $TRUE; $AllowVersionChanges = $TRUE;
$InstallerArguments += "-AgentVersion '$AgentVersion'"; $InstallerArguments += "-AgentVersion '$AgentVersion'";
$InstallerArguments += '-AllowVersionChanges'; $InstallerArguments += '-AllowVersionChanges 1';
Write-Host ([string]::Format('Updating/Downgrading Icinga 2 Agent to version: "{0}"', $AgentVersion)); Write-Host ([string]::Format('Updating/Downgrading Icinga 2 Agent to version: "{0}"', $AgentVersion));
} }
@ -194,12 +258,13 @@ function Start-IcingaAgentInstallWizard()
if ($null -eq $AddDirectorGlobal) { if ($null -eq $AddDirectorGlobal) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to add the global zone "director-global"?' -Default 'y').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to add the global zone "director-global"?' -Default 'y').result -eq 1) {
$AddDirectorGlobal = $TRUE; $AddDirectorGlobal = $TRUE;
$InstallerArguments += ("-AddDirectorGlobal 1");
} else { } else {
$AddDirectorGlobal = $FALSE; $AddDirectorGlobal = $FALSE;
$InstallerArguments += ("-AddDirectorGlobal 0");
} }
} }
$InstallerArguments += ("-AddDirectorGlobal $AddDirectorGlobal");
if ($AddDirectorGlobal) { if ($AddDirectorGlobal) {
$GlobalZoneConfig += 'director-global'; $GlobalZoneConfig += 'director-global';
} }
@ -207,12 +272,13 @@ function Start-IcingaAgentInstallWizard()
if ($null -eq $AddGlobalTemplates) { if ($null -eq $AddGlobalTemplates) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to add the global zone "global-templates"?' -Default 'y').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to add the global zone "global-templates"?' -Default 'y').result -eq 1) {
$AddGlobalTemplates = $TRUE; $AddGlobalTemplates = $TRUE;
$InstallerArguments += ("-AddGlobalTemplates 1");
} else { } else {
$AddGlobalTemplates = $FALSE; $AddGlobalTemplates = $FALSE;
$InstallerArguments += ("-AddGlobalTemplates 0");
} }
} }
$InstallerArguments += ("-AddGlobalTemplates $AddGlobalTemplates");
if ($AddGlobalTemplates) { if ($AddGlobalTemplates) {
$GlobalZoneConfig += 'global-templates'; $GlobalZoneConfig += 'global-templates';
} }
@ -233,12 +299,16 @@ function Start-IcingaAgentInstallWizard()
[bool]$CanConnectToParent = $FALSE; [bool]$CanConnectToParent = $FALSE;
if ($AcceptConnections -eq 0) { if ($null -eq $AcceptConnections) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Is this Agent able to connect to its parent node for certificate generation?' -Default 'y').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Is this Agent able to connect to its parent node for certificate generation?' -Default 'y').result -eq 1) {
$CanConnectToParent = $TRUE; $CanConnectToParent = $TRUE;
$InstallerArguments += ("-AcceptConnections 1");
} else {
$InstallerArguments += ("-AcceptConnections 0");
} }
} else { } elseif ($AcceptConnections) {
$CanConnectToParent = $TRUE; $CanConnectToParent = $TRUE;
$InstallerArguments += ("-AcceptConnections 1");
} }
if ($CanConnectToParent) { if ($CanConnectToParent) {
@ -255,11 +325,22 @@ function Start-IcingaAgentInstallWizard()
} }
} }
} else { } else {
if ([string]::IsNullOrEmpty($CAFile)) { if ([string]::IsNullOrEmpty($CAFile) -And $null -eq $EmptyCA) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Is your public Icinga 2 CA (ca.crt) available on a local, network or web share?' -Default 'y').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Is your public Icinga 2 CA (ca.crt) available on a local, network or web share?' -Default 'y').result -eq 1) {
$CAFile = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please provide the full path to your ca.crt file' -Default 'v').answer; $CAFile = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please provide the full path to your ca.crt file' -Default 'v').answer;
$InstallerArguments += "-CAFile $CAFile"; $InstallerArguments += "-CAFile $CAFile";
$InstallerArguments += "-EmptyCA 0";
} else {
$InstallerArguments += "-CAFile ''";
$InstallerArguments += "-EmptyCA 1"
} }
} else {
if ([string]::IsNullOrEmpty($CAFile)) {
$InstallerArguments += "-CAFile ''";
} else {
$InstallerArguments += "-CAFile $CAFile";
}
$InstallerArguments += "-EmptyCA $EmptyCA"
} }
} }
@ -304,60 +385,9 @@ function Start-IcingaAgentInstallWizard()
$InstallerArguments += "-RunInstaller"; $InstallerArguments += "-RunInstaller";
Write-Host 'The wizard is complete. These are the configured settings:'; Write-Host 'The wizard is complete. These are the configured settings:';
foreach ($entry in $ProvidedArgs.Keys) { Write-Host '========'
if ($entry -eq 'ProvidedArgs' -Or $entry -eq 'SkipDirectorQuestion') {
continue;
}
[bool]$SkipArgument = $FALSE;
if ($OverrideDirectorVars -eq $FALSE) {
switch ($entry) {
'InstallFrameworkService' { break; };
'FrameworkServiceUrl' { break; };
'ServiceDirectory' { break; };
'ServiceBin' { break; };
'UseDirectorSelfService' { break; };
'DirectorUrl' { break; };
'SelfServiceAPIKey' { break; };
'OverrideDirectorVars' { break; };
Default {
$SkipArgument = $TRUE;
break;
}
}
if ($SkipArgument) {
continue;
}
}
[bool]$KnownArgument = $FALSE;
foreach ($item in $InstallerArguments) {
if ($item -like "-$entry *" -Or $item -eq "-$entry") {
$KnownArgument = $TRUE;
break;
}
}
if ($KnownArgument) {
continue;
}
$Value = $ProvidedArgs[$entry];
if ($Value -is [System.Object]) {
$Value = [string]::Join(',', $Value);
}
if ($OverrideDirectorVars -eq $FALSE) {
#$ClearedArguments += [string]::Format("-{0} '{1}'", $entry, $Value);
#continue;
}
$InstallerArguments += [string]::Format("-{0} '{1}'", $entry, $Value);
}
Write-Host ($InstallerArguments | Out-String); Write-Host ($InstallerArguments | Out-String);
Write-Host '========'
if (-Not $RunInstaller) { if (-Not $RunInstaller) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Is this configuration correct?' -Default 'y').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Is this configuration correct?' -Default 'y').result -eq 1) {
@ -396,6 +426,69 @@ function Start-IcingaAgentInstallWizard()
} }
} }
function Set-IcingaWizardArgument()
{
param(
[hashtable]$DirectorArgs,
[string]$WizardArg,
$Value,
$Default = $null,
$InstallerArguments
);
if ($DirectorArgs.Overrides.ContainsKey($WizardArg)) {
$Override = $DirectorArgs.Overrides[$WizardArg];
if ($Value -is [array]) {
$Override = [string]::Join(',', $Override);
}
$InstallerArguments += "-$WizardArg $Override";
return @{
'Value' = $Override;
'Args' = $InstallerArguments;
};
}
$RetValue = $null;
if ($DirectorArgs.Arguments.ContainsKey($WizardArg)) {
$RetValue = $DirectorArgs.Arguments[$WizardArg];
if ($Value -is [array]) {
$RetValue = [string]::Join(',', $RetValue);
}
} else {
if ($null -ne $Value -Or [string]::IsNullOrEmpty($Value) -eq $FALSE) {
if ($Value -is [array]) {
$Value = [string]::Join(',', $Value);
}
$InstallerArguments += "-$WizardArg $Value";
return @{
'Value' = $Value;
'Args' = $InstallerArguments;
};
} else {
return @{
'Value' = $Default;
'Args' = $InstallerArguments;
};
}
}
if ([string]::IsNullOrEmpty($Value) -eq $FALSE) {
if ($Value -is [array]) {
$Value = [string]::Join(',', $Value);
}
$InstallerArguments += "-$WizardArg $Value";
return @{
'Value' = $Value;
'Args' = $InstallerArguments;
};
}
return @{
'Value' = $RetValue;
'Args' = $InstallerArguments;
};
}
function Get-IcingaAgentInstallCommand() function Get-IcingaAgentInstallCommand()
{ {
param( param(
@ -411,9 +504,9 @@ function Get-IcingaAgentInstallCommand()
); );
if ($PrintConsole) { if ($PrintConsole) {
Write-Host '####' Write-Host '===='
Write-Host $Installer -ForegroundColor ([System.ConsoleColor]::Cyan); Write-Host $Installer -ForegroundColor ([System.ConsoleColor]::Cyan);
Write-Host '####' Write-Host '===='
} else { } else {
return $Installer; return $Installer;
} }