Enhance backtunnel-share with improved desktop integration, port collision checks, and pre-flight validations

This commit is contained in:
2025-09-14 14:11:36 +02:00
parent 07dbd79aa2
commit b1dd9bfc83
6 changed files with 61 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
#!/usr/bin/env bash
# Copyright (c) 2025. LUXIM d.o.o., Slovenia - Matjaž Mozetič.
# Licensed under the GNU GPL v3.0
# backtunnel-share: Share a folder using reverse SSH for a limited duration
# Syntax: backtunnel-share /path/to/folder with remoteuser:remotehost for 2h
@@ -163,8 +164,23 @@ fi
echo "Tip: On the remote side, mount with:"
echo " backtunnel-access '${FOLDER}' from ${REMOTE_USER}@${REMOTE_HOST} -p ${TUNNEL_PORT}"
echo "To stop sharing early: press Ctrl+C here."
# --- optional pre-flight: warn if remote loopback port is already in use (best-effort) ---
if ssh -o BatchMode=yes -o ConnectTimeout=5 "${REMOTE_USER}@${REMOTE_HOST}" \
"command -v nc >/dev/null 2>&1 && nc -z 127.0.0.1 ${TUNNEL_PORT}"; then
echo "⚠️ Port ${TUNNEL_PORT} on remote 127.0.0.1 appears in use; choose another with -p." >&2
# Uncomment the next line to make it a hard failure:
# exit 1
fi
# Bind reverse to 127.0.0.1 on the REMOTE host (private-by-default).
# Keepalive so the tunnel drops on dead links.
# Exit fast if the reverse bind fails (e.g., port in use).
timeout "$DURATION" ssh -N \
-o ExitOnForwardFailure=yes \
-o ServerAliveInterval=15 \
-o ServerAliveCountMax=3 \
-R "${TUNNEL_PORT}:localhost:${LOCAL_SSH_PORT}" \
-- "${REMOTE_USER}@${REMOTE_HOST}"

View File

@@ -44,4 +44,12 @@ if [[ -d /usr/share/applications ]]; then
sudo install -m 0644 desktop/backtunnel.desktop /usr/share/applications/backtunnel.desktop || true
fi
# Refresh desktop DB and KDE service cache (best-effort)
command -v update-desktop-database >/dev/null 2>&1 && sudo update-desktop-database -q || true
if command -v kbuildsycoca6 >/dev/null 2>&1; then
kbuildsycoca6 --noincremental >/dev/null 2>&1 || true
elif command -v kbuildsycoca5 >/dev/null 2>&1; then
kbuildsycoca5 --noincremental >/dev/null 2>&1 || true
fi
echo "✅ BackTunnel installed. You may need to restart your shell and Dolphin."

View File

@@ -39,4 +39,12 @@ sudo rm -f /usr/share/kservices5/ServiceMenus/backtunnel_access.desktop || true
echo "🧹 Removing desktop launcher ..."
sudo rm -f /usr/share/applications/backtunnel.desktop || true
# Refresh desktop DB and KDE service cache (best-effort)
command -v update-desktop-database >/dev/null 2>&1 && sudo update-desktop-database -q || true
if command -v kbuildsycoca6 >/dev/null 2>&1; then
kbuildsycoca6 --noincremental >/dev/null 2>&1 || true
elif command -v kbuildsycoca5 >/dev/null 2>&1; then
kbuildsycoca5 --noincremental >/dev/null 2>&1 || true
fi
echo "✅ Uninstall complete."