Home > other >  Latest version of libssh2 and libssl2 using bash command?
Latest version of libssh2 and libssl2 using bash command?

Time:04-22

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?

CodePudding user response:

In your first snippet:

  • You're filtering the 1.10.0 version in your egrep with (\.[0-9])* which should be (\.[0-9] )*.
  • For numeric sorting on these subrevisions, sort needs more options: -t. -k 1,1n -k 2,2n
  • I've switched to not do reverse sorting but using tail instead of head, 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 of egrep "OpenSSL(_[0-9]) [a-zA-Z]?$", I'd naively use egrep -i "OpenSSL([_.-][0-9]) [a-zA-Z]?$".
  • Consequently, the version "extraction" with cut fails for the newer versions. Spontaneously, I chose to use sed 's/.*openssl.//i' to do the same.
  • Again I've switched from using head to tail.
  • Note that the sorting suffers from the same problem as in the first snippet, i.e. when these subrevisions start rolling over, e.g. from 3.9... to 3.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

CodePudding user response:

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 "(?<=-).*"
  • Related