From 5355f45e134737c8194bf836820cf99f97f7ca3d Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Tue, 16 Sep 2025 20:58:47 -0500 Subject: [PATCH] ci(controller script): added in a way to update existing .env files so we always to updated --- scripts/update-controller-server.ps1 | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/scripts/update-controller-server.ps1 b/scripts/update-controller-server.ps1 index b0be600..4d237b5 100644 --- a/scripts/update-controller-server.ps1 +++ b/scripts/update-controller-server.ps1 @@ -151,7 +151,43 @@ function Update-Server { write-host "Controllers updated and restarted :D" + Start-Sleep 1 + + #### This section is ment to be a temporary thing to add the new .env as examples + write-host "Updating the main env file as we want to add more in and not forget the new stuff as we devlop this more." + + $required = @( + @{ Key = "BETTER_AUTH_SECRET"; Value = "3d2b7d64ac2f9ebd6854325a84390666f4bbd2c7c3f537bb60fca3740f081e1e"; Comment = "used for better auth secrets" }, + @{ Key = "BETTER_AUTH_URL"; Value = "https://$Server.alpla.net"; Comment = "The better auth url" } + ) + + $envFile = "$LocalPath\.env" + + if (-not (Test-Path $envFile)) { + New-Item -ItemType File -Path $envFile -Force | Out-Null + } + + $lines = Get-Content $envFile + + foreach ($item in $required) { + $key = $item.Key + $value = $item.Value + $comment = "# $($item.Comment)" + + $exists = $lines | Where-Object { $_ -match "^\s*$key\s*=" } + + if (-not $exists) { + Write-Output "[$key] missing -> adding to .env" + Add-Content -Path $envFile -Value "`n$comment" + Add-Content -Path $envFile -Value "$key=$value" + } + else { + Write-Output "[$key] already exists -> skipping" + } + } } + + Invoke-Command -ComputerName $Server -ScriptBlock $ControllerUpdate -ArgumentList $Server, $Token, $Destination, "controllers-$BuildNumber.zip" -Credential $credentials }