#!/usr/bin/env bash
# Print a ready-to-paste scp command for pulling a file from this host
# to the user's Windows machine over Tailscale SSH.
set -euo pipefail

HOST="vasily@msi.tail0b014a.ts.net"

if [[ $# -ne 1 ]]; then
  echo "usage: t3-deliver <file-or-directory>" >&2
  exit 1
fi

path="$1"
if [[ ! -e "$path" ]]; then
  echo "t3-deliver: no such path: $path" >&2
  exit 1
fi

if [[ "$path" != /* ]]; then
  path="$(realpath "$path")"
else
  path="$(realpath -m "$path")"
fi

flags=""
if [[ -d "$path" ]]; then
  flags="-r "
fi

echo "Paste in cmd or PowerShell on your Windows machine:"
echo
echo "${flags}scp ${HOST}:\"${path}\" ."
