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



我正在尝试使用自己的bash脚本Frugghi issh脚本来为Apple平台生成libssl和libssh库。我想尝试自己的 bash 脚本的原因是获取最近的库并保持更新。

我有两个bash脚本来检测最新版本的openssl和libssh2库:

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,第二个脚本获取 1.1.1n 系列的 OpenSSL 而不是 3.0.2(尽管两者相同)。我想这与定义的正则表达式有关。有人可以解决这个脚本错误吗?

在您的第一个代码段中:

  • 您正在使用(.[0-9])*过滤egrep中的1.10.0版本,哪些版本应该(.[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]?$"
  • 因此,对于较新版本,带有cut的版本"提取"失败。自发地,我选择使用sed 's/.*openssl.//i'来做同样的事情。
  • 我再次从使用head切换到tail.
  • 请注意sorting遇到了与第一个代码段相同的问题,即当这些子修订开始滚动时,例如从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

你需要Perl风格的正则表达式匹配,它执行grep-oP选项。

获取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 "(?<=-).*"

最新更新