Discussion:
preserving file attributes from make install in rpm spec file
Bob Beers
2007-12-13 15:20:45 UTC
Permalink
I am new to rpm building and trying to do the right thing.

I want to build an rpm from a set of files which comes
with a Makefile install target that sets ownership
and permissions differently for different files.

When executing make install (as root) everything is ok,
but trying to build the rpm as non-root fails
with "cannot change ownership of `/var/tmp/...' : Operation not permitted"

The Makefile has (simplified version)
install:
$(INSTALL) -d $(DESTDIR)$(BINDIR)
#any group
$(INSTALL) -m 755 file01 $(DESTDIR)$(BINDIR)
$(INSTALL) -m 644 file02 $(DESTDIR)$(BINDIR)
#wheel group
$(INSTALL) -m 750 -g wheel file03 $(DESTDIR)$(BINDIR)
#aaa group
$(INSTALL) -m 750 -g aaa file04 $(DESTDIR)$(BINDIR)
#bbb group
$(INSTALL) -m 750 -g bbb file05 $(DESTDIR)$(BINDIR)

The spec file has:

%install
make DESTDIR=%buildroot/ install

Obviously I'm overlooking something. I am sure this is not that unusual.

BTW, and I know I should not do it, if I build the rpm as root,
the permissions are fine, but all files are root:root.

-Bob
Matthew Miller
2007-12-13 15:24:43 UTC
Permalink
Post by Bob Beers
Obviously I'm overlooking something. I am sure this is not that unusual.
BTW, and I know I should not do it, if I build the rpm as root,
the permissions are fine, but all files are root:root.
The solution is to not set the permissions (for permissions out of the
ordinary) in the Makefile but to do so in the %files section of the
specfile.
--
Matthew Miller ***@mattdm.org <http://mattdm.org/>
Boston University Linux ------> <http://linux.bu.edu/>
Jeff Johnson
2007-12-13 15:35:14 UTC
Permalink
Post by Bob Beers
I am new to rpm building and trying to do the right thing.
I want to build an rpm from a set of files which comes
with a Makefile install target that sets ownership
and permissions differently for different files.
When executing make install (as root) everything is ok,
but trying to build the rpm as non-root fails
with "cannot change ownership of `/var/tmp/...' : Operation not permitted"
The Makefile has (simplified version)
$(INSTALL) -d $(DESTDIR)$(BINDIR)
#any group
$(INSTALL) -m 755 file01 $(DESTDIR)$(BINDIR)
$(INSTALL) -m 644 file02 $(DESTDIR)$(BINDIR)
#wheel group
$(INSTALL) -m 750 -g wheel file03 $(DESTDIR)$(BINDIR)
#aaa group
$(INSTALL) -m 750 -g aaa file04 $(DESTDIR)$(BINDIR)
#bbb group
$(INSTALL) -m 750 -g bbb file05 $(DESTDIR)$(BINDIR)
%install
make DESTDIR=%buildroot/ install
Obviously I'm overlooking something. I am sure this is not that unusual.
BTW, and I know I should not do it, if I build the rpm as root,
the permissions are fine, but all files are root:root.
What you miss is %attr markers in the %files manifest.

Add explicit
%attr(mode,user,group)
(substituting the actual values for "mode", "user", "group" above)
for paths listed in the %files manifest.

There is also %defattr, and there's a certain art to expressing
%attr so that itscopes correctly across glob patterns, but rpm
packaging easily separates the actual {mode,user,group} used
during build from the same tuple used during install.

hth

73 de Jeff
Bob Beers
2007-12-13 16:03:55 UTC
Permalink
Post by Jeff Johnson
What you miss is %attr markers in the %files manifest.
Add explicit
%attr(mode,user,group)
(substituting the actual values for "mode", "user", "group" above)
for paths listed in the %files manifest.
There is also %defattr, and there's a certain art to expressing
%attr so that itscopes correctly across glob patterns, but rpm
packaging easily separates the actual {mode,user,group} used
during build from the same tuple used during install.
Thank you Jeff and Matthew for the rapid responses!

Do I understand correctlythat I can
omit the make install line in %install section
if I add appropriate %attr lines in the %file section?

Something like this?

%files
%attr(755,root,root)
/usr/local/bin/file01
%attr(644,root,root)
/usr/local/bin/file02
%attr(750,root,wheel)
/usr/local/bin/file03
%attr(750,root,aaa)
/usr/local/bin/file04
%attr(750,root,bbb)
/usr/local/bin/file05

-Bob
Jeff Johnson
2007-12-13 16:26:49 UTC
Permalink
Post by Bob Beers
Post by Jeff Johnson
What you miss is %attr markers in the %files manifest.
Add explicit
%attr(mode,user,group)
(substituting the actual values for "mode", "user", "group" above)
for paths listed in the %files manifest.
There is also %defattr, and there's a certain art to expressing
%attr so that itscopes correctly across glob patterns, but rpm
packaging easily separates the actual {mode,user,group} used
during build from the same tuple used during install.
Thank you Jeff and Matthew for the rapid responses!
Do I understand correctlythat I can
omit the make install line in %install section
if I add appropriate %attr lines in the %file section?
You can't omit "make install" (and adding the DESTDIR=%{buildroot}
is perfectly sane if that is what you are doing).

Think of %{buildroot} as a staging area for package contents. However
you populate, with cp, or install or ... any other means. But you need to
populate the %{buildroot} with the contents that you want in packages.

(Note: yes I'm perfectly aware that one can package w/o BuildRoot:, but
let's not go there please.)
Post by Bob Beers
Something like this?
%files
%attr(755,root,root)
/usr/local/bin/file01
%attr(644,root,root)
/usr/local/bin/file02
%attr(750,root,wheel)
/usr/local/bin/file03
%attr(750,root,aaa)
/usr/local/bin/file04
%attr(750,root,bbb)
/usr/local/bin/file05
The scoping is up to next newline, so make sure the %attr is
on the same line as the path or pattern.

73 de Jeff
Bob Beers
2007-12-13 16:44:12 UTC
Permalink
Post by Jeff Johnson
The scoping is up to next newline, so make sure the %attr is
on the same line as the path or pattern.
Oh, ok, great!

I've got it correct now!

Thanks very much to Matthew Miller and Jeff Johnson for the rapid,
expert advice!

-Bob

Matthew Miller
2007-12-13 16:27:50 UTC
Permalink
Post by Bob Beers
Do I understand correctlythat I can
omit the make install line in %install section
if I add appropriate %attr lines in the %file section?
You can't completely omit installing the files into the buildroot -- you'll
still need to get them there somehow.
--
Matthew Miller ***@mattdm.org <http://mattdm.org/>
Boston University Linux ------> <http://linux.bu.edu/>
Bob Beers
2007-12-13 16:40:42 UTC
Permalink
Post by Matthew Miller
Post by Bob Beers
Do I understand correctlythat I can
omit the make install line in %install section
if I add appropriate %attr lines in the %file section?
You can't completely omit installing the files into the buildroot -- you'll
still need to get them there somehow.
ok, got it. I made a new target in the Make file: plaininstall, which
does not try to change ownership. I also changed .spec to
%install
make DESTDIR=/ plaininstall
Post by Matthew Miller
--
Boston University Linux ------> <http://linux.bu.edu/>
_______________________________________________
Rpm-list mailing list
https://www.redhat.com/mailman/listinfo/rpm-list
Loading...