Merge branch 'master' into onboard-spoke-logic

This commit is contained in:
2026-04-19 14:05:54 -07:00

View File

@@ -136,7 +136,7 @@ $PKG_INSTALL vim "$AUTOSSH_PKG" "$OPENSSH_PKG" git
info "Installing Docker..." info "Installing Docker..."
if ! command -v docker >/dev/null 2>&1; then if ! command -v docker >/dev/null 2>&1; then
if [ "$PKG_MANAGER" = "apt" ]; then if [ "$PKG_MANAGER" = "apt" ]; then
$PKG_INSTALL docker.io docker-compose $PKG_INSTALL docker.io docker-cli docker-compose
else else
curl -fsSL https://get.docker.com | bash curl -fsSL https://get.docker.com | bash
fi fi
@@ -184,9 +184,10 @@ info "Hostname set to: $SPOKE_NAME"
header "SSH Key Setup" header "SSH Key Setup"
echo "How would you like to handle the SSH key for the tunnel to $HUB_HOST?" echo "How would you like to handle the SSH key for the tunnel to $HUB_HOST?"
echo " 1) Generate a new key automatically" 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 "" echo ""
read -rp "Choose [1/2]: " KEY_CHOICE read -rp "Choose [1/2/3]: " KEY_CHOICE
case "$KEY_CHOICE" in case "$KEY_CHOICE" in
1) 1)
@@ -217,6 +218,34 @@ case "$KEY_CHOICE" in
read -rp "Press ENTER once the key has been added to ${HUB_HOST}..." read -rp "Press ENTER once the key has been added to ${HUB_HOST}..."
;; ;;
2) 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 read -rp "Enter a name for the key file [hubkey]: " KEY_NAME
KEY_NAME="${KEY_NAME:-hubkey}" KEY_NAME="${KEY_NAME:-hubkey}"
KEY_PATH="$SSH_DIR/$KEY_NAME" KEY_PATH="$SSH_DIR/$KEY_NAME"
@@ -308,7 +337,7 @@ find_free_port() {
echo "$port" echo "$port"
return 0 return 0
fi fi
warn "Port $port is in use, trying next..." echo -e "${YELLOW}[!]${NC} Port $port is in use, trying next..." >&2
done done
return 1 return 1
} }