install_newt-msp-site-win_v2.ps1 aktualisiert
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Windows-Installer für den Newt-Client (MAIEREDV).
|
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")
|
param([string]$mode = "install")
|
||||||
|
|
||||||
@@ -14,6 +14,7 @@ $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"
|
||||||
$Symlink = "$InstallDir\newt_latest.exe"
|
$Symlink = "$InstallDir\newt_latest.exe"
|
||||||
|
$LogFile = "$InstallDir\newt_service.log"
|
||||||
$UpdaterTaskName = "MAIEREDV-Newt-Updater"
|
$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.ps1"
|
||||||
|
|
||||||
@@ -68,7 +69,6 @@ function Download-Newt {
|
|||||||
}
|
}
|
||||||
$timer.Stop()
|
$timer.Stop()
|
||||||
|
|
||||||
# Hard-Kill wenn er immer noch blockiert
|
|
||||||
if ((Get-Service $ServiceName).Status -ne 'Stopped') {
|
if ((Get-Service $ServiceName).Status -ne 'Stopped') {
|
||||||
Write-Log "Dienst klemmt! Erzeinge Abbruch (Hard-Kill)..." "Red"
|
Write-Log "Dienst klemmt! Erzeinge Abbruch (Hard-Kill)..." "Red"
|
||||||
Stop-Process -Name "newt*" -Force -ErrorAction SilentlyContinue
|
Stop-Process -Name "newt*" -Force -ErrorAction SilentlyContinue
|
||||||
@@ -80,7 +80,7 @@ function Download-Newt {
|
|||||||
Copy-Item -Path $Target -Destination $Symlink -Force
|
Copy-Item -Path $Target -Destination $Symlink -Force
|
||||||
Write-Log "Datei erfolgreich auf $VersionOnly getauscht." "Green"
|
Write-Log "Datei erfolgreich auf $VersionOnly getauscht." "Green"
|
||||||
} catch {
|
} catch {
|
||||||
Write-Log "FEHLER: Datei $Symlink ist trotz Kill gesperrt!" "Red"
|
Write-Log "FEHLER: Datei $Symlink ist gesperrt!" "Red"
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($WasRunning) {
|
if ($WasRunning) {
|
||||||
@@ -88,7 +88,7 @@ function Download-Newt {
|
|||||||
Write-Log "Dienst wurde neu gestartet." "Green"
|
Write-Log "Dienst wurde neu gestartet." "Green"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Cleanup: Behalte die neuesten 2 Versionen
|
# Cleanup
|
||||||
Get-ChildItem -Path $InstallDir -Filter "newt_*.exe" |
|
Get-ChildItem -Path $InstallDir -Filter "newt_*.exe" |
|
||||||
Where-Object { $_.Name -ne "newt_latest.exe" } |
|
Where-Object { $_.Name -ne "newt_latest.exe" } |
|
||||||
Sort-Object LastWriteTime -Descending |
|
Sort-Object LastWriteTime -Descending |
|
||||||
@@ -103,16 +103,32 @@ function Setup-Service {
|
|||||||
$PangolinEndpoint = Read-Host "Endpoint"
|
$PangolinEndpoint = Read-Host "Endpoint"
|
||||||
$ArgList = "--id ${PangolinID} --secret ${PangolinSecret} --endpoint ${PangolinEndpoint}"
|
$ArgList = "--id ${PangolinID} --secret ${PangolinSecret} --endpoint ${PangolinEndpoint}"
|
||||||
|
|
||||||
|
Write-Log "Erstelle Dienst und setze Log-Pfade..." "Cyan"
|
||||||
& nssm install $ServiceName "$Symlink" $ArgList
|
& 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 AppRotateFiles 1
|
||||||
& nssm set $ServiceName AppRotateOnline 1
|
& nssm set $ServiceName AppRotateOnline 1
|
||||||
& nssm set $ServiceName AppRotateBytes 10485760
|
& nssm set $ServiceName AppRotateBytes 10485760
|
||||||
|
|
||||||
Start-Service $ServiceName
|
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 {
|
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'))"
|
$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`""
|
$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
|
$Principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
|
||||||
|
|
||||||
Register-ScheduledTask -Action $Action -Trigger $Trigger -Principal $Principal -TaskName $UpdaterTaskName -Force | Out-Null
|
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 ---
|
# --- Main Logic ---
|
||||||
Prepare-Environment
|
Prepare-Environment
|
||||||
|
|
||||||
# Wenn die latest.exe fehlt oder wir im Install-Mode sind -> Installieren
|
|
||||||
if (!(Test-Path $Symlink) -or ($mode -eq "install")) {
|
if (!(Test-Path $Symlink) -or ($mode -eq "install")) {
|
||||||
$v = (Invoke-RestMethod "https://api.github.com/repos/${Repo}/releases/latest").tag_name
|
$v = (Invoke-RestMethod "https://api.github.com/repos/${Repo}/releases/latest").tag_name
|
||||||
Download-Newt $v
|
Download-Newt $v
|
||||||
Setup-Service
|
Setup-Service
|
||||||
Setup-Task
|
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)) {
|
elseif ($mode -eq "update" -or (Test-Path $Symlink)) {
|
||||||
$v = (Invoke-RestMethod "https://api.github.com/repos/${Repo}/releases/latest").tag_name
|
$v = (Invoke-RestMethod "https://api.github.com/repos/${Repo}/releases/latest").tag_name
|
||||||
$vO = $v.TrimStart('v')
|
$vO = $v.TrimStart('v')
|
||||||
if (!(Test-Path "${InstallDir}\newt_${vO}.exe")) {
|
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
|
Download-Newt $v
|
||||||
} else {
|
} else {
|
||||||
Write-Log "System ist aktuell ($vO)." "Cyan"
|
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 }
|
if ((Get-Service $ServiceName).Status -ne 'Running') { Start-Service $ServiceName }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user