可以在以下位置安装cpackstrict OS版本软件包 [英] cpack restrict OS version package can be installed on
问题描述
我为多个操作系统版本(包括RHEL7& amp;RHEL8(或大致相同的CentOS7& 8).
I create packages for several OS versions including RHEL7 & RHEL8 (or mostly equally CentOS7 & 8).
可以安装为.el7构建的软件包.在.el8上.但它通常不起作用(例如由于未定义的符号等).理想情况下,我想使安装失败,并显示一条错误消息,例如此软件包仅用于RHEL7/CentOS7".
It is possible to install a package built for .el7. on .el8. but it will typically not work (for example due to undefined symbols etc). Ideally I would like to make the installation fail with an error message like "this package is only intend for RHEL7/CentOS7".
我该怎么做?更具体地说,如何使用CPack/CMake做到这一点?
How can I do this? More specifically how can I do this with CPack/CMake?
如果您还可以提供适用于Debian版本的说明,请加分.
Bonus points if you can also given an explanation suitable for Debian versions.
到目前为止,我有一些想法:
Here are some ideas I have so far:
- 以某种方式使用 dist标签,请参见:
- https://serverfault.com/questions/283330/rpm-spec-conditionalrequire-based-distro-version
- 在预安装脚本中检查
uname -r
答案的一部分在这里: - Check
uname -r
at install time in a pre-install script Part of that answer is here: - 如何在rpmbuild规范文件中检查操作系统版本
- https://unix.stackexchange.com/questions/9296/how-can-i-specify-os-conditional-build-requirements-in-an-rpm-spec-file
- 另一种选择是在仅存在于RHEL7而不存在于RHEL8的软件包上添加%requires,反之亦然.该软件包还需要在CentOS上存在,并且不要以某种方式更改,如果升级则会使安装失败.有人知道合适的包装要依靠吗?
- 在安装时
我不太确定如何使用cpack做到这一点.我不想生成自定义规格文件,因为构建机制已经足够复杂.
I'm not quite sure how to do that using cpack. I do not want to generate a custom spec file as the build machinery is already complex enough.
例如:
>rpm -q --whatprovides /etc/redhat-release
centos-release-8.2-2.2004.0.1.el8.x86_64
这看起来像是一个不错的选择,但是如果我添加对centos-release-8.2的依赖,然后他们后来升级到centos-release-8.3或使用RedHat,则将无法使用.
This looks like a good candidate but if I add a dependency on centos-release-8.2 and they later upgrade to centos-release-8.3 or use RedHat instead this will not work.
推荐答案
I did this before by having a stanza in %pre
that stopped it:
if [ -n "%{dist}" ]; then
PKG_VER=`echo %{dist} | perl -ne '/el(\d)/ && print $1'`
THIS_VER=`perl -ne '/release (\d)/ && print $1' /etc/redhat-release`
if [ -n "${PKG_VER}" -a -n "${THIS_VER}" ]; then
if [ ${PKG_VER} -ne ${THIS_VER} ]; then
for i in `seq 20`; do echo ""; done
echo "WARNING: This RPM is for CentOS${PKG_VER}, but you seem to be running CentOS${THIS_VER}" >&2
echo "You might want to uninstall these RPMs immediately and get the CentOS${THIS_VER} version." >&2
for i in `seq 5`; do echo "" >&2; done
fi
fi
fi
记住-您 在RPM安装中没有任何用户交互.您可以让它失败而不是警告您.这取决于你.
Remember - you cannot have any user interaction in RPM installation. You could have it fail instead of warn tho; that's up to you.
这篇关于可以在以下位置安装cpackstrict OS版本软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!