Packaging using Pbuilder

From LSDevLinux
Jump to: navigation, search

This is a small exercise designed to teach how to do packaging using pbuilder. Most of the information presented here is from Martin Hosken with some additional information provided by Sue Newland testing this exercise on a Debian system.

Day1:

There are two parts to packaging:

  1. Creating the packaging files and getting everything to bundle up nicely the first time
  2. Maintaining the package.

Since 1 is much harder than 2, we'll start with two.

The first requirement is a nice clean machine on which to build the package. This can be a pain to find, so there is a nifty system called pbuilder that will create the nice clean environment to do the build.

To use this approach, you will need 100MB worth of internet access (or someone can hand you most of that in a file, which we'll come to later).

OK. First step, install pbuilder. Since you are packaging, I'll use command lines rather than synaptic everywhere.

$ sudo apt-get install pbuilder

well that didn't take much  :)

One of the Debian systems on which this was tested did not install one of the dependency at this point, cdebootstrap, so that needed to be installed in a separate step.

Now we create the build environment

$ pbuilder --create

this will take a while and will probably ask you for your password since I think it does at least one sudo in all that.

Now you have nearly all you need to build a package.

The next part will describe how to download an existing package, upgrade the source code and versioning and to build it using pbuilder.

The create step did not work properly on the Debian system being tested, so below are some additional steps to help resolve the problems.

Sorry. Forgot you were running on Debian.

OK. Time to dig a little deeper.

man pbuilder will tell you that pbuilder looks for its config file in ~/.pbuilderrc which is overlayed over /etc/pbuilderrc and for lack of /etc/pbuilderrc it uses /usr/share/pbuilder/pbuilderrc. I would not recommend editing either of these latter two files. Instead, I would

$ cp /usr/share/pbuilder/pbuilderrc ~/.pbuilderrc

and then start editing it.

Here you can set whatever distribution and the urls for that distribution so that your system will download the right setup. Notice pbuilder can work happily with any distribution (well Debian based) that is happy with the kernel you are running. For packaging stuff that isn't hacking with the kernel, any kernel will do.

The next problem the Debian test system ran into was that the create command could not be run as a normal user, so instead use

$ sudo pbuilder --create

Doing this still failed because of some other issues. Pbuilder was trying to set up an environment for sid and what was actually wanted was one for Ubuntu Gutsy. So after following Martin's second set of instructions and creating a ~/.pbuilderrc configuration file, that could then be edited to change the location of the repository site to be Ubuntu Gutsy instead of Debian and also to change the distribution to the appropriate one, in this case to Gutsy. At this stage the proxy setup may also need to be edited in this ~/.pbuilderrc file.

After correcting the configuration file the next problem encountered involved the keyring from the Ubuntu repository. Since this was not an Ubuntu system there were no keys from the Ubuntu repository on the Debian keyring so the create step still failed. To add this key, download the .deb file from the site http://packages.ubuntu.com/gutsy/ubuntu-keyring, click all in the lower left corner under Architecture, and download the package from one of the mirror sites listed there by right-clicking a mirror and clicking Save Link As. Install this file using a command such as:

$ sudo dpkg -i ubuntu-keyring_2007.06.11_all.deb

After taking care of these various issues the create command finally worked.

Day 2;

By now you have installed pbuilder and are ready to build a package. In this part we will download an existing source package from a different distribution and update it and build it using pbuilder.

Normally when you want to download the source of a package you can type:

$ apt-get source bibledit

But there is no source package for us to download, yet. So we will have to snatch it from a repository directly. A source package consists of at least 2 files. The first file has the filename of the form <package>_<debian_version>.dsc and consists of information about the package, it's name, version, what packages are needed to build this package and also a list of files that constitute the source.

For this exercise

. Create an empty directory to work in

 navigate to http://packages.sil.org/ubuntu/dists/hardy/main/source
 download bibledit_3.1-1ubuntu~hardy1~sil1ubuntu1.dsc
 download bibledit_3.1-1ubuntu~hardy1~sil1ubuntu1.tar.gz

Not the best versioning on this package, but we'll come to that.

Now we need to unpack this, we could just unpack the tarball but it's probably better to use the right tool because not all source packages are just a simple tarball:

$ dpkg-source -x bibledit_3.1-1ubuntu~hardy1~sil1ubuntu1.dsc

This will create a subdirectory bibledit-3.1-1 which would normally be the source directory with a debian/ subdirectory added. But due to the way this program has been packaged the source directory simply consists of a tarball with the source in. This approach is very nice to work with, but harder to learn.

Part of the core of the packaging process is the debian/changelog which contains entries giving the history of the package. The most important part of this file is the first line. It contains:

the package name the package version the distribution we are building for

There is a useful program to help with this: dch. We'll assume you are building for gutsy, so change the commands accordingly

$ dch -Dgutsy -n

Up should come your favourite (or otherwise) editor containing the new changelog with a first line of:

bibledit (3.1-1ubuntu1~hardy1~sil1ubuntu1.1) intrepid; urgency=low

your distro may be different (why my devscripts have just updated to start outputting intrepid I don't know). Now to edit it to what we want.

Change the version to (3.1-1ubuntu1~<distro>1~sil1) Change intrepid to be the distro you want to build for <distro> Change the comment to something more interesting if you want.

Save and exit the editor.

OK now we are ready to build the thing.

$ pdebuild

it'll ask you for your password to be able to access stuff in /var/cache and the chroot environment.

I'll stop there, because I'm sure you'll have problems at some point along the way. So let's talk about them. If not, then you should find some nice stuff in /var/cache/pbuilder/results or whatever the location is that you put into your pbuilder configuration file.