#!/bin/bash # OC Monitor - One-click agent install set -e SERVER="" TOKEN="" NAME="" ROLE="worker" while getopts "s:t:n:r:" opt; do case $opt in s)SERVER="$OPTARG";;t)TOKEN="$OPTARG";;n)NAME="$OPTARG";;r)ROLE="$OPTARG";;esac done if [ -z "$SERVER" ] || [ -z "$TOKEN" ]; then echo "Usage: $0 -s SERVER_URL -t AUTH_TOKEN [-n NAME] [-r ROLE]" echo " -s Server URL (e.g. http://1.2.3.4:3800)" echo " -t Auth token" echo " -n Node name (default: hostname)" echo " -r Role: master|worker (default: worker)" exit 1 fi [ -z "$NAME" ] && NAME=$(hostname) AGENT="/usr/local/bin/oc-monitor-agent.sh" echo "🐾 OC Monitor Agent Installer" echo "==============================" # Check deps for cmd in python3 curl; do command -v $cmd &>/dev/null || { echo "❌ $cmd not found"; exit 1; } done # Download agent echo "📦 Downloading agent..." curl -fsSL https://cdn.jsdelivr.net/gh/xmg0828888/oc-monitor/agent/agent.sh -o "$AGENT" chmod +x "$AGENT" # Detect init system if [ "$(uname)" = "Darwin" ]; then PLIST="$HOME/Library/LaunchAgents/com.oc-monitor.agent.plist" echo "🍎 Setting up launchd service..." cat > "$PLIST" < Labelcom.oc-monitor.agent ProgramArguments /bin/bash$AGENT -s$SERVER -t$TOKEN -n$NAME -r$ROLE RunAtLoad KeepAlive StandardOutPath/tmp/oc-monitor-agent.log StandardErrorPath/tmp/oc-monitor-agent.log EOF launchctl unload "$PLIST" 2>/dev/null || true launchctl load "$PLIST" echo "✅ Agent running (launchd)" else echo "🐧 Setting up systemd service..." cat > /etc/systemd/system/oc-monitor-agent.service <