Skip to content

Instantly share code, notes, and snippets.

@tcely
Created February 25, 2015 02:14
Show Gist options
  • Save tcely/bfb100780dc807451b00 to your computer and use it in GitHub Desktop.
Save tcely/bfb100780dc807451b00 to your computer and use it in GitHub Desktop.
RedHat has made it difficult to enforce which version of the OS your RPM should be installed on. This is my solution to these rather thorny problems.
# Determine the OS version across the various forks using %{dist} detail from the building machine's kernel release.
# Versions 6 & 7 started including including the architecture in the kernel **release** field. We have to deal with that stupidity too.
%define osVersion %(uname -r | awk -F '.' '{for (i=NF; i > 0; i--) if ($i !~ /^(x86_64|i[36]86)$/) { print gensub(/^[^0-9]+/, "", "", $i); exit; }}')
# I wish redhat-release provided the major number, but that only started with 7 from what I've found. Even after adding a number to the redhat-release provide, they started using 7.0, just to make things difficult.
# Add conflicts as appropriate for the various RedHat major versions.
%if 0%{?osVersion} == 5
Conflicts: upstart, systemd
%endif
%if 0%{?osVersion} == 6
Conflicts: SysVinit < 2.86-24, systemd
# upstart provides SysVinit = 2.86-24, and we don't want to conflict with that here.
%endif
%if 0%{?osVersion} == 7
Conflicts: SysVinit, upstart
%endif
# 64 bit RPMs won't install on 32 bit systems already, the block below prevents the opposite too.
%ifnarch x86_64
Conflicts: /usr/lib64
%endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment