176 lines
4.3 KiB
Bash
176 lines
4.3 KiB
Bash
#!/bin/ash
|
|
|
|
if [ "$1" = "" ]; then
|
|
echo "First argument is empty!"
|
|
echo "Type help for more information"
|
|
exit 1
|
|
fi
|
|
|
|
if [ "$1" = "help" ]; then
|
|
echo "There is help but more information is available at github.com/ZoLuSs/rmmagent-script"
|
|
echo ""
|
|
echo "INSTALL args:"
|
|
echo " 1: 'install'"
|
|
echo " 2: Mesh agent URL"
|
|
echo " 3: API URL"
|
|
echo " 4: Client ID"
|
|
echo " 5: Site ID"
|
|
echo " 6: Auth Key"
|
|
echo " 7: Agent Type ('server' or 'workstation')"
|
|
echo ""
|
|
echo "UPDATE args:"
|
|
echo " 1: 'update'"
|
|
echo ""
|
|
echo "UNINSTALL args:"
|
|
echo " 1: 'uninstall'"
|
|
echo " 2: Mesh agent FQDN"
|
|
echo " 3: Mesh agent ID (in single quotes)"
|
|
echo ""
|
|
exit 0
|
|
fi
|
|
|
|
if [ "$1" != "install" ] && [ "$1" != "update" ] && [ "$1" != "uninstall" ]; then
|
|
echo "First argument must be 'install', 'update', or 'uninstall'!"
|
|
echo "Type help for more information"
|
|
exit 1
|
|
fi
|
|
|
|
# Detect 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 ;;
|
|
esac
|
|
|
|
# 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
|
|
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"
|
|
|
|
go_install() {
|
|
if ! command -v go >/dev/null 2>&1; then
|
|
case $system in
|
|
amd64) url=$go_url_amd64 ;;
|
|
x86) url=$go_url_x86 ;;
|
|
arm64) url=$go_url_arm64 ;;
|
|
armv6) url=$go_url_armv6 ;;
|
|
esac
|
|
wget -O /tmp/golang.tar.gz "$url"
|
|
rm -rf /usr/local/go/
|
|
tar -xzf /tmp/golang.tar.gz -C /usr/local/
|
|
rm /tmp/golang.tar.gz
|
|
export PATH=$PATH:/usr/local/go/bin
|
|
echo "Go is installed."
|
|
fi
|
|
}
|
|
|
|
agent_compile() {
|
|
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 || exit 1
|
|
case $system in
|
|
amd64) arch=amd64 ;;
|
|
x86) arch=386 ;;
|
|
arm64) arch=arm64 ;;
|
|
armv6) arch=arm ;;
|
|
esac
|
|
env CGO_ENABLED=0 GOOS=linux GOARCH=$arch go build -ldflags "-s -w" -o /tmp/temp_rmmagent
|
|
cd /
|
|
rm -rf /tmp/rmmagent-master
|
|
}
|
|
|
|
install_agent() {
|
|
cp /tmp/temp_rmmagent /usr/local/bin/rmmagent
|
|
chmod +x /usr/local/bin/rmmagent
|
|
/usr/local/bin/rmmagent -m install -api "$rmm_url" -client-id "$rmm_client_id" \
|
|
-site-id "$rmm_site_id" -agent-type "$rmm_agent_type" -auth "$rmm_auth"
|
|
|
|
# Create OpenRC service script
|
|
cat << 'EOF' > /etc/init.d/tacticalagent
|
|
#!/sbin/openrc-run
|
|
|
|
description="Tactical RMM Linux Agent"
|
|
command="/usr/local/bin/rmmagent"
|
|
command_args="-m svc"
|
|
pidfile="/run/tacticalagent.pid"
|
|
command_background="yes"
|
|
depend() {
|
|
need net
|
|
}
|
|
|
|
start_pre() {
|
|
checkpath --directory --owner root --mode 0755 /run
|
|
}
|
|
EOF
|
|
|
|
chmod +x /etc/init.d/tacticalagent
|
|
rc-update add tacticalagent default
|
|
rc-service tacticalagent start
|
|
}
|
|
|
|
install_mesh() {
|
|
wget -O /tmp/meshagent "$mesh_url"
|
|
chmod +x /tmp/meshagent
|
|
mkdir -p /opt/tacticalmesh
|
|
/tmp/meshagent -install --installPath="/opt/tacticalmesh"
|
|
rm /tmp/meshagent
|
|
}
|
|
|
|
uninstall_agent() {
|
|
rc-service tacticalagent stop
|
|
rc-update del tacticalagent default
|
|
rm /etc/init.d/tacticalagent
|
|
rm /usr/local/bin/rmmagent
|
|
}
|
|
|
|
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 +x /tmp/meshinstall.sh
|
|
/tmp/meshinstall.sh uninstall "https://$mesh_fqdn" "$mesh_id" \
|
|
|| /tmp/meshinstall.sh uninstall
|
|
rm /tmp/meshinstall.sh
|
|
}
|
|
|
|
case $1 in
|
|
install)
|
|
go_install
|
|
install_mesh
|
|
agent_compile
|
|
install_agent
|
|
echo "Tactical Agent Install is done"
|
|
exit 0
|
|
;;
|
|
update)
|
|
go_install
|
|
agent_compile
|
|
# replace binary
|
|
rc-service tacticalagent stop
|
|
cp /tmp/temp_rmmagent /usr/local/bin/rmmagent
|
|
chmod +x /usr/local/bin/rmmagent
|
|
rc-service tacticalagent start
|
|
echo "Tactical Agent Update is done"
|
|
exit 0
|
|
;;
|
|
uninstall)
|
|
uninstall_agent
|
|
uninstall_mesh
|
|
echo "Tactical Agent Uninstall is done"
|
|
exit 0
|
|
;;
|
|
esac
|