#!/usr/bin/env bash set -euo pipefail # Obermon Agent Installer # Usage: curl -sL https://get.obermon.com | bash -s -- --key=YOUR_KEY BASE_URL="https://get.obermon.com" INSTALL_DIR="/usr/local/bin" BINARY="obermon-agent" SERVICE="obermon-agent" RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' log() { echo -e "${GREEN}[obermon]${NC} $1"; } warn() { echo -e "${YELLOW}[obermon]${NC} $1"; } err() { echo -e "${RED}[obermon]${NC} $1" >&2; exit 1; } # ─── Parse arguments ────────────────────────────────────────── AGENT_KEY="" HUB="https://hub.obermon.com" while [[ $# -gt 0 ]]; do case $1 in --key=*) AGENT_KEY="${1#*=}" ;; --hub=*) HUB="${1#*=}" ;; *) warn "Unknown option: $1" ;; esac shift done [ -z "$AGENT_KEY" ] && err "Missing --key. Get your key from the Obermon dashboard." # ─── Detect platform ───────────────────────────────────────── OS=$(uname -s | tr '[:upper:]' '[:lower:]') ARCH=$(uname -m) case "$ARCH" in x86_64) ARCH="amd64" ;; aarch64|arm64) ARCH="arm64" ;; *) err "Unsupported architecture: $ARCH" ;; esac [ "$OS" != "linux" ] && err "This installer supports Linux only. On macOS use: go run ./cmd/agent" FILE="${BINARY}-${OS}-${ARCH}" log "" log "Installing Obermon Agent..." log " Platform: ${OS}/${ARCH}" log " Hub: ${HUB}" log " Key: ${AGENT_KEY:0:12}..." log "" # ─── Download binary ───────────────────────────────────────── log "Downloading ${FILE}..." curl -fsSL "${BASE_URL}/${FILE}" -o "/tmp/${BINARY}" || err "Download failed. Is get.obermon.com reachable?" chmod +x "/tmp/${BINARY}" sudo mv "/tmp/${BINARY}" "${INSTALL_DIR}/${BINARY}" log "Binary installed to ${INSTALL_DIR}/${BINARY}" # ─── Create systemd service ─────────────────────────────────── log "Configuring systemd service..." sudo tee /etc/systemd/system/${SERVICE}.service > /dev/null << EOF [Unit] Description=Obermon Monitoring Agent After=network-online.target Wants=network-online.target [Service] Type=simple ExecStart=${INSTALL_DIR}/${BINARY} Restart=always RestartSec=5 Environment=OBERMON_KEY=${AGENT_KEY} Environment=OBERMON_HUB=${HUB} [Install] WantedBy=multi-user.target EOF sudo systemctl stop ${SERVICE} 2>/dev/null || true sudo systemctl daemon-reload sudo systemctl enable ${SERVICE} sudo systemctl start ${SERVICE} # ─── Verify ─────────────────────────────────────────────────── sleep 2 if systemctl is-active --quiet ${SERVICE}; then log "" log "✅ Obermon Agent installed and running!" log "" log " Status: sudo systemctl status ${SERVICE}" log " Logs: sudo journalctl -u ${SERVICE} -f" log " Stop: sudo systemctl stop ${SERVICE}" log " Remove: sudo systemctl disable ${SERVICE} && sudo rm ${INSTALL_DIR}/${BINARY}" log "" log "Your server should appear in the dashboard within 30 seconds." else err "Agent installed but failed to start. Check: sudo journalctl -u ${SERVICE} -e" fi