ci(controller script): added in a way to update existing .env files so we always to updated
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user