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).
|
||||
v2.5 - Prozess-fokussierter Kill & Immediate-Action.
|
||||
v2.6 - Fix für Parser-Error (Variable Drive Reference) & Encoding.
|
||||
#>
|
||||
param([string]$mode = "install")
|
||||
|
||||
@@ -35,21 +35,19 @@ function Download-Newt {
|
||||
catch { Invoke-WebRequest -Uri $Url -OutFile $Target -UseBasicParsing }
|
||||
}
|
||||
|
||||
# --- RADIKALER KILL-BLOCK ---
|
||||
Write-Log "Bereite Datei-Update vor..." "Yellow"
|
||||
Write-Log "Vorbereitung Datei-Update..." "Yellow"
|
||||
|
||||
# 1. Dienst deaktivieren & stoppen
|
||||
if (Get-Service $ServiceName -ErrorAction SilentlyContinue) {
|
||||
Set-Service $ServiceName -StartupType Disabled
|
||||
Stop-Service $ServiceName -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
# 2. PROZESS-CHECK (Nicht Dienst-Check!)
|
||||
# Wir loopen max. 5 mal und versuchen zu killen
|
||||
# Prozess-Kill ohne Doppelpunkt-Variablen-Falle
|
||||
for ($i = 1; $i -le 5; $i++) {
|
||||
$Procs = Get-Process -Name "newt*" -ErrorAction SilentlyContinue
|
||||
if ($Procs) {
|
||||
Write-Log "Versuch $i: Kill hängende Prozesse ($($Procs.Count))..." "Red"
|
||||
$pCount = $Procs.Count
|
||||
Write-Log "Versuch $i - Kill hängende Prozesse ($pCount)..." "Red"
|
||||
taskkill.exe /F /T /IM "newt*" 2>$null
|
||||
Start-Sleep -Seconds 3
|
||||
} else {
|
||||
@@ -57,34 +55,29 @@ function Download-Newt {
|
||||
}
|
||||
}
|
||||
|
||||
# 3. RENAME-TEST (Die ultimative Prüfung)
|
||||
try {
|
||||
if (Test-Path $Symlink) {
|
||||
$TempName = "$Symlink.dead_" + (Get-Date -Format "yyyyMMdd_HHmmss")
|
||||
# Wenn Move-Item fehlschlägt, ist die Datei noch gelockt
|
||||
Move-Item -Path $Symlink -Destination $TempName -Force -ErrorAction Stop
|
||||
Write-Log "Dateipfad durch Umbenennen freigegeben." "Green"
|
||||
Write-Log "Alte Datei verschoben." "Green"
|
||||
}
|
||||
Copy-Item -Path $Target -Destination $Symlink -Force
|
||||
Write-Log "Update erfolgreich eingespielt." "Green"
|
||||
Write-Log "Update erfolgreich." "Green"
|
||||
} catch {
|
||||
Write-Log "KRITISCH: Datei immer noch gesperrt durch Kernel-Lock!" "Red"
|
||||
Write-Log "Der Update wird erst nach einem System-Reboot aktiv." "Yellow"
|
||||
Write-Log "Dateisperre konnte nicht gelöst werden." "Red"
|
||||
}
|
||||
|
||||
# Dienst wieder auf Kurs bringen
|
||||
Set-Service $ServiceName -StartupType Automatic
|
||||
Start-Service $ServiceName -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
function Setup-Service {
|
||||
if (!(Get-Service $ServiceName -ErrorAction SilentlyContinue)) {
|
||||
Write-Log "--- Erst-Konfiguration ---" "Yellow"
|
||||
Write-Log "Setup Dienst..." "Yellow"
|
||||
$PangolinID = Read-Host "ID"; $PangolinSecret = Read-Host "Secret"; $PangolinEndpoint = Read-Host "Endpoint"
|
||||
$ArgList = "--id ${PangolinID} --secret ${PangolinSecret} --endpoint ${PangolinEndpoint}"
|
||||
& nssm install $ServiceName "$Symlink" $ArgList
|
||||
}
|
||||
# Log-Repair & Rotation (Immer ausführen)
|
||||
& nssm set $ServiceName AppStdout "$LogFile"
|
||||
& nssm set $ServiceName AppStderr "$LogFile"
|
||||
& nssm set $ServiceName AppRotateFiles 1
|
||||
@@ -93,8 +86,8 @@ function Setup-Service {
|
||||
}
|
||||
|
||||
function Setup-Task {
|
||||
$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`""
|
||||
$IexCmd = "[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 `"$IexCmd`""
|
||||
$Trigger = New-ScheduledTaskTrigger -Daily -At 3am
|
||||
$Principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
|
||||
Register-ScheduledTask -Action $Action -Trigger $Trigger -Principal $Principal -TaskName $UpdaterTaskName -Force | Out-Null
|
||||
@@ -118,8 +111,8 @@ elseif ($mode -eq "update" -or (Test-Path $Symlink)) {
|
||||
if (!(Test-Path "${InstallDir}\newt_${vO}.exe")) {
|
||||
Download-Newt $v
|
||||
} else {
|
||||
Write-Log "System aktuell ($vO)." "Cyan"
|
||||
Setup-Service # Sicherstellen dass Logs gehen
|
||||
Write-Log "System aktuell." "Cyan"
|
||||
Setup-Service
|
||||
if ((Get-Service $ServiceName).Status.value__ -ne 4) { Start-Service $ServiceName }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user