feat: Enhance disk selection with default pre-selection and input validation, and add a mock loop device.
This commit is contained in:
parent
747085e5fd
commit
c9b8743d18
2 changed files with 15 additions and 3 deletions
|
|
@ -16,6 +16,7 @@ echo "Using mock directory: $MOCK_DIR"
|
||||||
cat > "$MOCK_BIN/lsblk" <<'EOF'
|
cat > "$MOCK_BIN/lsblk" <<'EOF'
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
if [[ "$*" == *"-p -dno NAME,SIZE,MODEL"* ]]; then
|
if [[ "$*" == *"-p -dno NAME,SIZE,MODEL"* ]]; then
|
||||||
|
echo "/dev/loop0 1G Mock_Loop"
|
||||||
echo "/dev/vda 100G Mock_Disk"
|
echo "/dev/vda 100G Mock_Disk"
|
||||||
echo "/dev/vdb 50G Mock_Secondary"
|
echo "/dev/vdb 50G Mock_Secondary"
|
||||||
elif [[ "$*" == *"-p -nlo NAME,SIZE,TYPE /dev/vda"* ]]; then
|
elif [[ "$*" == *"-p -nlo NAME,SIZE,TYPE /dev/vda"* ]]; then
|
||||||
|
|
|
||||||
17
z.sh
17
z.sh
|
|
@ -3,6 +3,7 @@
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Configuration variables (will be populated via user selection or defaults if user press enter for each input)
|
# 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"
|
seed_device="/dev/vda1"
|
||||||
sprout_device="/dev/vda2"
|
sprout_device="/dev/vda2"
|
||||||
efi_device="/dev/vda3"
|
efi_device="/dev/vda3"
|
||||||
|
|
@ -20,9 +21,19 @@ for i in "${!disks[@]}"; do
|
||||||
done
|
done
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
read -r -p "Select a disk to choose partitions from (default 1): " REPLY
|
def_idx=1
|
||||||
REPLY=${REPLY:-1}
|
if [[ -n "$selected_disk" ]]; then
|
||||||
if [[ "$REPLY" -gt 0 && "$REPLY" -le "${#disks[@]}" ]]; 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))]}"
|
disk_info="${disks[$((REPLY-1))]}"
|
||||||
selected_disk=$(echo "$disk_info" | awk '{print $1}')
|
selected_disk=$(echo "$disk_info" | awk '{print $1}')
|
||||||
break
|
break
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue