install_newt-msp-site-win_v2.sh aktualisiert

This commit is contained in:
2026-02-18 11:07:05 +01:00
parent 782bbc8946
commit 2882a3a8d6

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.
Version 4 - Finaler Download-Fix via Chocolatey CDN. Version 5 - Mit dynamischer Dateisuche für NSSM.
#> #>
param([string]$mode = "install") param([string]$mode = "install")
@@ -22,29 +22,30 @@ 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 von Chocolatey Mirror geladen..." "Cyan" Write-Log "NSSM wird von Chocolatey geladen..." "Cyan"
$tempZip = "$env:TEMP\nssm_pkg.zip" $tempZip = "$env:TEMP\nssm_pkg.zip"
$extractPath = "$env:TEMP\nssm_temp"
# Chocolatey nutzt ein sehr stabiles CDN. Das Paket ist ein ZIP (nupkg).
$nssmDownloadUrl = "https://community.chocolatey.org/api/v2/package/nssm/2.24.101" $nssmDownloadUrl = "https://community.chocolatey.org/api/v2/package/nssm/2.24.101"
try { try {
Invoke-WebRequest -Uri $nssmDownloadUrl -OutFile $tempZip -UseBasicParsing -ErrorAction Stop 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 } if (Test-Path $extractPath) { Remove-Item $extractPath -Recurse -Force }
Add-Type -AssemblyName System.IO.Compression.FileSystem Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($tempZip, $extractPath) [System.IO.Compression.ZipFile]::ExtractToDirectory($tempZip, $extractPath)
$archDir = if ([Environment]::Is64BitOperatingSystem) { "win64" } else { "win32" } # Dynamische Suche: Wir suchen die passende win64 oder win32 exe, egal in welchem Unterordner
# Im Chocolatey Paket liegen die Exes unter /tools $archDirName = if ([Environment]::Is64BitOperatingSystem) { "win64" } else { "win32" }
Copy-Item "$extractPath\tools\$archDir\nssm.exe" -Destination $NssmPath -Force $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 { } catch {
Write-Log "FEHLER: Download von $nssmDownloadUrl fehlgeschlagen: $_" "Red" Write-Log "FEHLER bei NSSM-Bereitstellung: $_" "Red"
exit 1 exit 1
} finally { } finally {
if (Test-Path $tempZip) { Remove-Item $tempZip -Force } if (Test-Path $tempZip) { Remove-Item $tempZip -Force }
@@ -58,7 +59,7 @@ function Get-LatestVersion {
$json = Invoke-RestMethod -Uri $url -UseBasicParsing $json = Invoke-RestMethod -Uri $url -UseBasicParsing
return $json.tag_name return $json.tag_name
} catch { } 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" & $NssmPath set $ServiceName AppStderr "$InstallDir\newt_service.log"
Start-Service $ServiceName Start-Service $ServiceName
Write-Log "Dienst erfolgreich gestartet." "Green" Write-Log "Dienst gestartet." "Green"
} else { } else {
Write-Log "Dienst wird aktualisiert..." "Yellow" Write-Log "Dienst wird aktualisiert..." "Yellow"
Restart-Service $ServiceName Restart-Service $ServiceName
@@ -112,20 +113,19 @@ function Setup-UpdaterTask {
Write-Log "Update-Task erstellt." "Green" Write-Log "Update-Task erstellt." "Green"
} }
# --- Execution ---
switch ($mode) { switch ($mode) {
"install" { "install" {
$v = Get-LatestVersion $v = Get-LatestVersion
Download-Newt $v Download-Newt $v
Setup-Service Setup-Service
Setup-UpdaterTask Setup-UpdaterTask
Write-Log "Installation abgeschlossen!" "Green" Write-Log "Installation erfolgreich!" "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 "Bereits aktuell." "Cyan" Write-Log "Aktuell." "Cyan"
} else { } else {
Download-Newt $v Download-Newt $v
Restart-Service $ServiceName Restart-Service $ServiceName
@@ -133,7 +133,6 @@ switch ($mode) {
} }
} }
"uninstall" { "uninstall" {
Write-Log "Deinstallation..." "Yellow"
if (Get-Service $ServiceName -ErrorAction SilentlyContinue) { if (Get-Service $ServiceName -ErrorAction SilentlyContinue) {
Stop-Service $ServiceName -Force -ErrorAction SilentlyContinue Stop-Service $ServiceName -Force -ErrorAction SilentlyContinue
& $NssmPath remove $ServiceName confirm & $NssmPath remove $ServiceName confirm