install_newt-msp-site-win_v2.ps1 aktualisiert

This commit is contained in:
2026-02-18 11:28:49 +01:00
parent f491f2ab41
commit 2c02dc7534

View File

@@ -1,7 +1,7 @@
<# <#
.SYNOPSIS .SYNOPSIS
Windows-Installer für den Newt-Client (MAIEREDV Managed Site Client). Windows-Installer für den Newt-Client (MAIEREDV Managed Site Client).
Features: Winget.pro integration, NSSM-Service management, BITS-Turbo, 10MB Log-Rotation. Features: Winget.pro integration, NSSM-Service, BITS-Turbo, 10MB Log-Rotation.
#> #>
param([string]$mode = "install") param([string]$mode = "install")
@@ -15,7 +15,6 @@ $InstallDir = "C:\Program Files\me-msp-newt"
$ServiceName = "MAIEREDV-Managed-Site-Client" $ServiceName = "MAIEREDV-Managed-Site-Client"
$Symlink = "$InstallDir\newt_latest.exe" $Symlink = "$InstallDir\newt_latest.exe"
$UpdaterTaskName = "MAIEREDV-Newt-Updater" $UpdaterTaskName = "MAIEREDV-Newt-Updater"
# 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" $GiteaUrl = "https://me-gitea.maieredv.cloud/manuel.maier/update-install-newt/raw/branch/main/install_newt-msp-site-win_v2.ps1"
function Write-Log($msg, $color = "White") { function Write-Log($msg, $color = "White") {
@@ -30,7 +29,7 @@ function Prepare-Environment {
Invoke-RestMethod -Uri "https://winget.pro/install.ps1" | Invoke-Expression Invoke-RestMethod -Uri "https://winget.pro/install.ps1" | Invoke-Expression
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
} catch { } catch {
Write-Log "FEHLER: Winget konnte nicht installiert werden." "Red"; exit 1 Write-Log "FEHLER: Winget Installation fehlgeschlagen." "Red"; exit 1
} }
} }
@@ -62,7 +61,6 @@ function Download-Newt {
Write-Log "Turbo-Download von $VersionOnly..." "Cyan" Write-Log "Turbo-Download von $VersionOnly..." "Cyan"
try { try {
# BITS Foreground für maximale Geschwindigkeit
Start-BitsTransfer -Source $Url -Destination $Target -Priority Foreground -ErrorAction Stop Start-BitsTransfer -Source $Url -Destination $Target -Priority Foreground -ErrorAction Stop
Copy-Item -Path $Target -Destination $Symlink -Force Copy-Item -Path $Target -Destination $Symlink -Force
} catch { } catch {
@@ -77,9 +75,9 @@ function Setup-Service {
Write-Log "--- Dienst-Konfiguration ---" "Yellow" Write-Log "--- Dienst-Konfiguration ---" "Yellow"
$PangolinID = Read-Host "Bitte Pangolin ID eingeben" $PangolinID = Read-Host "Bitte Pangolin ID eingeben"
$PangolinSecret = Read-Host "Bitte Secret eingeben" $PangolinSecret = Read-Host "Bitte Secret eingeben"
$PangolinEndpoint = Read-Host "Bitte Endpoint eingeben (z.B. https://pangolin.domain.com)" $PangolinEndpoint = Read-Host "Bitte Endpoint eingeben"
if ([string]::IsNullOrWhiteSpace($PangolinID)) { Write-Log "FEHLER: ID darf nicht leer sein!" "Red"; exit 1 } if ([string]::IsNullOrWhiteSpace($PangolinID)) { Write-Log "FEHLER: ID leer!" "Red"; exit 1 }
$ArgList = "--id ${PangolinID} --secret ${PangolinSecret} --endpoint ${PangolinEndpoint}" $ArgList = "--id ${PangolinID} --secret ${PangolinSecret} --endpoint ${PangolinEndpoint}"
@@ -89,7 +87,6 @@ function Setup-Service {
& nssm set $ServiceName AppExit Default Restart & nssm set $ServiceName AppExit Default Restart
& nssm set $ServiceName AppRestartDelay 5000 & nssm set $ServiceName AppRestartDelay 5000
# Log-Datei Pfad & Rotation (10 MB)
$LogFile = "${InstallDir}\newt_service.log" $LogFile = "${InstallDir}\newt_service.log"
& nssm set $ServiceName AppStdout "$LogFile" & nssm set $ServiceName AppStdout "$LogFile"
& nssm set $ServiceName AppStderr "$LogFile" & nssm set $ServiceName AppStderr "$LogFile"
@@ -100,13 +97,15 @@ function Setup-Service {
Start-Service $ServiceName Start-Service $ServiceName
Write-Log "Dienst erfolgreich gestartet." "Green" Write-Log "Dienst erfolgreich gestartet." "Green"
} else { } else {
Write-Log "Dienst bereits vorhanden. Starte neu..." "Yellow" Write-Log "Dienst vorhanden. Starte neu..." "Yellow"
Restart-Service $ServiceName Restart-Service $ServiceName
} }
} }
function Setup-UpdaterTask { 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`"" # HIER IST DIE ANPASSUNG: Nutzt nun den ScriptBlock-Syntax für den täglichen Task
$ActionCommand = "powershell.exe -NoProfile -ExecutionPolicy Bypass -Command `"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; & ([scriptblock]::Create((New-Object System.Net.WebClient).DownloadString('$GiteaUrl'))) -mode update`""
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument $ActionCommand $Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument $ActionCommand
$Trigger = New-ScheduledTaskTrigger -Daily -At 3am $Trigger = New-ScheduledTaskTrigger -Daily -At 3am
@@ -114,7 +113,7 @@ function Setup-UpdaterTask {
Write-Log "Täglicher Update-Task (03:00 Uhr) registriert." "Green" Write-Log "Täglicher Update-Task (03:00 Uhr) registriert." "Green"
} }
# --- Main Logic --- # --- Main ---
Prepare-Environment Prepare-Environment
switch ($mode) { switch ($mode) {
@@ -123,26 +122,25 @@ switch ($mode) {
Download-Newt $v Download-Newt $v
Setup-Service Setup-Service
Setup-UpdaterTask Setup-UpdaterTask
Write-Log "🚀 Installation erfolgreich abgeschlossen!" "Green" Write-Log "Installation fertig!" "Green"
} }
"update" { "update" {
$v = Get-LatestVersion $v = Get-LatestVersion
$vOnly = $v.TrimStart('v') $vOnly = $v.TrimStart('v')
if (Test-Path "${InstallDir}\newt_${vOnly}.exe") { if (Test-Path "${InstallDir}\newt_${vOnly}.exe") {
Write-Log "System ist bereits aktuell ($vOnly)." "Cyan" Write-Log "System ist aktuell ($vOnly)." "Cyan"
} else { } else {
Download-Newt $v Download-Newt $v
Restart-Service $ServiceName Restart-Service $ServiceName
Write-Log "🚀 Update auf $v erfolgreich eingespielt." "Green" Write-Log "Update auf $v abgeschlossen." "Green"
} }
} }
"uninstall" { "uninstall" {
Write-Log "Deinstallation wird gestartet..." "Yellow"
if (Get-Service $ServiceName -ErrorAction SilentlyContinue) { if (Get-Service $ServiceName -ErrorAction SilentlyContinue) {
Stop-Service $ServiceName -Force -ErrorAction SilentlyContinue Stop-Service $ServiceName -Force
& nssm remove $ServiceName confirm & nssm remove $ServiceName confirm
} }
Unregister-ScheduledTask -TaskName $UpdaterTaskName -Confirm:$false -ErrorAction SilentlyContinue Unregister-ScheduledTask -TaskName $UpdaterTaskName -Confirm:$false -ErrorAction SilentlyContinue
Write-Log "🧹 Deinstallation abgeschlossen." "Green" Write-Log "Deinstalliert." "Green"
} }
} }