8 Commits

2 changed files with 40 additions and 23 deletions

View File

@@ -81,6 +81,11 @@ KEY_PATH="$SSH_DIR/$KEY_NAME"
mkdir -p "$(dirname "$RCLONE_CONF")"
header "Checking Tunnel"
info "Verifying spoke SSH service is reachable on port $TUNNEL_PORT..."
# Test TCP connectivity first
if ! timeout 5 bash -c "cat < /dev/null > /dev/tcp/localhost/$TUNNEL_PORT" 2>/dev/null; then
die "Cannot connect to port $TUNNEL_PORT on localhost — is the tunnel up?"
fi
info "Scanning spoke host key..."
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?"
@@ -91,9 +96,6 @@ while IFS= read -r KEYSCAN_LINE; do
fi
done <<<"$KEYSCAN"
info "Verifying spoke SSH service is reachable on port $TUNNEL_PORT..."
info "Note: Password authentication should be enabled on the spoke for initial key setup."
header "Generating Hub SSH Key"
if [ -f "$KEY_PATH" ]; then
warn "Key $KEY_PATH already exists, skipping generation."

View File

@@ -136,7 +136,7 @@ $PKG_INSTALL vim "$AUTOSSH_PKG" "$OPENSSH_PKG" git
info "Installing Docker..."
if ! command -v docker >/dev/null 2>&1; then
if [ "$PKG_MANAGER" = "apt" ]; then
$PKG_INSTALL docker.io docker-compose
$PKG_INSTALL docker.io docker-cli docker-compose
else
curl -fsSL https://get.docker.com | bash
fi
@@ -184,9 +184,10 @@ info "Hostname set to: $SPOKE_NAME"
header "SSH Key Setup"
echo "How would you like to handle the SSH key for the tunnel to $HUB_HOST?"
echo " 1) Generate a new key automatically"
echo " 2) Use an existing key (paste the private key)"
echo " 2) Choose an existing key from $SSH_DIR"
echo " 3) Paste a private key manually"
echo ""
read -rp "Choose [1/2]: " KEY_CHOICE
read -rp "Choose [1/2/3]: " KEY_CHOICE
case "$KEY_CHOICE" in
1)
@@ -217,6 +218,34 @@ case "$KEY_CHOICE" in
read -rp "Press ENTER once the key has been added to ${HUB_HOST}..."
;;
2)
mkdir -p "$SSH_DIR"
chown "$SPOKE_USER":"$SPOKE_USER" "$SSH_DIR"
chmod 700 "$SSH_DIR"
AVAILABLE_KEYS=()
while IFS= read -r keyfile; do
AVAILABLE_KEYS+=("$keyfile")
done < <(find "$SSH_DIR" -maxdepth 1 -type f ! -name "*.pub" ! -name "known_hosts" ! -name "authorized_keys" ! -name "config" | sort)
if [ ${#AVAILABLE_KEYS[@]} -eq 0 ]; then
die "No private keys found in $SSH_DIR."
fi
echo "Available keys:"
for i in "${!AVAILABLE_KEYS[@]}"; do
echo " $i) ${AVAILABLE_KEYS[$i]}"
done
echo ""
read -rp "Choose key [0]: " KEY_IDX
KEY_IDX="${KEY_IDX:-0}"
[[ "$KEY_IDX" =~ ^[0-9]+$ ]] && [ "$KEY_IDX" -lt "${#AVAILABLE_KEYS[@]}" ] || die "Invalid choice."
KEY_PATH="${AVAILABLE_KEYS[$KEY_IDX]}"
KEY_NAME="$(basename "$KEY_PATH")"
info "Using existing key: $KEY_PATH"
echo ""
read -rp "Press ENTER once the public key has been added to ${HUB_HOST} authorized_keys..."
;;
3)
read -rp "Enter a name for the key file [hubkey]: " KEY_NAME
KEY_NAME="${KEY_NAME:-hubkey}"
KEY_PATH="$SSH_DIR/$KEY_NAME"
@@ -308,7 +337,7 @@ find_free_port() {
echo "$port"
return 0
fi
warn "Port $port is in use, trying next..."
echo -e "${YELLOW}[!]${NC} Port $port is in use, trying next..." >&2
done
return 1
}
@@ -376,21 +405,7 @@ echo -e " Spoke name: ${GREEN}$SPOKE_NAME${NC}"
echo -e " Tunnel port: ${GREEN}$TUNNEL_PORT${NC} on $HUB_HOST"
echo -e " SSH key: ${GREEN}$KEY_PATH${NC}"
echo ""
echo -e "${YELLOW}The hub owner needs to do the following on ${HUB_HOST}:${NC}"
echo -e "${YELLOW}Next step — on the hub, run as ${HUB_USER}:${NC}"
echo ""
echo " 1. Generate a hub->spoke key:"
echo " ssh-keygen -t ed25519 -f ~/.ssh/${HUB_USER}-${SPOKE_NAME}-$(date +%Y%m)"
echo ""
echo " 2. Copy it to this spoke through the tunnel:"
echo " ssh-copy-id -i ~/.ssh/${HUB_USER}-${SPOKE_NAME}-$(date +%Y%m).pub -p $TUNNEL_PORT ${HUB_USER}@localhost"
echo ""
echo " 3. Add an rclone remote in ~/.config/rclone/rclone.conf:"
echo " [${SPOKE_NAME}-remote]"
echo " type = sftp"
echo " host = localhost"
echo " port = $TUNNEL_PORT"
echo " key_file = /home/$HUB_USER/.ssh/${HUB_USER}-${SPOKE_NAME}-$(date +%Y%m)"
echo " shell_type = unix"
echo " md5sum_command = md5sum"
echo " sha1sum_command = sha1sum"
echo " cd tinyboard && ./setup.sh # choose option 2 (onboard spoke)"
echo ""