70 lines
2.6 KiB
Bash
70 lines
2.6 KiB
Bash
$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')
|
|
}
|
|
|
|
# 2. Download & Symlink (Copy)
|
|
function Install-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
|
|
}
|
|
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
|
|
|
|
Register-ScheduledTask -Action $Action -Trigger $Trigger -TaskName $TaskName -User "SYSTEM" -Force
|
|
Write-Host "✅ Daily update task created." -ForegroundColor Green
|
|
}
|
|
|
|
# Main Logic (vereinfacht)
|
|
$Latest = Get-LatestVersion
|
|
Install-Newt $Latest
|
|
Setup-Service
|
|
Setup-UpdateTask |