Search code examples
rpmrpmbuildrpm-spec

RPM Spec file unpack tar.gz into multiple locations


With the help of this manual im trying to generate my first RPM. My goal is to generate an rpm that unpacks my file project.tar.gz into multiple destination directories.

lets say I have the following sturcture in the tar.gz:

/part-one
   /file-one.py
   /file-two.py
/part-two  
   /file-one.py
   /file-two.py
   /subdirectory
       /file-one.py
       /file-two.py

I want part-one to be installed into /opt/project-one/libs/ and part-two into /opt/project-two/libs/specific-dir/

Do I need to place all files that are in the tar.gz inside the %files body item like:?

%files
/part-one/file-one.py
/part-one/file-two.py
/part-two/file-one.py
/part-two/file-two.py
/part-two/subdirectory/file-one.py
/part-two/subdirectory/file-two.py

And how do I specify the target of those files?

I understood when I use:

%prep
%setup -q

The content of the tar.gz is automatically unpacked and I do not need to add an unpack commands.


Solution

  • After %setup, you would need a %install section and then a %file section.

    %install section installs/copies the unpacked source (your tarball) into appropriate target directories (/opt/....). Here is an example

    %setup -q
    
    %build
    # empty
    
    %install
    # create target dirs
    install -p -d -m 0755 /opt/project-one/libs
    install -p -d -m 0755 /opt/project-two/libs/subdirectory
    
    # copy files
    install -m 0644 part-one/*.py /opt/project-one/libs/
    install -m 0644 part-two/*.py /opt/project-two/lib/subdirectory
    
    %files
    # This should take care of all files inside these dirs.
    /opt/project-one/
    /opt/project-two