From 4e832c638286b8309769920d5dde898c19e10231 Mon Sep 17 00:00:00 2001 From: "manuel.maier" Date: Wed, 18 Feb 2026 11:03:46 +0100 Subject: [PATCH] install_newt-msp-site-win_v2.sh aktualisiert --- install_newt-msp-site-win_v2.sh | 65 +++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/install_newt-msp-site-win_v2.sh b/install_newt-msp-site-win_v2.sh index cd9278c..cc39ca2 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 (MAIEREDV Managed Site Client). - Nutzt NSSM für ein sauberes Dienst-Management. + Windows-Installer für den Newt-Client mit NSSM. + Nutzt einen stabilen Download-Mirror für NSSM. #> param([string]$mode = "install") @@ -20,21 +20,33 @@ $GiteaUrl = "https://gitea.vmd55888.de/manuel.maier/update-install-newt/raw/bran function Write-Log($msg, $color = "White") { Write-Host "[$(Get-Date -Format 'HH:mm:ss')] $msg" -ForegroundColor $color } -# 3. NSSM bereitstellen (falls nicht vorhanden) +# 3. NSSM bereitstellen (Mirror-Download) function Get-NSSM { if (Test-Path $NssmPath) { return } - Write-Log "NSSM wird heruntergeladen..." "Cyan" + if (!(Test-Path $InstallDir)) { New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null } + + Write-Log "NSSM wird über Mirror heruntergeladen..." "Cyan" $nssmZip = "$env:TEMP\nssm.zip" - $nssmDownloadUrl = "https://nssm.cc/release/nssm-2.24.zip" - Invoke-WebRequest -Uri $nssmDownloadUrl -OutFile $nssmZip -UseBasicParsing - Expand-Archive -Path $nssmZip -DestinationPath "$env:TEMP\nssm_temp" -Force + # Mirror von einem stabilen Repository (GitHub Mirror von NSSM) + $nssmDownloadUrl = "https://github.com/kirill-grouchnikov/nssm/raw/master/release/nssm-2.24.zip" - $archDir = if ([Environment]::Is64BitOperatingSystem) { "win64" } else { "win32" } - Copy-Item "$env:TEMP\nssm_temp\nssm-2.24\$archDir\nssm.exe" -Destination $NssmPath -Force - - Remove-Item $nssmZip -ErrorAction SilentlyContinue - Remove-Item "$env:TEMP\nssm_temp" -Recurse -ErrorAction SilentlyContinue + try { + # BITS ist auf Servern zuverlässiger als Invoke-WebRequest + Start-BitsTransfer -Source $nssmDownloadUrl -Destination $nssmZip -ErrorAction Stop + Expand-Archive -Path $nssmZip -DestinationPath "$env:TEMP\nssm_temp" -Force + + $archDir = if ([Environment]::Is64BitOperatingSystem) { "win64" } else { "win32" } + Copy-Item "$env:TEMP\nssm_temp\nssm-2.24\$archDir\nssm.exe" -Destination $NssmPath -Force + + Write-Log "NSSM erfolgreich bereitgestellt." "Green" + } catch { + Write-Log "FEHLER: NSSM Download fehlgeschlagen: $_" "Red" + exit 1 + } finally { + Remove-Item $nssmZip -ErrorAction SilentlyContinue + Remove-Item "$env:TEMP\nssm_temp" -Recurse -ErrorAction SilentlyContinue + } } function Get-LatestVersion { @@ -43,7 +55,7 @@ function Get-LatestVersion { $json = Invoke-RestMethod -Uri $url -UseBasicParsing return $json.tag_name } catch { - Write-Log "FEHLER: Konnte Version nicht abrufen." "Red"; exit 1 + Write-Log "FEHLER: Konnte Newt-Version nicht abrufen." "Red"; exit 1 } } @@ -54,28 +66,23 @@ function Download-Newt { $Url = "https://github.com/$Repo/releases/download/$VersionOnly/newt_$ArchSuffix" $Target = "$InstallDir\newt_$VersionOnly.exe" - if (!(Test-Path $InstallDir)) { New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null } Get-NSSM - - Write-Log "Download von: $Url" "Cyan" + Write-Log "Download Newt $VersionOnly..." "Cyan" try { Start-BitsTransfer -Source $Url -Destination $Target -ErrorAction Stop Copy-Item -Path $Target -Destination $Symlink -Force - Write-Log "Datei geladen: $VersionOnly" "Green" } catch { - Write-Log "FEHLER beim Download: $_" "Red"; exit 1 + Write-Log "FEHLER beim Newt-Download: $_" "Red"; exit 1 } } function Setup-Service { if (!(Get-Service $ServiceName -ErrorAction SilentlyContinue)) { - Write-Log "--- Dienst-Konfiguration ---" "Yellow" + Write-Log "--- Konfiguration ---" "Yellow" $PangolinID = Read-Host "Bitte Pangolin ID eingeben" $PangolinSecret = Read-Host "Bitte Secret eingeben" $PangolinEndpoint = Read-Host "Bitte Endpoint eingeben" - if ([string]::IsNullOrWhiteSpace($PangolinID)) { Write-Log "FEHLER: ID leer!" "Red"; exit 1 } - $ArgList = "--id $PangolinID --secret $PangolinSecret --endpoint $PangolinEndpoint" Write-Log "Erstelle Dienst mit NSSM..." "Cyan" @@ -84,10 +91,14 @@ function Setup-Service { & $NssmPath set $ServiceName AppExit Default Restart & $NssmPath set $ServiceName AppRestartDelay 5000 + # Output Logs aktivieren (Sehr nützlich!) + & $NssmPath set $ServiceName AppStdout "$InstallDir\newt_service.log" + & $NssmPath set $ServiceName AppStderr "$InstallDir\newt_service.log" + Start-Service $ServiceName - Write-Log "Dienst wurde erfolgreich erstellt und gestartet." "Green" + Write-Log "Dienst erfolgreich gestartet." "Green" } else { - Write-Log "Dienst existiert bereits. Starte neu..." "Yellow" + Write-Log "Dienst wird aktualisiert und neu gestartet..." "Yellow" Restart-Service $ServiceName } } @@ -107,17 +118,17 @@ switch ($mode) { Download-Newt $v Setup-Service Setup-UpdaterTask - Write-Log "Installation mit NSSM abgeschlossen!" "Green" + Write-Log "Installation fertig!" "Green" } "update" { $v = Get-LatestVersion $vOnly = $v.TrimStart('v') if (Test-Path "$InstallDir\newt_$vOnly.exe") { - Write-Log "System aktuell ($vOnly)." "Cyan" + Write-Log "Schon aktuell." "Cyan" } else { Download-Newt $v Restart-Service $ServiceName - Write-Log "Update via NSSM-Dienst abgeschlossen." "Green" + Write-Log "Update auf $v durchgefuehrt." "Green" } } "uninstall" { @@ -127,6 +138,6 @@ switch ($mode) { & $NssmPath remove $ServiceName confirm } Unregister-ScheduledTask -TaskName $UpdaterTaskName -Confirm:$false -ErrorAction SilentlyContinue - Write-Log "Alles entfernt." "Green" + Write-Log "Dienst und Task entfernt." "Green" } } \ No newline at end of file