More fixes to mirrorsetup

This commit is contained in:
myve 2026-10-04 08:23:55 +00:00
commit a4e86694f2

View file

@ -530,10 +530,10 @@ function mirrorsetup
# This is the minimal safe usage needed for bash array handling
if [[ -n "${!var_name}" ]]
then
eval "pairArray=(\"\${${var_name}[@]}\")"
eval "pairArray=(\"\${${var_name}[@]}\")"
else
# If no content, create empty array
pairArray=()
# If no content, create empty array
pairArray=()
fi
# Validate selections - check invalid drives first
@ -545,27 +545,27 @@ function mirrorsetup
local found=false
for available in "${available_drives[@]}"
do
if [[ "$drive" == "$available" ]]
if [[ "${drive}" == "${available}" ]]
then
found=true
break
fi
done
if [[ "$found" == false ]]
if [[ "${found}" == false ]]
then
say as warning "Invalid drive selected: $drive"
say as warning "Invalid drive selected: ${drive}"
valid=false
break
fi
done
# Only continue with other validations if drives are valid
if [[ "$valid" == true ]]
if [[ "${valid}" == true ]]
then
# Check for duplicates
local unique_count=$(printf '%s\n' "${pairArray[@]}" | sort | uniq | wc -l)
local total_count=${#pairArray[@]}
if [[ $unique_count -lt $total_count ]]
if [[ ${unique_count} -lt ${total_count} ]]
then
say as warning "Duplicate entries detected"
valid=false
@ -576,40 +576,40 @@ function mirrorsetup
then
say as warning 'Mirrored pairs must have at least two drives'
valid=false
fi
# Check for stray drives (only after we know drives are valid)
local remaining_after=$(( ${#available_drives[@]} - ${#pairArray[@]} ))
if [[ $remaining_after -eq 1 ]] && [[ ${#available_drives[@]} -gt ${#pairArray[@]} ]]
then
say as warning 'Remaining drive does not have a mirror pair'
valid=false
else
# Only check for stray drives if we have a valid pool (at least 2 drives)
local remaining_after=$(( ${#available_drives[@]} - ${#pairArray[@]} ))
if [[ ${remaining_after} -eq 1 ]] && [[ ${#available_drives[@]} -gt ${#pairArray[@]} ]]
then
say as warning 'Remaining drive does not have a mirror pair'
valid=false
fi
fi
fi
# Process valid pool
if [[ "$valid" == true ]]
if [[ "${valid}" == true ]]
then
# Store this mirror pool configuration
pools[$pool_count]="${pairArray[*]}"
pools[${pool_count}]="${pairArray[*]}"
((pool_count++))
# Remove selected drives from available list
local new_available=()
for drive in "${available_drives[@]}"
do
local is_selected=false
local is_selected=false
for selected in "${pairArray[@]}"
do
if [[ "$drive" == "$selected" ]]
if [[ "${drive}" == "${selected}" ]]
then
is_selected=true
break
fi
done
if [[ "$is_selected" == false ]]
if [[ "${is_selected}" == false ]]
then
new_available+=("$drive")
new_available+=("${drive}")
fi
done
available_drives=("${new_available[@]}")
@ -623,7 +623,7 @@ function mirrorsetup
unset zrootlayout
for ((i=0; i<pool_count; i++))
do
local drives="${pools[$i]}"
local drives="${pools[${i}]}"
say as success "zroot mirror $((i+1)): ${drives}"
zrootlayout+=("mirror ${drives}")
done