Im trying to learn how to create RPMs but am a little confused by the spec file.
Im trying to package up some Python scripts, rather than binary files, and I want them to be installed in a subdirectory under /usr/local which I shall refer to as /usr/local/X
Ive put the scripts in a tarball under /home/me/X/RPM/SOURCES
but Im getting terribly confused over what to put in the %build %install and %files sections
If I set $RPM_BUILD_ROOT to /home/me/X/RPM/temp then put
%prep
%setup -q
that will unpack the tarball, yes?, but where to, /home/me/X/RPM/temp ?
how would I then tell it to move the files I want from there into /usr/local/X and set appropriate permissions on them? The examples online all assume you have a makefile with a make install target, could I simply use the cp command under the %install section? But where am I copying from and to?
My brain is tied in knots!
Many thanks
Andrew
-----Original Message----- From: CentOS [mailto:centos-bounces@centos.org] On Behalf Of Andrew W Sent: Thursday, November 23, 2017 10:39 AM To: centos@centos.org Subject: [CentOS] Creating Spec file for RPM
Im trying to learn how to create RPMs but am a little confused by the spec file.
Im trying to package up some Python scripts, rather than binary files, and I want them to be installed in a subdirectory under /usr/local which I shall refer to as /usr/local/X
Ive put the scripts in a tarball under /home/me/X/RPM/SOURCES
You are using rpm-build and not building as root, right?
but Im getting terribly confused over what to put in the %build %install and %files sections
If I set $RPM_BUILD_ROOT to /home/me/X/RPM/temp then put
%prep
%setup -q
that will unpack the tarball, yes?, but where to, /home/me/X/RPM/temp ?
how would I then tell it to move the files I want from there into /usr/local/X and set appropriate permissions on them? The examples online all assume you have a makefile with a make install target, could I simply use the cp command under the %install section? But where am I copying from and to?
I have packaged a few Python based applications and it’s a bit different. I can send you some samples that are simple, but I learned by looking at modules provided by the base platform and reading their specs.
On 23/11/2017 19:24, Joseph L. Casale wrote:
-----Original Message----- From: CentOS [mailto:centos-bounces@centos.org] On Behalf Of Andrew W Sent: Thursday, November 23, 2017 10:39 AM To: centos@centos.org Subject: [CentOS] Creating Spec file for RPM
Im trying to learn how to create RPMs but am a little confused by the spec file.
Im trying to package up some Python scripts, rather than binary files, and I want them to be installed in a subdirectory under /usr/local which I shall refer to as /usr/local/X
Ive put the scripts in a tarball under /home/me/X/RPM/SOURCES
You are using rpm-build and not building as root, right?
but Im getting terribly confused over what to put in the %build %install and %files sections
If I set $RPM_BUILD_ROOT to /home/me/X/RPM/temp then put
%prep
%setup -q
that will unpack the tarball, yes?, but where to, /home/me/X/RPM/temp ?
how would I then tell it to move the files I want from there into /usr/local/X and set appropriate permissions on them? The examples online all assume you have a makefile with a make install target, could I simply use the cp command under the %install section? But where am I copying from and to?
No special permissions. Use 'rpmbuild' tool that works in a dedicated directory in your home.
See https://wiki.centos.org/HowTos/SetupRpmBuildEnvironment
--On Thursday, November 23, 2017 5:39 PM +0000 Andrew W andrewjameswood@ymail.com wrote:
I want them to be installed in a subdirectory under /usr/local which I shall refer to as /usr/local/X
/usr/local is for stuff installed by the local admin outside the package manager. I'd recommend using /opt/X for your installation. /opt is for 3rd party stuff.
Some tutorials that might help:
https://wiki.centos.org/HowTos/SetupRpmBuildEnvironment
https://tecadmin.net/create-rpm-of-your-own-script-in-centosredhat/
On 23/11/17 18:39, Andrew W wrote:
Im trying to learn how to create RPMs but am a little confused by the spec file.
OK.
I don't see a reply that answer your questions directly, so here I go...
Im trying to package up some Python scripts, rather than binary files, and I want them to be installed in a subdirectory under /usr/local which I shall refer to as /usr/local/X
Ive put the scripts in a tarball under /home/me/X/RPM/SOURCES
Is this /home/me/RPM your rpm topdir? On my setup, sources should go in $HOME/rpmbuild/SOURCES (see below.)
but Im getting terribly confused over what to put in the %build %install and %files sections
Build is building - compiling if you are using a "compiled language".
Install should put everything on the directory where you want the final rpm to install it - but prefixed by the "build root" (i.e. your $RPM_BUILD_ROOT discussed below.)
Files is a list of files to include in the package. It should match what you install to the build root. If you list a directory, all its files are recursively included, unless you put "%dir" in front of it.
If I set $RPM_BUILD_ROOT to /home/me/X/RPM/temp then put
How so you set this up? In the environment?
Usually, you include something like BuildRoot: /home/me/X/RPM/temp in the spec file, and "rpmbuild" sets up the variable for you during build. You can also use %{buildroot}. See https://www.redhat.com/archives/rpm-list/2002-July/msg00110.html. These days you generally get a usable build root without specifying anything.
"%{...}" represents the expansion of a so-called rpm macro - it's the rpm macro equivalent to the shell's "${...}". rpmbuild defines a number of macros for you automatically and/or reads in definitions from config files; more on that below.
%prep
%setup -q
that will unpack the tarball, yes?, but where to, /home/me/X/RPM/temp ?
No. It will unpack to a directory specified by the rpm configuration. On my system (CentOS 6), the default is $HOME/rpmbuild. The configuration takes the form of an rpm macro, which is defined in /usr/lib/rpm/macros or /etc/rpm/macros. Look for _builddir and also _topdir in these files. (There may also be a user-specific location where you can configure this. I forget, as I'm generally OK with the defaults.)
You should probably replace "setup -q" with just "setup", as the unpack command will then tell you more.
how would I then tell it to move the files I want from there into /usr/local/X and set appropriate permissions on them? The examples online all assume you have a makefile with a make install target, could I simply use the cp command under the %install section?
Yes. You can put any shell command there. You should just copy the files to your install location "under the build root", i.e. for instance %{buildroot}/usr/local/X a.k.a. ${RPM_BUILD_ROOT}/usr/local/X.
There are also macros that contain various standard commands, so you can for instance write "%{__cp}" instead of "cp". This is supposed to make the spec file more portable. Have a look /usr/lib/rpm/macros*.
I wouldn't install on /usr/local, by the way (like some others who've responded.) Personally, I reckon /usr should be OK when using the "native" package manager, but some people argue that /opt is more proper. I'd use macros for this, too, anyhow. See _prefix, _bindir, _libdir etc. in the above mentioned files.
But where am I copying from and to?
You copy from the current directory, where you'll find your tarball contents - rpmbuild automatically changes to the appropriate location. For the "to" part, see above.
You should probably make sure the tarball has a toplevel directory of the form <name>-<version>, by the way. But see http://ftp.rpm.org/max-rpm/s1-rpm-specref-macros.html.
My brain is tied in knots!
Better?
- Toralf
Many thanks
Andrew
CentOS mailing list CentOS@centos.org https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.centos.org_mailma...