Add --agent-id parameter to unified agent installers

The unified installer was missing --agent-id support that existed in
the legacy host-agent installer. This parameter allows users to specify
a custom agent identifier instead of using auto-generated IDs.

Updated both install.sh (Linux/macOS/Synology/Unraid) and install.ps1
(Windows) to accept --agent-id and pass it through to the agent binary.

Related to #772
This commit is contained in:
rcourtman 2025-11-28 06:08:42 +00:00
parent 1b866598c4
commit 1fd439237d
2 changed files with 13 additions and 1 deletions

View file

@ -10,7 +10,8 @@ param (
[bool]$EnableHost = $true,
[bool]$EnableDocker = $false,
[bool]$Insecure = $false,
[bool]$Uninstall = $false
[bool]$Uninstall = $false,
[string]$AgentId = ""
)
$ErrorActionPreference = "Stop"
@ -292,6 +293,7 @@ $ServiceArgs = @(
if ($EnableHost) { $ServiceArgs += "--enable-host" }
if ($EnableDocker) { $ServiceArgs += "--enable-docker" }
if ($Insecure) { $ServiceArgs += "--insecure" }
if (-not [string]::IsNullOrWhiteSpace($AgentId)) { $ServiceArgs += @("--agent-id", "`"$AgentId`"") }
$BinPath = "`"$DestPath`" $($ServiceArgs -join ' ')"

View file

@ -10,6 +10,7 @@
# --enable-host Enable host metrics (default: true)
# --enable-docker Enable docker metrics (default: false)
# --interval <dur> Reporting interval (default: 30s)
# --agent-id <id> Custom agent identifier (default: auto-generated)
# --uninstall Remove the agent
set -euo pipefail
@ -48,6 +49,7 @@ ENABLE_HOST="true"
ENABLE_DOCKER="false"
UNINSTALL="false"
INSECURE="false"
AGENT_ID=""
# --- Helper Functions ---
log_info() { printf "[INFO] %s\n" "$1"; }
@ -70,6 +72,7 @@ build_exec_args() {
if [[ "$ENABLE_HOST" == "true" ]]; then EXEC_ARGS="$EXEC_ARGS --enable-host"; fi
if [[ "$ENABLE_DOCKER" == "true" ]]; then EXEC_ARGS="$EXEC_ARGS --enable-docker"; fi
if [[ "$INSECURE" == "true" ]]; then EXEC_ARGS="$EXEC_ARGS --insecure"; fi
if [[ -n "$AGENT_ID" ]]; then EXEC_ARGS="$EXEC_ARGS --agent-id ${AGENT_ID}"; fi
}
# Build exec args as array for direct execution (proper quoting)
@ -79,6 +82,7 @@ build_exec_args_array() {
if [[ "$ENABLE_HOST" == "true" ]]; then EXEC_ARGS_ARRAY+=(--enable-host); fi
if [[ "$ENABLE_DOCKER" == "true" ]]; then EXEC_ARGS_ARRAY+=(--enable-docker); fi
if [[ "$INSECURE" == "true" ]]; then EXEC_ARGS_ARRAY+=(--insecure); fi
if [[ -n "$AGENT_ID" ]]; then EXEC_ARGS_ARRAY+=(--agent-id "$AGENT_ID"); fi
}
# --- Parse Arguments ---
@ -93,6 +97,7 @@ while [[ $# -gt 0 ]]; do
--disable-docker) ENABLE_DOCKER="false"; shift ;;
--insecure) INSECURE="true"; shift ;;
--uninstall) UNINSTALL="true"; shift ;;
--agent-id) AGENT_ID="$2"; shift 2 ;;
*) fail "Unknown argument: $1" ;;
esac
done
@ -305,6 +310,11 @@ if [[ "$OS" == "darwin" ]]; then
PLIST_ARGS="${PLIST_ARGS}
<string>--insecure</string>"
fi
if [[ -n "$AGENT_ID" ]]; then
PLIST_ARGS="${PLIST_ARGS}
<string>--agent-id</string>
<string>${AGENT_ID}</string>"
fi
cat > "$PLIST" <<EOF
<?xml version="1.0" encoding="UTF-8"?>