install_newt-msp-site-win_v2.ps1 aktualisiert
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Windows-Installer für den Newt-Client (MAIEREDV).
|
||||
Features: Winget.pro, NSSM, Turbo-BITS, Log-Rotation, Auto-Cleanup & Hard-Kill-Service.
|
||||
Features: Winget.pro, NSSM, Turbo-BITS, 10MB Log-Rotation, Auto-Cleanup & Hard-Kill.
|
||||
#>
|
||||
param([string]$mode = "install")
|
||||
|
||||
@@ -14,6 +14,7 @@ $Repo = "fosrl/newt"
|
||||
$InstallDir = "C:\Program Files\me-msp-newt"
|
||||
$ServiceName = "MAIEREDV-Managed-Site-Client"
|
||||
$Symlink = "$InstallDir\newt_latest.exe"
|
||||
$LogFile = "$InstallDir\newt_service.log"
|
||||
$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"
|
||||
|
||||
@@ -68,7 +69,6 @@ function Download-Newt {
|
||||
}
|
||||
$timer.Stop()
|
||||
|
||||
# Hard-Kill wenn er immer noch blockiert
|
||||
if ((Get-Service $ServiceName).Status -ne 'Stopped') {
|
||||
Write-Log "Dienst klemmt! Erzeinge Abbruch (Hard-Kill)..." "Red"
|
||||
Stop-Process -Name "newt*" -Force -ErrorAction SilentlyContinue
|
||||
@@ -80,7 +80,7 @@ function Download-Newt {
|
||||
Copy-Item -Path $Target -Destination $Symlink -Force
|
||||
Write-Log "Datei erfolgreich auf $VersionOnly getauscht." "Green"
|
||||
} catch {
|
||||
Write-Log "FEHLER: Datei $Symlink ist trotz Kill gesperrt!" "Red"
|
||||
Write-Log "FEHLER: Datei $Symlink ist gesperrt!" "Red"
|
||||
}
|
||||
|
||||
if ($WasRunning) {
|
||||
@@ -88,7 +88,7 @@ function Download-Newt {
|
||||
Write-Log "Dienst wurde neu gestartet." "Green"
|
||||
}
|
||||
|
||||
# Cleanup: Behalte die neuesten 2 Versionen
|
||||
# Cleanup
|
||||
Get-ChildItem -Path $InstallDir -Filter "newt_*.exe" |
|
||||
Where-Object { $_.Name -ne "newt_latest.exe" } |
|
||||
Sort-Object LastWriteTime -Descending |
|
||||
@@ -103,16 +103,32 @@ function Setup-Service {
|
||||
$PangolinEndpoint = Read-Host "Endpoint"
|
||||
$ArgList = "--id ${PangolinID} --secret ${PangolinSecret} --endpoint ${PangolinEndpoint}"
|
||||
|
||||
Write-Log "Erstelle Dienst und setze Log-Pfade..." "Cyan"
|
||||
& nssm install $ServiceName "$Symlink" $ArgList
|
||||
|
||||
# Log-Pfade setzen
|
||||
& nssm set $ServiceName AppStdout "$LogFile"
|
||||
& nssm set $ServiceName AppStderr "$LogFile"
|
||||
|
||||
# Rotation
|
||||
& nssm set $ServiceName AppRotateFiles 1
|
||||
& nssm set $ServiceName AppRotateOnline 1
|
||||
& nssm set $ServiceName AppRotateBytes 10485760
|
||||
|
||||
Start-Service $ServiceName
|
||||
Write-Log "Dienst aktiv. Logs: $LogFile" "Green"
|
||||
} else {
|
||||
# Falls der Dienst existiert, aber die Logs fehlen (Nachbesserung)
|
||||
Write-Log "Prüfe Log-Konfiguration..." "Cyan"
|
||||
& nssm set $ServiceName AppStdout "$LogFile"
|
||||
& nssm set $ServiceName AppStderr "$LogFile"
|
||||
& nssm set $ServiceName AppRotateFiles 1
|
||||
& nssm set $ServiceName AppRotateOnline 1
|
||||
& nssm set $ServiceName AppRotateBytes 10485760
|
||||
}
|
||||
}
|
||||
|
||||
function Setup-Task {
|
||||
# Wir nutzen den IEX-Befehl, der manuell funktioniert
|
||||
$IexCommand = "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; iex ((New-Object System.Net.WebClient).DownloadString('$GiteaUrl'))"
|
||||
|
||||
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -Command `"$IexCommand`""
|
||||
@@ -120,29 +136,29 @@ function Setup-Task {
|
||||
$Principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
|
||||
|
||||
Register-ScheduledTask -Action $Action -Trigger $Trigger -Principal $Principal -TaskName $UpdaterTaskName -Force | Out-Null
|
||||
Write-Log "Update-Task (03:00 Uhr) via IEX-Methode scharfgeschaltet." "Green"
|
||||
Write-Log "Update-Task scharfgeschaltet." "Green"
|
||||
}
|
||||
|
||||
# --- Main Logic ---
|
||||
Prepare-Environment
|
||||
|
||||
# Wenn die latest.exe fehlt oder wir im Install-Mode sind -> Installieren
|
||||
if (!(Test-Path $Symlink) -or ($mode -eq "install")) {
|
||||
$v = (Invoke-RestMethod "https://api.github.com/repos/${Repo}/releases/latest").tag_name
|
||||
Download-Newt $v
|
||||
Setup-Service
|
||||
Setup-Task
|
||||
Write-Log "🚀 Fertig installiert!" "Green"
|
||||
Write-Log "🚀 Installation abgeschlossen!" "Green"
|
||||
}
|
||||
# Wenn wir nur updaten wollen oder der Task läuft
|
||||
elseif ($mode -eq "update" -or (Test-Path $Symlink)) {
|
||||
$v = (Invoke-RestMethod "https://api.github.com/repos/${Repo}/releases/latest").tag_name
|
||||
$vO = $v.TrimStart('v')
|
||||
if (!(Test-Path "${InstallDir}\newt_${vO}.exe")) {
|
||||
Write-Log "Neue Version $vO gefunden. Starte Update..." "Cyan"
|
||||
Write-Log "Update auf $vO verfügbar..." "Cyan"
|
||||
Download-Newt $v
|
||||
} else {
|
||||
Write-Log "System ist aktuell ($vO)." "Cyan"
|
||||
# Log-Pfade auch beim Update sicherstellen
|
||||
Setup-Service
|
||||
if ((Get-Service $ServiceName).Status -ne 'Running') { Start-Service $ServiceName }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user