Files
jarvis/agent/install-mac.sh

136 lines
4.0 KiB
Bash

#!/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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>$SERVICE_LABEL</string>
<key>ProgramArguments</key>
<array>
<string>$PYTHON3</string>
<string>$INSTALL_DIR/jarvis-agent.py</string>
</array>
<key>EnvironmentVariables</key>
<dict>
<key>JARVIS_CONFIG</key>
<string>$INSTALL_DIR/config.json</string>
<key>JARVIS_STATE</key>
<string>$INSTALL_DIR/state.json</string>
</dict>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>$INSTALL_DIR/jarvis-agent.log</string>
<key>StandardErrorPath</key>
<string>$INSTALL_DIR/jarvis-agent.log</string>
</dict>
</plist>
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 ""