#!/usr/bin/env bash # Agent Desk: AI agents trading Robinhood Wallet perps (Lighter, Robinhood Chain) from your own server. # # curl -fsSL https://agent-desk.fun/install.sh | sudo bash -s -- https://agent-desk.fun # # What it does (5-10 min on a fresh Ubuntu 22.04/24.04 or Debian 12 server): # - creates a "desk" user (no sudo) and installs Node 22 # - installs the agent CLIs: Claude Code, Codex, Gemini CLI, OpenCode # - installs the desk as a service that restarts on its own # - puts it behind Caddy with automatic HTTPS, closes every other port # - prints the private link to choose your password # # Your funds never touch this server: it only holds a Lighter trading key, which you # lock to trading during setup, so Lighter refuses any withdrawal or transfer from it. # # Options (environment variables): # DESK_DOMAIN=desk.example.com your own domain (A record -> this server). Default: .sslip.io # DESK_AGENTS=0 do not install the agent CLIs # DESK_SSH_PORT=2222 SSH port to keep open (auto-detected by default) set -euo pipefail SOURCE="${1:-${DESK_SOURCE:-}}" APP_DIR=/opt/agent-desk DESK_USER=desk PORT=8790 LOG=/var/log/agent-desk-install.log c_ok=$'\e[32m'; c_warn=$'\e[33m'; c_err=$'\e[31m'; c_b=$'\e[1m'; c_0=$'\e[0m' step() { printf '\n%s==>%s %s\n' "$c_b" "$c_0" "$*"; } ok() { printf ' %s✓%s %s\n' "$c_ok" "$c_0" "$*"; } warn() { printf ' %s!%s %s\n' "$c_warn" "$c_0" "$*"; } die() { printf '\n%sError:%s %s\n' "$c_err" "$c_0" "$*" >&2; exit 1; } run() { "$@" >>"$LOG" 2>&1 || die "command failed: $* (details in $LOG)"; } as_desk() { sudo -u "$DESK_USER" -H bash -lc "$1" >>"$LOG" 2>&1; } [ "$(id -u)" -eq 0 ] || die "run as root: curl -fsSL /install.sh | sudo bash -s -- " [ -n "$SOURCE" ] || die "missing site URL. Usage: curl -fsSL https://SITE/install.sh | sudo bash -s -- https://SITE" case "$SOURCE" in https://*) ;; *) die "site URL must start with https://";; esac SOURCE="${SOURCE%/}" . /etc/os-release 2>/dev/null || true [ "${ID:-}" = "ubuntu" ] || [ "${ID:-}" = "debian" ] || die "this installer supports Ubuntu 22.04/24.04 and Debian 12" : >"$LOG" printf '%sAgent Desk installer%s (log: %s)\n' "$c_b" "$c_0" "$LOG" # ------------------------------------------------------------------ system step "System packages" export DEBIAN_FRONTEND=noninteractive run apt-get update -y run apt-get install -y --no-install-recommends ca-certificates curl gnupg git ufw unattended-upgrades tar sudo run dpkg-reconfigure -f noninteractive unattended-upgrades if ! command -v node >/dev/null || [ "$(node -p 'process.versions.node.split(".")[0]')" -lt 20 ]; then run bash -c "curl -fsSL https://deb.nodesource.com/setup_22.x | bash -" run apt-get install -y nodejs fi ok "Node $(node --version) + automatic security updates" # ------------------------------------------------------------------ user step "Desk user" id "$DESK_USER" >/dev/null 2>&1 || run useradd -m -s /bin/bash "$DESK_USER" DESK_HOME=$(getent passwd "$DESK_USER" | cut -d: -f6) ok "user '$DESK_USER' (no sudo)" # ------------------------------------------------------------------ app step "Agent Desk" TMP=$(mktemp -d); trap 'rm -rf "$TMP"' EXIT run curl -fsSL "$SOURCE/release/agent-desk.tar.gz" -o "$TMP/app.tar.gz" run tar -xzf "$TMP/app.tar.gz" -C "$TMP" [ -f "$TMP/agent-desk/server/server.mjs" ] || die "release archive is incomplete" mkdir -p "$APP_DIR" # keep data (password, trading key, settings) across updates [ -d "$APP_DIR/data" ] && mv "$APP_DIR/data" "$TMP/data-keep" rm -rf "$APP_DIR/server" "$APP_DIR/public" cp -a "$TMP/agent-desk/." "$APP_DIR/" [ -d "$TMP/data-keep" ] && mv "$TMP/data-keep" "$APP_DIR/data" mkdir -p "$APP_DIR/data" chown -R "$DESK_USER:$DESK_USER" "$APP_DIR" chmod 700 "$APP_DIR/data" as_desk "cd $APP_DIR/server && npm ci --omit=dev --no-audit --no-fund" || die "npm install failed (details in $LOG)" ok "installed in $APP_DIR" # ------------------------------------------------------------------ agents if [ "${DESK_AGENTS:-1}" != "0" ]; then step "Agent CLIs" as_desk 'mkdir -p ~/.npm-global && npm config set prefix ~/.npm-global && npm install -g @anthropic-ai/claude-code @openai/codex @google/gemini-cli opencode-ai' \ && ok "Claude Code, Codex, Gemini CLI, OpenCode" \ || warn "some agent CLIs failed to install (see $LOG); you can retry: sudo -u desk -i npm install -g " grep -q npm-global "$DESK_HOME/.profile" 2>/dev/null || echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >>"$DESK_HOME/.profile" fi # ------------------------------------------------------------------ service step "Service" cat >/etc/systemd/system/agent-desk.service </dev/null 2>&1 && break; sleep 1; done curl -fsS "http://127.0.0.1:$PORT/api/auth" >/dev/null 2>&1 || die "the desk did not start: journalctl -u agent-desk -n 50" ok "running (restarts automatically, starts on boot)" # ------------------------------------------------------------------ HTTPS step "HTTPS" IP=$(curl -fsS4 https://api.ipify.org 2>/dev/null || hostname -I | awk '{print $1}') DOMAIN="${DESK_DOMAIN:-${IP//./-}.sslip.io}" if ! command -v caddy >/dev/null; then run bash -c "curl -fsSL 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor --yes -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg" run bash -c "curl -fsSL 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' -o /etc/apt/sources.list.d/caddy-stable.list" run apt-get update -y run apt-get install -y caddy fi cat >/etc/caddy/Caddyfile </dev/null 2>&1 && SSH_PORT=$(sshd -T 2>/dev/null | awk '/^port /{print $2; exit}' || true) case "$SSH_PORT" in ''|*[!0-9]*) SSH_PORT=22 ;; esac run ufw default deny incoming run ufw default allow outgoing run ufw allow "${SSH_PORT}/tcp" run ufw allow 80/tcp run ufw allow 443/tcp run ufw --force enable ok "only SSH (port $SSH_PORT), HTTP and HTTPS are open" # ------------------------------------------------------------------ done TOKEN=$(node -e "try{const a=require('$APP_DIR/data/auth.json');process.stdout.write(a.hash?'':a.setupToken||'')}catch{}") cat <