Skip to content

Instantly share code, notes, and snippets.

@Driste
Last active September 20, 2017 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Driste/ff13a888e977cb3c32eb1038cb722a61 to your computer and use it in GitHub Desktop.
Save Driste/ff13a888e977cb3c32eb1038cb722a61 to your computer and use it in GitHub Desktop.
RPM

RPM: Red-Hat Package Manager

The basic procedure to build an RPM is as follows:

  • Get the source code you are building the RPM for to build on your system.
  • Make a patch of any changes you had to make to the sources to get them to build properly.
  • Make a spec file for the package.
  • Make sure everything is in its proper place.
  • Build the package using RPM.

The Spec file

The spec file is required when building a RPM. The file holds the description and the instructions of how to build the software along with a file list of the binaries required for the install.

Below will be the portions of the spec file and their descriptions:

The header

Summary: A visual aid for the physical location of devices in your datacenter's racks.
Name: racmon
Version: 0.1.1
Release: 1
Copyright: GNU
Group: Documentation
Source: https://github.com/Driste/racmon-0.1.1.tar.gz
Patch: racmon-0.1.1-buildroot.patch
BuildRoot: /var/tmp/%{name}-buildroot
  • Summary: This is a one line description of the package.
  • Name: This must be the name string from the rpm filename you plan to use.
  • Version: This must be the version string from the rpm filename you plan to use.
  • Release: This is the release number for a package of the same version (ie. if we make a package and find it to be slightly broken and need to make it again, the next package would be release number 2).
  • Copyright: This line tells how a package is copyrighted. You should use something like GPL, BSD, MIT, public domain, distributable, or commercial.
  • Group: This line is used to tell high level installation programs (such as Red Hat's gnorpm) where to place this particular program in its hierarchical structure. You can find the latest description in /usr/doc/rpm*/GROUPS.
  • Source: This line points at the HOME location of the pristine source file. It is used if you ever want to get the source again or check for newer versions. Caveat: The filename in this line MUST match the filename you have on your own system (ie. don't download the source file and change its name).
  • Patch: This is the place you can find the patch if you need to download it again. Caveat: The filename here must match the one you use when you make YOUR patch.
  • BuildRoot: This line allows you to specify a directory as the "root" for building and installing the new package. You can use this to help test your package before having it installed on your machine.

Description

%description

This is a multi-line field that should be used to give a comprehensive description of the package.

%description
Racmon is a application that allows the system administrator to
view the physical locations and configurations of devices in
their datacenter. It is a web application with appliance features
to check the network and statuses of the racks.

Prep

%prep

The second section of the spec file is the prep. This with where you get the sources ready to build. You need to do anything here to get the sources patched and setup like the need to be setup to do a make. In other words, this is where you would unpack the sources and cd into the source directory.

%prep
%setup -q
%patch -p1 -b .buildroot

%setup macro:

%patch macro:

Build

Pre Install

Install

Post Install

Clean

Pre Uninstall

Uninstall

Post Uninstall

Files

Changelog

Resources

Pretty much taken from this, but now in better format.

Summary: A program that ejects removable media using software control.
Name: eject
Version: 2.0.2
Release: 3
Copyright: GPL
Group: System Environment/Base
Source: http://metalab.unc.edu/pub/Linux/utils/disk-management/eject-2.0.2.tar.gz
Patch: eject-2.0.2-buildroot.patch
BuildRoot: /var/tmp/%{name}-buildroot
%description
The eject program allows the user to eject removable media
(typically CD-ROMs, floppy disks or Iomega Jaz or Zip disks)
using software control. Eject can also control some multi-
disk CD changers and even some devices' auto-eject features.
Install eject if you'd like to eject removable media using
software control.
%prep
%setup -q
%patch -p1 -b .buildroot
%build
make RPM_OPT_FLAGS="$RPM_OPT_FLAGS"
%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/usr/bin
mkdir -p $RPM_BUILD_ROOT/usr/man/man1
install -s -m 755 eject $RPM_BUILD_ROOT/usr/bin/eject
install -m 644 eject.1 $RPM_BUILD_ROOT/usr/man/man1/eject.1
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
%doc README TODO COPYING ChangeLog
/usr/bin/eject
/usr/man/man1/eject.1
%changelog
* Sun Mar 21 1999 Cristian Gafton <gafton@redhat.com>
- auto rebuild in the new build environment (release 3)
* Wed Feb 24 1999 Preston Brown <pbrown@redhat.com>
- Injected new description and group.
[ Some changelog entries trimmed for brevity. -Editor. ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment