Tutorial :What is the minimum I have to do to create an RPM file?



Question:

I just want to create an RPM file to distribute my Linux binary "foobar", with only a couple of dependencies. It has a config file, /etc/foobar.conf and should be installed in /usr/bin/foobar.

Unfortunately the documentation for RPM is 27 chapters long and I really don't have a day to sit down and read this, because I am also busy making .deb and EXE installers for other platforms.

What is the absolute minimum I have to do to create an RPM? Assume the foobar binary and foobar.conf are in the current working directory.


Solution:1

I often do binary rpm per packaging proprietary apps - also moster as websphere - on linux. So my experience could be useful also a you, besides that it would better to do a TRUE RPM if you can. But i digress.

So the a basic step for packaging your (binary) program is as follow - in which i suppose the program is toybinprog with version 1.0, have a conf to be installed in /etc/toybinprog/toybinprog.conf and have a bin to be installed in /usr/bin called tobinprog :

1. create your rpm build env for RPM < 4.6,4.7

mkdir -p ~/rpmbuild/{RPMS,SRPMS,BUILD,SOURCES,SPECS,tmp}    cat <<EOF >~/.rpmmacros  %_topdir   %(echo $HOME)/rpmbuild  %_tmppath  %{_topdir}/tmp  EOF    cd ~/rpmbuild  

2. create the tarball of your project

mkdir toybinprog-1.0  mkdir -p toybinprog-1.0/usr/bin  mkdir -p toybinprog-1.0/etc/toybinprog  install -m 755 toybinprog toybinprog-1.0/usr/bin  install -m 644 toybinprog.conf toybinprog-1.0/etc/toybinprog/    tar -zcvf toybinprog-1.0.tar.gz toybinprog-1.0/  

3. Copy to the sources dir

cp toybinprog-1.0.tar.gz SOURCES/    cat <<EOF > SPECS/toybinprog.spec  # Don't try fancy stuff like debuginfo, which is useless on binary-only  # packages. Don't strip binary too  # Be sure buildpolicy set to do nothing  %define        __spec_install_post %{nil}  %define          debug_package %{nil}  %define        __os_install_post %{_dbpath}/brp-compress    Summary: A very simple toy bin rpm package  Name: toybinprog  Version: 1.0  Release: 1  License: GPL+  Group: Development/Tools  SOURCE0 : %{name}-%{version}.tar.gz  URL: http://toybinprog.company.com/    BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root    %description  %{summary}    %prep  %setup -q    %build  # Empty section.    %install  rm -rf %{buildroot}  mkdir -p  %{buildroot}    # in builddir  cp -a * %{buildroot}      %clean  rm -rf %{buildroot}      %files  %defattr(-,root,root,-)  %config(noreplace) %{_sysconfdir}/%{name}/%{name}.conf  %{_bindir}/*    %changelog  * Thu Apr 24 2009  Elia Pinto <devzero2000@rpm5.org> 1.0-1  - First Build    EOF  

4. build the source and the binary rpm

rpmbuild -ba SPECS/toybinprog.spec  

And that's all.

Hope this help


Solution:2

As an application distributor, fpm sounds perfect for your needs. There is an example here which shows how to package an app from source. FPM can produce both deb files and RPM files.


Solution:3

Similarly, I needed to create an rpm with just a few files. Since these files were source controlled, and because it seemed silly, I didn't want to go through taring them up just to have rpm untar them. I came up with the following:

  1. Set up your environment:

    mkdir -p ~/rpm/{BUILD,RPMS}

    echo '%_topdir %(echo "$HOME")/rpm' > ~/.rpmmacros

  2. Create your spec file, foobar.spec, with the following contents:

    Summary: Foo to the Bar  Name: foobar  Version: 0.1  Release: 1  Group: Foo/Bar  License: FooBarPL  Source: %{expand:%%(pwd)}  BuildRoot: %{_topdir}/BUILD/%{name}-%{version}-%{release}    %description  %{summary}    %prep  rm -rf $RPM_BUILD_ROOT  mkdir -p $RPM_BUILD_ROOT/usr/bin  mkdir -p $RPM_BUILD_ROOT/etc  cd $RPM_BUILD_ROOT  cp %{SOURCEURL0}/foobar ./usr/bin/  cp %{SOURCEURL0}/foobar.conf ./etc/    %clean  rm -r -f "$RPM_BUILD_ROOT"    %files  %defattr(644,root,root)  %config(noreplace) %{_sysconfdir}/foobar.conf  %defattr(755,root,root)  %{_bindir}/foobar  
  3. Build your rpm: rpmbuild -bb foobar.spec

There's a little hackery there specifying the 'source' as your current directory, but it seemed far more elegant then the alternative, which was to, in my case, write a separate script to create a tarball, etc, etc.

Note: In my particular situation, my files were arranged in folders according to where they needed to go, like this:

./etc/foobar.conf  ./usr/bin/foobar  

and so the prep section became:

%prep  rm -rf $RPM_BUILD_ROOT  mkdir -p $RPM_BUILD_ROOT  cd $RPM_BUILD_ROOT  tar -cC %{SOURCEURL0} --exclude 'foobar.spec' -f - ./ | tar xf -  

Which is a little cleaner.

Also, I happen to be on a RHEL5.6 with rpm versions 4.4.2.3, so your mileage may vary.


Solution:4

For quick RPM building, check out Togo:

https://github.com/genereese/togo-rpm

The project has a Quick-Start guide and I was able to create a basic RPM in less than 3 minutes.

Example using the data provided in the original question:

1) Create the project directory using the script:

$ togo project create foobar; cd foobar  

