I use setup.py to create all kinds of RPMs. The solution for me is a little different. I also believe that it is more reliable for two reasons:
- I can explicitly override file permissions
- I do not need to know the uid and gid of the user. Instead, I can use plain text.
here is a working example
from distutils.core import setup import distutils.command.bdist_rpm import distutils.command.install version='13' data_files = [ ('/usr/share/blah', ['README', 'test.sh']), ] permissions = [ ('/usr/share/blah', 'test.sh', '(755, sri, sri)'), ] class bdist_rpm(distutils.command.bdist_rpm.bdist_rpm): def _make_spec_file(self): spec = distutils.command.bdist_rpm.bdist_rpm._make_spec_file(self) for path, files , perm in permissions:
Let me explain what happens in more detail. RPMs are created from the SPEC file. bdist_rpm creates the SPEC file. In the SPEC file, you can select permissions and ownership of the file by providing the% attr parameter.
In the example, to make test.sh executable and owned by user 'sri', I would add %attr(755, sri, sri) to the end of the SPEC file.
Therefore, when I override the behavior of bdist_rpm._make_spec_file, all I do is add a line for each file I want to override permissions on.
The full SPEC file from this example will look like this:
%define name sri-testme %define version 13 %define unmangled_version 13 %define release 1 Summary: This is garganbe and is only used to test the permision flag behavior Name: %{name} Version: %{version} Release: %{release} Source0: %{name}-%{unmangled_version}.tar.gz License: UNKNOWN Group: Development/Libraries BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot Prefix: %{_prefix} BuildArch: noarch Vendor: Chris Gembarowski < chrisg@summationresearch.com > Url: https://www.python.org/sigs/distutils-sig/ %description UNKNOWN %prep %setup -n %{name}-%{unmangled_version} %build python setup.py build %install python setup.py install -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES %clean rm -rf $RPM_BUILD_ROOT %post
source share