install_newt-msp-site_v2.sh aktualisiert
This commit is contained in:
+18
-19
@@ -1,26 +1,27 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Windows-Installer für den Newt-Client.
|
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")
|
param([string]$mode = "install")
|
||||||
|
|
||||||
|
# 1. Stabilität & Encoding
|
||||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||||
|
|
||||||
# --- Konfiguration ---
|
# 2. Konfiguration
|
||||||
$Repo = "fosrl/newt"
|
$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"
|
||||||
$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.1.ps1"
|
||||||
|
|
||||||
function Write-Log($msg, $color = "White") {
|
function Write-Log($msg, $color = "White") {
|
||||||
Write-Host "[$(Get-Date -Format 'HH:mm:ss')] $msg" -ForegroundColor $color
|
Write-Host "[$(Get-Date -Format 'HH:mm:ss')] $msg" -ForegroundColor $color
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Umgebung vorbereiten ---
|
# 3. Umgebung vorbereiten
|
||||||
function Prepare-Environment {
|
function Prepare-Environment {
|
||||||
if (!(Get-Command winget -ErrorAction SilentlyContinue)) {
|
if (!(Get-Command winget -ErrorAction SilentlyContinue)) {
|
||||||
Write-Log "Winget fehlt. Installiere via winget.pro..." "Cyan"
|
Write-Log "Winget fehlt. Installiere via winget.pro..." "Cyan"
|
||||||
@@ -49,7 +50,7 @@ function Get-LatestVersion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Download & Cleanup ---
|
# 4. Download & Cleanup
|
||||||
function Download-Newt {
|
function Download-Newt {
|
||||||
param($FullVersion)
|
param($FullVersion)
|
||||||
$ArchSuffix = if ([Environment]::Is64BitOperatingSystem) { "windows_amd64.exe" } else { "windows_386.exe" }
|
$ArchSuffix = if ([Environment]::Is64BitOperatingSystem) { "windows_amd64.exe" } else { "windows_386.exe" }
|
||||||
@@ -79,7 +80,7 @@ function Download-Newt {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Copy-Item -Path $Target -Destination $Symlink -Force
|
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 {
|
} catch {
|
||||||
Write-Log "FEHLER: Datei blockiert." "Red"
|
Write-Log "FEHLER: Datei blockiert." "Red"
|
||||||
}
|
}
|
||||||
@@ -94,10 +95,7 @@ function Download-Newt {
|
|||||||
Where-Object { $_.Name -ne "newt_latest.exe" } |
|
Where-Object { $_.Name -ne "newt_latest.exe" } |
|
||||||
Sort-Object LastWriteTime -Descending |
|
Sort-Object LastWriteTime -Descending |
|
||||||
Select-Object -Skip 2
|
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 {
|
function Setup-Service {
|
||||||
@@ -122,21 +120,18 @@ function Setup-Service {
|
|||||||
& nssm set $ServiceName AppRotateBytes 10485760
|
& nssm set $ServiceName AppRotateBytes 10485760
|
||||||
|
|
||||||
Start-Service $ServiceName
|
Start-Service $ServiceName
|
||||||
|
Write-Log "Dienst gestartet." "Green"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Setup-UpdaterTask {
|
function Setup-UpdaterTask {
|
||||||
# Wir bauen den Befehl so um, dass er robuster gegenüber Gänsefüßchen ist
|
$ActionScript = "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; `$s = (New-Object System.Net.WebClient).DownloadString('$GiteaUrl'); `$b = [scriptblock]::Create(`$s); & `$b -mode update"
|
||||||
$ScriptBody = "[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`""
|
||||||
$ActionCommand = "powershell.exe -NoProfile -ExecutionPolicy Bypass -Command `"$ScriptBody`""
|
|
||||||
|
|
||||||
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -Command `"$ScriptBody`""
|
|
||||||
$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
|
||||||
|
|
||||||
# Task registrieren
|
|
||||||
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) mit SYSTEM-Principal registriert." "Green"
|
Write-Log "Update-Task (03:00 Uhr) registriert." "Green"
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Main ---
|
# --- Main ---
|
||||||
@@ -148,7 +143,7 @@ switch ($mode) {
|
|||||||
Download-Newt $v
|
Download-Newt $v
|
||||||
Setup-Service
|
Setup-Service
|
||||||
Setup-UpdaterTask
|
Setup-UpdaterTask
|
||||||
Write-Log "🚀 Installation abgeschlossen!" "Green"
|
Write-Log "Installation abgeschlossen!" "Green"
|
||||||
}
|
}
|
||||||
"update" {
|
"update" {
|
||||||
$v = Get-LatestVersion
|
$v = Get-LatestVersion
|
||||||
@@ -166,15 +161,19 @@ switch ($mode) {
|
|||||||
|
|
||||||
if ($NeedsUpdate) {
|
if ($NeedsUpdate) {
|
||||||
Download-Newt $v
|
Download-Newt $v
|
||||||
|
Write-Log "Update auf $v erledigt." "Green"
|
||||||
} else {
|
} else {
|
||||||
|
Write-Log "System aktuell ($vOnly)." "Cyan"
|
||||||
if ((Get-Service $ServiceName).Status -ne 'Running') { Start-Service $ServiceName }
|
if ((Get-Service $ServiceName).Status -ne 'Running') { Start-Service $ServiceName }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"uninstall" {
|
"uninstall" {
|
||||||
|
Write-Log "Deinstallation..." "Yellow"
|
||||||
if (Get-Service $ServiceName -ErrorAction SilentlyContinue) {
|
if (Get-Service $ServiceName -ErrorAction SilentlyContinue) {
|
||||||
Stop-Service $ServiceName -Force
|
Stop-Service $ServiceName -Force -ErrorAction SilentlyContinue
|
||||||
& nssm remove $ServiceName confirm
|
& nssm remove $ServiceName confirm
|
||||||
}
|
}
|
||||||
Unregister-ScheduledTask -TaskName $UpdaterTaskName -Confirm:$false -ErrorAction SilentlyContinue
|
Unregister-ScheduledTask -TaskName $UpdaterTaskName -Confirm:$false -ErrorAction SilentlyContinue
|
||||||
|
Write-Log "Alles entfernt." "Green"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user