windows installation with token built in?
-
is there a way to install with the token preconfigured so i can have an easier deployment? eg can the token be passed via cmd line to run the installer ? Its not a huge deal but id rather distribute a USB stick and have someone just double click a bat file.
edit: ideally with a pre-configured command as well. I really only need it to launch a browser remotely but id like to not have to manually configure it on each computer
-
@Irfan-Khan, yes, if your script creates a .TRIGGERcmdData folder in the user's home folder and prepopulates it with these 3 files, it can run the installer and the installer should find the existing data and use it instead of prompting for a token.
Please look at your C:\Users\(username)\.TRIGGERcmdData folder. You'll see these 3 files:
- token.tkn <- your token for the agent to login.
- computerid.cfg <- the computer in your account that the agent will use.
- commands.json <- the commands the agent will sync to that computer.
If those files exist already when the agent is installed, the agent will use them.
If you want to get fancy you can create a computer with a specific name (or use %COMPUTERNAME% if it's Windows) in the script with this API call:
https://github.com/rvmey/aks-tcmd-demo/blob/master/demo.sh#L11 -
I dont know if im misunderstanding .. but the computerid.cfg would have to be generated during an install, correct?
I can copy the tkn and json, and can create the computers with an API call...
are you saying create the computer in the API first, and then copy that computer ID into the cfg file?
so id pre-create the .TRIGGERcmdData folder, populate with the 3 files, and then run the installer?
can i pull the computer id based on name via API? that way the script can look for a specific computer name, pull the id, and save it to the cfg file before the installer runs?
-
ok i see i can get a computer list from /computer/list.
so i will have to:
1- create the computer via API
2- get the computer id via api
3- save the id to a computerid.cfg file
4- copy over the tkn
5- copy over the json file to copy commands
6- run the installerand then on launch it should automatically attach to the computer i named, with commands already added.
id prefer to be able to skip 1/2/3 and just copy the tkn and json and let it create a new computer itsself.. and then on the portal id simply rename it manually for my automations.. but it seems that i cannot install with just the tkn and json in the folder... the application fails to launch correctly. if i have all 3 files it will install ad run preconfigured... but not without the cfg file.
-
@Irfan-Khan, this API call takes a computer name and a token as input, and outputs a computer ID, so your script could do what the agent code does and detect the computer's name with COMPUTERNAME environment variable, or you could use the user's username as the computer name via the USERNAME env var.
This is bash script code, but I can give you a python or Windows batch script example if you want.
export COMPUTER_ID=$(curl -H "Authorization: Bearer ${TOKEN}" "https://www.triggercmd.com/api/computer/save?name=${COMPUTER_NAME}&voice=container" | jq -r .data.id)
-
@Russ yes im running it in windows batch. that would be great
-
@Irfan-Khan, here's a batch file example. If you have questions I can explain it.
set /p TCMD_TOKEN=<%USERPROFILE%\.TRIGGERcmdData\token.tkn curl -H "Authorization: Bearer %TCMD_TOKEN%" "https://www.triggercmd.com/api/computer/save?name=%COMPUTERNAME%&voice=%USERNAME%" > %TEMP%\new_computer.json set /p json_string= < %TEMP%\new_computer.json del %TEMP%\new_computer.json echo %json_string% | jq -r .data.id > %TEMP%\new_computerid.cfg set /p NEW_COMPUTERID=<%TEMP%\new_computerid.cfg del %TEMP%\new_computerid.cfg (echo | set /p=%NEW_COMPUTERID%)> %USERPROFILE%\.TRIGGERcmdData\computerid.cfg
The batch file requires curl and jq.
The TRIGGERcmd agent won't work with a computerid.cfg file that has trailing space at the end of the computer id, and it has to be a single line (no newline character at the end). That last line of the script avoids both. The parentheses strip off the trailing space, and I used echo | set /p= instead of just echo because echo adds a newline character.
-
Thank you. I got the script to add the tkn and copy the commands i want and create the cfg.but when i run the installer after the script the app fails to launch.it loads into the tray, but its non-functional. looking at the debug log i see: (redacted computer idand user folder)My mistake, my token.tkn had a line break in it that broke things. fixed that and it all works.
Checking if the 6xxxxxxxxxxxxxxxxxxxx computer exists. Error while checking whether computer exists in your account. TypeError: The header content contains invalid characters at ClientRequest.OutgoingMessage.setHeader (_http_outgoing.js:346:11) at new ClientRequest (_http_client.js:85:14) at Object.exports.request (http.js:31:10) at Object.exports.request (https.js:199:15) at Request.start (C:\Users\xxxx\AppData\Local\TRIGGERcmdAgent\app-1.0.25\resources\app\node_modules\request\request.js:751:32) at Request.end (C:\Users\xxxx\AppData\Local\TRIGGERcmdAgent\app-1.0.25\resources\app\node_modules\request\request.js:1505:10) at end (C:\Users\xxxx\AppData\Local\TRIGGERcmdAgent\app-1.0.25\resources\app\node_modules\request\request.js:564:14) at Immediate.<anonymous> (C:\Users\xxxx\AppData\Local\TRIGGERcmdAgent\app-1.0.25\resources\app\node_modules\request\request.js:578:7) at runCallback (timers.js:574:20) at tryOnImmediate (timers.js:554:5)
-
Doh. looks like my token.tkn had a line break in it. oops.
it all works fine now thank you
-
@Irfan-Khan, I hope you'll share your end product when you get it all figured out.
-
-