在正则表达式中更改libssh2和libssl2的版本?

发布于 2025-01-22 11:48:13 字数 879 浏览 2 评论 0原文

我正在尝试拥有自己的bash脚本frugghi issh脚本来为苹果平台生成libssl和libssh库。我想尝试自己的bash脚本的原因是获取最近的libs并继续更新。

我有两个bash脚本来检测openssl和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
}

但是,

    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

}

第一个脚本获取了1.9.0版本的libssh2,而不是1.10.0,而第二个脚本fetches openssl openssl openssl openssl则为1.1.1n系列而不是3.0.2.2 (尽管两者都是一样的)。我想这与定义的正则表达式有关。有人可以整理此脚本错误吗?

I am trying to have my own bash script Frugghi issh script 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]?
quot; | 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]?
quot; | 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 (though both are same). I guess it is something related to the regular expression defined . Can someone sort out this script error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤蝉 2025-01-29 11:48:13

在您的第一个片段中:

  • 您正在1.10.0版本中的egrep 带有(\。[0-9])* wher应该是(\。[0-9]+)*
  • 对于这些子修复的数字排序,sort需要更多选项:-t。 -K 1,1N -K 2,2N
  • 我切换到不进行反向排序,但使用tail而不是head,因为反向排序不以某种方式使用其他选项(至少在我的机器上)。

解决方案:

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

输出:

1.10.0

在第二个片段中:

  • 命名和标点符号从1.x更改为3.x版本,因此它们被egrep滤除。而不是egrep“ openssl(_ [0-9])+[a-za-z]?$“,我都会天真地使用egrep -i” openssl([_.--- ] [0-9])+[a-za-z]?$“
  • 因此,具有剪切的“提取”版本对于新版本失败。自发地,我选择使用sed's /.* openssl .// i'做同样的事情。
  • 再次,我已经从使用head转换为tail
  • 注意 sort遇到与第一个摘要相同的问题,即当这些子修复开始滚动时,例如3.9 ... 3.10 ...,您需要添加与上面的相同选项。

解决方案:

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 _ .

输出:

3.0.2

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]?
quot; | \
     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]?
quot; | \
    sed 's/.*openssl.//i' | sort -t _ | tail -n 1 | tr _ .

Output:

3.0.2
挥剑断情 2025-01-29 11:48:13

您需要perl样式的正则匹配,该匹配是-op grep的选项。

获取libssh2最新版本。

git ls-remote --tags https://github.com/libssh2/libssh2.git | grep -oP "libssh2-([\d.]*)" | tail -1 | grep -oP "(?<=-).*"

获取openssl最新版本。

git ls-remote --tags git://git.openssl.org/openssl.git | grep -oP "openssl-([\d.]*)" | tail -1 | grep -oP "(?<=-).*"

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 "(?<=-).*"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文