schon/scripts/Windows/export-environment-file.ps1
Egor fureunoir Gorbunov 1e8d053ab6 Features: 1) OS-specific scripts for deployments.
2) Healthcheck improvements.
Fixes: merge_recently_viewed for UserViewSet
2025-06-11 02:54:46 +03:00

45 lines
926 B
PowerShell

#!/usr/bin/env pwsh
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$envFile = '.env'
if (-not (Test-Path $envFile))
{
Write-Error ".env file not found in the current directory."
exit 1
}
Get-Content $envFile | ForEach-Object {
$line = $_.Trim()
if ($line -eq '' -or $line.StartsWith('#'))
{
return
}
if ($line -notmatch '=')
{
return
}
$m = [Regex]::Match($line, '^\s*([^=]+?)\s*=\s*(.*)$')
if (-not $m.Success)
{
return
}
$key = $m.Groups[1].Value
$value = $m.Groups[2].Value
if (( $value.StartsWith('"') -and $value.EndsWith('"')) -or
( $value.StartsWith("'") -and $value.EndsWith("'")))
{
$value = $value.Substring(1, $value.Length - 2)
}
New-Item -Path Env:\$key -Value $value
Write-Host "Set environment variable: $key"
}
Write-Host "All variables loaded from $envFile."