111 lines
3.3 KiB
Bash
Executable File
111 lines
3.3 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Build OPNsense RMM Agent Plugin Package
|
|
#
|
|
# Usage: ./build.sh [version]
|
|
# Example: ./build.sh 1.0.0
|
|
#
|
|
# Prerequisites:
|
|
# - Go 1.24+ (for cross-compilation)
|
|
# - FreeBSD pkg tools (runs on the target OPNsense, or use pkg-create on FreeBSD)
|
|
#
|
|
# This script:
|
|
# 1. Cross-compiles the agent binary (freebsd/amd64)
|
|
# 2. Assembles the staging directory
|
|
# 3. Creates a +MANIFEST for pkg
|
|
# 4. Outputs a .tar that can be installed with `pkg add`
|
|
|
|
set -e
|
|
|
|
VERSION="${1:-1.0.0}"
|
|
NAME="os-rmm-agent"
|
|
STAGEDIR="$(pwd)/stage"
|
|
BUILDDIR="$(pwd)/../build"
|
|
PKGFILE="$(pwd)/${NAME}-${VERSION}.pkg"
|
|
|
|
echo "==> Building RMM Agent Plugin v${VERSION}"
|
|
|
|
# 1. Build agent binary
|
|
echo "==> Compiling agent (freebsd/amd64)..."
|
|
cd ../agent
|
|
GOOS=freebsd GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" -o "${BUILDDIR}/rmm-agent" .
|
|
cd ../opnsense-plugin
|
|
echo " Binary: ${BUILDDIR}/rmm-agent ($(ls -lh ${BUILDDIR}/rmm-agent | awk '{print $5}'))"
|
|
|
|
# 2. Assemble staging directory
|
|
echo "==> Assembling staging directory..."
|
|
rm -rf "${STAGEDIR}"
|
|
mkdir -p "${STAGEDIR}/usr/local"
|
|
|
|
# Plugin files
|
|
cp -R src/etc "${STAGEDIR}/usr/local/"
|
|
cp -R src/opnsense "${STAGEDIR}/usr/local/"
|
|
cp -R src/usr/local/etc "${STAGEDIR}/usr/local/"
|
|
mkdir -p "${STAGEDIR}/usr/local/rmm"
|
|
cp "${BUILDDIR}/rmm-agent" "${STAGEDIR}/usr/local/rmm/rmm-agent"
|
|
|
|
# Set permissions
|
|
chmod +x "${STAGEDIR}/usr/local/rmm/rmm-agent"
|
|
chmod +x "${STAGEDIR}/usr/local/etc/rc.d/rmm_agent"
|
|
chmod +x "${STAGEDIR}/usr/local/opnsense/scripts/rmmagent/setup.sh"
|
|
chmod +x "${STAGEDIR}/usr/local/opnsense/scripts/OPNsense/RMMAgent/generate_config.php"
|
|
|
|
# 3. Create +MANIFEST
|
|
echo "==> Creating package manifest..."
|
|
cat > "${STAGEDIR}/+MANIFEST" << EOF
|
|
name: ${NAME}
|
|
version: ${VERSION}
|
|
origin: sysutils/${NAME}
|
|
comment: RMM Agent for OPNsense
|
|
maintainer: cm@cynfo.com
|
|
www: https://git.cynfo.net/christian/rmm
|
|
prefix: /usr/local
|
|
desc: <<EOD
|
|
RMM Agent for OPNsense - Remote Monitoring & Management
|
|
Collects system data and reports to central RMM backend.
|
|
Configurable via OPNsense WebGUI under Services > RMM Agent.
|
|
EOD
|
|
categories: [sysutils]
|
|
deps:
|
|
opnsense: {origin: opnsense/opnsense, version: "24.7"}
|
|
scripts:
|
|
post-install: |
|
|
/usr/local/etc/rc.d/opnsense-configd restart
|
|
echo "RMM Agent Plugin installed."
|
|
echo "Configure via: Services > RMM Agent"
|
|
pre-deinstall: |
|
|
/usr/local/etc/rc.d/rmm_agent stop 2>/dev/null || true
|
|
/usr/sbin/sysrc -x rmm_agent_enable 2>/dev/null || true
|
|
post-deinstall: |
|
|
/usr/local/etc/rc.d/opnsense-configd restart
|
|
echo "RMM Agent Plugin removed."
|
|
EOF
|
|
|
|
# 4. Create package (tar format compatible with `pkg add`)
|
|
echo "==> Creating package..."
|
|
cd "${STAGEDIR}"
|
|
|
|
# Generate file list
|
|
find usr -type f | sort > /tmp/rmm-pkg-files.txt
|
|
|
|
# Create the pkg using tar (FreeBSD pkg format)
|
|
tar -czf "${PKGFILE}" +MANIFEST -C "${STAGEDIR}" $(cat /tmp/rmm-pkg-files.txt)
|
|
|
|
cd ..
|
|
rm -rf "${STAGEDIR}"
|
|
rm -f /tmp/rmm-pkg-files.txt
|
|
|
|
echo ""
|
|
echo "==> Package erstellt: ${PKGFILE}"
|
|
echo " Version: ${VERSION}"
|
|
echo " Groesse: $(ls -lh ${PKGFILE} | awk '{print $5}')"
|
|
echo ""
|
|
echo "==> Installation auf OPNsense:"
|
|
echo " scp ${PKGFILE} root@opnsense:/tmp/"
|
|
echo " ssh root@opnsense 'pkg add /tmp/${NAME}-${VERSION}.pkg'"
|
|
echo ""
|
|
echo "==> Danach:"
|
|
echo " - WebGUI oeffnen → Services → RMM Agent"
|
|
echo " - Backend URL und API Key eintragen"
|
|
echo " - Aktiviert ankreuzen → Speichern"
|