From 49df2bdf74f8a27981269b5cdafb77c646b3982f Mon Sep 17 00:00:00 2001 From: Hector van der Aa Date: Wed, 22 Apr 2026 19:10:09 +0200 Subject: [PATCH] V0.1.3 --- part1.sh | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/part1.sh b/part1.sh index bac31c0..bf338c4 100644 --- a/part1.sh +++ b/part1.sh @@ -78,9 +78,9 @@ prompt_passphrase() { local pass2="" while true; do - read -r -s -p "Enter SSH key passphrase: " pass1 + IFS= read -r -s -p "Enter SSH key passphrase: " pass1 printf '\n' - read -r -s -p "Confirm SSH key passphrase: " pass2 + IFS= read -r -s -p "Confirm SSH key passphrase: " pass2 printf '\n' if [[ "$pass1" == "$pass2" ]]; then @@ -121,6 +121,28 @@ extract_host_from_git_url() { return 1 } +add_host_to_known_hosts() { + local host="$1" + + if [[ -z "$host" ]]; then + return 1 + fi + + if ! command_exists ssh-keyscan; then + warn "ssh-keyscan is not installed; skipping known_hosts update for $host" + return 1 + fi + + mkdir -p "$HOME_DIR/.ssh" + touch "$HOME_DIR/.ssh/known_hosts" + + if ssh-keygen -F "$host" -f "$HOME_DIR/.ssh/known_hosts" >/dev/null 2>&1; then + return 0 + fi + + ssh-keyscan -H "$host" >>"$HOME_DIR/.ssh/known_hosts" 2>/dev/null || true +} + install_pacman_package() { local package="$1" sudo pacman -S --needed --noconfirm "$package" @@ -276,10 +298,7 @@ if prompt_yes_no "Create or reuse an SSH key for git access?" "Y"; then if prompt_yes_no "Add a git host to ~/.ssh/known_hosts?" "Y"; then git_host="$(prompt_required_value "Git host (for ssh-keyscan):")" - if command_exists ssh-keyscan; then - touch "$HOME_DIR/.ssh/known_hosts" - ssh-keyscan -H "$git_host" >>"$HOME_DIR/.ssh/known_hosts" 2>/dev/null || true - fi + add_host_to_known_hosts "$git_host" fi if prompt_yes_no "Copy the public SSH key to the clipboard?" "Y"; then @@ -314,16 +333,16 @@ if prompt_yes_no "Clone a dotfiles repository into ~/.config?" "Y"; then fi if [[ -n "$dotfiles_repo" ]]; then + if dotfiles_host="$(extract_host_from_git_url "$dotfiles_repo")"; then + if prompt_yes_no "Add the dotfiles git host to ~/.ssh/known_hosts before cloning?" "Y"; then + add_host_to_known_hosts "$dotfiles_host" + fi + fi + git clone "$dotfiles_repo" "$config_target" - if prompt_yes_no "Add the dotfiles git host to ~/.ssh/known_hosts?" "Y"; then - if dotfiles_host="$(extract_host_from_git_url "$dotfiles_repo")"; then - mkdir -p "$HOME_DIR/.ssh" - touch "$HOME_DIR/.ssh/known_hosts" - ssh-keyscan -H "$dotfiles_host" >>"$HOME_DIR/.ssh/known_hosts" 2>/dev/null || true - else - warn "Could not determine a host from '$dotfiles_repo'" - fi + if ! dotfiles_host="$(extract_host_from_git_url "$dotfiles_repo")"; then + warn "Could not determine a host from '$dotfiles_repo'" fi fi fi