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