#!/bin/bash # JARVIS Agent Installer — macOS # Usage: bash install-mac.sh --jarvis-url https://jarvis.orbishosting.com --key YOUR_KEY # Or one-liner: bash <(curl -sSL https://jarvis.orbishosting.com/agent/install-mac.sh) --key YOUR_KEY set -e JARVIS_URL="https://jarvis.orbishosting.com" REG_KEY="" INSTALL_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 "$REG_KEY" ]]; then read -rp "Registration key: " REG_KEY fi JARVIS_URL="${JARVIS_URL%/}" echo "" echo " ====================================" echo " JARVIS Agent Installer v3.0 " echo " ====================================" echo "" # Check for Python3 PYTHON3=$(command -v 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 2>&1))" mkdir -p "$INSTALL_DIR" # Download macOS-native agent script SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd || echo "")" if [[ -f "$SCRIPT_DIR/jarvis-agent-mac.py" ]]; then cp "$SCRIPT_DIR/jarvis-agent-mac.py" "$INSTALL_DIR/jarvis-agent.py" echo "Copied agent from local directory." else echo "Downloading macOS agent..." curl -sSL "$JARVIS_URL/agent/jarvis-agent-mac.py" -o "$INSTALL_DIR/jarvis-agent.py" echo "Downloaded." fi chmod +x "$INSTALL_DIR/jarvis-agent.py" HOSTNAME=$(hostname -f 2>/dev/null || hostname) AGENT_ID="${HOSTNAME}_mac" # Write config (preserve existing) if [[ ! -f "$INSTALL_DIR/config.json" ]]; then cat > "$INSTALL_DIR/config.json" << JSONEOF { "jarvis_url": "$JARVIS_URL", "registration_key": "$REG_KEY", "hostname": "$HOSTNAME", "agent_id": "$AGENT_ID", "agent_type": "macos", "poll_interval": 30, "heartbeat_every": 10, "update_check_hours": 24, "watch_services": [], "allow_shell_commands": false } JSONEOF chmod 600 "$INSTALL_DIR/config.json" echo "Config written to $INSTALL_DIR/config.json" else echo "Config already exists — preserving $INSTALL_DIR/config.json" fi # 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 $INSTALL_DIR/config.json JARVIS_STATE $INSTALL_DIR/state.json RunAtLoad KeepAlive StandardOutPath $INSTALL_DIR/jarvis-agent.log StandardErrorPath $INSTALL_DIR/jarvis-agent.log PLISTEOF # Load/reload the service launchctl unload "$PLIST_PATH" 2>/dev/null || true launchctl load "$PLIST_PATH" sleep 2 if launchctl list 2>/dev/null | grep -q "$SERVICE_LABEL"; then echo "" echo " JARVIS Agent installed and running." echo " Machine : $HOSTNAME ($AGENT_ID)" echo " JARVIS : $JARVIS_URL" echo " Logs : tail -f $INSTALL_DIR/jarvis-agent.log" echo " Config : $INSTALL_DIR/config.json" echo " Stop : launchctl unload $PLIST_PATH" echo " Update : curl -sSL $JARVIS_URL/agent/install-mac.sh | bash -s -- --key $REG_KEY" else echo "" echo " Agent installed but not detected as running. Check logs:" echo " tail -f $INSTALL_DIR/jarvis-agent.log" fi echo ""