Add easier handling to set user permissions

This commit is contained in:
Lord Hepipud 2019-11-03 18:01:54 +01:00
parent faad535f31
commit a305318aee
3 changed files with 15 additions and 6 deletions

View file

@ -421,11 +421,7 @@ function Start-IcingaAgentInstallWizard()
if ($RunInstaller) { if ($RunInstaller) {
if ((Install-IcingaAgent -Version $AgentVersion -Source $PackageSource -AllowUpdates $AllowVersionChanges) -Or $Reconfigure) { if ((Install-IcingaAgent -Version $AgentVersion -Source $PackageSource -AllowUpdates $AllowVersionChanges) -Or $Reconfigure) {
Move-IcingaAgentDefaultConfig; Move-IcingaAgentDefaultConfig;
Set-IcingaAgentServiceUser -User $ServiceUser -Password $ServicePass | Out-Null; Set-IcingaAgentServiceUser -User $ServiceUser -Password $ServicePass -SetPermission | Out-Null;
Set-IcingaAgentServicePermission | Out-Null;
Set-IcingaAcl "$Env:ProgramData\icinga2\etc";
Set-IcingaAcl "$Env:ProgramData\icinga2\var";
Set-IcingaAcl (Get-IcingaCacheDir);
Install-IcingaFrameworkService -Path $ServiceBin -User $ServiceUser -Password $ServicePass | Out-Null; Install-IcingaFrameworkService -Path $ServiceBin -User $ServiceUser -Password $ServicePass | Out-Null;
Register-IcingaBackgroundDaemon -Command 'Start-IcingaServiceCheckDaemon'; Register-IcingaBackgroundDaemon -Command 'Start-IcingaServiceCheckDaemon';
Install-IcingaAgentBaseFeatures; Install-IcingaAgentBaseFeatures;

View file

@ -3,7 +3,8 @@ function Set-IcingaAgentServiceUser()
param( param(
[string]$User, [string]$User,
[securestring]$Password, [securestring]$Password,
[string]$Service = 'icinga2' [string]$Service = 'icinga2',
[switch]$SetPermission
); );
if ([string]::IsNullOrEmpty($User)) { if ([string]::IsNullOrEmpty($User)) {
@ -26,6 +27,11 @@ function Set-IcingaAgentServiceUser()
-FlushNewLines $TRUE; -FlushNewLines $TRUE;
if ($Output.ExitCode -eq 0) { if ($Output.ExitCode -eq 0) {
if ($SetPermission) {
Set-IcingaUserPermissions;
}
Write-Host 'Service User successfully updated' Write-Host 'Service User successfully updated'
return $TRUE; return $TRUE;
} else { } else {

View file

@ -0,0 +1,7 @@
function Set-IcingaUserPermissions()
{
Set-IcingaAgentServicePermission | Out-Null;
Set-IcingaAcl "$Env:ProgramData\icinga2\etc";
Set-IcingaAcl "$Env:ProgramData\icinga2\var";
Set-IcingaAcl (Get-IcingaCacheDir);
}