问题
I create packages for several OS versions including RHEL7 & RHEL8 (or mostly equally CentOS7 & 8).
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".
How can I do this? More specifically how can I do this with CPack/CMake?
Bonus points if you can also given an explanation suitable for Debian versions.
Here are some ideas I have so far:
- Use dist tags somehow, see:
- https://serverfault.com/questions/283330/rpm-spec-conditional-require-based-of-distro-version
- Check
uname -r
at install time in a pre-install script Part of that answer is here:
- How to check os version in rpmbuild spec file
- https://unix.stackexchange.com/questions/9296/how-can-i-specify-os-conditional-build-requirements-in-an-rpm-spec-file
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.
- Another option would be to add a %requires on a package that only exists on RHEL7 but not RHEL8 or visa versa. That package would need to also exist on CentOS and not change in a way that would make the installation fail if it is upgraded. Does anyone know a suitable package to depend on?
For example:
>rpm -q --whatprovides /etc/redhat-release
centos-release-8.2-2.2004.0.1.el8.x86_64
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.
回答1:
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
Remember - you cannot have any user interaction in RPM installation. You could have it fail instead of warn tho; that's up to you.
来源:https://stackoverflow.com/questions/63807365/cpack-restrict-os-version-package-can-be-installed-on