use the version that is longest for the loop

This commit is contained in:
m0duspwnens
2024-09-03 13:00:37 -04:00
parent a920adcf7f
commit 6d7b76115f

View File

@@ -168,7 +168,7 @@ check_salt_minion_status() {
return $status return $status
} }
# compare es versions and return the highest version # Compare es versions and return the highest version
compare_es_versions() { compare_es_versions() {
# Save the original IFS # Save the original IFS
local OLD_IFS="$IFS" local OLD_IFS="$IFS"
@@ -179,9 +179,15 @@ compare_es_versions() {
# Restore the original IFS # Restore the original IFS
IFS="$OLD_IFS" IFS="$OLD_IFS"
# Determine the maximum length between the two version arrays
local max_len=${#ver1[@]}
if [[ ${#ver2[@]} -gt $max_len ]]; then
max_len=${#ver2[@]}
fi
# Compare each segment of the versions # Compare each segment of the versions
for ((i=0; i<${#ver1[@]}; i++)); do for ((i=0; i<max_len; i++)); do
# if a segment in ver1 or ver2 is missing, set it to 0 # If a segment in ver1 or ver2 is missing, set it to 0
if [[ -z ${ver1[i]} ]]; then if [[ -z ${ver1[i]} ]]; then
ver1[i]=0 ver1[i]=0
fi fi