diff --git a/.codex b/.codex new file mode 100644 index 0000000..e69de29 diff --git a/part1.sh b/part1.sh index 8efa32e..ea2bb0a 100644 --- a/part1.sh +++ b/part1.sh @@ -20,6 +20,8 @@ command_exists() { command -v "$1" >/dev/null 2>&1 } +AUTO_INSTALL_DEPS=0 + find_ssh_key_in_dir() { local ssh_dir="$1" local key_file="" @@ -46,7 +48,6 @@ wait_for_ssh_key() { local preferred_path="$1" local ssh_dir="$HOME_DIR/.ssh" local detected_key="" - local reply="" mkdir -p "$ssh_dir" chmod 700 "$ssh_dir" @@ -64,22 +65,8 @@ wait_for_ssh_key() { info "Waiting for an SSH key to appear in $ssh_dir" printf 'Create the key in another terminal, then press Enter here to continue.\n' printf 'Expected path: %s (with matching .pub file)\n' "$preferred_path" - - while true; do - read -r -p "Press Enter once you have generated the SSH key... " reply - - if [[ -f "$preferred_path" && -f "$preferred_path.pub" ]]; then - printf '%s' "$preferred_path" - return 0 - fi - - if detected_key="$(find_ssh_key_in_dir "$ssh_dir")"; then - printf '%s' "$detected_key" - return 0 - fi - - warn "No key was found. Please press Enter when you have created the key." - done + read -r -p "Press Enter once you have generated the SSH key... " + printf '%s' "$preferred_path" } prompt_yes_no() { @@ -107,6 +94,18 @@ prompt_yes_no() { done } +prompt_dependency_yes_no() { + local prompt="$1" + local default="${2:-Y}" + + if [[ "$AUTO_INSTALL_DEPS" -eq 1 ]]; then + printf '%s\n' "$prompt [auto-yes]" + return 0 + fi + + prompt_yes_no "$prompt" "$default" +} + prompt_value() { local prompt="$1" local default="${2:-}" @@ -264,7 +263,11 @@ cd "$HOME_DIR" info "Interactive Arch post-install" -if prompt_yes_no "Update the system first?" "Y"; then +if prompt_yes_no "Auto-install dependency packages and tooling without per-item prompts?" "N"; then + AUTO_INSTALL_DEPS=1 +fi + +if prompt_dependency_yes_no "Update the system first?" "Y"; then info "Updating system" sudo pacman -Syu --noconfirm fi @@ -307,21 +310,21 @@ declare -a PACMAN_PACKAGES=( info "Package selection" for package in "${PACMAN_PACKAGES[@]}"; do - if prompt_yes_no "Install package '$package'?" "Y"; then + if prompt_dependency_yes_no "Install package '$package'?" "Y"; then install_pacman_package "$package" fi done -if prompt_yes_no "Install AUR helper 'yay'?" "Y"; then +if prompt_dependency_yes_no "Install AUR helper 'yay'?" "Y"; then install_yay fi -if command_exists yay && prompt_yes_no "Install AUR package 'zen-browser-bin'?" "Y"; then +if command_exists yay && prompt_dependency_yes_no "Install AUR package 'zen-browser-bin'?" "Y"; then info "Installing zen-browser-bin" yay -S --needed --noconfirm zen-browser-bin fi -if prompt_yes_no "Install ble.sh?" "Y"; then +if prompt_dependency_yes_no "Install ble.sh?" "Y"; then if [[ ! -f "$HOME_DIR/.local/share/blesh/ble.sh" ]]; then info "Installing ble.sh" git clone --recursive --depth 1 --shallow-submodules https://github.com/akinomyoga/ble.sh.git "$TMP_DIR/ble.sh" @@ -335,7 +338,7 @@ if prompt_yes_no "Install ble.sh?" "Y"; then append_if_missing '[ -f "$HOME/.config/blerc" ] && source "$HOME/.config/blerc"' "$HOME_DIR/.blerc" fi -if prompt_yes_no "Enable starship in ~/.bashrc?" "Y"; then +if prompt_dependency_yes_no "Enable starship in ~/.bashrc?" "Y"; then info "Configuring shell" append_if_missing 'eval "$(starship init bash)"' "$BASHRC" fi @@ -354,8 +357,17 @@ if prompt_yes_no "Wait for an existing SSH key for git access?" "Y"; then ssh_key_path="$(prompt_required_value "SSH key path:" "$HOME_DIR/.ssh/id_ed25519")" ssh_key_path="$(wait_for_ssh_key "$ssh_key_path")" - chmod 600 "$ssh_key_path" - chmod 644 "$ssh_key_path.pub" + if [[ -f "$ssh_key_path" ]]; then + chmod 600 "$ssh_key_path" + else + warn "Private key '$ssh_key_path' was not found; continuing without changing permissions" + fi + + if [[ -f "$ssh_key_path.pub" ]]; then + chmod 644 "$ssh_key_path.pub" + else + warn "Public key '$ssh_key_path.pub' was not found; clipboard copy will be skipped" + fi if prompt_yes_no "Add a git host to ~/.ssh/known_hosts?" "Y"; then git_host="$(prompt_required_value "Git host (for ssh-keyscan):")" @@ -363,7 +375,9 @@ if prompt_yes_no "Wait for an existing SSH key for git access?" "Y"; then fi if prompt_yes_no "Copy the public SSH key to the clipboard?" "Y"; then - if command_exists wl-copy; then + if [[ ! -f "$ssh_key_path.pub" ]]; then + warn "Public key '$ssh_key_path.pub' is not available yet" + elif command_exists wl-copy; then wl-copy <"$ssh_key_path.pub" info "Your public SSH key has been copied to the clipboard" else @@ -395,7 +409,7 @@ if prompt_yes_no "Remap ThinkPad Alt to Super with keyd?" "Y"; then fi fi -if prompt_yes_no "Set up uv with Python 3.14 and global tools?" "Y"; then +if prompt_dependency_yes_no "Set up uv with Python 3.14 and global tools?" "Y"; then if command_exists uv; then info "Configuring uv" uv python install 3.14