|
| 1 | +#!/bin/bash |
| 2 | +# mor-launch-headless.sh — launchd-compatible Morpheus proxy-router launcher |
| 3 | +# |
| 4 | +# Retrieves wallet private key from 1Password at runtime via macOS Keychain. |
| 5 | +# Designed to run under launchd KeepAlive — runs in foreground via exec. |
| 6 | +# |
| 7 | +# If 1Password is not configured, falls back to macOS Keychain (everclaw-wallet). |
| 8 | +# |
| 9 | +# Usage: Called by com.morpheus.router launchd plist (not manually) |
| 10 | + |
| 11 | +MORPHEUS_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 12 | +cd "$MORPHEUS_DIR" |
| 13 | + |
| 14 | +# Source .env for ETH_NODE_ADDRESS and other config |
| 15 | +if [[ -f .env ]]; then |
| 16 | + set -a |
| 17 | + source .env |
| 18 | + set +a |
| 19 | +fi |
| 20 | + |
| 21 | +# --- Key retrieval: try 1Password first, then macOS Keychain --- |
| 22 | +WALLET_KEY="" |
| 23 | + |
| 24 | +# Method 1: 1Password service account |
| 25 | +OP_TOKEN=$(security find-generic-password -a "bernardo-agent" -s "op-service-account-token" -w 2>/dev/null || true) |
| 26 | +if [[ -n "$OP_TOKEN" ]]; then |
| 27 | + export OP_SERVICE_ACCOUNT_TOKEN="$OP_TOKEN" |
| 28 | + WALLET_KEY=$(op item get "Base Session Key" --vault "Bernardo Agent Vault" --fields "Private Key" --reveal 2>/dev/null || true) |
| 29 | +fi |
| 30 | + |
| 31 | +# Method 2: macOS Keychain (everclaw-wallet.mjs stores keys here) |
| 32 | +if [[ -z "$WALLET_KEY" ]]; then |
| 33 | + WALLET_KEY=$(security find-generic-password -s "everclaw-wallet" -w 2>/dev/null || true) |
| 34 | +fi |
| 35 | + |
| 36 | +if [[ -z "$WALLET_KEY" ]]; then |
| 37 | + echo "$(date -u +%Y-%m-%dT%H:%M:%S) FATAL: Cannot retrieve wallet key from 1Password or Keychain" >&2 |
| 38 | + exit 1 |
| 39 | +fi |
| 40 | + |
| 41 | +export WALLET_PRIVATE_KEY="$WALLET_KEY" |
| 42 | +export ETH_NODE_ADDRESS="${ETH_NODE_ADDRESS:-https://base-mainnet.public.blastapi.io}" |
| 43 | + |
| 44 | +# Ensure log directory exists |
| 45 | +mkdir -p "$MORPHEUS_DIR/data/logs" |
| 46 | + |
| 47 | +echo "$(date -u +%Y-%m-%dT%H:%M:%S) Starting proxy-router (headless, launchd-managed)" |
| 48 | + |
| 49 | +# Run in foreground so launchd can track the process |
| 50 | +exec ./proxy-router |
0 commit comments