#!/usr/bin/env bash
set -euo pipefail
host="${LAPTOP_HOST:-brag-pipe-fur-kneel.emperor-ratio.ts.net}"
port="${LAPTOP_PORT:-2222}"
key="${LAPTOP_SSH_KEY:-$HOME/.ssh/id_ed25519_laptop_agent}"
remote_path="${1:-/Users/sebas}"
mount_name="${2:-$(basename "$remote_path")}" 
mount_root="${LAPTOP_MOUNT_ROOT:-$HOME/mnt/laptop}"
mount_point="$mount_root/$mount_name"
if ! command -v sshfs >/dev/null 2>&1; then
  echo "sshfs not installed on Pi. Install first, then retry." >&2
  exit 1
fi
mkdir -p "$mount_point"
sshfs_opts=(reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,auto_cache,defer_permissions,port="$port",IdentitiesOnly=yes)
if [[ -f "$key" ]]; then
  sshfs_opts+=(IdentityFile="$key")
fi
sshfs "$host:$remote_path" "$mount_point" -o "$(IFS=,; echo "${sshfs_opts[*]}")"
printf '%s\n' "$mount_point"
