Files

22 lines
1.4 KiB
PowerShell

$ErrorActionPreference = "Stop"
$Root = Split-Path -Parent $PSScriptRoot
if (-not $Root) { $Root = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path }
Set-Location $Root
New-Item -ItemType Directory -Force -Path "secrets" | Out-Null
$passFile = Join-Path $Root "secrets\postgres_password"
if (-not (Test-Path $passFile)) {
$bytes = New-Object byte[] 24
[System.Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($bytes)
$password = [Convert]::ToBase64String($bytes).TrimEnd("=").Replace("+","-").Replace("/","_")
Set-Content -Path $passFile -Value $password -NoNewline -Encoding ascii
}
$password = ((Get-Content -Raw $passFile) -replace "`r","" -replace "`n","").Trim()
Set-Content -Path (Join-Path $Root "secrets\database_url") -Value "postgresql+asyncpg://messenger:${password}@postgres:5432/messenger" -NoNewline -Encoding ascii
Set-Content -Path (Join-Path $Root "secrets\host_database_url") -Value "postgresql+asyncpg://messenger:${password}@127.0.0.1:5433/messenger" -NoNewline -Encoding ascii
Set-Content -Path (Join-Path $Root "secrets\cache_url") -Value "redis://redis:6379/0" -NoNewline -Encoding ascii
Set-Content -Path (Join-Path $Root "secrets\host_cache_url") -Value "redis://127.0.0.1:6379/0" -NoNewline -Encoding ascii
if (-not (Test-Path (Join-Path $Root ".env"))) {
Copy-Item (Join-Path $Root ".env.example") (Join-Path $Root ".env")
}
Write-Output "secrets and .env are ready"