From 747085e5fdf4afad4951b5a1791e0f6df7d22769 Mon Sep 17 00:00:00 2001 From: Zeev Diukman Date: Sun, 18 Jan 2026 08:47:41 +0200 Subject: [PATCH] feat: Implement default partition selections for Seed, Sprout, and EFI devices, allowing users to accept them by pressing Enter. --- test_z.sh | 6 +++--- z.sh | 30 ++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/test_z.sh b/test_z.sh index 4957383..d8b0876 100644 --- a/test_z.sh +++ b/test_z.sh @@ -81,9 +81,9 @@ echo "--- Starting z.sh in Mock Environment ---" # Run z.sh and provide sequence of inputs for test scenario 1 (Default settings) # Input sequence: # 1 (Enter) - Select Disk 1 -# 1 (Enter) - Select Seed -# 1 (Enter) - Select Sprout -# 1 (Enter) - Select EFI +# (Enter) - Select Seed (should default to /dev/vda1) +# (Enter) - Select Sprout (should default to /dev/vda2) +# (Enter) - Select EFI (should default to /dev/vda3) # yes - Confirm formatting # (Enter) - Default packages # Yes - Confirm installation diff --git a/z.sh b/z.sh index fbf8894..5565748 100755 --- a/z.sh +++ b/z.sh @@ -2,10 +2,10 @@ set -e -# Configuration variables (will be populated via user selection) -seed_device="" -sprout_device="" -efi_device="" +# Configuration variables (will be populated via user selection or defaults if user press enter for each input) +seed_device="/dev/vda1" +sprout_device="/dev/vda2" +efi_device="/dev/vda3" # 1. Select Disk echo "Available storage disks:" @@ -55,9 +55,19 @@ get_partition() { done while true; do - read -r -p "$ps3_val (default 1): " REPLY - REPLY=${REPLY:-1} - if [[ "$REPLY" -gt 0 && "$REPLY" -le "${#parts[@]}" ]]; then + local def_idx=1 + if [[ -n "$default_val" ]]; then + for i in "${!parts[@]}"; do + if [[ "${parts[i]}" == "$default_val"* ]]; then + def_idx=$((i+1)) + break + fi + done + fi + + read -r -p "$ps3_val (default $def_idx): " REPLY + REPLY=${REPLY:-$def_idx} + if [[ "$REPLY" =~ ^[0-9]+$ ]] && [[ "$REPLY" -gt 0 && "$REPLY" -le "${#parts[@]}" ]]; then selection="${parts[$((REPLY-1))]}" eval "$var_name=$(echo "$selection" | cut -d' ' -f1)" break @@ -67,9 +77,9 @@ get_partition() { done } -get_partition "--- Select Seed Partition ---" "Seed device: " seed_device -get_partition "--- Select Sprout Partition ---" "Sprout device: " sprout_device -get_partition "--- Select EFI Partition ---" "EFI device: " efi_device +get_partition "--- Select Seed Partition ---" "Seed device: " seed_device "$seed_device" +get_partition "--- Select Sprout Partition ---" "Sprout device: " sprout_device "$sprout_device" +get_partition "--- Select EFI Partition ---" "EFI device: " efi_device "$efi_device" echo "" echo "Configuration Summary:"