From 81e9aa6fdcce3a87480588553d738b27ab7737c3 Mon Sep 17 00:00:00 2001 From: mattchis <1776285+mattchis@users.noreply.github.com> Date: Thu, 8 Dec 2022 13:50:12 -0700 Subject: [PATCH 1/6] Fixes for the /root/.profile file: - Fixed the issue when installing the LinuxRMM-Script the /root/.profile PATH variable is incorrect. - Added a check_profile function to check the integrity of the /root/.profile PATH variable and correct any issues it my find. Running the update function will correct the profile as well. --- rmmagent-linux.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/rmmagent-linux.sh b/rmmagent-linux.sh index 92fbe9b..6ae0f16 100644 --- a/rmmagent-linux.sh +++ b/rmmagent-linux.sh @@ -119,7 +119,7 @@ function go_install() { export GOPATH=/usr/local/go export GOCACHE=/root/.cache/go-build - echo "export PATH=/usr/local/go/bin" >> /root/.profile + echo "export PATH=$PATH:/usr/local/go/bin" >> /root/.profile echo "Golang Install Done !" } @@ -193,15 +193,35 @@ function install_mesh() { rm /tmp/meshagent.msh } +function check_profile () { + source /etc/environment + profile_file="/root/.profile" + path_count=$(cat $profile_file | grep -o "export PATH=/usr/local/go/bin" | wc -l) + if [[ $path_count -ne 0 ]]; then + echo "Removing incorrect \$PATH variable\(s\)" + sed -i "/export\ PATH\=\/usr\/local\/go\/bin/d" $profile_file + fi + + path_count=$(cat $profile_file | grep -o "export PATH=\$PATH:/usr/local/go/bin" | wc -l) + if [[ $path_count -ne 1 ]]; then + echo "Fixing \$PATH Variable" + sed -i "/export\ PATH\=\$PATH\:\/usr\/local\/go\/bin/d" $profile_file + echo "export PATH=\$PATH:/usr/local/go/bin" >> $profile_file + fi + source $profile_file +} + case $1 in install) go_install + check_profile install_mesh agent_compile install_agent echo "Tactical Agent Install is done" exit 0;; update) + check_profile go_install agent_compile update_agent From ff0eb12f2a739839462af0fece601d0b56589892 Mon Sep 17 00:00:00 2001 From: mattchis <1776285+mattchis@users.noreply.github.com> Date: Thu, 8 Dec 2022 14:00:16 -0700 Subject: [PATCH 2/6] Added a dependency check for unzip. If unzip is not found the script will exit. --- rmmagent-linux.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rmmagent-linux.sh b/rmmagent-linux.sh index 6ae0f16..5cd3c19 100644 --- a/rmmagent-linux.sh +++ b/rmmagent-linux.sh @@ -1,4 +1,10 @@ #!/bin/bash +if ! command -v unzip &> /dev/null +then + echo "unzip could not be found. Please install unzip." + exit 0 +fi + if [[ $1 == "" ]]; then echo "First argument is empty !" echo "Type help for more information" From 39a78fcaa2229ab84963ab2c2feee8fddee74712 Mon Sep 17 00:00:00 2001 From: mattchis <1776285+mattchis@users.noreply.github.com> Date: Thu, 8 Dec 2022 14:19:13 -0700 Subject: [PATCH 3/6] Fixed issue with double entry of PATH variable with new chek_profile function. --- rmmagent-linux.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rmmagent-linux.sh b/rmmagent-linux.sh index 5cd3c19..e8d285b 100644 --- a/rmmagent-linux.sh +++ b/rmmagent-linux.sh @@ -121,11 +121,9 @@ function go_install() { tar -xvzf /tmp/golang.tar.gz -C /usr/local/ rm /tmp/golang.tar.gz - export PATH=$PATH:/usr/local/go/bin export GOPATH=/usr/local/go export GOCACHE=/root/.cache/go-build - echo "export PATH=$PATH:/usr/local/go/bin" >> /root/.profile echo "Golang Install Done !" } @@ -219,8 +217,8 @@ function check_profile () { case $1 in install) - go_install check_profile + go_install install_mesh agent_compile install_agent From 60fb82a49fa64d7a4ee5d42206d9c80b252142c3 Mon Sep 17 00:00:00 2001 From: mattchis <1776285+mattchis@users.noreply.github.com> Date: Thu, 8 Dec 2022 16:59:21 -0700 Subject: [PATCH 4/6] Added the following: - uninstall_agent function - uninstall_mesh function - User input support for forcibly uninstalling TRMM and Mesh agent. Updated the following: - Updated readme.md with how to use the uninstall feature. --- README.md | 31 +++++++++++++++++++++++++- rmmagent-linux.sh | 55 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 81 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4d89fdc..5ab3bee 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ The argument are: 3. Mesh agent - The url givent by mesh for installing new agent. + The url given by mesh for installing new agent. Go to mesh.fqdn.com > Add agent > Installation Executable Linux / BSD / macOS > **Select the good system type** Copy **ONLY** the URL with the quote. @@ -69,3 +69,32 @@ Simply launch the script that match your system with *update* as argument. ```bash ./rmmagent-linux.sh update ``` + +## Uninstall +To uninstall agent launch the script with this arguement: + +```bash +./rmmagent-linux.sh uninstall 'Mesh FQDN' 'Mesh ID' +``` +Note: Single quotes must be around the Mesh ID for it to uninstall the mesh agent properly + +The argument are: + +2. Mesh FQDN + + Example of FQDN: mesh.fqdn.com + +3. Mesh ID + + The url givent by mesh for installing new agent. + Go to mesh.fqdn.com > Add agent > Linux / BSD (Uninstall) > Copy **ONLY** the last value with the single quotes. + You are looking for a 64 charaters long value of random letter case, numbers, and special characters. + +### Example +```bash +./rmmagent-linux.sh uninstall mesh.fqdn.com 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' +``` + +### WARNING +- You should **only** attempt this if the agent removal feaure on TacticalRMM is not working. +- Running uninstall will **not** remove the connections from the TacticalRMM and MeshCentral Dashboard. You will need to manually remove them. It only forcefully removes the agents from your linux box. \ No newline at end of file diff --git a/rmmagent-linux.sh b/rmmagent-linux.sh index e8d285b..dbd05ee 100644 --- a/rmmagent-linux.sh +++ b/rmmagent-linux.sh @@ -14,7 +14,7 @@ fi if [[ $1 == "help" ]]; then echo "There is help but more information is available at github.com/ZoLuSs/rmmagent-script" echo "" - echo "List of argument (no argument name):" + echo "List of INSTALL/UPDATE argument (no argument name):" echo "Arg 1: 'install' or 'update'" echo "Arg 2: System type 'amd64' 'x86' 'arm64' 'armv6'" echo "Arg 3: Mesh agent URL" @@ -24,12 +24,18 @@ if [[ $1 == "help" ]]; then echo "Arg 7: Auth Key" echo "Arg 8: Agent Type 'server' or 'workstation'" echo "" + echo "List of UNINSTALL argument (no argument name):" + echo "Arg 1: 'uninstall'" + echo "Arg 2: Mesh agent FQDN (i.e. mesh.domain.com)" + echo "Arg 3: Mesh agent id (The id needs to have single quotes around it)" + echo "" echo "Only argument 1 is needed for update" + echo "" exit 0 fi -if [[ $1 != "install" && $1 != "update" ]]; then - echo "First argument can only be 'install' or 'update' !" +if [[ $1 != "install" && $1 != "update" && $1 != "uninstall" ]]; then + echo "First argument can only be 'install' or 'update' or 'uninstall' !" echo "Type help for more information" exit 1 fi @@ -40,7 +46,7 @@ if [[ $1 == "install" && $2 == "" ]]; then exit 1 fi -if [[ $2 != "amd64" && $2 != "x86" && $2 != "arm64" && $2 != "armv6" ]]; then +if [[ $1 == "install" && $2 != "amd64" && $2 != "x86" && $2 != "arm64" && $2 != "armv6" ]]; then echo "This argument can only be 'amd64' 'x86' 'arm64' 'armv6' !" echo "Type help for more information" exit 1 @@ -88,6 +94,18 @@ if [[ $1 == "install" && $8 != "server" && $8 != "workstation" ]]; then exit 1 fi +if [[ $1 == "uninstall" && $2 == "" ]]; then + echo "Argument 2 (Mesh agent FQDN) is empty !" + echo "Type help for more information" + exit 1 +fi + +if [[ $1 == "uninstall" && $3 == "" ]]; then + echo "Argument 3 (Mesh agent id) is empty !" + echo "Type help for more information" + exit 1 +fi + ## Setting var for easy scription system=$2 mesh_url=$3 @@ -96,6 +114,9 @@ rmm_client_id=$5 rmm_site_id=$6 rmm_auth=$7 rmm_agent_type=$8 +## Uninstall var for easy scription +mesh_fqdn=$2 +mesh_id=$3 go_url_amd64="https://go.dev/dl/go1.18.3.linux-amd64.tar.gz" go_url_x86="https://go.dev/dl/go1.18.3.linux-386.tar.gz" @@ -215,6 +236,25 @@ function check_profile () { source $profile_file } +function uninstall_agent() { + systemctl stop tacticalagent + systemctl disable tacticalagent + rm /etc/systemd/system/tacticalagent.service + systemctl daemon-reload + rm /usr/local/bin/rmmagent + rm /etc/tacticalagent + sed -i "/export\ PATH\=\$PATH\:\/usr\/local\/go\/bin/d" /root/.profile +} + +function uninstall_mesh() { + (wget "https://$mesh_fqdn/meshagents?script=1" -O /tmp/meshinstall.sh || wget "https://$mesh_fqdn/meshagents?script=1" --no-proxy -O /tmp/meshinstall.sh) + chmod 755 /tmp/meshinstall.sh + (/tmp/meshinstall.sh uninstall https://$mesh_fqdn $mesh_id || /tmp/meshinstall.sh uninstall uninstall uninstall https://$mesh_fqdn $mesh_id) + rm /tmp/meshinstall.sh + rm meshagent + rm meshagent.msh +} + case $1 in install) check_profile @@ -231,4 +271,11 @@ update) update_agent echo "Tactical Agent Update is done" exit 0;; +uninstall) + check_profile + uninstall_agent + uninstall_mesh + echo "Tactical Agent Uninstall is done" + echo "You may need to manually remove the agents orphaned connections on TacticalRMM and MeshCentral" + exit 0;; esac From 32b5b8e2580b9d972cb555ecad6206cfcafe5a00 Mon Sep 17 00:00:00 2001 From: mattchis <1776285+mattchis@users.noreply.github.com> Date: Thu, 8 Dec 2022 17:08:19 -0700 Subject: [PATCH 5/6] Corrected misspelled word. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ab3bee..2c4764e 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ The argument are: 3. Mesh ID - The url givent by mesh for installing new agent. + The url given by mesh for installing new agent. Go to mesh.fqdn.com > Add agent > Linux / BSD (Uninstall) > Copy **ONLY** the last value with the single quotes. You are looking for a 64 charaters long value of random letter case, numbers, and special characters. From 7709e2895633d5faad0a5bc0333c3894de4ea97a Mon Sep 17 00:00:00 2001 From: mattchis <1776285+mattchis@users.noreply.github.com> Date: Thu, 8 Dec 2022 17:10:35 -0700 Subject: [PATCH 6/6] More corrections. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c4764e..3bfebbf 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ The argument are: 3. Mesh ID - The url given by mesh for installing new agent. + The ID given by mesh for installing new agent. Go to mesh.fqdn.com > Add agent > Linux / BSD (Uninstall) > Copy **ONLY** the last value with the single quotes. You are looking for a 64 charaters long value of random letter case, numbers, and special characters.