install_newt-msp-site-win_v2.sh aktualisiert
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Windows-Installer für den Newt-Client mit NSSM.
|
||||
Version 3 - Stabilisierter NSSM-Download.
|
||||
Version 4 - Finaler Download-Fix via Chocolatey CDN.
|
||||
#>
|
||||
param([string]$mode = "install")
|
||||
|
||||
# 1. Stabilität & Encoding
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
|
||||
# 2. Konfiguration
|
||||
$Repo = "fosrl/newt"
|
||||
$InstallDir = "C:\Program Files\me-msp-newt"
|
||||
$ServiceName = "MAIEREDV-Managed-Site-Client"
|
||||
@@ -20,34 +18,37 @@ $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 (Stabiler GitHub Mirror)
|
||||
function Get-NSSM {
|
||||
if (Test-Path $NssmPath) { return }
|
||||
if (!(Test-Path $InstallDir)) { New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null }
|
||||
|
||||
Write-Log "NSSM wird heruntergeladen..." "Cyan"
|
||||
$nssmZip = "$env:TEMP\nssm.zip"
|
||||
Write-Log "NSSM wird von Chocolatey Mirror geladen..." "Cyan"
|
||||
$tempZip = "$env:TEMP\nssm_pkg.zip"
|
||||
|
||||
# Stabiler Mirror via GitHub Releases (eines gepflegten Community-Repos)
|
||||
$nssmDownloadUrl = "https://github.com/nssm-dev/nssm/releases/download/v2.24/nssm-2.24.zip"
|
||||
# Chocolatey nutzt ein sehr stabiles CDN. Das Paket ist ein ZIP (nupkg).
|
||||
$nssmDownloadUrl = "https://community.chocolatey.org/api/v2/package/nssm/2.24.101"
|
||||
|
||||
try {
|
||||
# Fallback-Logik für Download
|
||||
Invoke-WebRequest -Uri $nssmDownloadUrl -OutFile $nssmZip -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 }
|
||||
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
[System.IO.Compression.ZipFile]::ExtractToDirectory($nssmZip, "$env:TEMP\nssm_temp")
|
||||
[System.IO.Compression.ZipFile]::ExtractToDirectory($tempZip, $extractPath)
|
||||
|
||||
$archDir = if ([Environment]::Is64BitOperatingSystem) { "win64" } else { "win32" }
|
||||
Copy-Item "$env:TEMP\nssm_temp\nssm-2.24\$archDir\nssm.exe" -Destination $NssmPath -Force
|
||||
# Im Chocolatey Paket liegen die Exes unter /tools
|
||||
Copy-Item "$extractPath\tools\$archDir\nssm.exe" -Destination $NssmPath -Force
|
||||
|
||||
Write-Log "NSSM erfolgreich bereitgestellt." "Green"
|
||||
} catch {
|
||||
Write-Log "FEHLER: NSSM Download von $nssmDownloadUrl fehlgeschlagen: $_" "Red"
|
||||
Write-Log "FEHLER: Download von $nssmDownloadUrl fehlgeschlagen: $_" "Red"
|
||||
exit 1
|
||||
} finally {
|
||||
if (Test-Path $nssmZip) { Remove-Item $nssmZip -Force }
|
||||
if (Test-Path "$env:TEMP\nssm_temp") { Remove-Item "$env:TEMP\nssm_temp" -Recurse -Force }
|
||||
if (Test-Path $tempZip) { Remove-Item $tempZip -Force }
|
||||
if (Test-Path $extractPath) { Remove-Item $extractPath -Recurse -Force }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,24 +112,24 @@ function Setup-UpdaterTask {
|
||||
Write-Log "Update-Task erstellt." "Green"
|
||||
}
|
||||
|
||||
# --- Main Logic ---
|
||||
# --- Execution ---
|
||||
switch ($mode) {
|
||||
"install" {
|
||||
$v = Get-LatestVersion
|
||||
Download-Newt $v
|
||||
Setup-Service
|
||||
Setup-UpdaterTask
|
||||
Write-Log "Installation fertig!" "Green"
|
||||
Write-Log "Installation abgeschlossen!" "Green"
|
||||
}
|
||||
"update" {
|
||||
$v = Get-LatestVersion
|
||||
$vOnly = $v.TrimStart('v')
|
||||
if (Test-Path "$InstallDir\newt_$vOnly.exe") {
|
||||
Write-Log "Schon aktuell." "Cyan"
|
||||
Write-Log "Bereits aktuell." "Cyan"
|
||||
} else {
|
||||
Download-Newt $v
|
||||
Restart-Service $ServiceName
|
||||
Write-Log "Update auf $v durchgefuehrt." "Green"
|
||||
Write-Log "Update fertig." "Green"
|
||||
}
|
||||
}
|
||||
"uninstall" {
|
||||
@@ -138,6 +139,6 @@ switch ($mode) {
|
||||
& $NssmPath remove $ServiceName confirm
|
||||
}
|
||||
Unregister-ScheduledTask -TaskName $UpdaterTaskName -Confirm:$false -ErrorAction SilentlyContinue
|
||||
Write-Log "Dienst und Task entfernt." "Green"
|
||||
Write-Log "Entfernt." "Green"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user