forked from finn/tinyboard
fix KEY_PATH init, compose.yaml sed, registry write, known_hosts dedup, fusermount3 compat
This commit is contained in:
@@ -32,7 +32,16 @@ if [ "$(id -u)" -eq 0 ]; then
|
|||||||
die "Run as the hub user, not root."
|
die "Run as the hub user, not root."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
check_deps rclone crontab fusermount python3
|
check_deps rclone crontab python3
|
||||||
|
|
||||||
|
FUSERMOUNT=""
|
||||||
|
if command -v fusermount3 >/dev/null 2>&1; then
|
||||||
|
FUSERMOUNT="fusermount3"
|
||||||
|
elif command -v fusermount >/dev/null 2>&1; then
|
||||||
|
FUSERMOUNT="fusermount"
|
||||||
|
else
|
||||||
|
die "Neither fusermount nor fusermount3 found"
|
||||||
|
fi
|
||||||
|
|
||||||
header "TinyBoard Hub — Offboard Spoke"
|
header "TinyBoard Hub — Offboard Spoke"
|
||||||
|
|
||||||
@@ -64,7 +73,7 @@ read -rp "Are you sure you want to offboard $SPOKE_NAME? [y/N]: " CONFIRM
|
|||||||
|
|
||||||
header "Unmounting Spoke"
|
header "Unmounting Spoke"
|
||||||
if mountpoint -q "$MOUNT_POINT" 2>/dev/null; then
|
if mountpoint -q "$MOUNT_POINT" 2>/dev/null; then
|
||||||
if fusermount -u "$MOUNT_POINT" 2>/dev/null; then
|
if $FUSERMOUNT -u "$MOUNT_POINT" 2>/dev/null; then
|
||||||
info "Unmounted $MOUNT_POINT."
|
info "Unmounted $MOUNT_POINT."
|
||||||
else
|
else
|
||||||
warn "Could not unmount $MOUNT_POINT — may already be unmounted."
|
warn "Could not unmount $MOUNT_POINT — may already be unmounted."
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ set -euo pipefail
|
|||||||
|
|
||||||
RCLONE_CONF="${HOME}/.config/rclone/rclone.conf"
|
RCLONE_CONF="${HOME}/.config/rclone/rclone.conf"
|
||||||
SSH_DIR="${HOME}/.ssh"
|
SSH_DIR="${HOME}/.ssh"
|
||||||
|
REGISTRY="${HOME}/.config/tinyboard/spokes"
|
||||||
|
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
@@ -76,7 +77,10 @@ header "Checking Tunnel"
|
|||||||
info "Scanning spoke host key..."
|
info "Scanning spoke host key..."
|
||||||
KEYSCAN=$(ssh-keyscan -p "$TUNNEL_PORT" -H localhost 2>/dev/null)
|
KEYSCAN=$(ssh-keyscan -p "$TUNNEL_PORT" -H localhost 2>/dev/null)
|
||||||
[ -n "$KEYSCAN" ] || die "Spoke not reachable on port $TUNNEL_PORT — is the tunnel up?"
|
[ -n "$KEYSCAN" ] || die "Spoke not reachable on port $TUNNEL_PORT — is the tunnel up?"
|
||||||
|
KEYSCAN_KEY=$(echo "$KEYSCAN" | awk '{print $3}')
|
||||||
|
if ! grep -qF "$KEYSCAN_KEY" "$SSH_DIR/known_hosts" 2>/dev/null; then
|
||||||
echo "$KEYSCAN" >> "$SSH_DIR/known_hosts"
|
echo "$KEYSCAN" >> "$SSH_DIR/known_hosts"
|
||||||
|
fi
|
||||||
|
|
||||||
info "Verifying spoke is reachable on port $TUNNEL_PORT..."
|
info "Verifying spoke is reachable on port $TUNNEL_PORT..."
|
||||||
retry_or_abort \
|
retry_or_abort \
|
||||||
@@ -128,6 +132,17 @@ else
|
|||||||
warn "rclone test failed. Check the remote config in $RCLONE_CONF."
|
warn "rclone test failed. Check the remote config in $RCLONE_CONF."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
header "Registering Spoke"
|
||||||
|
mkdir -p "$(dirname "$REGISTRY")"
|
||||||
|
MOUNT_POINT="${HOME}/mnt/${SPOKE_NAME}"
|
||||||
|
mkdir -p "$MOUNT_POINT"
|
||||||
|
if grep -q "^${SPOKE_NAME} " "$REGISTRY" 2>/dev/null; then
|
||||||
|
warn "$SPOKE_NAME already in registry, updating."
|
||||||
|
(grep -v "^${SPOKE_NAME} " "$REGISTRY" || true) > "${REGISTRY}.tmp" && mv "${REGISTRY}.tmp" "$REGISTRY"
|
||||||
|
fi
|
||||||
|
echo "${SPOKE_NAME} ${TUNNEL_PORT} ${KEY_PATH} ${MOUNT_POINT}" >> "$REGISTRY"
|
||||||
|
info "$SPOKE_NAME registered."
|
||||||
|
|
||||||
header "Onboarding Complete"
|
header "Onboarding Complete"
|
||||||
echo -e " Spoke: ${GREEN}$SPOKE_NAME${NC}"
|
echo -e " Spoke: ${GREEN}$SPOKE_NAME${NC}"
|
||||||
echo -e " Port: ${GREEN}$TUNNEL_PORT${NC}"
|
echo -e " Port: ${GREEN}$TUNNEL_PORT${NC}"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ set -euo pipefail
|
|||||||
HUB_HOST=""
|
HUB_HOST=""
|
||||||
HUB_USER=""
|
HUB_USER=""
|
||||||
SPOKE_USER=""
|
SPOKE_USER=""
|
||||||
|
KEY_PATH=""
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
SPOKE_DIR="$SCRIPT_DIR"
|
SPOKE_DIR="$SCRIPT_DIR"
|
||||||
COMPOSE="$SPOKE_DIR/compose.yaml"
|
COMPOSE="$SPOKE_DIR/compose.yaml"
|
||||||
@@ -303,7 +304,8 @@ info "Setting port to $TUNNEL_PORT and key to $KEY_NAME..."
|
|||||||
|
|
||||||
sed -i "s|-R [0-9]*:localhost:22|-R ${TUNNEL_PORT}:localhost:22|g" "$COMPOSE"
|
sed -i "s|-R [0-9]*:localhost:22|-R ${TUNNEL_PORT}:localhost:22|g" "$COMPOSE"
|
||||||
sed -i "s|-i /home/[^ ]*/\.ssh/[^ ]*|-i ${SSH_DIR}/${KEY_NAME}|g" "$COMPOSE"
|
sed -i "s|-i /home/[^ ]*/\.ssh/[^ ]*|-i ${SSH_DIR}/${KEY_NAME}|g" "$COMPOSE"
|
||||||
sed -i "s|/home/[^/]*/\.ssh/[^:]*:/home/[^/]*/\.ssh/[^:]*|${SSH_DIR}/${KEY_NAME}:${SSH_DIR}/${KEY_NAME}|g" "$COMPOSE"
|
sed -i "s|/home/[^/]*/\.ssh/[^:]*:${SSH_DIR}/[^:]*|${SSH_DIR}/${KEY_NAME}:${SSH_DIR}/${KEY_NAME}|g" "$COMPOSE"
|
||||||
|
sed -i "s|/home/[^/]*/\.ssh/known_hosts|${SSH_DIR}/known_hosts|g" "$COMPOSE"
|
||||||
sed -i "s|container_name: spoke-autossh|container_name: ${SPOKE_NAME}-autossh|g" "$COMPOSE"
|
sed -i "s|container_name: spoke-autossh|container_name: ${SPOKE_NAME}-autossh|g" "$COMPOSE"
|
||||||
sed -i "s|container_name: spoke-syncthing|container_name: ${SPOKE_NAME}-syncthing|g" "$COMPOSE"
|
sed -i "s|container_name: spoke-syncthing|container_name: ${SPOKE_NAME}-syncthing|g" "$COMPOSE"
|
||||||
sed -i "s|hostname: spoke-syncthing|hostname: ${SPOKE_NAME}-syncthing|g" "$COMPOSE"
|
sed -i "s|hostname: spoke-syncthing|hostname: ${SPOKE_NAME}-syncthing|g" "$COMPOSE"
|
||||||
@@ -325,7 +327,7 @@ docker compose up -d
|
|||||||
info "Waiting for tunnel to establish..."
|
info "Waiting for tunnel to establish..."
|
||||||
sleep 6
|
sleep 6
|
||||||
|
|
||||||
LOGS=$(docker logs "${SPOKE_NAME}-autossh" 2>&1 || docker logs spoke-autossh 2>&1 || true)
|
LOGS=$(docker logs "${SPOKE_NAME}-autossh" 2>&1 || true)
|
||||||
if echo "$LOGS" | grep -q "remote port forwarding failed"; then
|
if echo "$LOGS" | grep -q "remote port forwarding failed"; then
|
||||||
warn "Tunnel failed — port $TUNNEL_PORT may have been taken between check and connect."
|
warn "Tunnel failed — port $TUNNEL_PORT may have been taken between check and connect."
|
||||||
warn "Try running: docker compose down && docker compose up -d"
|
warn "Try running: docker compose down && docker compose up -d"
|
||||||
|
|||||||
Reference in New Issue
Block a user