#!/usr/bin/env bash # # hubspoke-helper.sh - Manage hub/spoke rclone mounts over reverse SSH # # This script helps configure and control the two sides: # - Spoke: establishes a reverse SSH tunnel (autossh) # - Hub: mounts the spoke's filesystem via rclone/sftp # # It expects service template files in: # ./spoke/autossh-tunnel.service # ./hub/rclone-mount@.service # # Those files can be copied or piped into place by this script. set -euo pipefail # ------------------------------------------------------------ # Configuration (adjust these to your environment) # ------------------------------------------------------------ SPOKE_AUTOSSH_SERVICE_SRC="./spoke/autossh-tunnel.service" HUB_RCLONE_SERVICE_SRC="./hub/rclone-mount@.service" # Default values (can be overridden with environment variables or interactive prompts) HUB_USER="${HUB_USER:-armbian}" HUB_HOST="${HUB_HOST:-oily.dad}" SPOKE_USER="${SPOKE_USER:-armbian}" TUNNEL_PORT="${TUNNEL_PORT:-11111}" SPOKE_SSH_KEY="${SPOKE_SSH_KEY:-$HOME/.ssh/armbian-brie-202604}" RCLONE_REMOTE_NAME="${RCLONE_REMOTE_NAME:-brie-remote}" MOUNT_POINT="${MOUNT_POINT:-$HOME/mnt/brie}" # ------------------------------------------------------------ # Helper functions # ------------------------------------------------------------ usage() { cat <&2 exit 1 } check_service_file() { local file="$1" if [ ! -f "$file" ]; then die "Service template not found: $file" fi } # ------------------------------------------------------------ # Spoke actions # ------------------------------------------------------------ spoke_show_cmd() { cat </dev/null && echo "Unmounted." || echo "Not mounted or already unmounted." } # ------------------------------------------------------------ # Main dispatch # ------------------------------------------------------------ if [ $# -lt 2 ]; then usage exit 1 fi ROLE="$1" ACTION="$2" case "$ROLE" in spoke) case "$ACTION" in show-cmd) spoke_show_cmd ;; install) spoke_install ;; start) spoke_start ;; stop) spoke_stop ;; status) spoke_status ;; *) die "Unknown action for spoke: $ACTION" ;; esac ;; hub) case "$ACTION" in show-cmd) hub_show_cmd ;; install) hub_install ;; start) hub_start ;; stop) hub_stop ;; status) hub_status ;; mount) hub_mount ;; unmount) hub_unmount ;; *) die "Unknown action for hub: $ACTION" ;; esac ;; *) usage exit 1 ;; esac