#!/bin/bash # JARVIS Agent Installer — macOS # Usage: bash install-mac.sh --jarvis-url https://jarvis.orbishosting.com --key YOUR_KEY set -e JARVIS_URL="" REG_KEY="" INSTALL_DIR="$HOME/.jarvis-agent" CONFIG_DIR="$HOME/.jarvis-agent" PLIST_PATH="$HOME/Library/LaunchAgents/com.jarvis.agent.plist" SERVICE_LABEL="com.jarvis.agent" while [[ $# -gt 0 ]]; do case "$1" in --jarvis-url) JARVIS_URL="$2"; shift 2 ;; --key) REG_KEY="$2"; shift 2 ;; *) echo "Unknown arg: $1"; exit 1 ;; esac done if [[ -z "$JARVIS_URL" ]]; then read -rp "JARVIS URL (e.g. https://jarvis.orbishosting.com): " JARVIS_URL fi if [[ -z "$REG_KEY" ]]; then read -rp "Registration key: " REG_KEY fi JARVIS_URL="${JARVIS_URL%/}" # Check for Python3 PYTHON3=$(command -v python3 2>/dev/null || command -v /usr/bin/python3 2>/dev/null || "") if [[ -z "$PYTHON3" ]]; then echo "Python 3 is required. Install it with:" echo " brew install python3" echo " or download from https://www.python.org/downloads/" exit 1 fi echo "Using Python: $PYTHON3 ($($PYTHON3 --version))" mkdir -p "$INSTALL_DIR" # Download or copy agent script SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" if [[ -f "$SCRIPT_DIR/jarvis-agent.py" ]]; then cp "$SCRIPT_DIR/jarvis-agent.py" "$INSTALL_DIR/jarvis-agent.py" else echo "Downloading agent..." curl -sSL "https://raw.githubusercontent.com/myronblair/jarvis/master/agent/jarvis-agent.py" \ -o "$INSTALL_DIR/jarvis-agent.py" fi chmod +x "$INSTALL_DIR/jarvis-agent.py" HOSTNAME=$(hostname -f 2>/dev/null || hostname) # Write config if [[ ! -f "$CONFIG_DIR/config.json" ]]; then cat > "$CONFIG_DIR/config.json" << JSONEOF { "jarvis_url": "$JARVIS_URL", "registration_key": "$REG_KEY", "hostname": "$HOSTNAME", "agent_type": "linux", "poll_interval": 30, "heartbeat_every": 10, "watch_services": [] } JSONEOF chmod 600 "$CONFIG_DIR/config.json" fi # Override state path in agent for macOS STATE_PATH="$INSTALL_DIR/state.json" # Write launchd plist mkdir -p "$HOME/Library/LaunchAgents" cat > "$PLIST_PATH" << PLISTEOF Label $SERVICE_LABEL ProgramArguments $PYTHON3 $INSTALL_DIR/jarvis-agent.py EnvironmentVariables JARVIS_CONFIG $CONFIG_DIR/config.json JARVIS_STATE $STATE_PATH RunAtLoad KeepAlive StandardOutPath $INSTALL_DIR/jarvis-agent.log StandardErrorPath $INSTALL_DIR/jarvis-agent.log PLISTEOF # Load the service launchctl unload "$PLIST_PATH" 2>/dev/null || true launchctl load "$PLIST_PATH" sleep 2 if launchctl list | grep -q "$SERVICE_LABEL"; then echo "" echo "✓ JARVIS Agent installed and running." echo " View logs: tail -f $INSTALL_DIR/jarvis-agent.log" echo " Config: $CONFIG_DIR/config.json" echo " Stop: launchctl unload $PLIST_PATH" else echo "⚠ Agent installed but not running. Check logs:" echo " tail -f $INSTALL_DIR/jarvis-agent.log" fi