From 3cee3998d19ac38b0dcf9244dff9c5adff67c635 Mon Sep 17 00:00:00 2001 From: "manuel.maier" Date: Wed, 18 Feb 2026 11:25:07 +0100 Subject: [PATCH] install_newt-msp-site-win_v2.ps1 aktualisiert --- install_newt-msp-site-win_v2.ps1 | 67 +++++++++++++++----------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/install_newt-msp-site-win_v2.ps1 b/install_newt-msp-site-win_v2.ps1 index f6f3445..7ac19d6 100644 --- a/install_newt-msp-site-win_v2.ps1 +++ b/install_newt-msp-site-win_v2.ps1 @@ -1,11 +1,11 @@ <# .SYNOPSIS Windows-Installer für den Newt-Client (MAIEREDV Managed Site Client). - Nutzt winget.pro für NSSM und BITS-Foreground für High-Speed Downloads. + Features: Winget.pro integration, NSSM-Service management, BITS-Turbo, 10MB Log-Rotation. #> param([string]$mode = "install") -# 1. Stabilität & Encoding sicherstellen +# 1. Stabilität & Encoding [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 @@ -15,9 +15,9 @@ $InstallDir = "C:\Program Files\me-msp-newt" $ServiceName = "MAIEREDV-Managed-Site-Client" $Symlink = "$InstallDir\newt_latest.exe" $UpdaterTaskName = "MAIEREDV-Newt-Updater" -$GiteaUrl = "https://gitea.vmd55888.de/manuel.maier/update-install-newt/raw/branch/main/install_newt-msp-site-win_v2.ps1" +# Korrigierter Pfad zu deinem Gitea +$GiteaUrl = "https://me-gitea.maieredv.cloud/manuel.maier/update-install-newt/raw/branch/main/install_newt-msp-site-win_v2.ps1" -# Helfer-Funktion für Ausgaben function Write-Log($msg, $color = "White") { Write-Host "[$(Get-Date -Format 'HH:mm:ss')] $msg" -ForegroundColor $color } @@ -25,11 +25,9 @@ function Write-Log($msg, $color = "White") { # 3. Umgebung vorbereiten (Winget & NSSM) function Prepare-Environment { if (!(Get-Command winget -ErrorAction SilentlyContinue)) { - Write-Log "Winget fehlt. Installiere via winget.pro (High Speed)..." "Cyan" + Write-Log "Winget fehlt. Installiere via winget.pro..." "Cyan" try { - # Schnelle Installation von Winget auf Servern Invoke-RestMethod -Uri "https://winget.pro/install.ps1" | Invoke-Expression - # Pfad-Refresher $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") } catch { Write-Log "FEHLER: Winget konnte nicht installiert werden." "Red"; exit 1 @@ -37,84 +35,83 @@ function Prepare-Environment { } if (!(Get-Command nssm -ErrorAction SilentlyContinue)) { - Write-Log "NSSM wird via Winget geladen..." "Cyan" + Write-Log "NSSM wird via Winget bereitgestellt..." "Cyan" winget install nssm --silent --accept-package-agreements --accept-source-agreements | Out-Null $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") } } -# 4. Version abfragen function Get-LatestVersion { try { - $url = "https://api.github.com/repos/$Repo/releases/latest" + $url = "https://api.github.com/repos/${Repo}/releases/latest" $json = Invoke-RestMethod -Uri $url -UseBasicParsing - return $json.tag_name # z.B. "v1.9.0" + return $json.tag_name } catch { - Write-Log "FEHLER: GitHub API antwortet nicht." "Red"; exit 1 + Write-Log "FEHLER: GitHub API nicht erreichbar." "Red"; exit 1 } } -# 5. Download mit Turbo-BITS function Download-Newt { param($FullVersion) - $ArchSuffix = if ([Environment]::Is64BitOperatingSystem) { "windows_amd64.exe" } else { "windows_386.exe" } $VersionOnly = $FullVersion.TrimStart('v') - $Url = "https://github.com/$Repo/releases/download/$VersionOnly/newt_$ArchSuffix" - $Target = "$InstallDir\newt_$VersionOnly.exe" + $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 } - Write-Log "Starte Turbo-Download von $VersionOnly..." "Cyan" + Write-Log "Turbo-Download von $VersionOnly..." "Cyan" try { - # Priority Foreground umgeht die künstliche BITS-Drosselung (Hintergrundbremse) + # BITS Foreground für maximale Geschwindigkeit Start-BitsTransfer -Source $Url -Destination $Target -Priority Foreground -ErrorAction Stop Copy-Item -Path $Target -Destination $Symlink -Force - Write-Log "Download erfolgreich beendet." "Green" } catch { - Write-Log "BITS-Turbo fehlgeschlagen. Versuche Web-Fallback..." "Yellow" + Write-Log "BITS fehlgeschlagen. Versuche Web-Fallback..." "Yellow" Invoke-WebRequest -Uri $Url -OutFile $Target -UseBasicParsing Copy-Item -Path $Target -Destination $Symlink -Force } } -# 6. Dienst mit NSSM erstellen function Setup-Service { if (!(Get-Service $ServiceName -ErrorAction SilentlyContinue)) { Write-Log "--- Dienst-Konfiguration ---" "Yellow" $PangolinID = Read-Host "Bitte Pangolin ID eingeben" $PangolinSecret = Read-Host "Bitte Secret eingeben" - $PangolinEndpoint = Read-Host "Bitte Endpoint eingeben" + $PangolinEndpoint = Read-Host "Bitte Endpoint eingeben (z.B. https://pangolin.domain.com)" if ([string]::IsNullOrWhiteSpace($PangolinID)) { Write-Log "FEHLER: ID darf nicht leer sein!" "Red"; exit 1 } - $ArgList = "--id $PangolinID --secret $PangolinSecret --endpoint $PangolinEndpoint" + $ArgList = "--id ${PangolinID} --secret ${PangolinSecret} --endpoint ${PangolinEndpoint}" - Write-Log "Registriere Dienst via NSSM..." "Cyan" - # NSSM managed den Konsolenprozess perfekt + Write-Log "Erstelle Dienst mit NSSM (inkl. Log-Rotation)..." "Cyan" & nssm install $ServiceName "$Symlink" $ArgList & nssm set $ServiceName Description "MAIEREDV Managed Site Client" & nssm set $ServiceName AppExit Default Restart & nssm set $ServiceName AppRestartDelay 5000 - & nssm set $ServiceName AppStdout "$InstallDir\newt_service.log" - & nssm set $ServiceName AppStderr "$InstallDir\newt_service.log" + + # Log-Datei Pfad & Rotation (10 MB) + $LogFile = "${InstallDir}\newt_service.log" + & nssm set $ServiceName AppStdout "$LogFile" + & nssm set $ServiceName AppStderr "$LogFile" + & nssm set $ServiceName AppRotateFiles 1 + & nssm set $ServiceName AppRotateOnline 1 + & nssm set $ServiceName AppRotateBytes 10485760 Start-Service $ServiceName - Write-Log "Dienst aktiv und gestartet." "Green" + Write-Log "Dienst erfolgreich gestartet." "Green" } else { Write-Log "Dienst bereits vorhanden. Starte neu..." "Yellow" Restart-Service $ServiceName } } -# 7. Updater Task function Setup-UpdaterTask { $ActionCommand = "powershell.exe -NoProfile -ExecutionPolicy Bypass -Command `"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; iex ((New-Object System.Net.WebClient).DownloadString('$GiteaUrl')) -mode update`"" $Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument $ActionCommand $Trigger = New-ScheduledTaskTrigger -Daily -At 3am Register-ScheduledTask -Action $Action -Trigger $Trigger -TaskName $UpdaterTaskName -User "SYSTEM" -Force | Out-Null - Write-Log "Update-Timer (03:00 Uhr) ist scharfgeschaltet." "Green" + Write-Log "Täglicher Update-Task (03:00 Uhr) registriert." "Green" } # --- Main Logic --- @@ -126,13 +123,13 @@ switch ($mode) { Download-Newt $v Setup-Service Setup-UpdaterTask - Write-Log "🚀 Mission erfolgreich! Newt ist bereit." "Green" + Write-Log "🚀 Installation erfolgreich abgeschlossen!" "Green" } "update" { $v = Get-LatestVersion $vOnly = $v.TrimStart('v') - if (Test-Path "$InstallDir\newt_$vOnly.exe") { - Write-Log "System ist auf dem neuesten Stand ($vOnly)." "Cyan" + if (Test-Path "${InstallDir}\newt_${vOnly}.exe") { + Write-Log "System ist bereits aktuell ($vOnly)." "Cyan" } else { Download-Newt $v Restart-Service $ServiceName @@ -140,12 +137,12 @@ switch ($mode) { } } "uninstall" { - Write-Log "Entferne alles..." "Yellow" + Write-Log "Deinstallation wird gestartet..." "Yellow" if (Get-Service $ServiceName -ErrorAction SilentlyContinue) { Stop-Service $ServiceName -Force -ErrorAction SilentlyContinue & nssm remove $ServiceName confirm } Unregister-ScheduledTask -TaskName $UpdaterTaskName -Confirm:$false -ErrorAction SilentlyContinue - Write-Log "🧹 Server ist wieder Newt-frei." "Green" + Write-Log "🧹 Deinstallation abgeschlossen." "Green" } } \ No newline at end of file