Skip to main content

Huntress Agent (Install) - MAC

Summary

This task will first check if Huntress is installed. If it is not, the script will attempt to install the agent and log the result for MAC machines.

Create Script

Please create a new "PowerShell" style script to implement this task.

Image 1
Image 2

Name: Huntress Agent (Install) - MAC
Description: This task will check if Huntress is installed. If not, it will attempt to install the agent and log the result for MAC machines.
Category: Custom

Image 3

Script

Row 1 Function: Script Log

Image 4

Input the following:

The script will detect the Huntress Agent, and if the agent is not found, it will install the agent.  

acct_key : @acct_key@
org_key: @ORG_Key@
tags: ['installation', 'logging']

Attempting to download the file using acct_key from the Huntress website as below:
https://huntress.io/script/darwin/@acctKey, and once downloaded, the agent will be attempted to install.

Row 2 Function: Set Pre-defined Variable

  • Select Set Pre-Defined Variable Function
    Image 5

  • Select Custom Field

  • Input acct_key as Variable name

  • Select Huntress Acct_Key custom field from the dropdown

  • Click Save

Image 6

Row 3 Function: Set Pre-defined Variable

  • Select Set Pre-Defined Variable Function
    Image 7

  • Select Custom Field

  • Input ORG_Key as Variable name

  • Select Huntress Org_Key custom field from the dropdown

  • Click Save

Image 8

Row 4 Function: Set Pre-defined Variable

  • Select Set Pre-Defined Variable Function
    Image 9

  • Select Custom Field

  • Input Tags as Variable name

  • Select Huntress Tag custom field from the dropdown

  • Click Save

Image 10

Row 5 Function: Bash Script

Image 11

Paste the following PowerShell script and set the expected script execution time to 900 seconds.

#!/bin/bash

# Check if Huntress is installed
if command -v huntress &> /dev/null
then
echo "Huntress agent is installed already."
exit 0
else
echo "Huntress is not installed. Proceeding with installation."
fi

# Download the Huntress installation script
curl -o /tmp/HuntressMacInstall.sh -L "https://huntress.io/script/darwin/@acctKey@"

# Execute the installation script
bash /tmp/HuntressMacInstall.sh -a @acctKey@ -o "@orgKey@" -t "@tags@"

# Revalidate if Huntress is installed
if command -v huntress &> /dev/null
then
echo "Huntress agent is installed successfully."
else
echo "Failed to install Huntress."
fi

Image 12

Step 6 Function: Script Log

  • Add a new row in the If Section of the If-Else part by clicking the Add Row button
  • Search and select the Script Log function.
  • Input the following:
%Output%

Image 13
Image 14

Step 7 Logic: If/Then

  • Add a new If/Then/Else logic from the Add Logic dropdown menu.
    Image 15

Row 7a Condition: Output Contains

  • Type Huntress agent is installed in the Value box.
    Image 16

Row 7b Function: Set Custom Field

  • Add a new row in the If Section of the If-Else part by clicking the Add Row button

  • Search and select the Set Custom Field function.
    Image 17

  • Search and select the Huntress Deploy_Result Custom Field.

  • Type Successfully Installed in the Value box and click the Save button.

Row 7c Function: Script Exit

  • Add a new row in the If Section of the If-Else part by clicking the Add Row button
  • Search and select the Script Exit function.
  • Leave the value blank to allow the script to exit on success.

Image 18
Image 19

Step 8 Function: Script Exit

  • Add a new row in the If Section of the If-Else part by clicking the Add Row button
  • Search and select the Script Log function.
  • Input the following:
Huntress Agent failed to install. Refer to the logs: %Output%

Image 20
Image 21

Step 10: Complete Script

Image 22

Script Deployment

This task must be scheduled on Deploy Huntress - MAC, the group for auto-deployment. The script can also be run manually if required.

Go to Automations > Tasks.
Search for Huntress Agent Install.
Then click on Schedule and select the Target:

Image 23

Select the group "Deploy Huntress - MAC" and save the selection.

Image 24

Once selected, click on Run to schedule the script as per requirement.

Output

  • Script log