Monday, March 28, 2022

[SOLVED] Install RPM package in a defined directory

Issue

I am trying to build my own RPM package with files and directories, I am trying to unpack the files and directories in the package under /usr/lib/python2.7/site-packages/

till now I am successful with RPM build but when I install it using command rpm -ivh mypackage.rpm it always unpacks all directories under rpm package in root (/) directory

Here is my spec file

Name:           mx_module
Version:        1
Release:        0
Summary:        An test script to see RPM working

BuildArch:      noarch
License:        GPL
Source0:        mx_module-1.0.tar.gz

%description
I am suppose to write some description here but I don't want to :(.

%prep
%setup -q
%build
%install
mkdir -p %{buildroot}/config/
cp -a config/ %{buildroot}/config/
cp -a ott_cms/ %{buildroot}/
cp -a truss_crud/ %{buildroot}/

%files
/config
/ott_cms
/truss_crud

%changelog
* Thu May 23 2019 Abhishek  1.0.0
  - Initial rpm release

I expect the installation of the package should be inside /usr/lib/python2.7/site-packages/ and not root(/) directory


Solution

you decide upon the final location inside your spec file, not during installation. You should change your spec file like this:

%install
mkdir -p %{buildroot}/usr/lib/python2.7/site-packages/config/
cp -a config/ %{buildroot}/usr/lib/python2.7/site-packages/config/
cp -a ott_cms/ %{buildroot}/usr/lib/python2.7/site-packages/
cp -a truss_crud/ %{buildroot}/usr/lib/python2.7/site-packages/

%files
/usr/lib/python2.7/site-packages/config
/usr/lib/python2.7/site-packages/ott_cms
/usr/lib/python2.7/site-packages/truss_crud

in your %install step; you create the whole tree under %buildroot; under %files you decide which files and directories really should belong to your final package.



Answered By - Chris Maes
Answer Checked By - David Marino (WPSolving Volunteer)