2025-09-19 15:30:41 +02:00
|
|
|
#!/usr/bin/env bash
|
2025-09-21 09:45:43 +02:00
|
|
|
# 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.
|
|
|
|
|
|
2025-09-19 15:30:41 +02:00
|
|
|
set -euo pipefail
|
|
|
|
|
FOLDER="${1:-}"
|
|
|
|
|
[[ -n "$FOLDER" ]] || { echo "Usage: backtunnel-share-tui <folder>"; exit 1; }
|
|
|
|
|
|
2025-09-21 09:45:43 +02:00
|
|
|
# ---- Interactive prompts (with sensible defaults) ----
|
2025-09-19 15:30:41 +02:00
|
|
|
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}"
|
|
|
|
|
|
2025-09-21 09:45:43 +02:00
|
|
|
# Invite toggles
|
2025-09-19 15:30:41 +02:00
|
|
|
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}"
|
|
|
|
|
|
2025-09-21 09:45:43 +02:00
|
|
|
# ---- Run the command ----
|
2025-09-19 15:30:41 +02:00
|
|
|
echo
|
|
|
|
|
echo "Running: backtunnel-share '$FOLDER' with '$REMOTE' for '$DUR' -p '$TPORT' -l '$LPORT' ${INV:+-i} ${QR:+--qr} --invite-mount '$MP'"
|
2025-09-21 09:45:43 +02:00
|
|
|
# Replace this process with backtunnel-share (no return after exec)
|
2025-09-19 15:30:41 +02:00
|
|
|
exec backtunnel-share "$FOLDER" with "$REMOTE" for "$DUR" -p "$TPORT" -l "$LPORT" ${INV:+-i} ${QR:+--qr} --invite-mount "$MP"
|