From ef82d9327d2ddb574a41f9936bcc0456cee3c261 Mon Sep 17 00:00:00 2001 From: beroodhunt Date: Thu, 29 Jan 2026 15:46:38 -0800 Subject: [PATCH 1/2] don't fail fast (-e) handle errors --- Bash/linux/huntress-linux-install.sh | 52 ++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 15 deletions(-) mode change 100644 => 100755 Bash/linux/huntress-linux-install.sh diff --git a/Bash/linux/huntress-linux-install.sh b/Bash/linux/huntress-linux-install.sh old mode 100644 new mode 100755 index e9dddb5..161bb14 --- a/Bash/linux/huntress-linux-install.sh +++ b/Bash/linux/huntress-linux-install.sh @@ -4,7 +4,7 @@ # Unauthorized copying of this file, via any medium is strictly prohibited # without the express written consent of Huntress Labs, Inc. -set -euo pipefail +set -uo pipefail declare ACCOUNT_KEY= declare ORG_KEY= @@ -104,17 +104,19 @@ get_user_creds() { # download latest Huntress package from S3 download_latest() { - status_code="0" + local url="${PORTAL_URL}/download/linux/${ACCOUNT_KEY}?arch=${ARCH}" + local status_code="0" + # If neither wget or curl exists on the system, then we fail at the previous validation step - if [ "$WGET_INSTALLED" = true ]; then - status_code=$(wget -S -pO "${HUNTRESS_PKG}" "${PORTAL_URL}/download/linux/${ACCOUNT_KEY}?arch=${ARCH}" 2>&1 \ - | grep "HTTP/" | awk '{print $2}') - else - status_code=$(curl -f -L -o "${HUNTRESS_PKG}" -w "%{http_code}" \ - "${PORTAL_URL}/download/linux/${ACCOUNT_KEY}?arch=${ARCH}") + if [ "$CURL_INSTALLED" = true ]; then + status_code=$(curl -f -L -o "${HUNTRESS_PKG}" -w "%{http_code}" "${url}") + elif [ "$WGET_INSTALLED" = true ]; then + # if there is a redirect, get the last http response code + status_code=$(wget -S -pO "${HUNTRESS_PKG}" "${url}" 2>&1 | grep "HTTP/" | awk '{print $2}' | tail -n 1 | tr -d '[:space:]' ) fi - if [ $? != 0 ]; then + if [ $? != 0 ] || [ "$status_code" != "200" ]; then + # provide helpful failure message if [ "$status_code" = "400" ]; then die "Account Key not valid." elif [ "$status_code" = "404" ]; then @@ -122,9 +124,15 @@ download_latest() { elif [ "$status_code" = "409" ]; then die "The Linux Beta has not been enabled for this account." fi - elif ! [ -f "$HUNTRESS_PKG" ]; then + + die "Failed to download installation package" + fi + + if ! [ -f "$HUNTRESS_PKG" ]; then die "File download failed." fi + + return 0 } # determine arch type @@ -158,6 +166,25 @@ validate_package() { fi } +test_url() { + # use curl if installed + if [ "$CURL_INSTALLED" = true ]; then + if curl -s -o /dev/null "$1"; then + return 0 # success + fi + elif [ "$WGET_INSTALLED" = true ]; then + wget --spider --quiet "$1" || local exit_code=$? + exit_code=${exit_code:-0} + + # return code 8 connection succeeded, but the server returned a non-200 status + if [ $exit_code -eq 0 ] || [ $exit_code -eq 8 ]; then + return 0 # success + fi + fi + + die "CONNECTION FAILURE: Unable to reach $1" +} + # Check minimum requirements validate_requirements() { log_info "[+] Validating requirements" @@ -188,11 +215,6 @@ validate_requirements() { die "REQUIREMENT FAILURE: curl or wget needs to be installed" fi - test_url() { - if ! curl -s -o /dev/null "$1"; then - die "CONNECTION FAILURE: Unable to reach $1" - fi - } test_url "https://huntress.io" test_url "https://s3.amazonaws.com" test_url "https://huntresscdn.com" From a662a31263d0a2fd8733e5f9fa76156bc422081d Mon Sep 17 00:00:00 2001 From: beroodhunt Date: Thu, 29 Jan 2026 19:42:11 -0800 Subject: [PATCH 2/2] shellcheck --- Bash/linux/huntress-linux-install.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Bash/linux/huntress-linux-install.sh b/Bash/linux/huntress-linux-install.sh index 161bb14..3deaf7c 100755 --- a/Bash/linux/huntress-linux-install.sh +++ b/Bash/linux/huntress-linux-install.sh @@ -106,16 +106,19 @@ get_user_creds() { download_latest() { local url="${PORTAL_URL}/download/linux/${ACCOUNT_KEY}?arch=${ARCH}" local status_code="0" + local exit_code=0 # If neither wget or curl exists on the system, then we fail at the previous validation step if [ "$CURL_INSTALLED" = true ]; then status_code=$(curl -f -L -o "${HUNTRESS_PKG}" -w "%{http_code}" "${url}") + exit_code=$? elif [ "$WGET_INSTALLED" = true ]; then # if there is a redirect, get the last http response code status_code=$(wget -S -pO "${HUNTRESS_PKG}" "${url}" 2>&1 | grep "HTTP/" | awk '{print $2}' | tail -n 1 | tr -d '[:space:]' ) + exit_code=$? fi - if [ $? != 0 ] || [ "$status_code" != "200" ]; then + if [ "$exit_code" != 0 ] || [ "$status_code" != "200" ]; then # provide helpful failure message if [ "$status_code" = "400" ]; then die "Account Key not valid." @@ -177,7 +180,7 @@ test_url() { exit_code=${exit_code:-0} # return code 8 connection succeeded, but the server returned a non-200 status - if [ $exit_code -eq 0 ] || [ $exit_code -eq 8 ]; then + if [ "$exit_code" -eq 0 ] || [ "$exit_code" -eq 8 ]; then return 0 # success fi fi