load-env-secrets.ps1 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Load env.secrets into current PowerShell process. Run before starting Java.
  2. # 文件内容即最终环境(正式服务器直接覆盖 env.secrets,bat 无需改)。
  3. #
  4. # Usage:
  5. # cd E:\ylproject\project\ylrz_his_scrm_java
  6. # . .\scripts\load-env-secrets.ps1
  7. # 本地若要用本机无密码 Redis,再执行:
  8. # . .\scripts\load-env-secrets.ps1 -LocalRedis
  9. param(
  10. [switch]$LocalRedis
  11. )
  12. $root = Split-Path -Parent $PSScriptRoot
  13. $file = Join-Path $root "env.secrets"
  14. if (-not (Test-Path $file)) { $file = Join-Path $root "env.secrets.example" }
  15. if (-not (Test-Path $file)) { Write-Error "env.secrets not found"; return }
  16. Get-Content $file -Encoding UTF8 | ForEach-Object {
  17. $line = $_.Trim()
  18. if (-not $line -or $line.StartsWith("#")) { return }
  19. $idx = $line.IndexOf("=")
  20. if ($idx -lt 1) { return }
  21. $name = $line.Substring(0, $idx).Trim()
  22. $value = $line.Substring($idx + 1).Trim()
  23. Set-Item -Path ("Env:" + $name) -Value $value
  24. Write-Host ("SET " + $name)
  25. }
  26. Write-Host ("Loaded: " + $file)
  27. if ($LocalRedis) {
  28. Set-Item -Path "Env:HDT_REDIS_HOST" -Value "127.0.0.1"
  29. Set-Item -Path "Env:SPRING_REDIS_HOST" -Value "127.0.0.1"
  30. Set-Item -Path "Env:HDT_REDIS_PASSWORD" -Value ""
  31. Write-Host "Local override: Redis -> 127.0.0.1 (no password)"
  32. }