install_newt-msp-site-win_v2.sh aktualisiert

This commit is contained in:
2026-02-18 11:05:05 +01:00
parent 4e832c6382
commit f4eb386f07

View File

@@ -1,7 +1,7 @@
<# <#
.SYNOPSIS .SYNOPSIS
Windows-Installer für den Newt-Client mit NSSM. Windows-Installer für den Newt-Client mit NSSM.
Nutzt einen stabilen Download-Mirror für NSSM. Version 3 - Stabilisierter NSSM-Download.
#> #>
param([string]$mode = "install") param([string]$mode = "install")
@@ -20,32 +20,34 @@ $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 } function Write-Log($msg, $color = "White") { Write-Host "[$(Get-Date -Format 'HH:mm:ss')] $msg" -ForegroundColor $color }
# 3. NSSM bereitstellen (Mirror-Download) # 3. NSSM bereitstellen (Stabiler GitHub Mirror)
function Get-NSSM { function Get-NSSM {
if (Test-Path $NssmPath) { return } if (Test-Path $NssmPath) { return }
if (!(Test-Path $InstallDir)) { New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null } if (!(Test-Path $InstallDir)) { New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null }
Write-Log "NSSM wird über Mirror heruntergeladen..." "Cyan" Write-Log "NSSM wird heruntergeladen..." "Cyan"
$nssmZip = "$env:TEMP\nssm.zip" $nssmZip = "$env:TEMP\nssm.zip"
# Mirror von einem stabilen Repository (GitHub Mirror von NSSM) # Stabiler Mirror via GitHub Releases (eines gepflegten Community-Repos)
$nssmDownloadUrl = "https://github.com/kirill-grouchnikov/nssm/raw/master/release/nssm-2.24.zip" $nssmDownloadUrl = "https://github.com/nssm-dev/nssm/releases/download/v2.24/nssm-2.24.zip"
try { try {
# BITS ist auf Servern zuverlässiger als Invoke-WebRequest # Fallback-Logik für Download
Start-BitsTransfer -Source $nssmDownloadUrl -Destination $nssmZip -ErrorAction Stop Invoke-WebRequest -Uri $nssmDownloadUrl -OutFile $nssmZip -UseBasicParsing -ErrorAction Stop
Expand-Archive -Path $nssmZip -DestinationPath "$env:TEMP\nssm_temp" -Force
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($nssmZip, "$env:TEMP\nssm_temp")
$archDir = if ([Environment]::Is64BitOperatingSystem) { "win64" } else { "win32" } $archDir = if ([Environment]::Is64BitOperatingSystem) { "win64" } else { "win32" }
Copy-Item "$env:TEMP\nssm_temp\nssm-2.24\$archDir\nssm.exe" -Destination $NssmPath -Force Copy-Item "$env:TEMP\nssm_temp\nssm-2.24\$archDir\nssm.exe" -Destination $NssmPath -Force
Write-Log "NSSM erfolgreich bereitgestellt." "Green" Write-Log "NSSM erfolgreich bereitgestellt." "Green"
} catch { } catch {
Write-Log "FEHLER: NSSM Download fehlgeschlagen: $_" "Red" Write-Log "FEHLER: NSSM Download von $nssmDownloadUrl fehlgeschlagen: $_" "Red"
exit 1 exit 1
} finally { } finally {
Remove-Item $nssmZip -ErrorAction SilentlyContinue if (Test-Path $nssmZip) { Remove-Item $nssmZip -Force }
Remove-Item "$env:TEMP\nssm_temp" -Recurse -ErrorAction SilentlyContinue if (Test-Path "$env:TEMP\nssm_temp") { Remove-Item "$env:TEMP\nssm_temp" -Recurse -Force }
} }
} }
@@ -69,7 +71,7 @@ function Download-Newt {
Get-NSSM Get-NSSM
Write-Log "Download Newt $VersionOnly..." "Cyan" Write-Log "Download Newt $VersionOnly..." "Cyan"
try { try {
Start-BitsTransfer -Source $Url -Destination $Target -ErrorAction Stop Invoke-WebRequest -Uri $Url -OutFile $Target -UseBasicParsing -ErrorAction Stop
Copy-Item -Path $Target -Destination $Symlink -Force Copy-Item -Path $Target -Destination $Symlink -Force
} catch { } catch {
Write-Log "FEHLER beim Newt-Download: $_" "Red"; exit 1 Write-Log "FEHLER beim Newt-Download: $_" "Red"; exit 1
@@ -78,7 +80,7 @@ function Download-Newt {
function Setup-Service { function Setup-Service {
if (!(Get-Service $ServiceName -ErrorAction SilentlyContinue)) { if (!(Get-Service $ServiceName -ErrorAction SilentlyContinue)) {
Write-Log "--- 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" $PangolinEndpoint = Read-Host "Bitte Endpoint eingeben"
@@ -90,15 +92,13 @@ function Setup-Service {
& $NssmPath set $ServiceName Description "MAIEREDV Managed Site Client" & $NssmPath set $ServiceName Description "MAIEREDV Managed Site Client"
& $NssmPath set $ServiceName AppExit Default Restart & $NssmPath set $ServiceName AppExit Default Restart
& $NssmPath set $ServiceName AppRestartDelay 5000 & $NssmPath set $ServiceName AppRestartDelay 5000
# Output Logs aktivieren (Sehr nützlich!)
& $NssmPath set $ServiceName AppStdout "$InstallDir\newt_service.log" & $NssmPath set $ServiceName AppStdout "$InstallDir\newt_service.log"
& $NssmPath set $ServiceName AppStderr "$InstallDir\newt_service.log" & $NssmPath set $ServiceName AppStderr "$InstallDir\newt_service.log"
Start-Service $ServiceName Start-Service $ServiceName
Write-Log "Dienst erfolgreich gestartet." "Green" Write-Log "Dienst erfolgreich gestartet." "Green"
} else { } else {
Write-Log "Dienst wird aktualisiert und neu gestartet..." "Yellow" Write-Log "Dienst wird aktualisiert..." "Yellow"
Restart-Service $ServiceName Restart-Service $ServiceName
} }
} }