Search code examples
compilationrpmrpmbuildrpm-spec

Add extra file into the rpm building process


i have the source-code of an application that supports adding python plugins. i have written a python script and want to build a custom rpm that by-default includes my script. So that i do not have to additionally add it after the rpm installation.

Now as far as i understand, there are two parts to this-

  1. Adding the file to the source code.
  2. Listing that file in the .spec file.

How do i know where to put the file in the source? How do i specify the path where i want my script to be copied? The spec file contains text like-

%if %{with_python}
%files python
%{_mandir}/man5/collectd-python*
%{_libdir}/%{name}/python.so

//Something like this?

// %{_libdir}/%{name}/gearman.py 
// %{_libdir}/%{name}/redis.py
%endif

Solution

  • You need to know where to place your script file on the target installation (e.g. /usr/lib/myApp/plugins/myNiceScript.py)

    In the spec-File (section %install) you have to copy your script under %{buildroot} into the target directory (which has to be created first.

    %install
    ...
    # in case the dir does not exist:
    mkdir -p %{buildroot}/usr/lib/myApp/plugins
    
    cp whereitis/myNiceScript.py   %{buildroot}/usr/lib/myApp/plugins
    

    At the end you have to define the file flags in the %files section. E.g. if your file has to have 644 under root:

    %files
    ...
    %defattr(644,root,root)
    /usr/lib/myApp/plugins/myNiceScript.py
    

    If your plugins directory is to be created during installation you need to define these flags too:

    %defattr(755,root,root)
    %dir /usr/lib/myApp/plugins