Build Debian packages and offer them in PPAs

Wrapped with a Bow on Top

© Lead Image © belchonock, 123RF.com

© Lead Image © belchonock, 123RF.com

Article from Issue 181/2015
Author(s):

Is the current package for your favorite Ubuntu program woefully behind the times? No problem: Just a few steps creates an updated Debian package that you can then share with others in a PPA.

Although your favorite Debian distro comes with many thousands of packages, some updated tools are still occasionally missing. Eventually, the maintainers might offer the corresponding packages themselves, but packaging these tools in a timely manner for each release of a distribution can be difficult.

If you want to use a new version of a program that is not yet included in your current distribution, you can create a solution yourself without any expertise in building Debian packages. If the package sources for the old version are available, constructing packages from them for the new version is usually pretty easy to do. A positive side effect is that you have the opportunity to do something good for the open source community: Provide your packages to Launchpad [1] via a PPA (Personal Package Archive) and share the results of your work with other users.

In this article, I describe an example of how to build a new, updated Debian package from old sources for the KDE backup software Kup. Most of your work will be in the terminal, because you'll be working in a chroot environment, which only makes sense from the command line. Basic knowledge of the command line's general functionality is therefore required, and you should be familiar with the important commands. The first step involves creating a suitable environment for constructing the package.

Preparation

Ubuntu currently uses the same package manager as is used in Debian, dpkg, so when I talk about "Debian packages," I am referring to archives for this kind of software management and not those that have been compiled for the Debian distribution.

The option to build and compile packages for Dpkg directly on the system already exists, although it is frowned on for several reasons – the main being that the required development environment is often missing, and Ubuntu desktop installations do not usually include any developer packages. The compiler (GCC or G++) and the development files for the libraries on the system are thus missing.

It might be possible to install all required packages later, but they would bloat the installation, and it would be more difficult to remove the installed software when you're done: Even the build-essential meta-package involves a good dozen packages as dependencies. Debootstrap is the better alternative: Using this tool you can create a virtual base installation of Ubuntu in the blink of an eye, which you can then access using the chroot command. Forget the tricks and gimmicks needed for bootloaders, because a simple environment does not act as a bootable system for the construction of packages.

Debootstrap creates a complete installation of a base system within a folder. To start, install the debootstrap package on an Ubuntu system – you can install the software either via the package manager in the graphical interface or at the command line – and then create a folder for building the packages. Next, create the environment according to the following format:

debootstrap <path> <suite>

Replace <suite> with the code name for the desired Ubuntu version. For example, if you want to create the package for version Ubuntu 15.04, the appropriate value would be vivid. If you want Debootstrap to use a local mirror rather than the default mirror, specify this by suffixing /ubuntu as the last parameter:

$ debootstrap vivid-chroot vivid \
  http://en.archive.ubuntu.com/ubuntu/
$ chroot vivid-chroot
# locale-gen <locale>
# apt-get install build-essential \
  devscripts fakeroot

Doing so will install the required packages in the vivid-chroot folder. Depending on your Internet connection, downloading the required packages could take a while.

The second line accesses the virtual Ubuntu system for the first time, and the next line adapts it to suit your needs. In fact, up to now you've only had a basic system with all the goodies missing. Therefore, the third command generates the locales, which can save some error messages if you don't speak American English (locale -a lists available locales), and the final command then sets up the developer packages you need within the virtual environment.

An editor for the command line is still missing: The Nano or Vim package provides this function. Installing Wget also ensures that you can download files from the command line. Your setup now provides the basic functions for building packages. The next step is to download the Ubuntu package sources on which you want to base the new package version.

Loading Old Sources

Developers have often created program packages that are not yet officially available in a package manager; however, they don't usually keep up with new versions for current distributions.

The backup program Kup [2] provides a perfect example: Kup has no packages for Ubuntu 15.04. The new version 0.6.0 is not packaged for Ubuntu, so you'll only find the old v0.5.1 from Ubuntu 14.10 on offer.

