More fixes to mirrorsetup

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

View file

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