install_newt-msp-site-win_v2.sh aktualisiert
This commit is contained in:
@@ -1,24 +1,21 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Windows-Installer für den Newt-Client (MAIEREDV Managed Site Client).
|
Windows-Installer für den Newt-Client.
|
||||||
Optimiert für Windows Server (BITS, TLS 1.2, sc.exe Fix).
|
Finaler Fix für sc.exe via CMD-Wrapper.
|
||||||
#>
|
#>
|
||||||
param([string]$mode = "install")
|
param([string]$mode = "install")
|
||||||
|
|
||||||
# 1. Stabilität & Encoding sicherstellen
|
# 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
|
||||||
|
|
||||||
# 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"
|
||||||
$TaskName = "Newt-Updater"
|
$TaskName = "Newt-Updater"
|
||||||
# Ersetze diesen Link durch deine finale Gitea-URL
|
|
||||||
$GiteaUrl = "https://gitea.vmd55888.de/manuel.maier/update-install-newt/raw/branch/main/install_newt-msp-site_v2.ps1"
|
$GiteaUrl = "https://gitea.vmd55888.de/manuel.maier/update-install-newt/raw/branch/main/install_newt-msp-site_v2.ps1"
|
||||||
|
|
||||||
# Helfer-Funktionen
|
|
||||||
function Write-Log($msg, $color = "White") { Write-Host "[$(Get-Date -Format 'HH:mm:ss')] $msg" -ForegroundColor $color }
|
function Write-Log($msg, $color = "White") { Write-Host "[$(Get-Date -Format 'HH:mm:ss')] $msg" -ForegroundColor $color }
|
||||||
|
|
||||||
function Get-LatestVersion {
|
function Get-LatestVersion {
|
||||||
@@ -34,10 +31,7 @@ function Get-LatestVersion {
|
|||||||
|
|
||||||
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" }
|
||||||
|
|
||||||
# URL-Pfad fixen (v entfernen)
|
|
||||||
$VersionOnly = $FullVersion.TrimStart('v')
|
$VersionOnly = $FullVersion.TrimStart('v')
|
||||||
$Url = "https://github.com/$Repo/releases/download/$VersionOnly/newt_$ArchSuffix"
|
$Url = "https://github.com/$Repo/releases/download/$VersionOnly/newt_$ArchSuffix"
|
||||||
$Target = "$InstallDir\newt_$VersionOnly.exe"
|
$Target = "$InstallDir\newt_$VersionOnly.exe"
|
||||||
@@ -60,28 +54,23 @@ function Setup-Service {
|
|||||||
Write-Log "--- Dienst-Konfiguration ---" "Yellow"
|
Write-Log "--- Dienst-Konfiguration ---" "Yellow"
|
||||||
$PangolinID = Read-Host "Bitte Pangolin ID eingeben"
|
$PangolinID = Read-Host "Bitte Pangolin ID eingeben"
|
||||||
$PangolinSecret = Read-Host "Bitte Secret eingeben"
|
$PangolinSecret = Read-Host "Bitte Secret eingeben"
|
||||||
$PangolinEndpoint = Read-Host "Bitte Endpoint eingeben (z.B. https://pangolin.domain.com)"
|
$PangolinEndpoint = Read-Host "Bitte Endpoint eingeben"
|
||||||
|
|
||||||
if ([string]::IsNullOrWhiteSpace($PangolinID)) { Write-Log "FEHLER: ID darf nicht leer sein!" "Red"; exit 1 }
|
if ([string]::IsNullOrWhiteSpace($PangolinID)) { Write-Log "FEHLER: ID leer!" "Red"; exit 1 }
|
||||||
|
|
||||||
|
# Wir bauen den Befehl für CMD.exe zusammen.
|
||||||
|
# Das ist der sicherste Weg, damit die Leerzeichen nach dem '=' erhalten bleiben.
|
||||||
$ArgList = "--id $PangolinID --secret $PangolinSecret --endpoint $PangolinEndpoint"
|
$ArgList = "--id $PangolinID --secret $PangolinSecret --endpoint $PangolinEndpoint"
|
||||||
# Wrapper für den Binärpfad
|
$BinaryPath = "powershell.exe -WindowStyle Hidden -Command \`"$Symlink $ArgList\`""
|
||||||
$BinaryPath = "powershell.exe -WindowStyle Hidden -Command `"$Symlink $ArgList`""
|
|
||||||
|
|
||||||
Write-Log "Erstelle Windows Dienst..." "Cyan"
|
|
||||||
|
|
||||||
# sc.exe braucht zwingend ein Leerzeichen NACH dem Gleichheitszeichen.
|
Write-Log "Erstelle Windows Dienst via CMD-Wrapper..." "Cyan"
|
||||||
# Das Array-Format stellt sicher, dass PowerShell diese nicht wegoptimiert.
|
|
||||||
$scArgs = @(
|
|
||||||
"create", $ServiceName,
|
|
||||||
"binPath=", $BinaryPath,
|
|
||||||
"DisplayName=", "MAIEREDV Managed Site Client",
|
|
||||||
"start=", "auto"
|
|
||||||
)
|
|
||||||
|
|
||||||
& sc.exe $scArgs
|
# Der Trick: Wir rufen cmd /c auf und übergeben den sc-Befehl als String.
|
||||||
|
# Beachte die Leerstellen nach den '=' Zeichen!
|
||||||
|
$cmdCommand = "sc create $ServiceName binPath= ""$BinaryPath"" DisplayName= ""MAIEREDV Managed Site Client"" start= auto"
|
||||||
|
|
||||||
|
cmd.exe /c $cmdCommand
|
||||||
|
|
||||||
# Kleiner Puffer für die Registrierung
|
|
||||||
Start-Sleep -Seconds 2
|
Start-Sleep -Seconds 2
|
||||||
|
|
||||||
if (Get-Service $ServiceName -ErrorAction SilentlyContinue) {
|
if (Get-Service $ServiceName -ErrorAction SilentlyContinue) {
|
||||||
@@ -98,15 +87,13 @@ function Setup-Service {
|
|||||||
|
|
||||||
function Setup-UpdateTask {
|
function Setup-UpdateTask {
|
||||||
$ActionCommand = "powershell.exe -NoProfile -ExecutionPolicy Bypass -Command `"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; iex ((New-Object System.Net.WebClient).DownloadString('$GiteaUrl')) -mode update`""
|
$ActionCommand = "powershell.exe -NoProfile -ExecutionPolicy Bypass -Command `"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; iex ((New-Object System.Net.WebClient).DownloadString('$GiteaUrl')) -mode update`""
|
||||||
|
|
||||||
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument $ActionCommand
|
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument $ActionCommand
|
||||||
$Trigger = New-ScheduledTaskTrigger -Daily -At 3am
|
$Trigger = New-ScheduledTaskTrigger -Daily -At 3am
|
||||||
|
|
||||||
Register-ScheduledTask -Action $Action -Trigger $Trigger -TaskName $TaskName -User "SYSTEM" -Force | Out-Null
|
Register-ScheduledTask -Action $Action -Trigger $Trigger -TaskName $TaskName -User "SYSTEM" -Force | Out-Null
|
||||||
Write-Log "Update-Task fuer 03:00 Uhr erstellt." "Green"
|
Write-Log "Update-Task erstellt." "Green"
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Hauptlogik ---
|
# --- Main Logic ---
|
||||||
switch ($mode) {
|
switch ($mode) {
|
||||||
"install" {
|
"install" {
|
||||||
$v = Get-LatestVersion
|
$v = Get-LatestVersion
|
||||||
@@ -119,7 +106,7 @@ switch ($mode) {
|
|||||||
$v = Get-LatestVersion
|
$v = Get-LatestVersion
|
||||||
$vOnly = $v.TrimStart('v')
|
$vOnly = $v.TrimStart('v')
|
||||||
if (Test-Path "$InstallDir\newt_$vOnly.exe") {
|
if (Test-Path "$InstallDir\newt_$vOnly.exe") {
|
||||||
Write-Log "System ist bereits aktuell ($vOnly)." "Cyan"
|
Write-Log "System aktuell ($vOnly)." "Cyan"
|
||||||
} else {
|
} else {
|
||||||
Download-Newt $v
|
Download-Newt $v
|
||||||
Restart-Service $ServiceName
|
Restart-Service $ServiceName
|
||||||
@@ -127,15 +114,11 @@ switch ($mode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"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
|
||||||
& sc.exe delete $ServiceName
|
cmd.exe /c "sc delete $ServiceName"
|
||||||
}
|
}
|
||||||
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false -ErrorAction SilentlyContinue
|
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false -ErrorAction SilentlyContinue
|
||||||
Write-Log "Dienst und Task entfernt." "Green"
|
Write-Log "Deinstalliert." "Green"
|
||||||
}
|
|
||||||
default {
|
|
||||||
Write-Log "Modus unbekannt: $mode" "Red"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user