'Latest version of libssh2 and libssl2 using bash command?
I am trying to have my own bash script with reference to https://github.com/Frugghi/iSSH2 to generate libssl and libssh libraries for apple platforms. Reason why i want to try my own bash script is to fetch the recent libs and keep updated.
I have two bash scripts to detect the recent version of openssl and libssh2 libs:
getLibssh2Version () {
if type git >/dev/null 2>&1; then
LIBSSH_VERSION=`git ls-remote --tags https://github.com/libssh2/libssh2.git | egrep "libssh2-[0-9]+(\.[0-9])*[a-zA-Z]?$" | cut -f 2 -d - | sort -t . -r | head -n 1`
LIBSSH_AUTO=true
}
and
getOpensslVersion () {
if type git >/dev/null 2>&1; then
LIBSSL_VERSION=`git ls-remote --tags git://git.openssl.org/openssl.git | egrep "OpenSSL(_[0-9])+[a-zA-Z]?$" | cut -f 2,3,4 -d _ | sort -t _ -r | head -n 1 | tr _ .`
LIBSSL_AUTO=true
}
But the first script fetches the Libssh2 of 1.9.0 version instead of 1.10.0 and the second script fetches OpenSSL of 1.1.1n series instead of 3.0.2 . I guess it is something related to the regular expression defined . Can someone sort out this script error?
Solution 1:[1]
In your first snippet:
- You're filtering the
1.10.0version in youregrepwith(\.[0-9])*which should be(\.[0-9]+)*. - For numeric sorting on these subrevisions,
sortneeds more options:-t. -k 1,1n -k 2,2n - I've switched to not do reverse sorting but using
tailinstead ofhead, as reverse sorting somehow does not work with the other options (on my machine, at least).
Solution:
git ls-remote --tags https://github.com/libssh2/libssh2.git | \
egrep "libssh2-[0-9]+(\.[0-9]+)*[a-zA-Z]?$" | \
cut -f 2 -d - | sort -t. -k 1,1n -k 2,2n | tail -n 1
Output:
1.10.0
In the second snippet:
- Naming and punctuation changed from 1.x to 3.x versions, so they are filtered out by the
egrep. Instead ofegrep "OpenSSL(_[0-9])+[a-zA-Z]?$", I'd naively useegrep -i "OpenSSL([_.-][0-9])+[a-zA-Z]?$". - Consequently, the version "extraction" with
cutfails for the newer versions. Spontaneously, I chose to usesed 's/.*openssl.//i'to do the same. - Again I've switched from using
headtotail. - Note that the
sorting suffers from the same problem as in the first snippet, i.e. when these subrevisions start rolling over, e.g. from3.9...to3.10..., you'll need to add the same options as above.
Solution:
git ls-remote --tags git://git.openssl.org/openssl.git | \
egrep -i "OpenSSL([_.-][0-9])+[a-zA-Z]?$" | \
sed 's/.*openssl.//i' | sort -t _ | tail -n 1 | tr _ .
Output:
3.0.2
Solution 2:[2]
You need Perl style regex matching which does the -oP option of grep.
Getting the libssh2 latest version.
git ls-remote --tags https://github.com/libssh2/libssh2.git | grep -oP "libssh2-([\d.]*)" | tail -1 | grep -oP "(?<=-).*"
Getting the openssl latest version.
git ls-remote --tags git://git.openssl.org/openssl.git | grep -oP "openssl-([\d.]*)" | tail -1 | grep -oP "(?<=-).*"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Artyom Vancyan |
