diff options
| author | Adam Malczewski <[email protected]> | 2026-06-21 21:17:18 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-06-21 21:17:18 +0900 |
| commit | 219e7f2dd0ff2d0125f18594c6c16a6c0aff6710 (patch) | |
| tree | bd2008c7c585123848d3eaf639347c167ba2fa9c /bin | |
| parent | 72747d341badd182338b80602a09f083d0400b14 (diff) | |
| download | dispatch-219e7f2dd0ff2d0125f18594c6c16a6c0aff6710.tar.gz dispatch-219e7f2dd0ff2d0125f18594c6c16a6c0aff6710.zip | |
fix(setup-env): set HOME so skills discovery works under systemd
The skills extension scans ~/.skills/ via os.homedir(). Under systemd as
root, this resolves to /root — no skills there. setup-env now resolves
the real user's home via SUDO_USER and writes HOME=<user home> to
/etc/dispatch/env.
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/setup-env | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/bin/setup-env b/bin/setup-env new file mode 100755 index 0000000..8baf326 --- /dev/null +++ b/bin/setup-env @@ -0,0 +1,75 @@ +#!/usr/bin/env bash +# bin/setup-env — create /etc/dispatch/env from the repo .env with system paths. +# Run this once before bin/install (or after, to refresh the config). +# +# Usage: sudo bin/setup-env + +set -euo pipefail + +HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT="$(cd "$HERE/.." && pwd)" + +if [[ "$(id -u)" -ne 0 ]]; then + echo "setup-env: must run as root (use sudo)" >&2 + exit 1 +fi + +mkdir -p /etc/dispatch /var/lib/dispatch /var/log/dispatch + +# Read the API keys from the repo .env (gitignored, local only) +ENV_FILE="$ROOT/.env" +if [[ ! -f "$ENV_FILE" ]]; then + echo "setup-env: $ENV_FILE not found — create it first (see .env.example)" >&2 + exit 1 +fi + +# Extract values from .env +source "$ENV_FILE" + +# Resolve the real user's home dir (for skills discovery — the skills extension +# scans ~/.skills/ via os.homedir(); under systemd as root this would be /root) +REAL_USER="${SUDO_USER:-$USER}" +REAL_HOME=$(getent passwd "$REAL_USER" | cut -d: -f6) +if [[ -z "$REAL_HOME" ]]; then + echo "setup-env: could not resolve home for user '$REAL_USER'" >&2 + exit 1 +fi + +# Write the system env file +tee /etc/dispatch/env > /dev/null << EOF +# /etc/dispatch/env — Dispatch server configuration (systemd EnvironmentFile) +# Generated by bin/setup-env from $ENV_FILE +# Edit manually, then: systemctl restart dispatch + +# ─── User environment (skills discovery uses \$HOME/.skills/) ──────────────── +HOME=$REAL_HOME + +# ─── Ports ─────────────────────────────────────────────────────────────────── +BACKEND_PORT=24991 +SURFACE_WS_PORT=24990 + +# ─── Frontend ──────────────────────────────────────────────────────────────── +DISPATCH_WEB_DIR=/usr/share/dispatch/web + +# ─── Provider (OpenCode Go / OpenAI-compatible) ────────────────────────────── +DISPATCH_API_KEY=${DISPATCH_API_KEY} +DISPATCH_BASE_URL=${DISPATCH_BASE_URL:-https://opencode.ai/zen/go/v1} +DISPATCH_MODEL=${DISPATCH_MODEL:-deepseek-v4-flash} + +# ─── Umans provider ────────────────────────────────────────────────────────── +${UMANS_API_KEY:+UMANS_API_KEY=${UMANS_API_KEY}} + +# ─── Data paths ────────────────────────────────────────────────────────────── +DISPATCH_DB=/var/lib/dispatch/dispatch.db +DISPATCH_TRACE_DB=/var/lib/dispatch/traces.db +DISPATCH_JOURNAL=/var/log/dispatch/app.ndjson +EOF + +chmod 600 /etc/dispatch/env + +echo "[setup-env] wrote /etc/dispatch/env" +echo " HOME=$REAL_HOME (skills: $REAL_HOME/.skills/)" +echo " DISPATCH_API_KEY=${DISPATCH_API_KEY:0:8}..." +${UMANS_API_KEY:+echo " UMANS_API_KEY=${UMANS_API_KEY:0:8}..."} +echo " Ports: HTTP=24991 WS=24990" +echo " Data: /var/lib/dispatch/ + /var/log/dispatch/" |
