Introduce `backtunnel-umount` as a portable unmount helper, preferring `fusermount3`, `fusermount`, or `umount`. Add `BACKTUNNEL_HOSTKEY_POLICY` for configurable host key handling in `backtunnel-share` and `backtunnel-access`. Update TUIs for remote folder prompts and mount point handling. Enhance bash completion for TUI commands with directory suggestions. Revamp terminal selection logic in `backtunnel-open-term` to prioritize modern emulators like wezterm. Extend tests with scaffolds for host key policy and unmount behavior. Update README with new scripts, workflows, features, and troubleshooting tips.
76 lines
2.4 KiB
Bash
76 lines
2.4 KiB
Bash
#!/usr/bin/env bash
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
# Copyright (c) 2025 LUXIM d.o.o., Slovenia
|
|
# Author: Matjaž Mozetič
|
|
#
|
|
# Name: backtunnel-access-tui
|
|
# Summary: Minimal TUI to mount a BackTunnel share into a chosen directory.
|
|
# Description:
|
|
# Interactive, terminal-based helper that asks for remote, tunnel port, and mount point,
|
|
# then invokes backtunnel-access to perform the actual sshfs mount. Defaults to mounting
|
|
# into the selected directory; if non-empty, proposes a "backtunnel" subdirectory.
|
|
#
|
|
# Usage:
|
|
# backtunnel-access-tui <selected-dir>
|
|
#
|
|
# Examples:
|
|
# backtunnel-access-tui ~/Downloads
|
|
#
|
|
# Dependencies:
|
|
# - bash
|
|
# - backtunnel-access (invoked via exec at the end)
|
|
#
|
|
# Exit codes:
|
|
# 0 success (exec replaces the shell on success)
|
|
# 1 invalid usage or mountpoint not writable
|
|
#
|
|
# Notes:
|
|
# - Expands leading "~" in the chosen mount point.
|
|
# - This tool only gathers inputs; mounting is performed by backtunnel-access.
|
|
|
|
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
|
|
|
|
# ---- Interactive prompts (with sensible defaults) ----
|
|
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}"
|
|
|
|
# Ask for the remote folder that should be mounted (first positional of backtunnel-access)
|
|
read -r -p "Remote folder path to mount [~/]: " FOLDER
|
|
FOLDER="${FOLDER:-~/}"
|
|
if [[ "$FOLDER" == "~" ]]; then
|
|
FOLDER="~/"
|
|
fi
|
|
|
|
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 '${FOLDER}' from '${REMOTE}' -p '${PORT}' -m '${MP}'"
|
|
echo "Note: the folder is accessed via SFTP on the remote through the reverse tunnel."
|
|
# Replace this process with backtunnel-access (no return to this script after exec)
|
|
exec backtunnel-access "$FOLDER" from "$REMOTE" -p "$PORT" -m "$MP"
|