Files

131 lines
5.4 KiB
Makefile
Raw Permalink Normal View History

# BackTunnel convenience Makefile (terminal/TUI service menus)
PREFIX ?= /usr
BINDIR := $(PREFIX)/bin
MANDIR := $(PREFIX)/share/man
KIO_SM := $(PREFIX)/share/kio/servicemenus
KSVC5 := $(PREFIX)/share/kservices5/ServiceMenus
APPDIR := $(PREFIX)/share/applications
BCOMP := $(PREFIX)/share/bash-completion/completions
SHAREDIR := $(PREFIX)/share/backtunnel
# Config paths for user init
XDG_CONFIG_HOME ?= $(HOME)/.config
BT_CFG_DIR := $(XDG_CONFIG_HOME)/backtunnel
BT_CFG_FILE := $(BT_CFG_DIR)/profiles.ini
BT_CFG_EXAMPLE := docs/profiles.ini.example
.PHONY: all init install uninstall refresh man check shellcheck help
all: help
help:
@echo "BackTunnel Makefile"
@echo " make init # Copy example profiles.ini for current user (first run)"
@echo " make install # Install scripts, man page, service menus (root)"
@echo " make uninstall # Remove installed files (root)"
@echo " make refresh # Refresh KDE/desktop caches (root)"
@echo " make man # View man page locally (man ./man/backtunnel.1)"
@echo " make check # Basic bash syntax check"
@echo " make shellcheck # ShellCheck (if installed)"
# --- First-time user init (no root needed) ---
init:
@mkdir -p "$(BT_CFG_DIR)"
@if [ -f "$(BT_CFG_FILE)" ]; then \
echo "profiles.ini already exists at $(BT_CFG_FILE) — skipping."; \
else \
if [ -f "$(BT_CFG_EXAMPLE)" ]; then \
cp "$(BT_CFG_EXAMPLE)" "$(BT_CFG_FILE)"; \
echo "Created $(BT_CFG_FILE) from $(BT_CFG_EXAMPLE)."; \
else \
echo "Example file $(BT_CFG_EXAMPLE) not found."; exit 1; \
fi \
fi
# --- Install/uninstall (root or DESTDIR) ---
install:
@install -Dm755 scripts/backtunnel-share "$(DESTDIR)$(BINDIR)/backtunnel-share"
@install -Dm755 scripts/backtunnel-access "$(DESTDIR)$(BINDIR)/backtunnel-access"
@install -Dm755 scripts/backtunnel-share-gui "$(DESTDIR)$(BINDIR)/backtunnel-share-gui"
@install -Dm755 scripts/backtunnel-access-gui "$(DESTDIR)$(BINDIR)/backtunnel-access-gui"
@install -Dm755 scripts/backtunnel-open-term "$(DESTDIR)$(BINDIR)/backtunnel-open-term"
@install -Dm755 scripts/backtunnel-share-tui "$(DESTDIR)$(BINDIR)/backtunnel-share-tui"
@install -Dm755 scripts/backtunnel-access-tui "$(DESTDIR)$(BINDIR)/backtunnel-access-tui"
@install -Dm644 man/backtunnel.1 "$(DESTDIR)$(MANDIR)/man1/backtunnel.1"
@install -Dm644 completions/backtunnel.bash "$(DESTDIR)$(BCOMP)/backtunnel-share"
@install -Dm644 completions/backtunnel.bash "$(DESTDIR)$(BCOMP)/backtunnel-access"
@install -Dm644 servicemenus/backtunnel_share.desktop "$(DESTDIR)$(KIO_SM)/backtunnel_share.desktop"
@install -Dm644 servicemenus/backtunnel_access.desktop "$(DESTDIR)$(KIO_SM)/backtunnel_access.desktop"
# Plasma 5 legacy path (harmless if unused)
@install -Dm644 servicemenus/backtunnel_share.desktop "$(DESTDIR)$(KSVC5)/backtunnel_share.desktop"
@install -Dm644 servicemenus/backtunnel_access.desktop "$(DESTDIR)$(KSVC5)/backtunnel_access.desktop"
# Optional desktop launcher if present
@if [ -f desktop/backtunnel.desktop ]; then \
install -Dm644 desktop/backtunnel.desktop "$(DESTDIR)$(APPDIR)/backtunnel.desktop"; \
fi
# Example profiles (system default + packaged fallback)
@install -Dm644 docs/profiles.ini.example "$(DESTDIR)/etc/backtunnel/profiles.ini"
@install -Dm644 docs/profiles.ini.example "$(DESTDIR)$(SHAREDIR)/profiles.ini"
@$(MAKE) refresh
uninstall:
@rm -f "$(DESTDIR)$(BINDIR)/backtunnel-share" \
"$(DESTDIR)$(BINDIR)/backtunnel-access" \
"$(DESTDIR)$(BINDIR)/backtunnel-share-gui" \
"$(DESTDIR)$(BINDIR)/backtunnel-access-gui" \
"$(DESTDIR)$(BINDIR)/backtunnel-open-term" \
"$(DESTDIR)$(BINDIR)/backtunnel-share-tui" \
"$(DESTDIR)$(BINDIR)/backtunnel-access-tui"
@rm -f "$(DESTDIR)$(MANDIR)/man1/backtunnel.1"
@rm -f "$(DESTDIR)$(BCOMP)/backtunnel-share" \
"$(DESTDIR)$(BCOMP)/backtunnel-access"
@rm -f "$(DESTDIR)$(KIO_SM)/backtunnel_share.desktop" \
"$(DESTDIR)$(KIO_SM)/backtunnel_access.desktop"
@rm -f "$(DESTDIR)$(KSVC5)/backtunnel_share.desktop" \
"$(DESTDIR)$(KSVC5)/backtunnel_access.desktop"
@rm -f "$(DESTDIR)$(APPDIR)/backtunnel.desktop" || true
# Do not remove /etc/backtunnel or /usr/share/backtunnel by default
# If you want to purge, run scripts/uninstall.sh with PURGE=1
@$(MAKE) refresh
# --- Cache refreshers (no-op if tools missing) ---
refresh:
@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 \
kbuildsycoca5 --noincremental >/dev/null 2>&1 || true; \
fi
# --- Dev helpers ---
man:
@man ./man/backtunnel.1
check:
@bash -n scripts/backtunnel-share
@bash -n scripts/backtunnel-access
@bash -n scripts/backtunnel-share-gui
@bash -n scripts/backtunnel-access-gui
@bash -n scripts/backtunnel-open-term
@bash -n scripts/backtunnel-share-tui
@bash -n scripts/backtunnel-access-tui
@echo "bash -n OK."
shellcheck:
@command -v shellcheck >/dev/null 2>&1 || { echo "ShellCheck not installed"; exit 1; }
@shellcheck scripts/backtunnel-share
@shellcheck scripts/backtunnel-access
@shellcheck scripts/backtunnel-share-gui
@shellcheck scripts/backtunnel-access-gui
@shellcheck scripts/backtunnel-open-term
@shellcheck scripts/backtunnel-share-tui
@shellcheck scripts/backtunnel-access-tui