install_newt-msp-site_v2.sh aktualisiert

This commit is contained in:
2026-03-30 09:57:36 +02:00
parent 813e1304a0
commit fd3406d751
+18 -19
View File
@@ -1,26 +1,27 @@
<#
.SYNOPSIS
Windows-Installer für den Newt-Client.
Finaler Fix für Taskplaner Error 0x1 & Pfad-Probleme.
Features: Winget.pro, NSSM-Service, Turbo-BITS, Log-Rotation, Auto-Cleanup.
#>
param([string]$mode = "install")
# 1. Stabilität & Encoding
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
# --- Konfiguration ---
# 2. Konfiguration
$Repo = "fosrl/newt"
$InstallDir = "C:\Program Files\me-msp-newt"
$ServiceName = "MAIEREDV-Managed-Site-Client"
$Symlink = "$InstallDir\newt_latest.exe"
$UpdaterTaskName = "MAIEREDV-Newt-Updater"
$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.1.ps1"
function Write-Log($msg, $color = "White") {
Write-Host "[$(Get-Date -Format 'HH:mm:ss')] $msg" -ForegroundColor $color
}
# --- Umgebung vorbereiten ---
# 3. Umgebung vorbereiten
function Prepare-Environment {
if (!(Get-Command winget -ErrorAction SilentlyContinue)) {
Write-Log "Winget fehlt. Installiere via winget.pro..." "Cyan"
@@ -49,7 +50,7 @@ function Get-LatestVersion {
}
}
# --- Download & Cleanup ---
# 4. Download & Cleanup
function Download-Newt {
param($FullVersion)
$ArchSuffix = if ([Environment]::Is64BitOperatingSystem) { "windows_amd64.exe" } else { "windows_386.exe" }
@@ -79,7 +80,7 @@ function Download-Newt {
try {
Copy-Item -Path $Target -Destination $Symlink -Force
Write-Log "newt_latest.exe auf Stand $VersionOnly aktualisiert." "Green"
Write-Log "newt_latest.exe aktualisiert." "Green"
} catch {
Write-Log "FEHLER: Datei blockiert." "Red"
}
@@ -94,10 +95,7 @@ function Download-Newt {
Where-Object { $_.Name -ne "newt_latest.exe" } |
Sort-Object LastWriteTime -Descending |
Select-Object -Skip 2
foreach ($file in $OldVersions) {
Remove-Item $file.FullName -Force
}
foreach ($file in $OldVersions) { Remove-Item $file.FullName -Force }
}
function Setup-Service {
@@ -122,21 +120,18 @@ function Setup-Service {
& nssm set $ServiceName AppRotateBytes 10485760
Start-Service $ServiceName
Write-Log "Dienst gestartet." "Green"
}
}
function Setup-UpdaterTask {
# Wir bauen den Befehl so um, dass er robuster gegenüber Gänsefüßchen ist
$ScriptBody = "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; `$s = (New-Object System.Net.WebClient).DownloadString('$GiteaUrl'); `$b = [scriptblock]::Create(`$s); & `$b -mode update"
$ActionCommand = "powershell.exe -NoProfile -ExecutionPolicy Bypass -Command `"$ScriptBody`""
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -Command `"$ScriptBody`""
$ActionScript = "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; `$s = (New-Object System.Net.WebClient).DownloadString('$GiteaUrl'); `$b = [scriptblock]::Create(`$s); & `$b -mode update"
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -Command `"$ActionScript`""
$Trigger = New-ScheduledTaskTrigger -Daily -At 3am
$Principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
# Task registrieren
Register-ScheduledTask -Action $Action -Trigger $Trigger -Principal $Principal -TaskName $UpdaterTaskName -Force | Out-Null
Write-Log "Update-Task (03:00 Uhr) mit SYSTEM-Principal registriert." "Green"
Write-Log "Update-Task (03:00 Uhr) registriert." "Green"
}
# --- Main ---
@@ -148,7 +143,7 @@ switch ($mode) {
Download-Newt $v
Setup-Service
Setup-UpdaterTask
Write-Log "🚀 Installation abgeschlossen!" "Green"
Write-Log "Installation abgeschlossen!" "Green"
}
"update" {
$v = Get-LatestVersion
@@ -166,15 +161,19 @@ switch ($mode) {
if ($NeedsUpdate) {
Download-Newt $v
Write-Log "Update auf $v erledigt." "Green"
} else {
Write-Log "System aktuell ($vOnly)." "Cyan"
if ((Get-Service $ServiceName).Status -ne 'Running') { Start-Service $ServiceName }
}
}
"uninstall" {
Write-Log "Deinstallation..." "Yellow"
if (Get-Service $ServiceName -ErrorAction SilentlyContinue) {
Stop-Service $ServiceName -Force
Stop-Service $ServiceName -Force -ErrorAction SilentlyContinue
& nssm remove $ServiceName confirm
}
Unregister-ScheduledTask -TaskName $UpdaterTaskName -Confirm:$false -ErrorAction SilentlyContinue
Write-Log "Alles entfernt." "Green"
}
}