diff --git a/api/tacticalrmm/core/agent_linux.sh b/api/tacticalrmm/core/agent_linux.sh index 3b15921636..736f590006 100755 --- a/api/tacticalrmm/core/agent_linux.sh +++ b/api/tacticalrmm/core/agent_linux.sh @@ -21,9 +21,19 @@ if [[ $DISPLAY ]]; then exit 1 fi +agentSvcName='tacticalagent.service' +agentSysD="/etc/systemd/system/${agentSvcName}" + +if [ -f "${agentSysD}" ]; then + CUSTOM_BIN_PATH=$(awk -F'=' '/ExecStart/ {print $2}' ${agentSysD} | awk '{print $1}' | xargs dirname) +else + CUSTOM_BIN_PATH="" +fi + DEBUG=0 INSECURE=0 NOMESH=0 +UNINSTALL=0 agentDL='agentDLChange' meshDL='meshDLChange' @@ -35,7 +45,22 @@ siteID='siteIDChange' agentType='agentTypeChange' proxy='' -agentBinPath='/usr/local/bin' +while [[ "$#" -gt 0 ]]; do + case $1 in + -debug | --debug | debug) DEBUG=1 ;; + -insecure | --insecure | insecure) INSECURE=1 ;; + -nomesh | --nomesh | nomesh) NOMESH=1 ;; + -uninstall | --uninstall | uninstall) UNINSTALL=1 ;; + -binpath | --binpath) CUSTOM_BIN_PATH="$2"; shift ;; + *) + echo "ERROR: Unknown parameter: $1" + exit 1 + ;; + esac + shift +done + +agentBinPath="${CUSTOM_BIN_PATH:-/usr/local/bin}" binName='tacticalagent' agentBin="${agentBinPath}/${binName}" agentConf='/etc/tacticalagent' @@ -137,28 +162,20 @@ Uninstall() { RemoveOldAgent } -if [ $# -ne 0 ] && [[ $1 =~ ^(uninstall|-uninstall|--uninstall)$ ]]; then +if [[ $UNINSTALL -eq 1 ]]; then Uninstall # Remove the current script rm "$0" exit 0 fi -while [[ "$#" -gt 0 ]]; do - case $1 in - -debug | --debug | debug) DEBUG=1 ;; - -insecure | --insecure | insecure) INSECURE=1 ;; - -nomesh | --nomesh | nomesh) NOMESH=1 ;; - *) - echo "ERROR: Unknown parameter: $1" - exit 1 - ;; - esac - shift -done - RemoveOldAgent +if [ ! -d "${agentBinPath}" ]; then + echo "Creating ${agentBinPath}" + mkdir -p ${agentBinPath} +fi + echo "Downloading tactical agent..." wget -q -O ${agentBin} "${agentDL}" if [ $? -ne 0 ]; then @@ -182,11 +199,6 @@ else MESH_NODE_ID=$(env XAUTHORITY=foo DISPLAY=bar ${agentBin} -m nixmeshnodeid) fi -if [ ! -d "${agentBinPath}" ]; then - echo "Creating ${agentBinPath}" - mkdir -p ${agentBinPath} -fi - INSTALL_CMD="${agentBin} -m install -api ${apiURL} -client-id ${clientID} -site-id ${siteID} -agent-type ${agentType} -auth ${token}" if [ "${MESH_NODE_ID}" != '' ]; then