#!/usr/bin/env bash
# 正向 SSH 隧道：本机 18080 → 105 goose-h5 :8080（g2 负载均衡 upstream）
set -euo pipefail

HOST="${G2_TUNNEL_HOST:-ssh105}"
LOCAL_PORT="${G2_TUNNEL_LOCAL_PORT:-18080}"
REMOTE_HOST="${G2_TUNNEL_REMOTE_HOST:-127.0.0.1}"
REMOTE_PORT="${G2_TUNNEL_REMOTE_PORT:-8080}"

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