Improves and standardizes the wizard even further

This commit is contained in:
Lord Hepipud 2020-05-29 14:49:34 +02:00
parent 6e50603b30
commit 6838933bd5
7 changed files with 20 additions and 24 deletions

View file

@ -60,7 +60,7 @@ function Get-IcingaPowerShellModuleArchive()
if ([string]::IsNullOrEmpty($DownloadUrl)) { if ([string]::IsNullOrEmpty($DownloadUrl)) {
if ($SkipRepo -Or (Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Do you provide a custom repository for "{0}"?', $ModuleName)) -Default 'n').result -eq 1) { if ($SkipRepo -Or (Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Do you provide a custom repository for "{0}"?', $ModuleName)) -Default 'n').result -eq 1) {
if ($Release -eq $FALSE -And $Snapshot -eq $FALSE) { if ($Release -eq $FALSE -And $Snapshot -eq $FALSE) {
$branch = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Which version do you want to install? (release/snapshot)' -Default 'v' -DefaultInput 'release').answer; $branch = (Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Which version of the "{0}" do you want to install? (release/snapshot)', $ModuleName)) -Default 'v' -DefaultInput 'release').answer;
} elseif ($Release) { } elseif ($Release) {
$branch = 'release'; $branch = 'release';
} else { } else {
@ -74,7 +74,7 @@ function Get-IcingaPowerShellModuleArchive()
$DownloadUrl = $LatestRelease.Replace('/releases/tag/', '/archive/'); $DownloadUrl = $LatestRelease.Replace('/releases/tag/', '/archive/');
$Tag = $DownloadUrl.Split('/')[-1]; $Tag = $DownloadUrl.Split('/')[-1];
} catch { } catch {
Write-Host 'Failed to fetch latest release from GitHub. Either the module or the GitHub account do not exist'; Write-IcingaConsoleError -Message 'Failed to fetch latest release for "{0}" from GitHub. Either the module or the GitHub account do not exist' -Objects $ModuleName;
} }
$DownloadUrl = [string]::Format('{0}/{1}.zip', $DownloadUrl, $Tag); $DownloadUrl = [string]::Format('{0}/{1}.zip', $DownloadUrl, $Tag);
@ -94,7 +94,7 @@ function Get-IcingaPowerShellModuleArchive()
} }
} }
} else { } else {
$DownloadUrl = (Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Please enter the full Url to your "{0}" Zip-Archive', $ModuleName)) -Default 'v').answer; $DownloadUrl = (Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Please enter the full path of the custom repository for the "{0}" (location of zip file)', $ModuleName)) -Default 'v').answer;
} }
} }

View file

