Search code examples
rpmrpmbuildrpm-spec

%attr in rpm.spec does not take env variable's value


I have a rpm.spec file in which i have to give file permissions for a file.

I want %attr to take $user and $group values during the rpm installation.(where i will be doing "export user=" and "export group=") but it does not take these values,instead gives a syntax error while installing the rpm.

I have something like this in my specfile

%pre

%files
%defattr(-,root,root,-)
<some_path>
%config /etc/akshatha
%doc /usr/share/doc/akshatha
%attr(0700,$user,$group) %dir directory_path
%attr(0700,$user,$group) %dir directory_path
%attr(0600,$user,$group) path_to_file 

this gives me an error, while installing the rpm as -

warning: user $user does not exist - using root
warning: group $group does not exist - using root

I have even tried giving %attr(0700,%{getenv:user},%{getenv:group}) but this fails while preparing the rpm itself saying

RPM build errors:
Bad syntax: %attr(0700)
make: *** [all] Error 1

Solution

  • This is not possible. %attr is fixed at build time; you specifically asked for "during the rpm installation" which won't work.

    In your %post you can chown but then that will break your verification.