11

If I have this line in the %files:

%attr(0555, myuser, myuser) /opt/myapp/lib/my.jar

Then my.jar will have myuser as owner, but directory /opt/myapp/lib will be owner by root. I don't want to write

%attr(0555, myuser, myuser) /opt/myapp/lib/

as I don't want all files in /opt/myapp/lib/ to be included.

How can I set owner for /opt/myapp/lib/ directory?

Thanks.

Eran Ben-Natan
  • 2,515
  • 2
  • 16
  • 19

2 Answers2

21

I'm not an RPM expert.. but as far as I know, you could use the %dir directive as follows:

%files
%dir %attr(0555, myuser, myuser) /opt/myapp/lib
%attr(0555, myuser, myuser) /opt/myapp/lib/my.jar

or, even simpler:

%files
%defattr(555,myuser,myuser,555)
%dir /opt/myapp/lib
/opt/myapp/lib/my.jar

The %dir directive allows you to add the directory, but not its content.

Javaguru
  • 890
  • 5
  • 10
  • 1
    The purpose of %dir is to create an empty dir (like logs dir) on the target machine. – Eran Ben-Natan Apr 03 '12 at 12:33
  • 4
    No, this is not true. ( See documentation: http://www.rpm.org/max-rpm-snapshot/s1-rpm-specref-files-list-directives.html ): The %dir directive is used to direct RPM to package only the directory itself, regardless of what files may reside in the directory at the time the package is created. – Javaguru Apr 03 '12 at 12:46
  • @Javaguru The link gives a 404 – sebix May 30 '17 at 12:35
  • 1
    @sebix: Documentation: http://ftp.rpm.org/max-rpm/s1-rpm-inside-files-list-directives.html#S3-RPM-INSIDE-DIR-DIRECTIVE – Javaguru Jul 27 '17 at 22:35
  • @Javaguru Thanks! – sebix Jul 29 '17 at 07:34
4

as the other "super-helpful" people say...%dir is for something else. The solution is to use %attr to set the user and group owner of your directory...since I've already set my directories to 755 using %defattr I use a single dash - in the %attr line to say..leave this the way it is.

%files
#%attr(<mode>, <user>, <group>) file
#%defattr(file perms, user, group, dir perms)
%defattr(644,apache,apache,755)
%attr(-,apache,apache) /var/www/coolapp
%attr(-,apache,apache) /var/www/coolapp/users
%attr(-,apache,apache) /var/www/coolapp/static
/var/www/coolapp/myDB.sqlite
/var/www/coolapp/__init__.py
/var/www/coolapp/settings.py
/var/www/coolapp/urls.py
/var/www/coolapp/wsgi.py
Chad Prey
  • 147
  • 2
  • 4