@echo off
rem ============================================================================
rem  PixelPup Remote Management agent - installer
rem  ONE file. Download it, right-click, Run as administrator. Nothing else.
rem
rem  Published at:  https://pixelpup.net/agent
rem
rem  WHAT THIS IS
rem  ------------
rem  The agent opens ONE outbound connection to pixelpup.net over port 443 and
rem  holds it. There is no rendezvous, no hole punching, no UDP, and no NAT
rem  traversal - the things that make a machine show "online" and still refuse
rem  every connection. If this PC can browse the web, support can reach it.
rem
rem  It does not replace RustDesk. RustDesk stays for interactive remote desktop.
rem  This is the channel that always answers, so a machine can be diagnosed and
rem  fixed even when RustDesk cannot connect to it.
rem
rem  MAINTENANCE WARNING - do NOT reformat the powershell lines below.
rem  Each `powershell -Command "..."` must stay on ONE line: inside a quoted
rem  string cmd.exe does NOT treat `^` as a line continuation, so a multi-line
rem  version passes a literal ^ to PowerShell and the block silently fails.
rem  This file must also stay CRLF - LF-only endings break batch parsing.
rem ============================================================================
Title PixelPup - Install Remote Management Agent

net session >nul 2>&1
if %errorlevel% neq 0 (
    echo Requesting administrator permission...
    powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
    exit /b
)

set "DEST=C:\ProgramData\PixelPup\mesh"
set "BASE=https://pixelpup.net"

color 0B
cls
echo.
echo    ==========================================================
echo         __      _
echo      o'')}____//     P I X E L P U P
echo       `_/      )     Remote Management Agent
echo       (_(_/-(_/
echo    ==========================================================
echo.

if not exist "%DEST%" mkdir "%DEST%" >nul 2>&1

echo [1/3] Downloading the agent...
powershell -NoProfile -Command "try{[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;foreach($f in 'meshagent.exe'){$d=Join-Path '%DEST%' $f;Invoke-WebRequest -Uri ('%BASE%/'+$f) -OutFile $d -UseBasicParsing -TimeoutSec 180;if((Get-Item $d).Length -lt 1000){throw ('truncated: '+$f)};Write-Host ('      got '+$f+' ('+[math]::Round((Get-Item $d).Length/1KB)+' KB)')}}catch{Write-Host ('      FAILED - '+$_.Exception.Message);exit 1}"
if errorlevel 1 (
    echo.
    echo    [X] Could not download from pixelpup.net.
    echo        Check this machine has internet access, then run this again.
    echo.
    pause
    exit /b 1
)

echo.
echo [2/3] Installing ^(this registers a background service^)...
rem -fullinstall installs the service. No .msh is needed: the exe was downloaded
rem with &meshid= so the server URL and group are embedded inside it.
rem (previous note about reading meshagent.msh from the same
rem folder for the server address and device-group identity.
pushd "%DEST%"
meshagent.exe -fullinstall
popd

echo.
echo [3/3] Verify...
powershell -NoProfile -Command "Start-Sleep -Seconds 6; $s=Get-Service 'Mesh Agent' -ErrorAction SilentlyContinue; if($s){Write-Host ('      Mesh Agent service: '+$s.Status)}else{Write-Host '      [!] Mesh Agent service not found - install may have failed'}"

echo.
echo    ==========================================================
echo      Done. This computer is now reachable for support whenever
echo      it has an internet connection.
echo    ==========================================================
echo.
pause
