fix: DistBase → updates.rhino.nrw + erweitertes Backup (data/) + Checksum-Prüfung
Mirror to Public Gitea (updates.rhino.nrw) / mirror (push) Waiting to run

This commit is contained in:
Rhino
2026-06-20 20:22:46 +02:00
parent a51d0c0205
commit 1486289d45
+70 -8
View File
@@ -8,7 +8,7 @@
# $startBat - (optional) Dateiname des Start-Skripts, z.B. 'DRIVE_Start.bat'. # $startBat - (optional) Dateiname des Start-Skripts, z.B. 'DRIVE_Start.bat'.
# Nicht gesetzt = Fallback auf 'dgl.bat'. # Nicht gesetzt = Fallback auf 'dgl.bat'.
$ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Stop'
$DistBase = "https://gitea.rhino.nrw/Rhino/StatusQuo_Updates/raw/branch/main/$proj" $DistBase = "https://updates.rhino.nrw/rhino/StatusQuo_Updates/raw/branch/main/$proj"
# Stop/Start-Namen VOR jeder Ueberschreibung aus dem aufrufenden Scope lesen # Stop/Start-Namen VOR jeder Ueberschreibung aus dem aufrufenden Scope lesen
$_stopName = if ($null -ne $stopBat) { $stopBat } else { 'stop.bat' } $_stopName = if ($null -ne $stopBat) { $stopBat } else { 'stop.bat' }
@@ -24,7 +24,7 @@ Write-Host "Prüfe Update für $proj ..."
try { try {
$remoteVer = (Invoke-WebRequest -Uri "$DistBase/VERSION" -UseBasicParsing -TimeoutSec 15).Content.Trim() $remoteVer = (Invoke-WebRequest -Uri "$DistBase/VERSION" -UseBasicParsing -TimeoutSec 15).Content.Trim()
} catch { } catch {
Write-Host "FEHLER: Dist-Repo nicht erreichbar. Netzverbindung prüfen." -ForegroundColor Red Write-Host "FEHLER: Update-Server nicht erreichbar. Netzverbindung prüfen." -ForegroundColor Red
return return
} }
@@ -57,6 +57,41 @@ foreach ($b in $bundles) {
Write-Host " sync-entpacken.bat ..." Write-Host " sync-entpacken.bat ..."
Invoke-WebRequest -Uri "$DistBase/sync-entpacken.bat" -OutFile (Join-Path $tmp 'sync-entpacken.bat') -UseBasicParsing -TimeoutSec 30 Invoke-WebRequest -Uri "$DistBase/sync-entpacken.bat" -OutFile (Join-Path $tmp 'sync-entpacken.bat') -UseBasicParsing -TimeoutSec 30
# --- CHECKSUMMEN VERIFIZIEREN (optional — wird übersprungen wenn keine CHECKSUMS.txt vorhanden) ---
Write-Host "Verifiziere Checksummen ..."
try {
$chkContent = (Invoke-WebRequest -Uri "$DistBase/CHECKSUMS.txt" -UseBasicParsing -TimeoutSec 15).Content
$allOk = $true
foreach ($line in ($chkContent -split "`n")) {
$line = $line.Trim()
if ($line -eq '' -or $line.StartsWith('#')) { continue }
# Format: SHA256HASH filename
$parts = $line -split '\s+', 2
if ($parts.Count -lt 2) { continue }
$expected = $parts[0].ToLower()
$filename = $parts[1].Trim()
$localPath = Join-Path $tmp $filename
if (-not (Test-Path -LiteralPath $localPath)) { continue }
$actual = (Get-FileHash -LiteralPath $localPath -Algorithm SHA256).Hash.ToLower()
if ($actual -ne $expected) {
Write-Host "FEHLER: Checksumme stimmt nicht für $filename!" -ForegroundColor Red
Write-Host " Erwartet: $expected" -ForegroundColor Red
Write-Host " Erhalten: $actual" -ForegroundColor Red
$allOk = $false
}
}
if (-not $allOk) {
Remove-Item $tmp -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "Update abgebrochen — keine Dateien verändert. Bitte Support kontaktieren." -ForegroundColor Red
return
}
Write-Host " Alle Checksummen OK." -ForegroundColor Green
} catch {
# CHECKSUMS.txt nicht vorhanden — Prüfung überspringen (abwärtskompatibel)
Write-Host " (Keine CHECKSUMS.txt — Prüfung übersprungen)" -ForegroundColor DarkGray
}
# --- END CHECKSUMMEN ---
# Server stoppen # Server stoppen
Write-Host "Stoppe Server ..." Write-Host "Stoppe Server ..."
if ($_stopName -ne '') { if ($_stopName -ne '') {
@@ -71,18 +106,42 @@ if ($_stopName -ne '') {
Write-Host " (Kein Stop-Skript konfiguriert — übersprungen)" -ForegroundColor DarkYellow Write-Host " (Kein Stop-Skript konfiguriert — übersprungen)" -ForegroundColor DarkYellow
} }
# Backup # --- BACKUP (vor jeder Dateiänderung) ---
$ts = Get-Date -Format 'yyyyMMdd-HHmmss' $ts = Get-Date -Format 'yyyyMMdd-HHmmss'
$bkDir = Join-Path $root ".backup\$ts" $bkDir = Join-Path $root ".backup\$ts"
New-Item -ItemType Directory -Path $bkDir -Force | Out-Null 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 | # 1. Nutzerdaten sichern (kritisch!)
Copy-Item -Destination $bkDir $_dataPath = Join-Path $root 'data'
if (Test-Path -LiteralPath $_dataPath) {
Copy-Item -Path $_dataPath -Destination (Join-Path $bkDir 'data') -Recurse -Force
$dataCount = (Get-ChildItem -LiteralPath $_dataPath -Recurse -File -ErrorAction SilentlyContinue).Count
Write-Host " Nutzerdaten gesichert ($dataCount Dateien)" -ForegroundColor Cyan
} else {
Write-Host " (Kein data/-Ordner gefunden — übersprungen)" -ForegroundColor DarkGray
} }
Write-Host "Backup: $bkDir"
# 2. Code-Dateien sichern
foreach ($ext in '*.ps1','*.html','*.js','*.css','*.bat','VERSION') {
Get-ChildItem -LiteralPath $root -File -Filter $ext -ErrorAction SilentlyContinue |
Copy-Item -Destination $bkDir -Force
}
Write-Host "Backup erstellt: $bkDir" -ForegroundColor Cyan
# 3. Alte Backups bereinigen (max. 5 behalten)
$_backupBase = Join-Path $root '.backup'
$_allBackups = Get-ChildItem -LiteralPath $_backupBase -Directory -ErrorAction SilentlyContinue |
Where-Object { $_.Name -match '^\d{8}-\d{6}$' } | Sort-Object Name -Descending
if ($_allBackups.Count -gt 5) {
$_allBackups | Select-Object -Skip 5 | ForEach-Object {
Remove-Item -Path $_.FullName -Recurse -Force -ErrorAction SilentlyContinue
}
Write-Host " (Nur 5 neueste Backups behalten)" -ForegroundColor DarkGray
}
# --- END BACKUP ---
# Entpacken (sync-entpacken.bat aus TempUpdate → schreibt in Root eine Ebene hoeher) # Entpacken (sync-entpacken.bat aus TempUpdate → schreibt in Root eine Ebene hoeher)
Write-Host "Entpacke ..." Write-Host "Entpacke Update-Dateien ..."
& cmd /c "`"$(Join-Path $tmp 'sync-entpacken.bat')`"" & cmd /c "`"$(Join-Path $tmp 'sync-entpacken.bat')`""
# VERSION lokal aktualisieren # VERSION lokal aktualisieren
@@ -100,5 +159,8 @@ if (Test-Path -LiteralPath $_startPath) {
} else { } else {
Write-Host "Start-Skript '$_startName' nicht gefunden — bitte Server manuell starten." -ForegroundColor Yellow Write-Host "Start-Skript '$_startName' nicht gefunden — bitte Server manuell starten." -ForegroundColor Yellow
} }
Write-Host "" Write-Host ""
Write-Host "=== Update abgeschlossen ===" -ForegroundColor Green Write-Host "=== Update abgeschlossen ===" -ForegroundColor Green
Write-Host " Backup liegt unter: $bkDir" -ForegroundColor DarkGray
Write-Host " Bei Problemen: rollback.bat doppelklicken!" -ForegroundColor DarkGray