Introduce terminal-based workflows for BackTunnel via TUI scripts and service menus

Add `backtunnel-open-term`, `backtunnel-share-tui`, and `backtunnel-access-tui` scripts for terminal-based interaction. Update Dolphin service menus to enable TUI workflows, with improved terminal detection logic. Enhance installation and uninstallation scripts to handle new files. Update README with terminal workflow details and logging information.
This commit is contained in:
2025-09-19 15:30:41 +02:00
parent f42344ebe8
commit 608a6a371f
9 changed files with 276 additions and 71 deletions

View File

@@ -0,0 +1,55 @@
#!/usr/bin/env bash
# Open a command in the user's available terminal emulator, with logging.
# Usage: backtunnel-open-term <cmd> [args...]
set -euo pipefail
LOG_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/backtunnel"
[[ -d "$LOG_DIR" ]] || mkdir -p "$LOG_DIR"
LOG_FILE="${LOG_DIR}/servicemenu.$(date +%Y%m%d-%H%M%S).log"
# Simple rotation: keep the last 10 files
ls -1t "$LOG_DIR"/servicemenu.*.log 2>/dev/null | awk 'NR>10{print}' | xargs -r rm -f
cmd=( "$@" )
{
echo "=== BackTunnel servicemenu ==="
echo "Time: $(date -Is)"
echo "PWD: $(pwd)"
echo "User: $(id -un) (uid=$(id -u))"
echo "Cmd: ${cmd[*]}"
echo "Env: BACKTUNNEL_DEBUG=${BACKTUNNEL_DEBUG:-} SHELL=${SHELL:-} DISPLAY=${DISPLAY:-}"
echo
# Prefer Konsole on KDE sessions; otherwise probe common terminals
detect_term() {
if [[ -n "${KDE_FULL_SESSION:-}" ]] && command -v konsole >/dev/null 2>&1; then
echo "konsole"; return
fi
for t in kitty alacritty kgx gnome-terminal tilix xfce4-terminal konsole xterm; do
if command -v "$t" >/dev/null 2>&1; then echo "$t"; return; fi
done
echo "" # none
}
term="$(detect_term)"
echo "Chosen terminal: ${term:-<none>}"; echo
# Run command in terminal (use hold/noclose if supported)
case "$term" in
konsole) exec konsole --noclose -e "${cmd[@]}" ;;
kitty) exec kitty -e "${cmd[@]}" ;;
alacritty) exec alacritty -e "${cmd[@]}" ;;
gnome-terminal) exec gnome-terminal -- bash -lc "exec \"${cmd[0]}\" ${cmd[@]:1}" ;;
kgx) exec kgx -- bash -lc "exec \"${cmd[0]}\" ${cmd[@]:1}" ;; # GNOME Console
tilix) exec tilix -e "${cmd[@]}" ;;
xfce4-terminal) exec xfce4-terminal -e "${cmd[@]}" ;;
xterm) exec xterm -hold -e "${cmd[@]}" ;;
*)
echo "No terminal emulator found. Running in background (nohup)."
nohup "${cmd[@]}" >/dev/null 2>&1 &
echo "Started in background (pid=$!)."
echo "Log: $LOG_FILE"
exit 0
;;
esac
} | tee -a "$LOG_FILE"