RPM: Packaging python client

Package Management Systems take care of everything from installation, upgrading, configuring to removing software packages. They are the original “Application Stores”. RPM is one such package manager used in various distributions like Fedora, CentOS, openSUSE, Mandriva etc.

Packages, in addition to the software and data, also have some meta data with them, such as the version number, license and dependencies.

To create an RPM package, you need the source files and a spec file that has information about your package.

A specification file looks like this:

Name:      popcorn
Version:   0.1
Release:   0
Summary:   Client for popularity contest for RPMs
License:   MIT
Url:       http://github.com/opensuse/popcorn
Group:     System/Packages
Source:    %{name}.tar.gz
Requires:  cron, python, rpm-python
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildArch: noarch

%description
Popcorn tracks the collection of packages and repositories that users have installed.

%prep
%setup -q -c -n %{name}

%build

%install
install -Dm755 popcorn-client %{buildroot}%{_bindir}/popcorn
install -Dm644 popcorn.conf   %{buildroot}%{_sysconfdir}/popcorn.conf
install -Dm755 popcorn.cron   %{buildroot}%{_sysconfdir}/cron.monthly/popcorn
install -Dm644 popcorn.log %{buildroot}%{_localstatedir}/log/popcorn.log

%clean
rm -rf %{buildroot}

%files
%defattr(-, root, root, -)
%doc README LICENSE
%{_bindir}/popcorn
%config(noreplace) %{_sysconfdir}/popcorn.conf
%config(noreplace) %{_sysconfdir}/cron.monthly/popcorn
%ghost %{_localstatedir}/log/popcorn.log

%changelog

Keep your spec file in ~/rpmbuild/SPECS directory, and source files in ~/rpmbuild/SOURCES directory.

Common tags used in SPEC file:

  • Name: The name of the package, SPEC file name should match this name. It should follow the package naming guidelines.

  • Version: Version number of your software.

  • Release: Start from 1 for a version, if a new package is released for the same version of software, increment release number.

  • Summary: One line summary of the package.

  • License: The open source license used. E.g. MIT, GPLv2

  • Url: The project website URL.

  • Group: Pre existing group for type of software. You can find the list of groups in /usr/share/doc/packages/rpm/GROUPS file on openSUSE.

  • Sources: Name of compressed source file.

  • Requires: List of packages required to run the software.

  • BuildArch: If the package is architecture independent, mention noarch.

  • %description: Longer description of the software.

  • %prep: Commands to prepare the program, e.g. decompressing the source files

  • %build: Commands for building/compiling source files for installation.

  • %install: Commands to install the program. This should copy files from buildroot to builddir.[1]

  • %clean: For cleaning the buildroot directory.

  • %files: Files to be placed in the binary RPM.

  • %changelog: Changes in the package.

Use rpmbuild -ba NAME.spec to build the pacakage.

rpmbuild reads the SPEC file and perform the following operations:

  • unpacks (%prep) sources from source directory to build directory

  • compiles (%build) files in build directory

  • %install: reads from build directory, and writes the files to be installed by an end user, in the build root directory.

  • creates binary rpm, source rpm package reading from build root directory.

RPMs are created in %_rpmdir directory, ~/rpmbuild/RPMS/noarch/ in this case. Use rpmlint to check common problems in RPM package.

Files included in packaged Popcorn[2] client:

  1. popcorn: the client python script that collects anonymous package usage data and sends to popcorn server.

  2. popcorn.conf: configuration file having basic settings for popcorn.

  3. popcorn.log: log file for data sent to server.

Popcorn is an openSUSE project[3] that tracks usage of linux packages.


Useful links:

[1] Reference: Fedora’s Guide for creating an RPM package

[2] My GSoC ‘12 Proposal for the project. Thanks Ionuț Arțăriși for mentoring :)

[3] https://github.com/opensuse/popcorn