@echo off setlocal EnableExtensions title GSP Windows Agent whoami /groups | find "S-1-16-12288" >nul 2>&1 if not "%errorLevel%" == "0" ( echo Failure: current permissions are inadequate. echo. echo Run this script with "Run as administrator". call :pause_on_error exit /b 1 ) set "WD=%~dp0" pushd "%WD%" >nul 2>&1 set "START_LOG_NATIVE=" set "BASH_EXE=" set "CYGWIN_ROOT=" if exist "%WD%bin\bash.exe" ( set "BASH_EXE=%WD%bin\bash.exe" set "CYGWIN_ROOT=%WD%" ) if not defined BASH_EXE if exist "%WD%..\bin\bash.exe" ( set "BASH_EXE=%WD%..\bin\bash.exe" for %%I in ("%WD%..") do set "CYGWIN_ROOT=%%~fI\" ) if not defined BASH_EXE if exist "%WD%..\..\bin\bash.exe" ( set "BASH_EXE=%WD%..\..\bin\bash.exe" for %%I in ("%WD%..\..") do set "CYGWIN_ROOT=%%~fI\" ) if not defined BASH_EXE if exist "C:\OGP64\bin\bash.exe" ( set "BASH_EXE=C:\OGP64\bin\bash.exe" set "CYGWIN_ROOT=C:\OGP64\" ) if not defined BASH_EXE if exist "C:\cygwin64\bin\bash.exe" ( set "BASH_EXE=C:\cygwin64\bin\bash.exe" set "CYGWIN_ROOT=C:\cygwin64\" ) if not defined BASH_EXE if exist "C:\cygwin\bin\bash.exe" ( set "BASH_EXE=C:\cygwin\bin\bash.exe" set "CYGWIN_ROOT=C:\cygwin\" ) if not defined BASH_EXE ( echo Failure: Cygwin bash.exe was not found. echo. echo Checked: echo %WD%bin\bash.exe echo %WD%..\bin\bash.exe echo %WD%..\..\bin\bash.exe echo C:\OGP64\bin\bash.exe echo C:\cygwin64\bin\bash.exe echo C:\cygwin\bin\bash.exe call :pause_on_error exit /b 1 ) if not exist "%CYGWIN_ROOT%OGP\ogp_agent.pl" ( echo Failure: OGP agent root was not found for detected Cygwin root. echo. echo Detected Cygwin root: echo %CYGWIN_ROOT% echo Expected agent file: echo %CYGWIN_ROOT%OGP\ogp_agent.pl call :pause_on_error exit /b 1 ) set "START_LOG_NATIVE=%CYGWIN_ROOT%var\log\gsp_agent_start.log" if not exist "%CYGWIN_ROOT%var\log" mkdir "%CYGWIN_ROOT%var\log" >nul 2>&1 set "PATH=%CYGWIN_ROOT%bin;%CYGWIN_ROOT%usr\sbin;%PATH%" set "CYGWIN=server ntsec" set "SHELL=/bin/bash" set "GSP_AGENT_START_LOG_NATIVE=%START_LOG_NATIVE%" set "GSP_AGENT_CYGWIN_ROOT=%CYGWIN_ROOT%" set "HELPER=/Install/agent_start_cygwin.sh" if exist "%CYGWIN_ROOT%OGP\Install\agent_start_cygwin.sh" set "HELPER=/OGP/Install/agent_start_cygwin.sh" if not exist "%CYGWIN_ROOT%Install\agent_start_cygwin.sh" if not exist "%CYGWIN_ROOT%OGP\Install\agent_start_cygwin.sh" ( echo Failure: agent_start_cygwin.sh was not found. echo. echo Expected one of: echo %CYGWIN_ROOT%Install\agent_start_cygwin.sh echo %CYGWIN_ROOT%OGP\Install\agent_start_cygwin.sh call :pause_on_error exit /b 1 ) echo Detected startup paths: echo Script directory: %WD% echo Cygwin root: %CYGWIN_ROOT% echo bash.exe: %BASH_EXE% echo OGP path: %CYGWIN_ROOT%OGP echo ogp_agent.pl: %CYGWIN_ROOT%OGP\ogp_agent.pl echo Config path: %CYGWIN_ROOT%OGP\Cfg echo Startup log: %START_LOG_NATIVE% echo. if exist "%START_LOG_NATIVE%" ( del /q "%START_LOG_NATIVE%" >nul 2>&1 ) rem Stop any existing agent processes whose PID files still exist. if exist "%CYGWIN_ROOT%var\run\pure-ftpd.pid" set /p PID1=<"%CYGWIN_ROOT%var\run\pure-ftpd.pid" if exist "%CYGWIN_ROOT%OGP\ogp_agent.pid" set /p PID2=<"%CYGWIN_ROOT%OGP\ogp_agent.pid" if exist "%CYGWIN_ROOT%OGP\ogp_agent_run.pid" set /p PID3=<"%CYGWIN_ROOT%OGP\ogp_agent_run.pid" if defined PID1 kill -15 %PID1% >nul 2>&1 if defined PID2 kill -15 %PID2% >nul 2>&1 if defined PID3 kill -15 %PID3% >nul 2>&1 echo Starting GSP Windows Agent with: echo %BASH_EXE% echo. "%BASH_EXE%" --login "%HELPER%" /OGP/ogp_agent_run.pid set "AGENT_EXIT=%ERRORLEVEL%" if not "%AGENT_EXIT%" == "0" ( echo. echo GSP Windows Agent exited with error code %AGENT_EXIT%. echo. echo ===== Last 100 lines of startup log: %START_LOG_NATIVE% ===== if exist "%START_LOG_NATIVE%" ( powershell -NoProfile -ExecutionPolicy Bypass -Command "Get-Content -LiteralPath '%START_LOG_NATIVE%' -Tail 100" 2>nul ) else ( echo Startup log was not created. ) call :pause_on_error exit /b %AGENT_EXIT% ) popd >nul 2>&1 exit /b 0 :pause_on_error if /I not "%GSP_AGENT_NO_PAUSE%"=="1" pause exit /b 0