Files
update-install-newt/install_newt-msp-site-win_v2.sh

70 lines
2.6 KiB
Bash

# 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"
function Get-LatestVersion {
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
}
}
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 -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
}
}
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://...)"
$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
}
}
# Haupt-Logik (Beispiel für --install)
$Latest = Get-LatestVersion
Download-Newt $Latest
Setup-Service