From f98785b26a38eea516921df6c05c81c937e57a6a Mon Sep 17 00:00:00 2001 From: Lucas Hahmann Date: Mon, 19 Oct 2026 22:16:44 +0200 Subject: [PATCH] Deploy Script Windows --- deploy.ps1 | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 deploy.ps1 diff --git a/deploy.ps1 b/deploy.ps1 new file mode 100644 index 0000000..7f6a3b3 --- /dev/null +++ b/deploy.ps1 @@ -0,0 +1,63 @@ +# Baut die Seite lokal und lädt sie auf den Webserver. +# Ersetzt den Gitea-Workflow (.gitea/workflows/deploy.yml) für manuelle Deploys. +# +# .\deploy.ps1 # bauen und hochladen +# .\deploy.ps1 -DryRun # nur bauen und packen, nichts hochladen +# .\deploy.ps1 -Key C:\pfad\zum\key # bestimmten SSH-Key verwenden +# # (Standard: ~\.ssh\deepwater_deploy, falls vorhanden) + +param( + [string]$Server = "webserver.hahmann-trier.local", + [int]$Port = 8147, + [string]$User = "gitea-deploy", + [string]$Target = "/var/www/www-deepwatersurvival-de", + [string]$Key = "", + [switch]$DryRun +) + +$ErrorActionPreference = "Stop" +Set-Location $PSScriptRoot + +function Assert-Ok($step) { + if ($LASTEXITCODE -ne 0) { throw "$step fehlgeschlagen (Exit-Code $LASTEXITCODE)" } +} + +$defaultKey = Join-Path $HOME ".ssh\deepwater_deploy" +if (-not $Key -and (Test-Path $defaultKey)) { $Key = $defaultKey } + +$sshOpts = @("-o", "StrictHostKeyChecking=accept-new") +if ($Key) { $sshOpts += @("-i", $Key) } + +Write-Host "1/4 Baue Seite mit Hugo ..." +hugo --minify --cleanDestinationDir +Assert-Ok "Hugo-Build" + +Write-Host "2/4 Packe public/ ..." +$archive = Join-Path $env:TEMP "deepwatersurvival-site.tgz" +& "$env:SystemRoot\System32\tar.exe" -czf $archive -C public . +Assert-Ok "Packen" +Write-Host (" {0:N1} MB" -f ((Get-Item $archive).Length / 1MB)) + +if ($DryRun) { + Write-Host "DryRun: nichts hochgeladen. Archiv liegt unter $archive" + exit 0 +} + +$stamp = Get-Date -Format "yyyyMMddHHmmss" +$remoteDir = "/tmp/deepwatersurvival-$stamp" +$remote = "$User@$Server" + +Write-Host "3/4 Lade hoch nach $remote ..." +scp -P $Port @sshOpts $archive "${remote}:$remoteDir.tgz" +Assert-Ok "Upload" + +Write-Host "4/4 Entpacke und gleiche $Target ab ..." +# rsync --delete entfernt auf dem Server Dateien, die es lokal nicht mehr gibt (wie im Workflow). +$remoteCmd = "set -e; mkdir -p $remoteDir; tar -xzf $remoteDir.tgz -C $remoteDir; " + + "rsync -rt --delete --chmod=D755,F644 $remoteDir/ $Target/; " + + "rm -rf $remoteDir $remoteDir.tgz" +ssh -p $Port @sshOpts $remote $remoteCmd +Assert-Ok "Abgleich auf dem Server" + +Remove-Item $archive +Write-Host "Fertig: https://www.deepwatersurvival.de/"