What looks like a dead end at first glance is really an opportunity: You can simply use the old packages from Ubuntu 4.10 as a basis for the new packages. The challenge is that you need to find the sources for the old packages.

The author, Simon Persson, supplies his software via KDE-look.org [3], which has a link to the project on the openSUSE Build Service [4]. This service also produces Debian packages on request, and I have used this option on many occasions.

At the time I was building a new Kup package, the table to the right on the Build Service page had xUbuntu_15.04 labeled as unresolvable, rather than the more desired succeeded; this informs you that Ubuntu 15.04 has no packages for the current version of the program.

Note, however, that Ubuntu 14.10 is labeled succeeded. If you click on the name of the distribution, you find the link Go to download repository – click this to get to the directory with the source files. Three files on this page form the basis for the Debian packages you will find in the amd64 and i386 folders also listed:

  • kup_0.5.1-1.diff.gz
  • kup_0.5.1-1.dsc
  • kup_0.5.1.orig.tar.gz

You need these three files so you can extract the sources and generate, together with the Debian changes, packages for version 0.6.0. Download the packages to the virtual chroot environment using wget and then extract the sources (Listing 1), which you will find in the ./kup-0.5.1/ folder.

Listing 1

Getting the Package Sources

 

You can get (wget) the sources for version 0.6.0 online [5]. Make sure to save the archive under the correct name straightaway; otherwise, dpkg-buildpackage will not be able to find it. The correct name is kup_0.6.0.orig.tar.gz. Enter

tar xvfz kup_0.6.0.orig.tar.gz

to extract the tarball. Finally, rename the newly created folder kup-0.6.0/.

Differences

The folder with the extracted Kup 0.5.1 Debian package differs from that for the Kup 0.6.0 sources by the presence of a debian/ folder, in which resides all the files with the rules for creating a Debian package. For logical reasons, copy this folder from the kup-0.5.1 directory into the kup-0.6.0 directory.

Now create a new entry in the changelog. Each Debian package has a file in which the most important changes are noted. You will find the changelog in the file debian/changelog. However, it is often a struggle to create the entry manually, especially because the log's syntax is not immediately obvious to everybody and the default syntax is strict. Instead, use the dch tool, which does most of the work for you. The tool derives the important values, such as your name and email address, from environment variables:

export DEBEMAIL="<Email address>"
export DEBFULLNAME="<First name surname>"
export EDITOR=nano

The above also sets the EDITOR variable to the desired value (Nano is the default in Ubuntu) to ensure the program uses your editor of choice.

Once these variables have been set, the dch -i command causes the tool to create a new entry in debian/changelog with the correct email and name values; then, the file opens in the editor specified (Figure 1).

Figure 1: The dch command lets you update the changelog to reflect updates to a package.

Correct the version number in the top line in parentheses – in the example, the new entry is 0.6.0-1 – and change UNRELEASED to vivid. This way, Launchpad knows the package is designed for Ubuntu version 15.04, and it builds appropriately for this platform. Use a brief description as the changelog entry – the example in Figure 1 is a reference to the new program version.

The steps completed so far always remain the same and are usually enough to package a new version of a program. The work then only involves

1. »Copying the debian folder into the unzipped source code of the new version

2. Making a changelog entry

3. Building a Debian source package with the dpkg-buildpackage tool

4. Uploading to the DEB package to the Launchpad auto-build.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Packages in systemd

    You might need to tweak your Debian or Ubuntu packages to get them to work with systemd.

  • Launchpad PPA: Canonical's Developer Service Launched

    Canonical, the company behind the Ubuntu Linux distribution has just launched its "Launchpad Personal Package Archive Service" for developers on the Canonical "Launchpad" platform.

  • Dgit

    Dgit combines the Debian archive with a Git repository, giving package maintainers some totally new options for managing Debian source packages.

  • Command Line – Package Management

    When human error stumps the Debian package manager, familiar tools like apt-get, aptitude, and dpkg can help restore functionality.

  • Flatpak and Snap

    The new container-inspired package formats Flatpak and Snap have landed in the territory occupied by conventional Linux package systems such as RPM and Dpkg.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News