2) Make your desired directory structure under ./root and copy your files into it:

$ mkdir -p root/etc; cp /path/to/foobar.conf root/etc/  $ mkdir -p root/usr/bin; cp /path/to/foobar root/usr/bin/  

3) Exclude system-owned directories from your RPM's ownership:

$ togo file exclude root/etc root/usr/bin  

4) (OPTIONAL) Modify the generated spec to change your package description/dependencies/version/whatever, etc.:

$ vi spec/header  

5) Build the RPM:

$ togo build package  

-and your RPM is spit out into the ./rpms directory.


Solution:5

If make config works for your program or you have a shell script which copies your two files to the appropriate place you can use checkinstall. Just go to the directory where your makefile is in and call it with the parameter -R (for RPM) and optionally with the installation script.


Solution:6

Easy way to build rpm package from binary (these steps were tested with Fedora 18):

1) First you have to install rpmdevtools, so run these commands (attention: run as normal user)

$ sudo yum install rpmdevtools rpmlint  $ rpmdev-setuptree  

2) In the ~/rpmbuild/SPECS folder create new file: package_name.spec

3) Open it with an editor (like gedit) and write this:

Name:           package_name  Version:        1.0  Release:        1  Summary:        Short description (first char has to be uppercase)    License:        GPL  URL:            www. your_website/    BuildRequires:  package_required >= (or ==, or <=) 1.0.3 (for example)    %description  Description with almost 79 characters (first char has to be uppercase)    #This is a comment (just as example)    %files  /usr/bin/binary_file.bin  /usr/share/applications/package_name.desktop  /usr/share/pixmaps/package_name.png    %changelog  * date Packager's Name <packager's_email> version-revision  - Summary of changes    #For more details see: docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/Packagers_Guide/sect-Packagers_Guide-Creating_a_Basic_Spec_File.html  

4) Make ~/rpmbuild/BUILDROOT/package_name-version-release.i386 and reproduce the paths where the files will be placed So in this case for example create:

  • ~/rpmbuild/BUILDROOT/package_name-version-release.i386/usr/bin/
  • ~/rpmbuild/BUILDROOT/package_name-version-release.i386/usr/share/applications/
  • ~/rpmbuild/BUILDROOT/package_name-version-release.i386/usr/share/pixmaps/

5) Put in these folders the files that you want insert in the package:

  • ~/rpmbuild/BUILDROOT/package_name-version-release.i386/usr/bin/binary_file.bin
  • ~/rpmbuild/BUILDROOT/package_name-version-release.i386/usr/share/applications/package_name.desktop
  • ~/rpmbuild/BUILDROOT/package_name-version-release.i386/usr/share/pixmaps/package_name.png

usr/share/pixmaps/package_name.png is the icon of binary usr/share/applications/package_name.desktop are the rules to insert the program in the menu entries

6) package_name.desktop must be like this:

[Desktop Entry]  Encoding=UTF-8  Type=Application  Name=example  GenericName=Short description  Comment=Comment of the application  Exec=package_name  Icon=package_name  Terminal=false  Categories=System;  

Categories are these: standards.freedesktop.org/menu-spec/latest/apa.html

7) Run $ rpmbuild -bb ~/rpmbuild/SPECS/package_name.spec

8) Your package was built into ~/rpmbuild/RPMS folder

if you install this package it's install:

  • /usr/bin/binary_file.bin
  • /usr/share/applications/package_name.desktop
  • /usr/share/pixmaps/package_name.png

Thanks to: losurs.org/docs/tips/redhat/binary-rpms

For more details to build rpm take a look at this link.

GUI java software to build rpm: https://sourceforge.net/projects/javarpmbuilder/


Solution:7

If you are familiar with Maven there also rpm-maven-plugin which simplifies making RPMs: you have to write only pom.xml which will be then used to build RPM. RPM build environment is created implicitly by the plugin.


Solution:8

Process of generating RPM from source file:

  1. download source file with.gz extention.
  2. install rpm-build and rpmdevtools from yum install. (rpmbuild folder will be generated...SPECS,SOURCES,RPMS.. folders will should be generated inside the rpmbuild folder).
  3. copy the source code.gz to SOURCES folder.(rpmbuild/SOURCES)
  4. Untar the tar ball by using the following command. go to SOURCES folder :rpmbuild/SOURCES where tar file is present. command: e.g tar -xvzf httpd-2.22.tar.gz httpd-2.22 folder will be generated in the same path.
  5. go to extracted folder and then type below command: ./configure --prefix=/usr/local/apache2 --with-included-apr --enable-proxy --enable-proxy-balancer --with-mpm=worker --enable-mods-static=all (.configure may vary according to source for which RPM has to built-- i have done for apache HTTPD which needs apr and apr-util dependency package).
  6. run below command once the configure is successful: make
  7. after successfull execution od make command run: checkinstall in tha same folder. (if you dont have checkinstall software please download latest version from site) Also checkinstall software has bug which can be solved by following way::::: locate checkinstallrc and then replace TRANSLATE = 1 to TRANSLATE=0 using vim command. Also check for exclude package: EXCLUDE="/selinux"
  8. checkinstall will ask for option (type R if you want tp build rpm for source file)
  9. Done .rpm file will be built in RPMS folder inside rpmbuild/RPMS file... ALL the BEST ....


Solution:9

RPMs are usually built from source, not the binaries.

You need to write the spec file that covers how to configure and compile your application; also, which files to include in your RPM.

A quick glance at the manual shows that most of what you need is covered in Chapter 8 -- also, as most RPM-based distributions have sources available, there's literally a zillion of examples of different approaches you could look at.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »