3

I've tried 'umask 77' in the shell, then building it with:

[non-root-user@machine SPECS]$ rpmbuild -bb SPECFILE.spec 

but I still get this from the output:

+ umask 022 
Radu Gasler
  • 896
  • 12
  • 17
aafc
  • 127
  • 2
  • 10

2 Answers2

3

You cannot change the umask from the shell because rpmbuild will always set a a fixed umask of 0022 before running %prep script.

Therefore, depending on what you're trying to achieve, you could try change the umask in the spec file, at the beginning the %prep section:

%prep
umask 077

But, if you're just trying to set the file permissions for the files in the RPM, the standard way is to use %defattr and %attr directives in the %files section:

  • %defattr sets the default attributes for files and folders:

    %defattr(<file mode>, <user>, <group>, <dir mode>)
    

some attributes may be omitted by replacing them with a dash (because the file is installed with those attributes properly set)

  • %attr sets the attributes for a single file or folder:

    %attr(<mode>, <user>, <group>) file/folder
    

As with %defattr if a particular attribute does not need to be specified, you can replace it with a dash (for example you can use it along with %defattr to keep the default value for that attribute)

A full example:

%files
# set default attributes for all files and folders:
%defattr(644, root, root, 755)
# make a file executable:
%attr(755, -, -) /usr/bin/myexec
# set a different owner for a file:
%attr(-, myuser, -) /var/log/mylog.log
# set different permissions, owner and group for a file:
%attr(600, myuser, mygroup) /home/myfile

For more details & examples you can take a look to:
http://www.rpm.org/max-rpm-snapshot/s1-rpm-specref-files-list-directives.html and
http://www.rpm.org/max-rpm/s1-rpm-anywhere-specifying-file-attributes.html

Radu Gasler
  • 896
  • 12
  • 17
0

I don't think changing the umask is what you should be doing. I assume you are unhappy with the permissions on the files coming out of the RPM. For that, you should be using %attr() and %defattr() in your %files section.

Aaron D. Marasco
  • 5,612
  • 3
  • 22
  • 34
  • Yeah, I just set all my specs to have 755. I am just trying to understand what -,root,root does and why I'd want to even bother with it. – aafc Sep 21 '12 at 17:20
  • Because you may want the files to be owned by another user. You would have the files created with the proper mask by the installer of, say, MySQL. Well, you want the files owned by the user "`mysql`" so you would use `%defattr(-,mysql,mysql)` and then only have the files that REALLY need to be root's tagged individually with `%attr()` flags. – Aaron D. Marasco Sep 22 '12 at 00:46