mirror of
https://git.myvelabs.com/lab/archlinux.git
synced 2026-10-16 09:24:03 +00:00
More fixes to mirrorsetup
This commit is contained in:
parent
59015d9d01
commit
a4e86694f2
1 changed files with 23 additions and 23 deletions
46
homelab.sh
46
homelab.sh
|
|
@ -530,10 +530,10 @@ function mirrorsetup
|
||||||
# This is the minimal safe usage needed for bash array handling
|
# This is the minimal safe usage needed for bash array handling
|
||||||
if [[ -n "${!var_name}" ]]
|
if [[ -n "${!var_name}" ]]
|
||||||
then
|
then
|
||||||
eval "pairArray=(\"\${${var_name}[@]}\")"
|
eval "pairArray=(\"\${${var_name}[@]}\")"
|
||||||
else
|
else
|
||||||
# If no content, create empty array
|
# If no content, create empty array
|
||||||
pairArray=()
|
pairArray=()
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Validate selections - check invalid drives first
|
# Validate selections - check invalid drives first
|
||||||
|
|
@ -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,40 +576,40 @@ 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
|
||||||
local new_available=()
|
local new_available=()
|
||||||
for drive in "${available_drives[@]}"
|
for drive in "${available_drives[@]}"
|
||||||
do
|
do
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue