Files
BackTunnel/scripts/backtunnel-share-tui

65 lines
2.1 KiB
Plaintext
Raw Normal View History

#!/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-share-tui
# Summary: Minimal TUI to start a time-bounded BackTunnel share with optional invite/QR.
# Description:
# Interactive, terminal-based helper that prompts for remote, duration, ports, and invite options,
# then invokes backtunnel-share to create a reverse-SSH tunnel for the selected folder.
# Can optionally include a ready-to-copy invite command and QR code for convenience.
#
# Usage:
# backtunnel-share-tui <folder>
#
# Examples:
# backtunnel-share-tui ~/projects
#
# Dependencies:
# - bash
# - backtunnel-share (invoked via exec at the end)
#
# Exit codes:
# 0 success (exec replaces this process on success)
# 1 invalid usage
#
# Notes:
# - This tool only collects inputs; the actual sharing is done by backtunnel-share.
set -euo pipefail
FOLDER="${1:-}"
[[ -n "$FOLDER" ]] || { echo "Usage: backtunnel-share-tui <folder>"; exit 1; }
# ---- 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 "Share duration (30m/2h/1d) [2h]: " DUR
DUR="${DUR:-2h}"
read -r -p "Tunnel port on remote [2222]: " TPORT
TPORT="${TPORT:-2222}"
read -r -p "Local sshd port to expose [22]: " LPORT
LPORT="${LPORT:-22}"
# Invite toggles
read -r -p "Print invite line for chat? (y/N): " yn
INV=; [[ "${yn,,}" == "y" ]] && INV="-i"
QR=
if [[ -n "$INV" ]]; then
read -r -p "Show QR code for the invite? (y/N): " yq
[[ "${yq,,}" == "y" ]] && QR="--qr"
fi
read -r -p "Invite: suggested mount point [/mnt/remote-rssh]: " MP
MP="${MP:-/mnt/remote-rssh}"
# ---- Run the command ----
echo
echo "Running: backtunnel-share '$FOLDER' with '$REMOTE' for '$DUR' -p '$TPORT' -l '$LPORT' ${INV:+-i} ${QR:+--qr} --invite-mount '$MP'"
# Replace this process with backtunnel-share (no return after exec)
exec backtunnel-share "$FOLDER" with "$REMOTE" for "$DUR" -p "$TPORT" -l "$LPORT" ${INV:+-i} ${QR:+--qr} --invite-mount "$MP"