diff --git a/install_newt-msp-site-win_v2.ps1 b/install_newt-msp-site-win_v2.ps1 index 7ac19d6..6f638ad 100644 --- a/install_newt-msp-site-win_v2.ps1 +++ b/install_newt-msp-site-win_v2.ps1 @@ -1,7 +1,7 @@ <# .SYNOPSIS Windows-Installer für den Newt-Client (MAIEREDV Managed Site Client). - Features: Winget.pro integration, NSSM-Service management, BITS-Turbo, 10MB Log-Rotation. + Features: Winget.pro integration, NSSM-Service, BITS-Turbo, 10MB Log-Rotation. #> param([string]$mode = "install") @@ -15,7 +15,6 @@ $InstallDir = "C:\Program Files\me-msp-newt" $ServiceName = "MAIEREDV-Managed-Site-Client" $Symlink = "$InstallDir\newt_latest.exe" $UpdaterTaskName = "MAIEREDV-Newt-Updater" -# Korrigierter Pfad zu deinem Gitea $GiteaUrl = "https://me-gitea.maieredv.cloud/manuel.maier/update-install-newt/raw/branch/main/install_newt-msp-site-win_v2.ps1" function Write-Log($msg, $color = "White") { @@ -30,7 +29,7 @@ function Prepare-Environment { Invoke-RestMethod -Uri "https://winget.pro/install.ps1" | Invoke-Expression $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") } catch { - Write-Log "FEHLER: Winget konnte nicht installiert werden." "Red"; exit 1 + Write-Log "FEHLER: Winget Installation fehlgeschlagen." "Red"; exit 1 } } @@ -62,7 +61,6 @@ function Download-Newt { Write-Log "Turbo-Download von $VersionOnly..." "Cyan" try { - # BITS Foreground für maximale Geschwindigkeit Start-BitsTransfer -Source $Url -Destination $Target -Priority Foreground -ErrorAction Stop Copy-Item -Path $Target -Destination $Symlink -Force } catch { @@ -77,9 +75,9 @@ function Setup-Service { Write-Log "--- Dienst-Konfiguration ---" "Yellow" $PangolinID = Read-Host "Bitte Pangolin ID 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 } $ArgList = "--id ${PangolinID} --secret ${PangolinSecret} --endpoint ${PangolinEndpoint}" @@ -89,7 +87,6 @@ function Setup-Service { & nssm set $ServiceName AppExit Default Restart & nssm set $ServiceName AppRestartDelay 5000 - # Log-Datei Pfad & Rotation (10 MB) $LogFile = "${InstallDir}\newt_service.log" & nssm set $ServiceName AppStdout "$LogFile" & nssm set $ServiceName AppStderr "$LogFile" @@ -100,13 +97,15 @@ function Setup-Service { Start-Service $ServiceName Write-Log "Dienst erfolgreich gestartet." "Green" } else { - Write-Log "Dienst bereits vorhanden. Starte neu..." "Yellow" + Write-Log "Dienst vorhanden. Starte neu..." "Yellow" Restart-Service $ServiceName } } function Setup-UpdaterTask { - $ActionCommand = "powershell.exe -NoProfile -ExecutionPolicy Bypass -Command `"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; iex ((New-Object System.Net.WebClient).DownloadString('$GiteaUrl')) -mode update`"" + # HIER IST DIE ANPASSUNG: Nutzt nun den ScriptBlock-Syntax für den täglichen Task + $ActionCommand = "powershell.exe -NoProfile -ExecutionPolicy Bypass -Command `"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; & ([scriptblock]::Create((New-Object System.Net.WebClient).DownloadString('$GiteaUrl'))) -mode update`"" + $Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument $ActionCommand $Trigger = New-ScheduledTaskTrigger -Daily -At 3am @@ -114,7 +113,7 @@ function Setup-UpdaterTask { Write-Log "Täglicher Update-Task (03:00 Uhr) registriert." "Green" } -# --- Main Logic --- +# --- Main --- Prepare-Environment switch ($mode) { @@ -123,26 +122,25 @@ switch ($mode) { Download-Newt $v Setup-Service Setup-UpdaterTask - Write-Log "🚀 Installation erfolgreich abgeschlossen!" "Green" + Write-Log "Installation fertig!" "Green" } "update" { $v = Get-LatestVersion $vOnly = $v.TrimStart('v') if (Test-Path "${InstallDir}\newt_${vOnly}.exe") { - Write-Log "System ist bereits aktuell ($vOnly)." "Cyan" + Write-Log "System ist aktuell ($vOnly)." "Cyan" } else { Download-Newt $v Restart-Service $ServiceName - Write-Log "🚀 Update auf $v erfolgreich eingespielt." "Green" + Write-Log "Update auf $v abgeschlossen." "Green" } } "uninstall" { - Write-Log "Deinstallation wird gestartet..." "Yellow" if (Get-Service $ServiceName -ErrorAction SilentlyContinue) { - Stop-Service $ServiceName -Force -ErrorAction SilentlyContinue + Stop-Service $ServiceName -Force & nssm remove $ServiceName confirm } Unregister-ScheduledTask -TaskName $UpdaterTaskName -Confirm:$false -ErrorAction SilentlyContinue - Write-Log "🧹 Deinstallation abgeschlossen." "Green" + Write-Log "Deinstalliert." "Green" } } \ No newline at end of file