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

前端 未结 9 1476
误落风尘
误落风尘 2020-12-04 04:20

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 installe

相关标签:
9条回答
  • 2020-12-04 05:04

    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/

    0 讨论(0)
  • 2020-12-04 05:06

    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.

    0 讨论(0)
  • 2020-12-04 05:10

    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.

    0 讨论(0)
  • 2020-12-04 05:12

    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.

    0 讨论(0)
  • 2020-12-04 05:13

    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.

    0 讨论(0)
  • 2020-12-04 05:14

    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.

    0 讨论(0)
提交回复
热议问题