install_newt-msp-site-win_v2.sh aktualisiert
This commit is contained in:
@@ -1,10 +1,6 @@
|
|||||||
<#
|
|
||||||
.SYNOPSIS
|
|
||||||
Windows-Pendant zum Newt-Installer.
|
|
||||||
#>
|
|
||||||
param([string]$mode = "install")
|
param([string]$mode = "install")
|
||||||
|
|
||||||
# TLS 1.2 erzwingen
|
# 1. TLS 1.2 erzwingen (Pflicht für GitHub auf Windows Server)
|
||||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||||
|
|
||||||
$Repo = "fosrl/newt"
|
$Repo = "fosrl/newt"
|
||||||
@@ -17,11 +13,12 @@ function Write-Info($msg) { Write-Host "[INFO] $msg" -ForegroundColor Green }
|
|||||||
function Write-Warn($msg) { Write-Host "[WARN] $msg" -ForegroundColor Yellow }
|
function Write-Warn($msg) { Write-Host "[WARN] $msg" -ForegroundColor Yellow }
|
||||||
function Write-ErrorMsg($msg) { Write-Host "[ERROR] $msg" -ForegroundColor Red; exit 1 }
|
function Write-ErrorMsg($msg) { Write-Host "[ERROR] $msg" -ForegroundColor Red; exit 1 }
|
||||||
|
|
||||||
|
# Neueste Version von GitHub API holen
|
||||||
function Get-LatestVersion {
|
function Get-LatestVersion {
|
||||||
try {
|
try {
|
||||||
$url = "https://api.github.com/repos/$Repo/releases/latest"
|
$url = "https://api.github.com/repos/$Repo/releases/latest"
|
||||||
$json = Invoke-RestMethod -Uri $url -UseBasicParsing
|
$json = Invoke-RestMethod -Uri $url -UseBasicParsing
|
||||||
# Wir speichern die Version EXAKT so wie GitHub sie ausgibt (meist mit v)
|
# Wir geben den reinen Tag zurück (z.B. "v1.9.0")
|
||||||
return $json.tag_name
|
return $json.tag_name
|
||||||
} catch {
|
} catch {
|
||||||
Write-ErrorMsg "Konnte Version nicht von GitHub abrufen."
|
Write-ErrorMsg "Konnte Version nicht von GitHub abrufen."
|
||||||
@@ -29,73 +26,81 @@ function Get-LatestVersion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Download-Newt {
|
function Download-Newt {
|
||||||
param($Version)
|
param($FullVersion)
|
||||||
# Architektur-Mapping
|
|
||||||
|
# Architektur bestimmen
|
||||||
$ArchSuffix = if ([Environment]::Is64BitOperatingSystem) { "windows_amd64.exe" } else { "windows_386.exe" }
|
$ArchSuffix = if ([Environment]::Is64BitOperatingSystem) { "windows_amd64.exe" } else { "windows_386.exe" }
|
||||||
|
|
||||||
# WICHTIG: Prüfen ob das 'v' schon im Tag ist
|
# URL FIX: Das 'v' für die URL entfernen, falls vorhanden (macht aus v1.9.0 -> 1.9.0)
|
||||||
$Tag = if ($Version.StartsWith("v")) { $Version } else { "v$Version" }
|
$VersionOnly = $FullVersion.TrimStart('v')
|
||||||
|
|
||||||
# Die Datei auf GitHub heißt oft einfach 'newt_windows_amd64.exe' (ohne Version im Dateinamen)
|
# Exakter URL-Aufbau basierend auf deinem funktionierenden curl-Link
|
||||||
$Url = "https://github.com/$Repo/releases/download/$Tag/newt_$ArchSuffix"
|
$Url = "https://github.com/$Repo/releases/download/$VersionOnly/newt_$ArchSuffix"
|
||||||
$Target = "$InstallDir\newt_$($Tag).exe"
|
$Target = "$InstallDir\newt_$VersionOnly.exe"
|
||||||
|
|
||||||
if (!(Test-Path $InstallDir)) { New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null }
|
if (!(Test-Path $InstallDir)) { New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null }
|
||||||
|
|
||||||
Write-Info "⬇️ Versuche Download von: $Url"
|
Write-Info "⬇️ Versuche Download von: $Url"
|
||||||
try {
|
try {
|
||||||
|
# BITS ist sauberer auf Servern
|
||||||
Start-BitsTransfer -Source $Url -Destination $Target -ErrorAction Stop
|
Start-BitsTransfer -Source $Url -Destination $Target -ErrorAction Stop
|
||||||
Copy-Item -Path $Target -Destination $Symlink -Force
|
Copy-Item -Path $Target -Destination $Symlink -Force
|
||||||
Write-Info "✅ Installiert: $Tag"
|
Write-Info "✅ Datei erfolgreich nach $Target geladen."
|
||||||
} catch {
|
} catch {
|
||||||
Write-ErrorMsg "Download fehlgeschlagen (404?). Prüfe ob die Datei unter $Url existiert. Fehler: $_"
|
Write-ErrorMsg "Download fehlgeschlagen. Bitte prüfe die URL: $Url. Fehler: $_"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Setup-Service {
|
function Setup-Service {
|
||||||
if (!(Get-Service $ServiceName -ErrorAction SilentlyContinue)) {
|
if (!(Get-Service $ServiceName -ErrorAction SilentlyContinue)) {
|
||||||
$PangolinID = Read-Host "🆔 Pangolin ID"
|
$PangolinID = Read-Host "🆔 Bitte Pangolin ID eingeben"
|
||||||
$PangolinSecret = Read-Host "🔑 Secret"
|
$PangolinSecret = Read-Host "🔑 Bitte Secret eingeben"
|
||||||
$PangolinEndpoint = Read-Host "🌐 Endpoint"
|
$PangolinEndpoint = Read-Host "🌐 Bitte Endpoint eingeben"
|
||||||
|
|
||||||
$ArgList = "--id $PangolinID --secret $PangolinSecret --endpoint $PangolinEndpoint"
|
$ArgList = "--id $PangolinID --secret $PangolinSecret --endpoint $PangolinEndpoint"
|
||||||
|
# Wrapper um PowerShell, damit der Dienst nicht wegen Timeouts crasht
|
||||||
$BinaryPath = "powershell.exe -WindowStyle Hidden -Command `"$Symlink $ArgList`""
|
$BinaryPath = "powershell.exe -WindowStyle Hidden -Command `"$Symlink $ArgList`""
|
||||||
|
|
||||||
|
Write-Info "🛠️ Erstelle Dienst..."
|
||||||
& sc.exe create $ServiceName binPath= $BinaryPath start= auto DisplayName= "MAIEREDV Managed Site Client"
|
& sc.exe create $ServiceName binPath= $BinaryPath start= auto DisplayName= "MAIEREDV Managed Site Client"
|
||||||
Start-Service $ServiceName
|
Start-Service $ServiceName
|
||||||
} else {
|
} else {
|
||||||
|
Write-Info "🔄 Dienst existiert bereits, starte neu..."
|
||||||
Restart-Service $ServiceName
|
Restart-Service $ServiceName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Setup-UpdateTask {
|
function Setup-UpdateTask {
|
||||||
# Hier deine Gitea URL eintragen
|
# DEINE GITEA URL HIER EINTRAGEN
|
||||||
$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"
|
||||||
|
|
||||||
$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-Info "✅ Update-Task registriert."
|
Write-Info "✅ Täglicher Update-Task (03:00) wurde erstellt."
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Ausführung ---
|
# --- Main Logic ---
|
||||||
switch ($mode) {
|
switch ($mode) {
|
||||||
"install" {
|
"install" {
|
||||||
$v = Get-LatestVersion
|
$v = Get-LatestVersion
|
||||||
Download-Newt $v
|
Download-Newt $v
|
||||||
Setup-Service
|
Setup-Service
|
||||||
Setup-UpdateTask
|
Setup-UpdateTask
|
||||||
|
Write-Info "🚀 Fertig!"
|
||||||
}
|
}
|
||||||
"update" {
|
"update" {
|
||||||
$v = Get-LatestVersion
|
$v = Get-LatestVersion
|
||||||
$Tag = if ($v.StartsWith("v")) { $v } else { "v$v" }
|
$vOnly = $v.TrimStart('v')
|
||||||
if (Test-Path "$InstallDir\newt_$Tag.exe") {
|
if (Test-Path "$InstallDir\newt_$vOnly.exe") {
|
||||||
Write-Info "Schon aktuell."
|
Write-Info "Bereits auf dem neuesten Stand ($vOnly)."
|
||||||
} else {
|
} else {
|
||||||
Download-Newt $v
|
Download-Newt $v
|
||||||
Restart-Service $ServiceName
|
Restart-Service $ServiceName
|
||||||
|
Write-Info "🚀 Update auf $v abgeschlossen."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"uninstall" {
|
"uninstall" {
|
||||||
@@ -103,6 +108,10 @@ switch ($mode) {
|
|||||||
Stop-Service $ServiceName
|
Stop-Service $ServiceName
|
||||||
& sc.exe delete $ServiceName
|
& sc.exe delete $ServiceName
|
||||||
}
|
}
|
||||||
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false
|
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false -ErrorAction SilentlyContinue
|
||||||
|
Write-Warn "🧹 Dienst und Task wurden entfernt."
|
||||||
|
}
|
||||||
|
default {
|
||||||
|
Write-ErrorMsg "Modus unbekannt. Nutze: install, update, uninstall"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user