Skip to content

Commit 01e3728

Browse files
committed
Compare version numbers properly
getssl uses cURL's version to determine what command options are valid. The previous shortcuts will fail when curl V8.10 is released. (8.9 is greater than 8.10). V8 is planned for release, in part to avoid a minor version of 100, which also would fail. check_version() will compare full or partial version strings by component, and is true if $1 is at least $2.
1 parent 2f45236 commit 01e3728

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

getssl

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@
269269
# 2021-07-30 Prefer API V2 when both offered (tlhackque) (#690) (2.40)
270270
# 2021-07-30 Run tests with -d to catch intermittent failures, Use fork's repo for upgrade tests. (tlhackque) (#692) (2.41)
271271
# 2021-08-26 Improve upgrade check & make upgrade do a full install when possible (tlhackque) (#694) (2.42)
272+
# 2021-09-02 Fix version compare - cURL v8 may have single digit minor numbers. (tlhackque) (2.43)
272273
# ----------------------------------------------------------------------------------------
273274

274275
case :$SHELLOPTS: in
@@ -277,7 +278,7 @@ esac
277278

278279
PROGNAME=${0##*/}
279280
PROGDIR="$(cd "$(dirname "$0")" || exit; pwd -P;)"
280-
VERSION="2.42"
281+
VERSION="2.43"
281282

282283
# defaults
283284
ACCOUNT_KEY_LENGTH=4096
@@ -924,6 +925,27 @@ check_getssl_upgrade() { # check if a more recent release is available
924925
graceful_exit
925926
}
926927

928+
check_version() { # true if version string $1 >= $2
929+
local v1 v2 i n1 n2 n
930+
# $1 and $2 can be different lengths, but all parts must be numeric
931+
if [[ "$1" == "$2" ]] ; then return 0; fi
932+
local IFS='.'
933+
# shellcheck disable=SC2206
934+
v1=($1)
935+
# shellcheck disable=SC2206
936+
v2=($2)
937+
n1="${#v1[@]}"
938+
n2="${#v2[@]}"
939+
if [[ "$n1" -ge "$n2" ]] ; then n="$n1" ; else n="$n2" ; fi
940+
for ((i=0; i<n; i++)) do
941+
n1="${v1[$i]:-0}"
942+
n2="${v2[$i]:-0}"
943+
if [[ $((10#$n1)) -gt $((10#$n2)) ]] ; then return 0 ; fi
944+
if [[ $((10#$n1)) -lt $((10#$n2)) ]] ; then return 1 ; fi
945+
done
946+
return 0
947+
}
948+
927949
clean_up() { # Perform pre-exit housekeeping
928950
umask "$ORIG_UMASK"
929951
if [[ $VALIDATE_VIA_DNS == "true" ]]; then
@@ -2346,8 +2368,7 @@ send_signed_request() { # Sends a request to the ACME server, signed with your p
23462368
dp="$TEMP_DIR/curl.dump"
23472369

23482370
CURL="curl ${_NOMETER} "
2349-
# shellcheck disable=SC2072
2350-
if [[ ! "${_CURL_VERSION}" < "7.33" ]]; then
2371+
if check_version "${_CURL_VERSION}" "7.33" ; then
23512372
CURL="$CURL --http1.1 "
23522373
fi
23532374

@@ -2846,8 +2867,7 @@ requires mktemp
28462867
# This would help with debugging transfer errors.
28472868

28482869
_CURL_VERSION="$(curl -V | head -1 | cut -d' ' -f2 )"
2849-
# shellcheck disable=SC2072
2850-
if [[ ! "${_CURL_VERSION}" < "7.67" ]]; then
2870+
if check_version "${_CURL_VERSION}" "7.67" ; then
28512871
_NOMETER="--no-progress-meter"
28522872
fi
28532873

0 commit comments

Comments
 (0)