feat: Enhance disk selection with default pre-selection and input validation, and add a mock loop device.

This commit is contained in:
Zeev Diukman 2026-01-18 08:49:54 +02:00
parent 747085e5fd
commit c9b8743d18
2 changed files with 15 additions and 3 deletions

View file

@ -16,6 +16,7 @@ echo "Using mock directory: $MOCK_DIR"
cat > "$MOCK_BIN/lsblk" <<'EOF'
#!/bin/bash
if [[ "$*" == *"-p -dno NAME,SIZE,MODEL"* ]]; then
echo "/dev/loop0 1G Mock_Loop"
echo "/dev/vda 100G Mock_Disk"
echo "/dev/vdb 50G Mock_Secondary"
elif [[ "$*" == *"-p -nlo NAME,SIZE,TYPE /dev/vda"* ]]; then

17
z.sh
View file

@ -3,6 +3,7 @@
set -e
# Configuration variables (will be populated via user selection or defaults if user press enter for each input)
selected_disk="/dev/vda"
seed_device="/dev/vda1"
sprout_device="/dev/vda2"
efi_device="/dev/vda3"
@ -20,9 +21,19 @@ for i in "${!disks[@]}"; do
done
while true; do
read -r -p "Select a disk to choose partitions from (default 1): " REPLY
REPLY=${REPLY:-1}
if [[ "$REPLY" -gt 0 && "$REPLY" -le "${#disks[@]}" ]]; then
def_idx=1
if [[ -n "$selected_disk" ]]; then
for i in "${!disks[@]}"; do
if [[ "${disks[i]}" == "$selected_disk"* ]]; then
def_idx=$((i+1))
break
fi
done
fi
read -r -p "Select a disk to choose partitions from (default $def_idx): " REPLY
REPLY=${REPLY:-$def_idx}
if [[ "$REPLY" =~ ^[0-9]+$ ]] && [[ "$REPLY" -gt 0 && "$REPLY" -le "${#disks[@]}" ]]; then
disk_info="${disks[$((REPLY-1))]}"
selected_disk=$(echo "$disk_info" | awk '{print $1}')
break