Friday, November 19, 2021

[SOLVED] When creating an rpm package, how can I retain the permissions same as that of the source directory I have provided?

Issue

My source directory that gets packaged has different permissions for some directories and files, do I have to explicitly use %attr for each directory and file? Is there a way to just use same permissions as the source?

Relevant spec file sections: %install cp -rp $RPM_BUILD_DIR/%{name}-%{version}/opt $RPM_BUILD_ROOT cp -rp $RPM_BUILD_DIR/%{name}-%{version}/var $RPM_BUILD_ROOT

and the %file section is: %files /opt /var

EDIT: SOLUTION (thanks to Chris Maes) use %defattr(-,-,-)


Solution

in that case, just use a dash (-):

%files
%defattr(-, user, group)
/path/to/files

from the documentation:

If a particular attribute does not need to be specified (usually because the file is installed with that attribute set properly), then that attribute may be replaced with a dash.



Answered By - Chris Maes