Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/enhanced agent script #1128

Merged
merged 4 commits into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,88 @@
setx /M AGENT_ENV "{{.trcDeployAgentEnv}}"
REM Installation instructions:
REM 1. This script expects the following files in the same directory as itself:
REM - nssm.exe
REM - serv_cert.pem
REM - trcsh.exe
REM 2. Copy this script alongside the above files into the Windows machine you wish to deploy it on
REM 3. Run this script as administrator (Right Click -> Run as Administrator)
REM 4. Answer the prompts as needed.
REM 5. The script should complete successfully, moving the above files and opening File Explorer at the install directory.
REM 6. Verify the TrcAgent is running successfully by examining the log file.

@echo off
@setlocal enableextensions
@cd /d "%~dp0"

echo Installing agent...
set /p "environment=What environment is this? (dev/QA) "

if not defined environment (
echo "No environment specified. exiting"
goto :exit
)

if "%environment%" NEQ "dev" if "%environment%" NEQ "QA" (
echo "Invalid environment. Expected dev or QA, got %environment%"
goto :exit
)

set /p "index=What environment index is this? (%environment%-#) "

set combined=%environment%-%index%
echo Constructed environment: %combined%

setx /M AGENT_ENV "%combined%"
setx /M AGENT_TOKEN "{{.trcDeployAgentToken}}"
setx /M DEPLOYMENTS "{{.trcDeployDeployments}}"
setx /M DEPLOYMENTS-%index% "{{.trcDeployDeployments}}"
setx /M VAULT_ADDR "{{.trcDeployVaultAddr}}"

.\nssm.exe install {{.trcDeployServiceName}} "{{.trcDeployExecutable}}"
.\nssm.exe set {{.trcDeployServiceName}} AppDirectory "{{.trcDeployStartDirectory}}"
echo Creating TrcDeploy directory
set startDir="{{.trcDeployStartDirectory}}"
set startDirTrailing=%startDir:~0,-1%
mkdir %startDir%

if exist .\trcsh.exe (
echo Detected trcsh.exe in same dir, moving to install folder...
move .\trcsh.exe %startDir%
) else (
echo Could not find trcsh.exe in same dir, exiting...
goto :exit
)

if exist .\serv_cert.pem (
echo Detected serv_cert.pem in same dir, moving to install folder...
move .\serv_cert.pem %startDir%
) else (
echo Could not find serv_cert.pem in same dir, exiting
goto :exit
)

if exist .\nssm.exe (
echo Detected nssm.exe in same dir, moving to install folder...
move .\nssm.exe %startDir%

if exist %startDirTrailing%\nssm.exe" (
echo Installing service
%startDirTrailing%\nssm.exe" install TrcDeploy "trcsh.exe"
%startDirTrailing%\nssm.exe" set TrcDeploy AppDirectory %startDir%
%startDirTrailing%\nssm.exe" set TrcDeploy AppParameters "-env=%combined%"

echo Starting TrcDeploy...
%startDirTrailing%\nssm.exe" start TrcDeploy
) else (
echo Error occured when moving...
)
) else (
echo Could not find nssm.exe in same dir, exiting
goto :exit
)


explorer %startDir%

echo Execution finished without problems... removing setup.cmd
del %0

:exit
pause