Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update agent_linux.sh #1809

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions api/tacticalrmm/core/agent_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading