openssl-apple/scripts/get-openssl-version.sh
Davide De Rosa 31c401bdf5
Mix OpenSSL patch and script version (#60)
SwiftPM only allows major.minor.patch version syntax, but we
need to avoid collisions.

E.g. OpenSSL 3.2.5 and script version 34 (0-99)

normalized_patch = (patch + 1) * 100 + script

-> 3.2.634

The +1 is necessary because e.g. 3.2.0 with script 34 would
translate to 3.2.34, which collides with OpenSSL versioning.

In this scheme, the repo tag will be of the form:

- .1xx (for 3.2.0)
- .2xx (for 3.2.1)
- ...

which is reversible to infer the OpenSSL patch.

E.g. 3.2.434

- Patch is 434
- OpenSSL patch is 434 / 100 - 1 = 3
- Script version is 434 % 100 = 34 (precondition is 0-99)

So 3.2.434 is OpenSSL 3.2.3 with script version 34
2023-12-16 13:56:52 +01:00

20 lines
751 B
Bash
Executable File

#!/bin/bash
function get_openssl_version() {
local std_version=$1
local script_version=${2:-}
script_version="$(printf '%02d' $script_version)"
if [[ ! "$std_version" =~ 3.*.* ]]; then
local generic_version=${std_version%?}
local subpatch=${std_version: -1}
local subpatch_number=$(($(printf '%d' \'$subpatch) - 97 + 1))
subpatch_number="$(printf '%02d' $subpatch_number)"
local normalized_version="${generic_version}${subpatch_number}${script_version}"
echo $normalized_version
return
fi
local minor_version="${std_version%.*}"
local patch_version="${std_version##*.}"
local normalized_patch_version=$((($patch_version + 1) * 100 + $script_version))
echo "${minor_version}.${normalized_patch_version}"
}