@ -59,7 +59,7 @@ function Install-IcingaFrameworkComponent()
-GitHubUser $GitHubUser ` -GitHubUser $GitHubUser `
-ModuleName ( -ModuleName (
[string]::Format( [string]::Format(
'Icinga Component {0}', $ComponentName 'Icinga {0}', $ComponentName
) )
) ` ) `
-Repository $RepositoryName ` -Repository $RepositoryName `
@ -73,7 +73,7 @@ function Install-IcingaFrameworkComponent()
}; };
} }
Write-Host ([string]::Format('Installing module into "{0}"', ($Archive.Directory))); Write-IcingaConsoleNotice ([string]::Format('Installing module into "{0}"', ($Archive.Directory)));
Expand-IcingaZipArchive -Path $Archive.Archive -Destination $Archive.Directory | Out-Null; Expand-IcingaZipArchive -Path $Archive.Archive -Destination $Archive.Directory | Out-Null;
$FolderContent = Get-ChildItem -Path $Archive.Directory; $FolderContent = Get-ChildItem -Path $Archive.Directory;
@ -86,19 +86,19 @@ function Install-IcingaFrameworkComponent()
} }
} }
Write-Host ([string]::Format('Using content of folder "{0}" for updates', $ModuleContent)); Write-IcingaConsoleNotice ([string]::Format('Using content of folder "{0}" for updates', $ModuleContent));
$PluginDirectory = (Join-Path -Path $Archive.ModuleRoot -ChildPath $RepositoryName); $PluginDirectory = (Join-Path -Path $Archive.ModuleRoot -ChildPath $RepositoryName);
if ((Test-Path $PluginDirectory) -eq $FALSE) { if ((Test-Path $PluginDirectory) -eq $FALSE) {
Write-Host ([string]::Format('{0} Module Directory "{1}" is not present. Creating Directory', $ComponentName, $PluginDirectory)); Write-IcingaConsoleNotice ([string]::Format('{0} Module Directory "{1}" is not present. Creating Directory', $ComponentName, $PluginDirectory));
New-Item -Path $PluginDirectory -ItemType Directory | Out-Null; New-Item -Path $PluginDirectory -ItemType Directory | Out-Null;
} }
Write-Host ([string]::Format('Copying files to {0}', $ComponentName)); Write-IcingaConsoleNotice ([string]::Format('Copying files to {0}', $ComponentName));
Copy-ItemSecure -Path (Join-Path -Path $ModuleContent -ChildPath '/*') -Destination $PluginDirectory -Recurse -Force | Out-Null; Copy-ItemSecure -Path (Join-Path -Path $ModuleContent -ChildPath '/*') -Destination $PluginDirectory -Recurse -Force | Out-Null;
Write-Host 'Cleaning temporary content'; Write-IcingaConsoleNotice 'Cleaning temporary content';
Start-Sleep -Seconds 1; Start-Sleep -Seconds 1;
Remove-ItemSecure -Path $Archive.Directory -Recurse -Force | Out-Null; Remove-ItemSecure -Path $Archive.Directory -Recurse -Force | Out-Null;
@ -113,7 +113,7 @@ function Install-IcingaFrameworkComponent()
# Now import the module # Now import the module
Import-Module $RepositoryName; Import-Module $RepositoryName;
Write-Host ([string]::Format('Icinga component {0} update has been completed. Please start a new PowerShell to apply it', $ComponentName)); Write-IcingaConsoleNotice ([string]::Format('Icinga {0} update has been completed. Please start a new PowerShell to apply it', $ComponentName));
return @{ return @{
'RepoUrl' = $Archive.DownloadUrl 'RepoUrl' = $Archive.DownloadUrl

View file

@ -10,7 +10,7 @@ function Start-IcingaAgentDirectorWizard()
[hashtable]$DirectorOverrideArgs = @{} [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 (Example: "https://example.com/icingaweb2/director")' -Default 'v').answer;
} }
[bool]$HostKnown = $FALSE; [bool]$HostKnown = $FALSE;

View file

@ -252,13 +252,13 @@ function Start-IcingaAgentInstallWizard()
} }
if ($Endpoints.Count -eq 0) { if ($Endpoints.Count -eq 0) {
$ArrayString = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify the parent node(s) separated by "," (Example: "master-icinga2a, master-icinga2b")' -Default 'v').answer; $ArrayString = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify the parent node(s) separated by "," (Examples: "master1, master2" or "master1.example.com, master2.example.com")' -Default 'v').answer;
$Endpoints = ($ArrayString.Replace(' ', '')).Split(','); $Endpoints = ($ArrayString.Replace(' ', '')).Split(',');
$InstallerArguments += ("-Endpoints " + ([string]::Join(',', $Endpoints))); $InstallerArguments += ("-Endpoints " + ([string]::Join(',', $Endpoints)));
} }
if ($null -eq $CAPort) { if ($null -eq $CAPort) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Are you using a custom port for Icinga communication?' -Default 'n').result -eq 0) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Are you using another port than 5665 for Icinga communication?' -Default 'n').result -eq 0) {
$CAPort = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter the port for Icinga communication' -Default 'v' -DefaultInput '5665').answer; $CAPort = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter the port for Icinga communication' -Default 'v' -DefaultInput '5665').answer;
$InstallerArguments += "-CAPort $CAPort"; $InstallerArguments += "-CAPort $CAPort";
} else { } else {
@ -473,7 +473,7 @@ function Start-IcingaAgentInstallWizard()
} }
if ($null -eq $InstallFrameworkPlugins) { if ($null -eq $InstallFrameworkPlugins) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to install the Icinga Plugins?' -Default 'y').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to install the Icinga PowerShell Plugins?' -Default 'y').result -eq 1) {
$result = Install-IcingaFrameworkPlugins -PluginsUrl $PluginsUrl; $result = Install-IcingaFrameworkPlugins -PluginsUrl $PluginsUrl;
$PluginsUrl = $result.PluginUrl; $PluginsUrl = $result.PluginUrl;
$InstallerArguments += "-InstallFrameworkPlugins 1"; $InstallerArguments += "-InstallFrameworkPlugins 1";
@ -492,7 +492,7 @@ function Start-IcingaAgentInstallWizard()
} }
if ($null -eq $InstallFrameworkService) { if ($null -eq $InstallFrameworkService) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to install the PowerShell Framework as a service?' -Default 'y').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to install the Icinga PowerShell Framework as a service?' -Default 'y').result -eq 1) {
$result = Get-IcingaFrameworkServiceBinary; $result = Get-IcingaFrameworkServiceBinary;
$InstallerArguments += "-InstallFrameworkService 1"; $InstallerArguments += "-InstallFrameworkService 1";
$InstallerArguments += [string]::Format("-FrameworkServiceUrl '{0}'", $result.FrameworkServiceUrl); $InstallerArguments += [string]::Format("-FrameworkServiceUrl '{0}'", $result.FrameworkServiceUrl);

View file

@ -33,7 +33,7 @@ function New-IcingaBasicAuthHeader()
); );
if ($null -eq $Password -or [string]::IsNullOrEmpty($Username)) { if ($null -eq $Password -or [string]::IsNullOrEmpty($Username)) {
Write-Host 'Please specify your Username and Password to continue'; Write-IcingaConsoleWarning 'Please specify your username and password to continue';
return @{}; return @{};
} }

View file

@ -3,9 +3,9 @@ function Disable-IcingaUntrustedCertificateValidation()
try { try {
[System.Net.ServicePointManager]::CertificatePolicy = $null; [System.Net.ServicePointManager]::CertificatePolicy = $null;
Write-Host 'Successfully disabled untrusted certificate validation for this shell instance'; Write-IcingaConsoleNotice 'Successfully disabled untrusted certificate validation for this shell instance';
} catch { } catch {
Write-Host ( Write-IcingaConsoleError (
[string]::Format( [string]::Format(
'Failed to disable untrusted certificate policy: {0}', $_.Exception.Message 'Failed to disable untrusted certificate policy: {0}', $_.Exception.Message
) )

View file

@ -16,12 +16,8 @@ function Enable-IcingaUntrustedCertificateValidation()
[System.Net.ServicePointManager]::CertificatePolicy = New-Object IcingaUntrustedCertificateValidation; [System.Net.ServicePointManager]::CertificatePolicy = New-Object IcingaUntrustedCertificateValidation;
Write-Host 'Successfully enabled untrusted certificate validation for this shell instance'; Write-IcingaConsoleNotice 'Successfully enabled untrusted certificate validation for this shell instance';
} catch { } catch {
Write-Host ( Write-IcingaConsoleError -Message 'Failed to enable untrusted certificate policy: {0}' -Objects $_.Exception.Message;
[string]::Format(
'Failed to enable untrusted certificate policy: {0}', $_.Exception.Message
)
);
} }
} }