Add accessor key authorization and enhance completion logic
Introduce `backtunnel-authorize` for managing restricted SFTP-only keys, and update `backtunnel-share` to support temporary accessor key authorization via `--allow-key` and `--allow-known`. Extend bash completion with profile, accessor, and SSH host suggestions. Revamp README sections to include updated workflows, quick starts, and key management details.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
# BackTunnel uninstaller (with optional PURGE=1 to remove shared defaults)
|
||||
# BackTunnel uninstaller (use PURGE=1 to remove /usr/share/backtunnel and /etc/backtunnel)
|
||||
set -euo pipefail
|
||||
|
||||
PREFIX=${PREFIX:-/usr}
|
||||
DESTDIR=${DESTDIR:-}
|
||||
PURGE=${PURGE:-0} # set PURGE=1 to remove /usr/share/backtunnel and /etc/backtunnel
|
||||
PURGE=${PURGE:-0}
|
||||
|
||||
BINDIR="$DESTDIR$PREFIX/bin"
|
||||
MANDIR="$DESTDIR$PREFIX/share/man/man1"
|
||||
@@ -15,73 +15,45 @@ BCOMP="$DESTDIR$PREFIX/share/bash-completion/completions"
|
||||
SHARE_DIR="$DESTDIR$PREFIX/share/backtunnel"
|
||||
ETC_DIR="$DESTDIR/etc/backtunnel"
|
||||
|
||||
say() { printf '[BackTunnel] %s\n' "$*"; }
|
||||
say_warn() { printf '[BackTunnel] WARN: %s\n' "$*" >&2; }
|
||||
say() { printf '[BackTunnel] %s\n' "$@"; }
|
||||
# ... existing code ...
|
||||
rm -f \
|
||||
"$BINDIR/backtunnel-share" \
|
||||
"$BINDIR/backtunnel-access" \
|
||||
"$BINDIR/backtunnel-share-gui" \
|
||||
"$BINDIR/backtunnel-access-gui" \
|
||||
"$BINDIR/backtunnel-open-term" \
|
||||
"$BINDIR/backtunnel-share-tui" \
|
||||
"$BINDIR/backtunnel-access-tui" \
|
||||
"$BINDIR/backtunnel-keys" \
|
||||
"$BINDIR/backtunnel-authorize" \
|
||||
"$BINDIR/backtunnel-auth-setup" \
|
||||
"$BINDIR/backtunnel-init"
|
||||
|
||||
# Portable directory prune: remove dir if empty, then move up until stop boundary
|
||||
prune_dir() {
|
||||
local dir="${1%/}"
|
||||
local stop="${2%/}"
|
||||
while [[ -n "$dir" && "$dir" != "/" && "$dir" != "$stop" ]]; do
|
||||
rmdir "$dir" 2>/dev/null || break
|
||||
dir="$(dirname "$dir")"
|
||||
done
|
||||
}
|
||||
|
||||
# Friendly notice if uninstalling the live system without root
|
||||
if [[ -z "$DESTDIR" && ${EUID:-$(id -u)} -ne 0 ]]; then
|
||||
say_warn "Running without root; some files may not be removed due to permissions."
|
||||
fi
|
||||
|
||||
say "Uninstalling from PREFIX=${PREFIX} DESTDIR=${DESTDIR} (PURGE=${PURGE})"
|
||||
|
||||
# --- Remove binaries ---
|
||||
rm -f "$BINDIR/backtunnel-share" \
|
||||
"$BINDIR/backtunnel-access" \
|
||||
"$BINDIR/backtunnel-auth-setup" \
|
||||
"$BINDIR/backtunnel-share-gui" \
|
||||
"$BINDIR/backtunnel-access-gui" \
|
||||
"$BINDIR/backtunnel-open-term" \
|
||||
"$BINDIR/backtunnel-share-tui" \
|
||||
"$BINDIR/backtunnel-access-tui"
|
||||
# Optionally remove helper that may be present on some installs
|
||||
rm -f "$BINDIR/backtunnel-init"
|
||||
|
||||
# --- Man page ---
|
||||
rm -f "$MANDIR/backtunnel.1"
|
||||
|
||||
# --- Bash completions ---
|
||||
rm -f "$BCOMP/backtunnel-share" \
|
||||
"$BCOMP/backtunnel-access"
|
||||
rm -f \
|
||||
"$BCOMP/backtunnel-share" \
|
||||
"$BCOMP/backtunnel-access"
|
||||
|
||||
# --- Dolphin service menus (Plasma 6 + legacy) ---
|
||||
rm -f "$KIO_SM/backtunnel_share.desktop" \
|
||||
"$KIO_SM/backtunnel_access.desktop" \
|
||||
"$KSVC5/backtunnel_share.desktop" \
|
||||
"$KSVC5/backtunnel_access.desktop"
|
||||
rm -f \
|
||||
"$KIO_SM/backtunnel_share.desktop" \
|
||||
"$KIO_SM/backtunnel_access.desktop" \
|
||||
"$KSVC5/backtunnel_share.desktop" \
|
||||
"$KSVC5/backtunnel_access.desktop"
|
||||
|
||||
# --- Optional desktop launcher ---
|
||||
rm -f "$APPDIR/backtunnel.desktop"
|
||||
|
||||
# --- Shared defaults (only if PURGE=1) ---
|
||||
# ... existing code ...
|
||||
# Optional purge of packaged defaults
|
||||
if [[ "$PURGE" = "1" ]]; then
|
||||
say "Purging shared defaults under $SHARE_DIR and $ETC_DIR"
|
||||
rm -f "$SHARE_DIR/profiles.ini" 2>/dev/null || true
|
||||
rm -f "$ETC_DIR/profiles.ini" 2>/dev/null || true
|
||||
# Remove directories if empty (and prune empty parents up to safe boundaries)
|
||||
prune_dir "$SHARE_DIR" "$DESTDIR$PREFIX/share"
|
||||
prune_dir "$ETC_DIR" "$DESTDIR/etc"
|
||||
else
|
||||
# Optionally clean up empty share dir if package manager removed files already
|
||||
prune_dir "$SHARE_DIR" "$DESTDIR$PREFIX/share"
|
||||
say "Keeping shared defaults: $SHARE_DIR/ and $ETC_DIR/ (set PURGE=1 to remove)"
|
||||
rm -rf "$SHARE_DIR" || true
|
||||
rm -rf "$ETC_DIR" || true
|
||||
say "Purged /usr/share/backtunnel and /etc/backtunnel"
|
||||
fi
|
||||
|
||||
# --- Refresh desktop/KDE cache (best-effort, skip during packaging) ---
|
||||
if [[ -z "$DESTDIR" ]]; then
|
||||
if command -v update-desktop-database >/dev/null 2>&1; then
|
||||
update-desktop-database -q || true
|
||||
fi
|
||||
# Refresh caches only if not in DESTDIR (packaging)
|
||||
if [[ -z "${DESTDIR}" ]]; then
|
||||
command -v update-desktop-database >/dev/null 2>&1 && 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
|
||||
|
||||
Reference in New Issue
Block a user