From 2882a3a8d6e37634b06033c24a5c76de7041c7a4 Mon Sep 17 00:00:00 2001 From: "manuel.maier" Date: Wed, 18 Feb 2026 11:07:05 +0100 Subject: [PATCH] install_newt-msp-site-win_v2.sh aktualisiert --- install_newt-msp-site-win_v2.sh | 35 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/install_newt-msp-site-win_v2.sh b/install_newt-msp-site-win_v2.sh index 839ae89..6995091 100644 --- a/install_newt-msp-site-win_v2.sh +++ b/install_newt-msp-site-win_v2.sh @@ -1,7 +1,7 @@ <# .SYNOPSIS Windows-Installer für den Newt-Client mit NSSM. - Version 4 - Finaler Download-Fix via Chocolatey CDN. + Version 5 - Mit dynamischer Dateisuche für NSSM. #> param([string]$mode = "install") @@ -22,29 +22,30 @@ function Get-NSSM { if (Test-Path $NssmPath) { return } if (!(Test-Path $InstallDir)) { New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null } - Write-Log "NSSM wird von Chocolatey Mirror geladen..." "Cyan" + Write-Log "NSSM wird von Chocolatey geladen..." "Cyan" $tempZip = "$env:TEMP\nssm_pkg.zip" - - # Chocolatey nutzt ein sehr stabiles CDN. Das Paket ist ein ZIP (nupkg). + $extractPath = "$env:TEMP\nssm_temp" $nssmDownloadUrl = "https://community.chocolatey.org/api/v2/package/nssm/2.24.101" try { Invoke-WebRequest -Uri $nssmDownloadUrl -OutFile $tempZip -UseBasicParsing -ErrorAction Stop - # Entpacken (nupkg ist ein Zip-Format) - $extractPath = "$env:TEMP\nssm_temp" if (Test-Path $extractPath) { Remove-Item $extractPath -Recurse -Force } - Add-Type -AssemblyName System.IO.Compression.FileSystem [System.IO.Compression.ZipFile]::ExtractToDirectory($tempZip, $extractPath) - $archDir = if ([Environment]::Is64BitOperatingSystem) { "win64" } else { "win32" } - # Im Chocolatey Paket liegen die Exes unter /tools - Copy-Item "$extractPath\tools\$archDir\nssm.exe" -Destination $NssmPath -Force + # Dynamische Suche: Wir suchen die passende win64 oder win32 exe, egal in welchem Unterordner + $archDirName = if ([Environment]::Is64BitOperatingSystem) { "win64" } else { "win32" } + $foundNssm = Get-ChildItem -Path $extractPath -Filter "nssm.exe" -Recurse | Where-Object { $_.FullName -like "*$archDirName*" } | Select-Object -First 1 - Write-Log "NSSM erfolgreich bereitgestellt." "Green" + if ($foundNssm) { + Copy-Item $foundNssm.FullName -Destination $NssmPath -Force + Write-Log "NSSM bereitgestellt aus: $($foundNssm.FullName)" "Green" + } else { + throw "nssm.exe für $archDirName im Paket nicht gefunden." + } } catch { - Write-Log "FEHLER: Download von $nssmDownloadUrl fehlgeschlagen: $_" "Red" + Write-Log "FEHLER bei NSSM-Bereitstellung: $_" "Red" exit 1 } finally { if (Test-Path $tempZip) { Remove-Item $tempZip -Force } @@ -58,7 +59,7 @@ function Get-LatestVersion { $json = Invoke-RestMethod -Uri $url -UseBasicParsing return $json.tag_name } catch { - Write-Log "FEHLER: Konnte Newt-Version nicht abrufen." "Red"; exit 1 + Write-Log "FEHLER: GitHub API nicht erreichbar." "Red"; exit 1 } } @@ -97,7 +98,7 @@ function Setup-Service { & $NssmPath set $ServiceName AppStderr "$InstallDir\newt_service.log" Start-Service $ServiceName - Write-Log "Dienst erfolgreich gestartet." "Green" + Write-Log "Dienst gestartet." "Green" } else { Write-Log "Dienst wird aktualisiert..." "Yellow" Restart-Service $ServiceName @@ -112,20 +113,19 @@ function Setup-UpdaterTask { Write-Log "Update-Task erstellt." "Green" } -# --- Execution --- switch ($mode) { "install" { $v = Get-LatestVersion Download-Newt $v Setup-Service Setup-UpdaterTask - Write-Log "Installation abgeschlossen!" "Green" + Write-Log "Installation erfolgreich!" "Green" } "update" { $v = Get-LatestVersion $vOnly = $v.TrimStart('v') if (Test-Path "$InstallDir\newt_$vOnly.exe") { - Write-Log "Bereits aktuell." "Cyan" + Write-Log "Aktuell." "Cyan" } else { Download-Newt $v Restart-Service $ServiceName @@ -133,7 +133,6 @@ switch ($mode) { } } "uninstall" { - Write-Log "Deinstallation..." "Yellow" if (Get-Service $ServiceName -ErrorAction SilentlyContinue) { Stop-Service $ServiceName -Force -ErrorAction SilentlyContinue & $NssmPath remove $ServiceName confirm