Friday, January 30, 2015

Rebuilding Fedora Packages for CentOS - A workflow

Why Rebuilding Packages

With the upgrade to CentOS 7, some of the services I was using are no more present in CentOS repositories. An example of this is BackupPC and ddclient, which I use for services and reachability of the machine.
I could install them through normal installation (tar.gz extraction,make config, make) but I feel this both as a waste and a danger. First of all, everybody using this will be doing the same, which is a wasted effort. Second,  I adopted CentOS for stability, which also means repeatability of configuration. Third, it's fun and satisfactory, run a yum install and having everything in place.

Fedora Compatibility

Upstream (aka "Red Hat Enterprise Linux 7") is mostly a combination of Fedora latest release (I guess from F18 onward), so in CentOS we find most of the novelties which have been developed in the last two to three years:
  • Systemd
  • Journal
  • FirewallD
  • Gnome 3
And a lot of other plumbing that I am forgetting about. Right now, repackaging an F21 spec for CentOS 7 is quite easy: these two distributions will slowly diverge in the next few years.

My Workflow

I adopted the following workflow: I assume that rpm development setup has been completed for the steps to succeed.

1 - Download source package

Downloading source packages is quite easy: install yum-utils on your fedora pc, and launch yumdownloader --source $packagename, eg:

yumdownloader --source ddclient

2 - Install src package

Copy the package on the CentOS machine, where a rpm dev environment is setup, and, as non-root account, install the src package. You will find the SPEC file in the ~/rpmbuild/SPECS directory, and source and patches in ~/rpmbuild/SOURCES.

3 - Adapt the SPEC file

You should edit the SPEC file, at least adding the CHANGELOG line in which you can write who you are, the date, and what you did. Experienced packagers can update the source files, apply further pathecs and so on. I suggest you check the following stuff:
  • the "Release:" line will contain a number, followed probably by %{?dist} macro, which will get substituted by the distribution abbreviation (el7 for centos, f21 for fedora). If not, correct it
  • Check the description and version, check with upstream if minor releases have been done, and if you wish to release a newer version of the package

4 - Rebuild the src package

Just type rpmbuild -bs $SPECFILE and you will have a new src package in ~/rpmbuild/SRPMS

5 - Mock build the package

Mock (yum install mock) will: 
  • create a chroot environment in /var/lib/mock/$target_architecture (in our case, epel-7-x86_64)
  • download build time packages 
  • build the package in the chroot environment
  • have a log of activities and the built packages in /var/lib/mock/$target_architecture/result
all of this simply entering: mock $src_package (eg - mock ~/rpmbuild/SRPMS/ddclient-3.8.2-2.el7.centos.src.rpm )

6 - Install the package

Time to test with a local installation of the package. Or you can deploy to your local repository for testing.

That's it. If you feel it, try to have a look at copr for distribution of your packages.


No comments: