#!/bin/sh
#
# RMM Agent Plugin Installer fuer OPNsense
#
# Usage:
# scp install.sh rmm-agent root@opnsense:/tmp/
# ssh root@opnsense '/bin/sh /tmp/install.sh'
#
# Oder remote:
# cat install.sh | ssh root@opnsense '/bin/sh'
#
set -e
BASEDIR="/tmp"
BINARY="${BASEDIR}/rmm-agent"
UPDATER_BINARY="${BASEDIR}/rmm-updater"
echo "========================================"
echo " RMM Agent Plugin Installer"
echo "========================================"
# Pruefen ob Binary vorhanden
if [ ! -f "${BINARY}" ]; then
echo "FEHLER: ${BINARY} nicht gefunden."
echo "Bitte vorher das Binary kopieren:"
echo " scp rmm-agent root@opnsense:/tmp/"
exit 1
fi
# Alten Agent stoppen falls vorhanden
echo "[1/8] Alte Dienste stoppen..."
/usr/local/etc/rc.d/rmm_updater stop 2>/dev/null || true
/usr/local/etc/rc.d/rmm_agent stop 2>/dev/null || true
pkill -9 -f rmm-agent 2>/dev/null || true
pkill -9 -f rmm-updater 2>/dev/null || true
# Binaries installieren
echo "[2/8] Binaries installieren..."
mkdir -p /usr/local/rmm
cp "${BINARY}" /usr/local/rmm/rmm-agent
chmod +x /usr/local/rmm/rmm-agent
if [ -f "${UPDATER_BINARY}" ]; then
cp "${UPDATER_BINARY}" /usr/local/rmm/rmm-updater
chmod +x /usr/local/rmm/rmm-updater
echo " Updater installiert"
else
echo " Updater-Binary nicht gefunden — uebersprungen"
fi
# rc.d Script
echo "[3/8] rc.d Service installieren..."
cat > /usr/local/etc/rc.d/rmm_agent << 'RCEOF'
#!/bin/sh
#
# PROVIDE: rmm_agent
# REQUIRE: NETWORKING
# KEYWORD: shutdown
. /etc/rc.subr
name="rmm_agent"
rcvar="rmm_agent_enable"
load_rc_config ${name}
: ${rmm_agent_enable:="NO"}
: ${rmm_agent_config:="/usr/local/rmm/config.yaml"}
: ${rmm_agent_logfile:="/var/log/rmm-agent.log"}
: ${rmm_agent_insecure:="YES"}
pidfile="/var/run/${name}.pid"
command="/usr/local/rmm/rmm-agent"
start_cmd="${name}_start"
stop_cmd="${name}_stop"
status_cmd="${name}_status"
rmm_agent_start()
{
if [ ! -f "${command}" ]; then
echo "rmm-agent binary not found: ${command}"
return 1
fi
if [ ! -f "${rmm_agent_config}" ]; then
echo "Config not found: ${rmm_agent_config}"
return 1
fi
echo "Starting ${name}."
INSECURE_FLAG=""
if checkyesno rmm_agent_insecure; then
INSECURE_FLAG="--insecure"
fi
/usr/sbin/daemon -f -p ${pidfile} -o ${rmm_agent_logfile} \
${command} --config ${rmm_agent_config} ${INSECURE_FLAG}
}
rmm_agent_stop()
{
if [ -f "${pidfile}" ]; then
echo "Stopping ${name}."
kill $(cat ${pidfile}) 2>/dev/null
rm -f ${pidfile}
else
echo "${name} is not running."
fi
}
rmm_agent_status()
{
if [ -f "${pidfile}" ] && kill -0 $(cat ${pidfile}) 2>/dev/null; then
echo "${name} is running as pid $(cat ${pidfile})."
else
echo "${name} is not running."
return 1
fi
}
run_rc_command "$1"
RCEOF
chmod +x /usr/local/etc/rc.d/rmm_agent
# Updater rc.d Service
cat > /usr/local/etc/rc.d/rmm_updater << 'RCEOF2'
#!/bin/sh
#
# PROVIDE: rmm_updater
# REQUIRE: NETWORKING rmm_agent
# KEYWORD: shutdown
. /etc/rc.subr
name="rmm_updater"
rcvar="${name}_enable"
command="/usr/local/rmm/rmm-updater"
pidfile="/var/run/${name}.pid"
logfile="/var/log/rmm-updater.log"
start_cmd="${name}_start"
stop_cmd="${name}_stop"
status_cmd="${name}_status"
rmm_updater_start()
{
if [ ! -f "${command}" ]; then
echo "rmm-updater binary not found: ${command}"
return 1
fi
if [ -f "$pidfile" ] && kill -0 $(cat "$pidfile") 2>/dev/null; then
echo "${name} already running"
return 0
fi
echo "Starting ${name}."
/usr/sbin/daemon -f -p "$pidfile" -o "$logfile" "$command"
}
rmm_updater_stop()
{
if [ -f "${pidfile}" ]; then
echo "Stopping ${name}."
kill $(cat ${pidfile}) 2>/dev/null
rm -f ${pidfile}
else
echo "${name} is not running."
fi
}
rmm_updater_status()
{
if [ -f "${pidfile}" ] && kill -0 $(cat ${pidfile}) 2>/dev/null; then
echo "${name} is running as pid $(cat ${pidfile})."
else
echo "${name} is not running."
return 1
fi
}
load_rc_config $name
: ${rmm_updater_enable:="NO"}
run_rc_command "$1"
RCEOF2
chmod +x /usr/local/etc/rc.d/rmm_updater
# MVC Plugin installieren
echo "[4/8] OPNsense MVC Plugin installieren..."
# Model
mkdir -p /usr/local/opnsense/mvc/app/models/OPNsense/RMMAgent/Menu
cat > /usr/local/opnsense/mvc/app/models/OPNsense/RMMAgent/RMMAgent.xml << 'XMLEOF'