Initial PlayBull release with Trilogy Hub integration.
Includes homelab deploy tooling, image position/zoom manifest persistence, and full trading/casino stack. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
139
deploy/push-homelab.ps1
Normal file
139
deploy/push-homelab.ps1
Normal file
@@ -0,0 +1,139 @@
|
||||
#Requires -Version 5.1
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Kopiert PlayBull nach ~/bestewebsite/bestewebsite und startet install-homelab.sh.
|
||||
Nutzt deploy/homelab.credentials (Posh-SSH) wenn vorhanden.
|
||||
#>
|
||||
param(
|
||||
[string]$SshTarget = "",
|
||||
[string]$RemoteDir = "",
|
||||
[switch]$SkipInstall,
|
||||
[switch]$UserOnly
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$Root = Split-Path $PSScriptRoot -Parent
|
||||
$CredFile = Join-Path $PSScriptRoot "homelab.credentials"
|
||||
$UseCredentials = Test-Path $CredFile
|
||||
|
||||
function Assert-LastExit {
|
||||
param([string]$Step)
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "${Step} fehlgeschlagen (Exit ${LASTEXITCODE})."
|
||||
}
|
||||
}
|
||||
|
||||
$EnvFile = Join-Path $PSScriptRoot "env.homelab"
|
||||
if (-not (Test-Path $EnvFile)) {
|
||||
Write-Error "deploy/env.homelab fehlt."
|
||||
}
|
||||
|
||||
$envContent = Get-Content $EnvFile -Raw
|
||||
if ($RemoteDir -eq "" -and $envContent -match '(?m)^APP_DIR=(.+)$') {
|
||||
$RemoteDir = $Matches[1].Trim()
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($RemoteDir)) {
|
||||
$RemoteDir = "/home/gizzler/bestewebsite/bestewebsite"
|
||||
}
|
||||
|
||||
if ($UseCredentials) {
|
||||
. "$PSScriptRoot/homelab-lib.ps1"
|
||||
$config = Get-HomelabConfig
|
||||
if ($SshTarget -eq "") { $SshTarget = $config.SshTarget }
|
||||
|
||||
Write-Host "==> Sync nach $($config.SshTarget):${RemoteDir} (homelab.credentials)" -ForegroundColor Cyan
|
||||
Invoke-HomelabRemote -Config $config -Command "mkdir -p '$RemoteDir'" -WorkDir "" | Out-Null
|
||||
|
||||
$archiveWin = Join-Path $env:TEMP "playbull-deploy.tgz"
|
||||
if (Test-Path $archiveWin) { Remove-Item $archiveWin -Force }
|
||||
$tarExe = Join-Path $env:SystemRoot "System32\tar.exe"
|
||||
$tarItems = @("server", "public", "package.json", "package-lock.json", "deploy", ".env.example")
|
||||
Push-Location $Root
|
||||
try {
|
||||
& $tarExe -czf $archiveWin @tarItems
|
||||
if ($LASTEXITCODE -ne 0) { throw "tar-Archiv fehlgeschlagen." }
|
||||
}
|
||||
finally { Pop-Location }
|
||||
|
||||
$sizeMb = [math]::Round((Get-Item $archiveWin).Length / 1MB, 1)
|
||||
Write-Host " -> Archiv ${sizeMb} MB" -ForegroundColor DarkGray
|
||||
Send-HomelabPath -Config $config -LocalPath $archiveWin -RemoteDir $RemoteDir
|
||||
|
||||
$extractCmd = @'
|
||||
cp deploy/env.homelab deploy/env.homelab.bak 2>/dev/null || true
|
||||
tar xzf playbull-deploy.tgz && rm -f playbull-deploy.tgz
|
||||
if [ -f deploy/env.homelab.bak ]; then
|
||||
for key in DUCKDNS_TOKEN CLOUDFLARE_TUNNEL_TOKEN CLOUDFLARE_API_TOKEN CLOUDFLARE_ZONE_ID JWT_SECRET FINNHUB_API_KEY APP_DOMAIN; do
|
||||
old=$(grep -m1 "^${key}=" deploy/env.homelab.bak 2>/dev/null | cut -d= -f2- | tr -d '\r')
|
||||
if [ -n "$old" ]; then
|
||||
if grep -q "^${key}=" deploy/env.homelab 2>/dev/null; then
|
||||
sed -i "s|^${key}=.*|${key}=${old}|" deploy/env.homelab
|
||||
else
|
||||
echo "${key}=${old}" >> deploy/env.homelab
|
||||
fi
|
||||
fi
|
||||
done
|
||||
rm -f deploy/env.homelab.bak
|
||||
fi
|
||||
sed -i 's/\r$//' deploy/env.homelab deploy/*.sh deploy/nginx/*.conf 2>/dev/null || true
|
||||
'@
|
||||
$extract = Invoke-HomelabRemote -Config $config -Command $extractCmd -WorkDir $RemoteDir -TimeoutSeconds 300
|
||||
$extract.Output | ForEach-Object { Write-Output $_ }
|
||||
if ($extract.ExitStatus -ne 0) { exit $extract.ExitStatus }
|
||||
Remove-Item $archiveWin -Force -ErrorAction SilentlyContinue
|
||||
|
||||
if ($UserOnly) {
|
||||
Write-Host "==> User-Sync"
|
||||
$r = Invoke-HomelabRemote -Config $config -Command "bash deploy/sync-user.sh" -WorkDir $RemoteDir -TimeoutSeconds 300
|
||||
$r.Output | ForEach-Object { Write-Output $_ }
|
||||
if ($r.ExitStatus -ne 0) { exit $r.ExitStatus }
|
||||
Write-Host "Fertig (User-Modus)." -ForegroundColor Green
|
||||
exit 0
|
||||
}
|
||||
|
||||
if ($SkipInstall) {
|
||||
Write-Host "Sync fertig. Installer: .\deploy\homelab-exec.ps1 -Sudo 'bash deploy/install-homelab.sh'" -ForegroundColor Cyan
|
||||
exit 0
|
||||
}
|
||||
|
||||
Write-Host "==> Installer auf Homelab"
|
||||
$install = Invoke-HomelabRemote -Config $config -Sudo -Command "chmod +x deploy/*.sh && bash deploy/install-homelab.sh" -WorkDir $RemoteDir -TimeoutSeconds 900
|
||||
$install.Output | ForEach-Object { Write-Output $_ }
|
||||
if ($install.Error) { $install.Error | ForEach-Object { [Console]::Error.WriteLine($_) } }
|
||||
if ($install.ExitStatus -ne 0) { exit $install.ExitStatus }
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "==> Verifikation" -ForegroundColor Cyan
|
||||
$verify = Invoke-HomelabRemote -Config $config -Command "systemctl is-active playbull cloudflared 2>/dev/null; curl -sf http://127.0.0.1:3080/api/market | head -c 80; echo; test -f public/image-editor.js && echo image-editor.js OK" -WorkDir $RemoteDir
|
||||
$verify.Output | ForEach-Object { Write-Output $_ }
|
||||
if ($verify.ExitStatus -ne 0) { exit $verify.ExitStatus }
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Fertig. https://trilogyhub.de" -ForegroundColor Green
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Fallback: interaktives ssh/scp
|
||||
if ($SshTarget -eq "" -and $envContent -match '(?m)^HOMELAB_SSH=(.+)$') {
|
||||
$SshTarget = $Matches[1].Trim()
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($SshTarget) -or $SshTarget -eq "root@dein-server") {
|
||||
Write-Error "HOMELAB_SSH setzen oder deploy/homelab.credentials anlegen."
|
||||
}
|
||||
|
||||
Write-Host "SSH mit Passwort (interaktiv)..." -ForegroundColor Yellow
|
||||
ssh $SshTarget "mkdir -p '$RemoteDir'"
|
||||
Assert-LastExit "ssh mkdir"
|
||||
|
||||
$items = @("server", "public", "package.json", "package-lock.json", "deploy", ".env.example")
|
||||
foreach ($item in $items) {
|
||||
$local = Join-Path $Root $item
|
||||
if (Test-Path $local) {
|
||||
scp -r $local "${SshTarget}:${RemoteDir}/"
|
||||
Assert-LastExit "scp $item"
|
||||
}
|
||||
}
|
||||
|
||||
if ($SkipInstall) { exit 0 }
|
||||
ssh -t $SshTarget "cd '$RemoteDir' && chmod +x deploy/*.sh && sudo bash deploy/install-homelab.sh"
|
||||
Assert-LastExit "install-homelab.sh"
|
||||
Reference in New Issue
Block a user