#!/usr/bin/env bash # Restore dexter/hedge state from GitHub (source of truth; /data is ephemeral), # then start all services under supervisord. No Caddy, no terminal. set -euo pipefail export HOME=/home/user STATE_DIR=/data/hedge-state DEXTER_LINK=/app/dexter/.dexter HEDGE_DB=/app/ai-hedge-fund/app/backend/hedge_fund.db if [[ -n "${GIT_BACKUP_TOKEN:-}" && -n "${STATE_REPO:-}" ]]; then REMOTE="https://x-access-token:${GIT_BACKUP_TOKEN}@github.com/${STATE_REPO}.git" echo "[entrypoint] restoring state from ${STATE_REPO} ..." rm -rf "$STATE_DIR" if git clone --depth 1 "$REMOTE" "$STATE_DIR" 2>/dev/null; then echo "[entrypoint] state repo cloned." else echo "[entrypoint] clone failed/empty — starting fresh." mkdir -p "$STATE_DIR"; git -C "$STATE_DIR" init -q git -C "$STATE_DIR" remote add origin "$REMOTE" 2>/dev/null || true fi git -C "$STATE_DIR" config user.email "dexter-space@users.noreply.github.com" git -C "$STATE_DIR" config user.name "dexter-space" mkdir -p "$STATE_DIR/dexter" "$STATE_DIR/hedge" rm -rf "$DEXTER_LINK"; ln -s "$STATE_DIR/dexter" "$DEXTER_LINK" mkdir -p "$(dirname "$HEDGE_DB")"; rm -f "$HEDGE_DB" ln -s "$STATE_DIR/hedge/hedge_fund.db" "$HEDGE_DB" STATE_DIR="$STATE_DIR" /usr/local/bin/state-backup.sh & echo "[entrypoint] state backup loop started." else echo "[entrypoint] GIT_BACKUP_TOKEN/STATE_REPO unset — running without persistence." mkdir -p "$DEXTER_LINK" fi exec /usr/bin/supervisord -c /etc/supervisord.conf