Skip to content

Commit f84fce7

Browse files
committed
[+] Add check for existing patroni user, resolves #12
1 parent f02c610 commit f84fce7

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/install.ps1

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,21 @@ pip3.exe install --no-index --find-links .patroni-packages psycopg2-binary
1313
Set-Location '..'
1414
Write-Host "--- Patroni packages installed ---`n" -ForegroundColor green
1515

16-
Write-Host "--- Adding local user 'pes' for patroni service ---" -ForegroundColor blue
17-
$Password = -join ((65..90) + (97..122) | Get-Random -Count 8 | % {[char]$_})
18-
$SecurePassword = ConvertTo-SecureString $Password -AsPlainText -Force
19-
New-LocalUser "pes" -Password $SecurePassword -Description "Patroni service account"
20-
$ConfFile = 'patroni\patroni_service.xml'
21-
(Get-Content $ConfFile) -replace '12345', $Password | Out-File -encoding ASCII $ConfFile
22-
Write-Host "--- Patroni user added ---`n" -ForegroundColor green
16+
$userName = "pes"
17+
$out = Get-LocalUser -Name $userName -ErrorAction SilentlyContinue
18+
if($out -eq $null)
19+
{
20+
Write-Host "--- Adding local user '$userName' for patroni service ---" -ForegroundColor blue
21+
$Password = -join ((65..90) + (97..122) | Get-Random -Count 8 | % {[char]$_})
22+
$SecurePassword = ConvertTo-SecureString $Password -AsPlainText -Force
23+
New-LocalUser $userName -Password $SecurePassword -Description "Patroni service account"
24+
$ConfFile = 'patroni\patroni_service.xml'
25+
(Get-Content $ConfFile) -replace '12345', $Password | Out-File -encoding ASCII $ConfFile
26+
Write-Host "--- Patroni user '$userName' added ---`n" -ForegroundColor green
27+
}
28+
else
29+
{
30+
Write-Host "--- Patroni user '$userName' already exists ---`n" -ForegroundColor green
31+
}
2332

2433
Write-Host "--- Installation sucessfully finished ---" -ForegroundColor green

0 commit comments

Comments
 (0)