1
votes

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

1
If rpms are anything like deb packages, you should reproduce the directory structure inside your rpm (so the rpm actually contains a usr directory that actually contains lib and so on). Do you have that in your package? - Federico klez Culloca
@Federico klez Culloca No, my rpm package is solely contains /config, /ott_cms and /truss_crud and I don't want to create directory structure like /usr/lib/python2.7/site-packages/ as site-packages/ directory has other sub-directories too and I just want to place these three directories under site-packages/ when rpm package is installed. - abhishek
Ok, but see here. In particular "When RPM is installed on the end user’s system, these files are extracted in the root directory, preserving the correct hierarchy." Which means that if you want the files to be placed inside /usr/lib/python2.7/site-packages when the rpm is installed, your rpm should contain a /usr/lib/python2.7/site-packages which will itself contain your /config, /ott_cms and /truss_crud directories. - Federico klez Culloca
@Federico klez Culloca, thanks for clearing things up for me, I was stuck in it since yesterday and was same going over same docs, tutorials and sites over and over again, Thanks for clearing it in just half hour - abhishek

1 Answers

0
votes

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.