38 lines
1.1 KiB
Plaintext
38 lines
1.1 KiB
Plaintext
|
|
#!/usr/bin/env bash
|
||
|
|
set -euo pipefail
|
||
|
|
SEL_DIR="${1:-}"
|
||
|
|
[[ -n "$SEL_DIR" ]] || { echo "Usage: backtunnel-access-tui <selected-dir>"; exit 1; }
|
||
|
|
|
||
|
|
# Defaults: mount INTO the selected folder
|
||
|
|
DEFAULT_MP="$SEL_DIR"
|
||
|
|
|
||
|
|
# If selected folder is not empty, propose subdir
|
||
|
|
if [[ -d "$SEL_DIR" ]] && [[ -n "$(ls -A -- "$SEL_DIR" 2>/dev/null || true)" ]]; then
|
||
|
|
DEFAULT_MP="$SEL_DIR/backtunnel"
|
||
|
|
fi
|
||
|
|
|
||
|
|
read -r -p "Remote (user@host or user:host) [user@vps.example.com]: " REMOTE
|
||
|
|
REMOTE="${REMOTE:-user@vps.example.com}"
|
||
|
|
|
||
|
|
read -r -p "Tunnel port on remote [2222]: " PORT
|
||
|
|
PORT="${PORT:-2222}"
|
||
|
|
|
||
|
|
read -r -p "Mount point [${DEFAULT_MP}]: " MP
|
||
|
|
MP="${MP:-$DEFAULT_MP}"
|
||
|
|
|
||
|
|
# Expand leading ~ if user typed it
|
||
|
|
if [[ "$MP" == "~"* ]]; then
|
||
|
|
MP="${MP/#\~/$HOME}"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Ensure mountpoint exists & is writable
|
||
|
|
mkdir -p -- "$MP"
|
||
|
|
if [[ ! -w "$MP" ]]; then
|
||
|
|
echo "Mount point '$MP' is not writable"; exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo
|
||
|
|
echo "Running: backtunnel-access '<remote-folder>' from '$REMOTE' -p '$PORT' -m '$MP'"
|
||
|
|
echo "Note: you'll be prompted on the remote for the exact folder (as per your workflow)."
|
||
|
|
exec backtunnel-access "$MP" from "$REMOTE" -p "$PORT" -m "$MP"
|