From a2a72e806a1682460fd036d41f8ce7412c2f3afb Mon Sep 17 00:00:00 2001 From: Pulse Monitor Date: Mon, 25 Aug 2025 13:55:17 +0000 Subject: [PATCH] fix: install script no longer crashes when comparing RC versions The version comparison function was attempting numeric comparisons on version parts containing RC suffixes (e.g., "0-rc" from "4.8.0-rc.2"), causing an "unbound variable" error due to set -u. Now properly strips and handles pre-release suffixes separately, allowing correct comparison of RC versions. Addresses discussion #344 comment from RLSinRFV --- install.sh | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 029f6a25c..a68fb91ff 100755 --- a/install.sh +++ b/install.sh @@ -636,9 +636,19 @@ compare_versions() { local v1="${1#v}" # Remove 'v' prefix local v2="${2#v}" - # Split versions into parts - IFS='.' read -ra V1_PARTS <<< "$v1" - IFS='.' read -ra V2_PARTS <<< "$v2" + # Strip any pre-release suffix (e.g., -rc.1, -beta, etc.) + local base_v1="${v1%%-*}" + local base_v2="${v2%%-*}" + local suffix_v1="${v1#*-}" + local suffix_v2="${v2#*-}" + + # If no suffix, suffix equals the full version + [[ "$suffix_v1" == "$v1" ]] && suffix_v1="" + [[ "$suffix_v2" == "$v2" ]] && suffix_v2="" + + # Split base versions into parts + IFS='.' read -ra V1_PARTS <<< "$base_v1" + IFS='.' read -ra V2_PARTS <<< "$base_v2" # Compare major.minor.patch for i in 0 1 2; do @@ -651,6 +661,21 @@ compare_versions() { fi done + # Base versions are equal, now compare suffixes + # No suffix (stable) > rc suffix + if [[ -z "$suffix_v1" ]] && [[ -n "$suffix_v2" ]]; then + return 1 # v1 (stable) > v2 (rc) + elif [[ -n "$suffix_v1" ]] && [[ -z "$suffix_v2" ]]; then + return 2 # v1 (rc) < v2 (stable) + elif [[ -n "$suffix_v1" ]] && [[ -n "$suffix_v2" ]]; then + # Both have suffixes, compare them lexicographically + if [[ "$suffix_v1" > "$suffix_v2" ]]; then + return 1 + elif [[ "$suffix_v1" < "$suffix_v2" ]]; then + return 2 + fi + fi + return 0 # versions are equal }