#!/usr/bin/env bash
# 反向 SSH 隧道：让 105 通过 127.0.0.1:19999 访问本机 SSH（MindSpace 共享挂载依赖）
set -euo pipefail

HOST="${MEMIND_TUNNEL_HOST:-ssh105}"
LOCAL_PORT="${MEMIND_TUNNEL_LOCAL_PORT:-22}"
REMOTE_PORT="${MEMIND_TUNNEL_REMOTE_PORT:-19999}"

exec ssh -N \
  -o ServerAliveInterval=30 \
  -o ServerAliveCountMax=3 \
  -o ExitOnForwardFailure=yes \
  -R "127.0.0.1:${REMOTE_PORT}:127.0.0.1:${LOCAL_PORT}" \
  "${HOST}"
