#!/usr/bin/env bash
# 06_direct_mount_puget_yukon.sh — mount puget + yukon DIRECTLY from VPS.
#
# Previously chain-mounted through lab (VPS → lab's ~/mnt/yukon → yukon). That made
# lab a single point of failure. Direct mount uses their Tailscale IPs.
#
# Prereqs:
#   * puget + yukon reachable via Tailscale from VPS (they're tailnet members)
#   * SSH key auth (Tailscale-SSH may require one-time browser auth click each)
#
# After this: /data/cameron/yukon_remote and /data/cameron/puget_remote (new) are
# direct sshfs mounts. If lab dies, these keep working.

set -euo pipefail

# Confirm Tailscale IPs (from `tailscale status` output as of 2026-07-06):
YUKON="cameron.smith@100.72.103.103"   # yukon (TRI machine, non-cameronsmith user)
PUGET="cameronsmith@100.104.232.94"     # puget-232243-01

SSHFS_OPTS="reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,follow_symlinks,cache=yes,kernel_cache,compression=no,uid=1011,gid=1011"

# --- Yukon direct mount ---
YUKON_MP="/data/cameron/yukon_remote"
mkdir -p "$YUKON_MP"
if ! mountpoint -q "$YUKON_MP"; then
  # Confirm the yukon-side path Cameron actually wants surfaced. Common candidates:
  #   /home/cameron/yam_para/data/  (rollouts + PKLs)
  #   /home/cameron/                (whole home)
  # Start with home dir and let Cameron adjust:
  echo "[mount] $YUKON → $YUKON_MP"
  sshfs "$YUKON:/home/cameron" "$YUKON_MP" -o "$SSHFS_OPTS" || echo "  WARN: yukon mount failed (Tailscale-SSH auth?)"
fi

# --- Puget direct mount ---
PUGET_MP="/data/cameron/puget_remote"
mkdir -p "$PUGET_MP"
if ! mountpoint -q "$PUGET_MP"; then
  echo "[mount] $PUGET → $PUGET_MP"
  sshfs "$PUGET:/home/cameronsmith" "$PUGET_MP" -o "$SSHFS_OPTS" || echo "  WARN: puget mount failed"
fi

echo
echo "==> Health probes:"
timeout 3 stat -c '%i' "$YUKON_MP" > /dev/null 2>&1 && echo "  OK    yukon direct" || echo "  HUNG  yukon (check Tailscale-SSH auth)"
timeout 3 stat -c '%i' "$PUGET_MP" > /dev/null 2>&1 && echo "  OK    puget direct" || echo "  HUNG  puget"

echo
echo "Note: agents that referenced yukon_remote via lab-chain path still work — same"
echo "path (/data/cameron/yukon_remote), different backing daemon."
