From 299f6c535527c6d336c91e016d90c24731e9b59a Mon Sep 17 00:00:00 2001 From: finn Date: Mon, 13 Apr 2026 12:53:14 -0700 Subject: [PATCH] restructure --- clean_wifi.sh | 16 -- hubspoke-helper.sh | 236 ++++++++---------- spoke/Dockerfile | 8 + aptprimary.sh => spoke/aptprimary.sh | 0 .../armb-not_logged_in_yet | 0 autohostname.sh => spoke/autohostname.sh | 0 .../clean_sensitive.sh | 0 spoke/compose.yaml | 20 ++ 8 files changed, 132 insertions(+), 148 deletions(-) delete mode 100755 clean_wifi.sh create mode 100644 spoke/Dockerfile rename aptprimary.sh => spoke/aptprimary.sh (100%) rename armb-not_logged_in_yet => spoke/armb-not_logged_in_yet (100%) rename autohostname.sh => spoke/autohostname.sh (100%) rename clean_sensitive.sh => spoke/clean_sensitive.sh (100%) create mode 100644 spoke/compose.yaml diff --git a/clean_wifi.sh b/clean_wifi.sh deleted file mode 100755 index 9f5b3e3..0000000 --- a/clean_wifi.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -# Simple script to clean WiFi SSID and KEY from configuration files -# Usage: ./clean_wifi.sh [filename] - -FILE="${1:-/home/finn/code/tinyboard/armb-not_logged_in_yet}" - -echo "Cleaning WiFi credentials from: $FILE" - -# Clean WiFi SSID (both commented and uncommented lines) -sed -i 's/^\(#*PRESET_NET_WIFI_SSID=\).*$/\1"[REDACTED]"/' "$FILE" - -# Clean WiFi KEY (both commented and uncommented lines) -sed -i 's/^\(#*PRESET_NET_WIFI_KEY=\).*$/\1"[REDACTED]"/' "$FILE" - -echo "creds wiped" diff --git a/hubspoke-helper.sh b/hubspoke-helper.sh index fa3cf14..15e8d39 100755 --- a/hubspoke-helper.sh +++ b/hubspoke-helper.sh @@ -1,200 +1,172 @@ #!/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. +# hubspoke-helper.sh - Manage hub/spoke rclone mounts +# Assumes spoke Docker files exist in ~/autossh-tunnel/ +# Assumes hub rclone service template is manually placed (or not needed) set -euo pipefail # ------------------------------------------------------------ -# Configuration (adjust these to your environment) +# Configuration (override with env vars if needed) # ------------------------------------------------------------ -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}" +TUNNEL_DIR="${TUNNEL_DIR:-$HOME/tinyboard/spoke}" +COMPOSE_FILE="${COMPOSE_FILE:-$TUNNEL_DIR/compose.yaml}" +RCLONE_REMOTE="${RCLONE_REMOTE:-brie-remote}" MOUNT_POINT="${MOUNT_POINT:-$HOME/mnt/brie}" # ------------------------------------------------------------ -# Helper functions +# Usage # ------------------------------------------------------------ usage() { - cat <&2 - exit 1 -} - -check_service_file() { - local file="$1" - if [ ! -f "$file" ]; then - die "Service template not found: $file" - fi + echo "ERROR: $*" >&2 + exit 1 } # ------------------------------------------------------------ -# Spoke actions +# Spoke actions (docker) # ------------------------------------------------------------ -spoke_show_cmd() { - cat </dev/null && echo "Unmounted." || echo "Not mounted or already unmounted." + fusermount -u "$MOUNT_POINT" 2>/dev/null && echo "Unmounted." || echo "Not mounted." } # ------------------------------------------------------------ -# Main dispatch +# Dispatch # ------------------------------------------------------------ if [ $# -lt 2 ]; then - usage - exit 1 + 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 \ No newline at end of file +spoke) + case "$ACTION" in + build) spoke_build ;; + start) spoke_start ;; + stop) spoke_stop ;; + restart) spoke_restart ;; + status) spoke_status ;; + logs) spoke_logs ;; + show-cmd) spoke_show_cmd ;; + *) die "Unknown action for spoke: $ACTION" ;; + esac + ;; +hub) + case "$ACTION" in + 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 + diff --git a/spoke/Dockerfile b/spoke/Dockerfile new file mode 100644 index 0000000..f02f89c --- /dev/null +++ b/spoke/Dockerfile @@ -0,0 +1,8 @@ +FROM debian:bookworm-slim +RUN apt-get update && apt-get install -y autossh openssh-client && rm -rf /var/lib/apt/lists/* +ARG UID=1000 +ARG GID=1000 +RUN groupadd -g ${GID} armbian && useradd -m -u ${UID} -g armbian armbian +USER armbian +WORKDIR /home/armbian +CMD ["autossh", "-M", "0", "-N"] \ No newline at end of file diff --git a/aptprimary.sh b/spoke/aptprimary.sh similarity index 100% rename from aptprimary.sh rename to spoke/aptprimary.sh diff --git a/armb-not_logged_in_yet b/spoke/armb-not_logged_in_yet similarity index 100% rename from armb-not_logged_in_yet rename to spoke/armb-not_logged_in_yet diff --git a/autohostname.sh b/spoke/autohostname.sh similarity index 100% rename from autohostname.sh rename to spoke/autohostname.sh diff --git a/clean_sensitive.sh b/spoke/clean_sensitive.sh similarity index 100% rename from clean_sensitive.sh rename to spoke/clean_sensitive.sh diff --git a/spoke/compose.yaml b/spoke/compose.yaml new file mode 100644 index 0000000..70e21be --- /dev/null +++ b/spoke/compose.yaml @@ -0,0 +1,20 @@ +version: '3.8' +services: + autossh: + image: spoke-autossh + container_name: spoke-autossh + restart: always + network_mode: host + environment: + - AUTOSSH_GATETIME=0 + command: > + autossh -M 0 -NT + -o "ServerAliveInterval=60" + -o "ServerAliveCountMax=3" + -R 11111:localhost:22 + -i /home/armbian/.ssh/oilykey2026 + armbian@oily.dad + volumes: + - /home/armbian/.ssh/oilykey2026:/home/armbian/.ssh/oilykey2026:ro + - /home/armbian/.ssh/known_hosts:/home/armbian/.ssh/known_hosts:ro + - /home/armbian/share:/home/armbian/share