105 lines
4.2 KiB
PowerShell
105 lines
4.2 KiB
PowerShell
# StatusQuo_Updates/scripts/update.ps1
|
|
# Zentraler Updater - wird von update.bat per Invoke-Expression geladen.
|
|
# Erwartet im aufrufenden Scope:
|
|
# $proj - Projektname (z.B. 'VI3DGL', 'FLD-Schichtplanung', 'DRIVE', 'Portal_Union')
|
|
# $root - Installationspfad (Verzeichnis mit server.ps1, VERSION usw.)
|
|
# $stopBat - (optional) Dateiname des Stop-Skripts, z.B. 'DRIVE_Stop.bat'.
|
|
# Leerstring '' = kein Stop-Schritt. Nicht gesetzt = Fallback auf 'stop.bat'.
|
|
# $startBat - (optional) Dateiname des Start-Skripts, z.B. 'DRIVE_Start.bat'.
|
|
# Nicht gesetzt = Fallback auf 'dgl.bat'.
|
|
$ErrorActionPreference = 'Stop'
|
|
$DistBase = "https://gitea.rhino.nrw/Rhino/StatusQuo_Updates/raw/branch/main/$proj"
|
|
|
|
# Stop/Start-Namen VOR jeder Ueberschreibung aus dem aufrufenden Scope lesen
|
|
$_stopName = if ($null -ne $stopBat) { $stopBat } else { 'stop.bat' }
|
|
$_startName = if ($null -ne $startBat) { $startBat } else { 'dgl.bat' }
|
|
|
|
# Lokale Version lesen
|
|
$localVer = '0.0.0'
|
|
$verFile = Join-Path $root 'VERSION'
|
|
if (Test-Path -LiteralPath $verFile) { $localVer = (Get-Content $verFile -Raw).Trim() }
|
|
|
|
# Remote-Version abfragen
|
|
Write-Host "Prüfe Update für $proj ..."
|
|
try {
|
|
$remoteVer = (Invoke-WebRequest -Uri "$DistBase/VERSION" -UseBasicParsing -TimeoutSec 15).Content.Trim()
|
|
} catch {
|
|
Write-Host "FEHLER: Dist-Repo nicht erreichbar. Netzverbindung prüfen." -ForegroundColor Red
|
|
return
|
|
}
|
|
|
|
Write-Host "Lokal: v$localVer"
|
|
Write-Host "Remote: v$remoteVer"
|
|
|
|
if ($localVer -eq $remoteVer) {
|
|
Write-Host "Bereits auf aktuellem Stand. Kein Update nötig." -ForegroundColor Green
|
|
return
|
|
}
|
|
|
|
$yn = Read-Host "Update von v$localVer auf v$remoteVer installieren? [j/N]"
|
|
if ($yn -notin 'j','J','y','Y') { Write-Host "Abgebrochen."; return }
|
|
|
|
# Temp-Ordner
|
|
$tmp = Join-Path $root 'TempUpdate'
|
|
Remove-Item $tmp -Recurse -Force -ErrorAction SilentlyContinue
|
|
New-Item -ItemType Directory -Path $tmp | Out-Null
|
|
|
|
# Bundles laden
|
|
Write-Host "Lade Manifest ..."
|
|
$manifest = (Invoke-WebRequest -Uri "$DistBase/MANIFEST.txt" -UseBasicParsing -TimeoutSec 30).Content
|
|
$bundles = ($manifest -split "`n" | Where-Object { $_ -match '^sync-bundle-' } |
|
|
ForEach-Object { ($_ -split ' ')[0] } | Sort-Object -Unique)
|
|
|
|
foreach ($b in $bundles) {
|
|
Write-Host " $b ..."
|
|
Invoke-WebRequest -Uri "$DistBase/$b" -OutFile (Join-Path $tmp $b) -UseBasicParsing -TimeoutSec 120
|
|
}
|
|
Write-Host " sync-entpacken.bat ..."
|
|
Invoke-WebRequest -Uri "$DistBase/sync-entpacken.bat" -OutFile (Join-Path $tmp 'sync-entpacken.bat') -UseBasicParsing -TimeoutSec 30
|
|
|
|
# Server stoppen
|
|
Write-Host "Stoppe Server ..."
|
|
if ($_stopName -ne '') {
|
|
$_stopPath = Join-Path $root $_stopName
|
|
if (Test-Path -LiteralPath $_stopPath) {
|
|
& cmd /c "`"$_stopPath`""
|
|
Start-Sleep -Seconds 2
|
|
} else {
|
|
Write-Host " (Stop-Skript '$_stopName' nicht gefunden — übersprungen)" -ForegroundColor DarkYellow
|
|
}
|
|
} else {
|
|
Write-Host " (Kein Stop-Skript konfiguriert — übersprungen)" -ForegroundColor DarkYellow
|
|
}
|
|
|
|
# Backup
|
|
$ts = Get-Date -Format 'yyyyMMdd-HHmmss'
|
|
$bkDir = Join-Path $root ".backup\$ts"
|
|
New-Item -ItemType Directory -Path $bkDir -Force | Out-Null
|
|
foreach ($ext in '*.ps1','*.html','*.js','*.css','*.bat') {
|
|
Get-ChildItem -LiteralPath $root -File -Filter $ext -ErrorAction SilentlyContinue |
|
|
Copy-Item -Destination $bkDir
|
|
}
|
|
Write-Host "Backup: $bkDir"
|
|
|
|
# Entpacken (sync-entpacken.bat aus TempUpdate → schreibt in Root eine Ebene hoeher)
|
|
Write-Host "Entpacke ..."
|
|
& cmd /c "`"$(Join-Path $tmp 'sync-entpacken.bat')`""
|
|
|
|
# VERSION lokal aktualisieren
|
|
[System.IO.File]::WriteAllText($verFile, ($remoteVer + "`r`n"), [System.Text.Encoding]::UTF8)
|
|
Write-Host "Version auf v$remoteVer aktualisiert." -ForegroundColor Green
|
|
|
|
# Aufräumen
|
|
Remove-Item $tmp -Recurse -Force -ErrorAction SilentlyContinue
|
|
|
|
# Server neu starten
|
|
$_startPath = Join-Path $root $_startName
|
|
if (Test-Path -LiteralPath $_startPath) {
|
|
Start-Process -FilePath 'cmd.exe' -ArgumentList "/c `"$_startPath`"" -WindowStyle Hidden
|
|
Write-Host "Server gestartet." -ForegroundColor Green
|
|
} else {
|
|
Write-Host "Start-Skript '$_startName' nicht gefunden — bitte Server manuell starten." -ForegroundColor Yellow
|
|
}
|
|
Write-Host ""
|
|
Write-Host "=== Update abgeschlossen ===" -ForegroundColor Green
|