install_newt-msp-site-win_v2.sh aktualisiert

This commit is contained in:
2026-02-18 10:42:39 +01:00
parent ff64f78174
commit 02bae9ae1a

View File

@@ -1,70 +1,70 @@
# TLS 1.2 erzwingen (Wichtig für GitHub/Downloads)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$Repo = "fosrl/newt"
$InstallDir = "C:\Program Files\me-msp-newt"
$ServiceName = "MAIEREDV-Managed-Site-Client"
$Symlink = "$InstallDir\newt_latest.exe"
# 1. Latest Version holen
function Get-LatestVersion {
$url = "https://api.github.com/repos/$Repo/releases/latest"
$json = Invoke-RestMethod -Uri $url
return $json.tag_name.TrimStart('v')
try {
$url = "https://api.github.com/repos/$Repo/releases/latest"
$json = Invoke-RestMethod -Uri $url -ErrorAction Stop
return $json.tag_name.TrimStart('v')
} catch {
Write-Error "Fehler beim Abrufen der Version: $_"
exit 1
}
}
# 2. Download & Symlink (Copy)
function Install-Newt {
function Download-Newt {
param($Version)
$Arch = if ([Environment]::Is64BitOperatingSystem) { "newt_windows_amd64.exe" } else { "newt_windows_386.exe" }
$Url = "https://github.com/$Repo/releases/download/v$Version/$Arch"
$Target = "$InstallDir\newt_$Version.exe"
if (!(Test-Path $InstallDir)) { New-Item -ItemType Directory -Path $InstallDir }
Write-Host "⬇️ Downloading $Url..." -ForegroundColor Cyan
Invoke-WebRequest -Uri $Url -OutFile "$Target"
# "Symlink" unter Windows ist zickig, wir kopieren einfach zur 'latest'
Copy-Item -Path $Target -Destination $Symlink -Force
Write-Host "✅ Installed version $Version" -ForegroundColor Green
}
# 3. Dienst nativ erstellen
function Setup-Service {
$PangolinID = Read-Host "ID"
$Secret = Read-Host "Secret" -AsSecureString
$Endpoint = Read-Host "Endpoint"
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Secret)
$PlainSecret = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
$Args = "--id $PangolinID --secret $PlainSecret --endpoint $Endpoint"
# Prüfen ob Dienst existiert, sonst erstellen
if (Get-Service $ServiceName -ErrorAction SilentlyContinue) {
Stop-Service $ServiceName
$service = Get-CimInstance Win32_Service -Filter "Name='$ServiceName'"
$service.Change($null, $null, $null, $null, $null, "$Symlink $Args")
} else {
New-Service -Name $ServiceName `
-BinaryPathName "$Symlink $Args" `
-DisplayName "MAIEREDV Managed Site Client" `
-StartupType Automatic
if (!(Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
Write-Host "⬇️ Downloading $Url ..." -ForegroundColor Cyan
try {
Invoke-WebRequest -Uri $Url -OutFile $Target -ErrorAction Stop
if (Test-Path $Target) {
Copy-Item -Path $Target -Destination $Symlink -Force
Write-Host "✅ Installiert: newt $Version" -ForegroundColor Green
}
} catch {
Write-Error "Download fehlgeschlagen: $_"
exit 1
}
Start-Service $ServiceName
}
# 4. Update Task (statt systemd timer)
function Setup-UpdateTask {
$TaskName = "Newt-Updater"
$Action = New-ScheduledTaskAction -Execute "PowerShell.exe" `
-Argument "-NoProfile -WindowStyle Hidden -Command ""& {Invoke-WebRequest -Uri 'DEINE_URL_ZUM_PS1' | PowerShell}"""
$Trigger = New-ScheduledTaskTrigger -Daily -At 3am
function Setup-Service {
# Abfrage nur, wenn Dienst noch nicht existiert
if (!(Get-Service $ServiceName -ErrorAction SilentlyContinue)) {
$PangolinID = Read-Host "🆔 Pangolin ID"
$PangolinSecret = Read-Host "🔑 Secret"
$PangolinEndpoint = Read-Host "🌐 Endpoint (z.B. https://...)"
Register-ScheduledTask -Action $Action -Trigger $Trigger -TaskName $TaskName -User "SYSTEM" -Force
Write-Host "✅ Daily update task created." -ForegroundColor Green
$ArgList = "--id $PangolinID --secret $PangolinSecret --endpoint $PangolinEndpoint"
# Nativer Windows Dienst (PowerShell Wrapper um Timeouts zu vermeiden)
New-Service -Name $ServiceName `
-BinaryPathName "powershell.exe -WindowStyle Hidden -Command & '$Symlink' $ArgList" `
-DisplayName "MAIEREDV Managed Site Client" `
-Description "Managed Newt Client by MAIEREDV" `
-StartupType Automatic
Start-Service $ServiceName
Write-Host "🛠️ Dienst $ServiceName wurde erstellt und gestartet." -ForegroundColor Green
} else {
Restart-Service $ServiceName
Write-Host "🔄 Dienst neu gestartet." -ForegroundColor Yellow
}
}
# Main Logic (vereinfacht)
# Haupt-Logik (Beispiel für --install)
$Latest = Get-LatestVersion
Install-Newt $Latest
Download-Newt $Latest
Setup-Service
Setup-UpdateTask