mirror of
https://github.com/netvolt/LinuxRMM-Script.git
synced 2025-08-13 11:27:01 +02:00
Merge pull request #33 from Brandon-Roff/main
Auto-detect system architecture using uname -m instead of manual input.
This commit is contained in:
34
README.md
34
README.md
@ -29,52 +29,66 @@ This will cause your screen to go blank for a second. You will be able to use re
|
||||
> If you encounter a 'file not found' error, you are likely using Ubuntu 19 or earlier. On these machines, the config file will be located on /etc/gdm/custom.conf. Modify the command above accordingly. <
|
||||
Please note that remote desktop features are only installed when you used the workstation agent. You may need to reinstall your mesh agent.
|
||||
|
||||
|
||||
## Automatically Detect System Architecture
|
||||
|
||||
The system architecture is now detected automatically using the following logic:
|
||||
|
||||
1. The `uname -m` command retrieves the current system's architecture.
|
||||
2. A `case` statement then checks the architecture and maps it to a standard format:
|
||||
- `x86_64` → `amd64` (for 64-bit Intel/AMD processors)
|
||||
- `i386` or `i686` → `x86` (for older 32-bit Intel processors)
|
||||
- `aarch64` → `arm64` (for 64-bit ARM processors, like Raspberry Pi 4 and Apple M1/M2 chips)
|
||||
- `armv6l` → `armv6` (for older ARM devices, like Raspberry Pi Zero)
|
||||
3. If the architecture isn't recognized, an error message is displayed, and the script exits to prevent issues.
|
||||
|
||||
This ensures the script adapts to different system types automatically without needing manual input.
|
||||
|
||||
|
||||
## Install
|
||||
To install the agent, launch the script with this argument:
|
||||
|
||||
```bash
|
||||
./rmmagent-linux.sh install 'System type' 'Mesh agent' 'API URL' 'Client ID' 'Site ID' 'Auth Key' 'Agent Type'
|
||||
./rmmagent-linux.sh install 'Mesh agent' 'API URL' 'Client ID' 'Site ID' 'Auth Key' 'Agent Type'
|
||||
```
|
||||
The compiling can be quite long, don't panic and wait few minutes... USE THE 'SINGLE QUOTES' IN ALL FIELDS!
|
||||
|
||||
The arguments are:
|
||||
|
||||
2. System type
|
||||
|
||||
Type of system. Can be 'amd64' 'x86' 'arm64' 'armv6'
|
||||
|
||||
3. Mesh agent
|
||||
1. Mesh agent
|
||||
|
||||
The url given by mesh for installing new agent.
|
||||
Go to mesh.example.com > Add agent > Installation Executable Linux / BSD / macOS > **Select the good system type**
|
||||
Copy **ONLY** the URL with the quote.
|
||||
|
||||
4. API URL
|
||||
2. API URL
|
||||
|
||||
Your api URL for agent communication usually https://api.example.com.
|
||||
|
||||
5. Client ID
|
||||
3. Client ID
|
||||
|
||||
The ID of the client in wich agent will be added.
|
||||
Can be viewed by hovering over the name of the client in the dashboard.
|
||||
|
||||
6. Site ID
|
||||
4. Site ID
|
||||
|
||||
The ID of the site in wich agent will be added.
|
||||
Can be viewed by hovering over the name of the site in the dashboard.
|
||||
|
||||
7. Auth Key
|
||||
5. Auth Key
|
||||
|
||||
Authentification key given by dashboard by going to dashboard > Agents > Install agent (Windows) > Select manual and show
|
||||
Copy **ONLY** the key after *--auth*.
|
||||
|
||||
8. Agent Type
|
||||
6. Agent Type
|
||||
|
||||
Can be *server* or *workstation* and define the type of agent.
|
||||
|
||||
### Example
|
||||
```bash
|
||||
./rmmagent-linux.sh install 'amd64' 'https://mesh.example.com/meshagents?id=XXXXX&installflags=X&meshinstall=X' 'https://api.example.com' 3 1 'XXXXX' server
|
||||
./rmmagent-linux.sh install 'https://mesh.example.com/meshagents?id=XXXXX&installflags=X&meshinstall=X' 'https://api.example.com' 3 1 'XXXXX' server
|
||||
```
|
||||
|
||||
## Update
|
||||
|
@ -10,17 +10,15 @@ if [[ $1 == "help" ]]; then
|
||||
echo ""
|
||||
echo "List of INSTALL argument (no argument name):"
|
||||
echo "Arg 1: 'install'"
|
||||
echo "Arg 2: System type 'amd64' 'x86' 'arm64' 'armv6'"
|
||||
echo "Arg 3: Mesh agent URL"
|
||||
echo "Arg 4: API URL"
|
||||
echo "Arg 5: Client ID"
|
||||
echo "Arg 6: Site ID"
|
||||
echo "Arg 7: Auth Key"
|
||||
echo "Arg 8: Agent Type 'server' or 'workstation'"
|
||||
echo "Arg 2: Mesh agent URL"
|
||||
echo "Arg 3: API URL"
|
||||
echo "Arg 4: Client ID"
|
||||
echo "Arg 5: Site ID"
|
||||
echo "Arg 6: Auth Key"
|
||||
echo "Arg 7: Agent Type 'server' or 'workstation'"
|
||||
echo ""
|
||||
echo "List of UPDATE argument (no argument name)"
|
||||
echo "Arg 1: 'update'"
|
||||
echo "Arg 2: System type 'amd64' 'x86' 'arm64' 'armv6'"
|
||||
echo ""
|
||||
echo "List of UNINSTALL argument (no argument name):"
|
||||
echo "Arg 1: 'uninstall'"
|
||||
@ -36,198 +34,79 @@ if [[ $1 != "install" && $1 != "update" && $1 != "uninstall" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $1 == "install" && $2 == "" ]]; then
|
||||
echo "Argument 2 (System type) is empty !"
|
||||
echo "Type help for more information"
|
||||
## Automatically detect system architecture
|
||||
system=$(uname -m)
|
||||
case $system in
|
||||
x86_64)
|
||||
system="amd64"
|
||||
;;
|
||||
i386|i686)
|
||||
system="x86"
|
||||
;;
|
||||
aarch64)
|
||||
system="arm64"
|
||||
;;
|
||||
armv6l)
|
||||
system="armv6"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported architecture: $system"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
if [[ $1 == "update" && $2 == "" ]]; then
|
||||
echo "Argument 2 (System type) is empty !"
|
||||
echo "Type help for more information"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
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
|
||||
fi
|
||||
|
||||
if [[ $1 == "install" && $3 == "" ]]; then
|
||||
echo "Argument 3 (Mesh agent URL) is empty !"
|
||||
echo "Type help for more information"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $1 == "install" && $4 == "" ]]; then
|
||||
echo "Argument 4 (API URL) is empty !"
|
||||
echo "Type help for more information"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $1 == "install" && $5 == "" ]]; then
|
||||
echo "Argument 5 (Client ID) is empty !"
|
||||
echo "Type help for more information"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $1 == "install" && $6 == "" ]]; then
|
||||
echo "Argument 6 (Site ID) is empty !"
|
||||
echo "Type help for more information"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $1 == "install" && $7 == "" ]]; then
|
||||
echo "Argument 7 (Auth Key) is empty !"
|
||||
echo "Type help for more information"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $1 == "install" && $8 == "" ]]; then
|
||||
echo "Argument 8 (Agent Type) is empty !"
|
||||
echo "Type help for more information"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $1 == "install" && $8 != "server" && $8 != "workstation" ]]; then
|
||||
echo "First argument can only be 'server' or 'workstation' !"
|
||||
echo "Type help for more information"
|
||||
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
|
||||
rmm_url=$4
|
||||
rmm_client_id=$5
|
||||
rmm_site_id=$6
|
||||
rmm_auth=$7
|
||||
rmm_agent_type=$8
|
||||
## Uninstall var for easy scription
|
||||
## Setting variables
|
||||
mesh_url=$2
|
||||
rmm_url=$3
|
||||
rmm_client_id=$4
|
||||
rmm_site_id=$5
|
||||
rmm_auth=$6
|
||||
rmm_agent_type=$7
|
||||
mesh_fqdn=$2
|
||||
mesh_id=$3
|
||||
## Setting Go verison to be installed
|
||||
go_version="1.21.6"
|
||||
|
||||
go_version="1.21.6"
|
||||
go_url_amd64="https://go.dev/dl/go$go_version.linux-amd64.tar.gz"
|
||||
go_url_x86="https://go.dev/dl/go$go_version.linux-386.tar.gz"
|
||||
go_url_arm64="https://go.dev/dl/go$go_version.linux-arm64.tar.gz"
|
||||
go_url_armv6="https://go.dev/dl/go$go_version.linux-armv6l.tar.gz"
|
||||
|
||||
function go_install() {
|
||||
if ! command -v go &> /dev/null; then
|
||||
## Installing golang
|
||||
case $system in
|
||||
amd64)
|
||||
wget -O /tmp/golang.tar.gz $go_url_amd64
|
||||
;;
|
||||
x86)
|
||||
wget -O /tmp/golang.tar.gz $go_url_x86
|
||||
;;
|
||||
arm64)
|
||||
wget -O /tmp/golang.tar.gz $go_url_arm64
|
||||
;;
|
||||
armv6)
|
||||
wget -O /tmp/golang.tar.gz $go_url_armv6
|
||||
;;
|
||||
esac
|
||||
|
||||
rm -rvf /usr/local/go/
|
||||
tar -xvzf /tmp/golang.tar.gz -C /usr/local/
|
||||
rm /tmp/golang.tar.gz
|
||||
export GOPATH=/usr/local/go
|
||||
export GOCACHE=/root/.cache/go-build
|
||||
|
||||
echo "Go is installed (version $go_current_version)."
|
||||
else
|
||||
# Get the current version of Go installed
|
||||
go_current_version=$(go version | awk '{print $3}' | sed 's/go//')
|
||||
|
||||
if [ "$go_current_version" != "$go_version" ]; then
|
||||
echo "Version mismatch. Current installed version is $go_current_version. Desired version is $go_version."
|
||||
echo "Installing Go $go_version..."
|
||||
## Installing golang
|
||||
case $system in
|
||||
amd64)
|
||||
wget -O /tmp/golang.tar.gz $go_url_amd64
|
||||
;;
|
||||
x86)
|
||||
wget -O /tmp/golang.tar.gz $go_url_x86
|
||||
;;
|
||||
arm64)
|
||||
wget -O /tmp/golang.tar.gz $go_url_arm64
|
||||
;;
|
||||
armv6)
|
||||
wget -O /tmp/golang.tar.gz $go_url_armv6
|
||||
;;
|
||||
esac
|
||||
|
||||
rm -rvf /usr/local/go/
|
||||
tar -xvzf /tmp/golang.tar.gz -C /usr/local/
|
||||
rm /tmp/golang.tar.gz
|
||||
export GOPATH=/usr/local/go
|
||||
export GOCACHE=/root/.cache/go-build
|
||||
|
||||
echo "Go $go_version installed."
|
||||
else
|
||||
echo "Go is up to date (version $go_current_version)."
|
||||
fi
|
||||
fi
|
||||
if ! command -v go &> /dev/null; then
|
||||
case $system in
|
||||
amd64) wget -O /tmp/golang.tar.gz "$go_url_amd64" ;;
|
||||
x86) wget -O /tmp/golang.tar.gz "$go_url_x86" ;;
|
||||
arm64) wget -O /tmp/golang.tar.gz "$go_url_arm64" ;;
|
||||
armv6) wget -O /tmp/golang.tar.gz "$go_url_armv6" ;;
|
||||
esac
|
||||
rm -rf /usr/local/go/
|
||||
tar -xvzf /tmp/golang.tar.gz -C /usr/local/
|
||||
rm /tmp/golang.tar.gz
|
||||
export PATH=$PATH:/usr/local/go/bin
|
||||
echo "Go is installed."
|
||||
fi
|
||||
}
|
||||
|
||||
function agent_compile() {
|
||||
## Compiling and installing tactical agent from github
|
||||
echo "Agent Compile begin"
|
||||
wget -O /tmp/rmmagent.tar.gz "https://github.com/amidaware/rmmagent/archive/refs/heads/master.tar.gz"
|
||||
tar -xf /tmp/rmmagent.tar.gz -C /tmp/
|
||||
rm /tmp/rmmagent.tar.gz
|
||||
cd /tmp/rmmagent-master
|
||||
case $system in
|
||||
amd64)
|
||||
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o /tmp/temp_rmmagent
|
||||
;;
|
||||
x86)
|
||||
env CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "-s -w" -o /tmp/temp_rmmagent
|
||||
;;
|
||||
arm64)
|
||||
env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w" -o /tmp/temp_rmmagent
|
||||
;;
|
||||
armv6)
|
||||
env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags "-s -w" -o /tmp/temp_rmmagent
|
||||
;;
|
||||
amd64) env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o /tmp/temp_rmmagent ;;
|
||||
x86) env CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "-s -w" -o /tmp/temp_rmmagent ;;
|
||||
arm64) env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w" -o /tmp/temp_rmmagent ;;
|
||||
armv6) env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags "-s -w" -o /tmp/temp_rmmagent ;;
|
||||
esac
|
||||
|
||||
cd /tmp
|
||||
rm -R /tmp/rmmagent-master
|
||||
}
|
||||
|
||||
function update_agent() {
|
||||
systemctl stop tacticalagent
|
||||
|
||||
cp /tmp/temp_rmmagent /usr/local/bin/rmmagent
|
||||
rm /tmp/temp_rmmagent
|
||||
|
||||
systemctl start tacticalagent
|
||||
}
|
||||
function install_agent() {
|
||||
cp /tmp/temp_rmmagent /usr/local/bin/rmmagent
|
||||
/tmp/temp_rmmagent -m install -api $rmm_url -client-id $rmm_client_id -site-id $rmm_site_id -agent-type $rmm_agent_type -auth $rmm_auth
|
||||
rm /tmp/temp_rmmagent
|
||||
|
||||
cat << "EOF" > /etc/systemd/system/tacticalagent.service
|
||||
[Unit]
|
||||
Description=Tactical RMM Linux Agent
|
||||
@ -243,38 +122,18 @@ KillMode=process
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now tacticalagent
|
||||
systemctl start tacticalagent
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now tacticalagent
|
||||
systemctl start tacticalagent
|
||||
}
|
||||
|
||||
function install_mesh() {
|
||||
## Installing mesh agent
|
||||
wget -O /tmp/meshagent $mesh_url
|
||||
chmod +x /tmp/meshagent
|
||||
mkdir /opt/tacticalmesh
|
||||
/tmp/meshagent -install --installPath="/opt/tacticalmesh"
|
||||
rm /tmp/meshagent
|
||||
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
|
||||
wget -O /tmp/meshagent $mesh_url
|
||||
chmod +x /tmp/meshagent
|
||||
mkdir /opt/tacticalmesh
|
||||
/tmp/meshagent -install --installPath="/opt/tacticalmesh"
|
||||
rm /tmp/meshagent
|
||||
rm /tmp/meshagent.msh
|
||||
}
|
||||
|
||||
function uninstall_agent() {
|
||||
@ -283,22 +142,18 @@ function uninstall_agent() {
|
||||
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
|
||||
rm -rf /etc/tacticalagent
|
||||
}
|
||||
|
||||
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)
|
||||
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)
|
||||
/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
|
||||
go_install
|
||||
install_mesh
|
||||
agent_compile
|
||||
@ -306,17 +161,14 @@ install)
|
||||
echo "Tactical Agent Install is done"
|
||||
exit 0;;
|
||||
update)
|
||||
check_profile
|
||||
go_install
|
||||
agent_compile
|
||||
update_agent
|
||||
install_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
|
||||
|
Reference in New Issue
Block a user