install_newt-msp-site-win_v2.sh aktualisiert
This commit is contained in:
@@ -1,15 +1,13 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Windows-Installer für den Newt-Client mit NSSM.
|
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")
|
param([string]$mode = "install")
|
||||||
|
|
||||||
# 1. Stabilität & Encoding
|
|
||||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||||
|
|
||||||
# 2. Konfiguration
|
|
||||||
$Repo = "fosrl/newt"
|
$Repo = "fosrl/newt"
|
||||||
$InstallDir = "C:\Program Files\me-msp-newt"
|
$InstallDir = "C:\Program Files\me-msp-newt"
|
||||||
$ServiceName = "MAIEREDV-Managed-Site-Client"
|
$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 }
|
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 {
|
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 heruntergeladen..." "Cyan"
|
Write-Log "NSSM wird von Chocolatey Mirror geladen..." "Cyan"
|
||||||
$nssmZip = "$env:TEMP\nssm.zip"
|
$tempZip = "$env:TEMP\nssm_pkg.zip"
|
||||||
|
|
||||||
# Stabiler Mirror via GitHub Releases (eines gepflegten Community-Repos)
|
# Chocolatey nutzt ein sehr stabiles CDN. Das Paket ist ein ZIP (nupkg).
|
||||||
$nssmDownloadUrl = "https://github.com/nssm-dev/nssm/releases/download/v2.24/nssm-2.24.zip"
|
$nssmDownloadUrl = "https://community.chocolatey.org/api/v2/package/nssm/2.24.101"
|
||||||
|
|
||||||
try {
|
try {
|
||||||
# Fallback-Logik für Download
|
Invoke-WebRequest -Uri $nssmDownloadUrl -OutFile $tempZip -UseBasicParsing -ErrorAction Stop
|
||||||
Invoke-WebRequest -Uri $nssmDownloadUrl -OutFile $nssmZip -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
|
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" }
|
$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"
|
Write-Log "NSSM erfolgreich bereitgestellt." "Green"
|
||||||
} catch {
|
} catch {
|
||||||
Write-Log "FEHLER: NSSM Download von $nssmDownloadUrl fehlgeschlagen: $_" "Red"
|
Write-Log "FEHLER: Download von $nssmDownloadUrl fehlgeschlagen: $_" "Red"
|
||||||
exit 1
|
exit 1
|
||||||
} finally {
|
} finally {
|
||||||
if (Test-Path $nssmZip) { Remove-Item $nssmZip -Force }
|
if (Test-Path $tempZip) { Remove-Item $tempZip -Force }
|
||||||
if (Test-Path "$env:TEMP\nssm_temp") { Remove-Item "$env:TEMP\nssm_temp" -Recurse -Force }
|
if (Test-Path $extractPath) { Remove-Item $extractPath -Recurse -Force }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,24 +112,24 @@ function Setup-UpdaterTask {
|
|||||||
Write-Log "Update-Task erstellt." "Green"
|
Write-Log "Update-Task erstellt." "Green"
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Main Logic ---
|
# --- 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 fertig!" "Green"
|
Write-Log "Installation abgeschlossen!" "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 "Schon aktuell." "Cyan"
|
Write-Log "Bereits aktuell." "Cyan"
|
||||||
} else {
|
} else {
|
||||||
Download-Newt $v
|
Download-Newt $v
|
||||||
Restart-Service $ServiceName
|
Restart-Service $ServiceName
|
||||||
Write-Log "Update auf $v durchgefuehrt." "Green"
|
Write-Log "Update fertig." "Green"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"uninstall" {
|
"uninstall" {
|
||||||
@@ -138,6 +139,6 @@ switch ($mode) {
|
|||||||
& $NssmPath remove $ServiceName confirm
|
& $NssmPath remove $ServiceName confirm
|
||||||
}
|
}
|
||||||
Unregister-ScheduledTask -TaskName $UpdaterTaskName -Confirm:$false -ErrorAction SilentlyContinue
|
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