2

Trying to create a spec file for a CentOS 6.5 system. The rpm should check release to add specific Requires: lines based on the OS version....and it doesn't work at all:

Spec file snippet:

%if 0%{?rhel} == 6
Requires: packageName
%endif
%description
Check dependencies and make OS modifications. 

%files

/etc/rpm/macros.dist:

# dist macros.

%rhel 6
%centos 6
%centos_ver 6
%dist .el6
%el6 1

According to many web pages I've been to, the code should work but I never get a message that packageName is required when installing the rpm..What am I missing here??

UPDATE...

Reinstalled my system and everything works OK now..Something must have mess up my environment on my test system...My original code now works

  • Does this seem applicable (use el6)? stackoverflow.com/questions/5135502/… – wazy Jul 22 '14 at 20:54
  • I saw that post..My RPM still doesn't add the Requires: line.. – GoinOff Jul 22 '14 at 21:13
  • Something was wrong with my original environment..After reinstalling the code in my post worked perfectly. – GoinOff Jul 23 '14 at 14:16
  • Funny how those things work. But glad you resolved your issue. – wazy Jul 23 '14 at 14:39
4

%{?rhel} will expand to 6. Therefore 0%{?rhel} will expand to 06 and it shouldn't match 6.

You probably want instead:

%if 0%{?rhel}
   Requires: packageName
%endif
%description
Check dependencies and make OS modifications. 

%files

This will expand to 0 if %{rhel} not defined and it will expand to 06 if it is defined. In spec-file-land, 0 is a false value and 06 is a true value.

Or, if you only want to match RHEL/CENTOS 6.X (instead of all RHELs/CENTOSs), use this, following the same logic as above:

%if 0%{?el6}
   Requires: packageName
%endif
%description
Check dependencies and make OS modifications. 

%files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.