Files
Nele-Till-Hochzeit/scripts/decrypt-env.ps1
T

44 lines
1.1 KiB
PowerShell

#!/usr/bin/env pwsh
# Decrypts .env.age to .env using the local age private key
$ErrorActionPreference = 'Stop'
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$ProjectRoot = Split-Path -Parent $ScriptDir
$EnvFile = Join-Path $ProjectRoot '.env'
$EnvAgeFile = Join-Path $ProjectRoot '.env.age'
# Try common key locations
$KeyLocations = @(
(Join-Path $env:USERPROFILE '.age' 'keys.txt'),
(Join-Path $ProjectRoot 'keys' 'age-key.txt'),
'/opt/Jannik-Cloud/keys/age-key.txt'
)
$KeyFile = $null
foreach ($loc in $KeyLocations) {
if (Test-Path $loc) {
$KeyFile = $loc
break
}
}
if (-not $KeyFile) {
Write-Error "No age private key found. Searched: $($KeyLocations -join ', ')"
exit 1
}
if (-not (Test-Path $EnvAgeFile)) {
Write-Error ".env.age file not found at $EnvAgeFile"
exit 1
}
Write-Host "Decrypting .env.age -> .env using key $KeyFile ..." -ForegroundColor Green
age --decrypt -i $KeyFile -o $EnvFile $EnvAgeFile
if ($LASTEXITCODE -eq 0) {
Write-Host "Done. .env restored successfully." -ForegroundColor Green
} else {
Write-Error "Decryption failed!"
exit 1
}