Use pBuilder to build packages for Ubuntu

With pBuilder you can set up a chroot environment and build packages for different Linux distributions on one machine. In this article I will show how to set up pBuilder on Ubuntu 10.04. But it should also work on other Linux distributions like Debian.

Build a package

At first we have to install the required packages pbuilder, debootstrap and devscripts.

$ apt-get install pbuilder debootstrap devscripts

Now it should be possible to create a build environment with the following command.

$ sudo pbuilder create

But we want to build packages for different Linux distributions so we have to create a script called .pbuilderrc in our home directory.

MIRRORSITE="http://de.archive.ubuntu.com/ubuntu/"
COMPONENTS="main restricted universe multiverse"

: ${DIST:="$(lsb_release --short --codename)"}

: ${ARCH:="$(dpkg --print-architecture)"}

NAME="$DIST"
if [ -n "${ARCH}" ]; then
 NAME="$NAME-$ARCH"
 DEBOOTSTRAPOPTS=("--arch" "$ARCH" "${DEBOOTSTRAPOPTS[@]}")
fi

# include extra stuff
if [ -n "${EXTRA}" -a -f ~/.pbuilderrc.$EXTRA ]; then
 . ~/.pbuilderrc.${EXTRA}
 NAME="$NAME-$EXTRA"
fi
BASETGZ="/var/cache/pbuilder/$NAME-base.tgz"
DISTRIBUTION="$DIST"
BUILDRESULT="/var/cache/pbuilder/$NAME/result/"
APTCACHE="/var/cache/pbuilder/$NAME/aptcache/"
BUILDPLACE="/var/cache/pbuilder/build/"

With this modification it's possible to set some configuration values for a single Linux distribution or a PPA. We create a file called .pbuilderrc.my-ppa to build test packages before uploading the source files to Launchpad.net.

OTHERMIRROR="deb http://ppa.launchpad.net/my/ppa/ubuntu $DIST main"

After this step we can create our build environment with the new options.

$ sudo DIST=lucid EXTRA=my-ppa pbuilder create

It's also possible to build 32Bit packages on a 64Bit system.

$ sudo DIST=lucid ARCH=i386 EXTRA=my-ppa pbuilder create

To build the package we have to do the following.

$ sudo DIST=lucid EXTRA=my-ppa pbuilder build my-package.dsc

Or we use the ARCH parameter.

$ sudo DIST=lucid ARCH=i386 EXTRA=my-ppa pbuilder build my-package.dsc

On a 64Bit system the results are available in the /var/cache/pbuilder/lucid-amd64-my-ppa/result/ directory.

Use local packages

To use the packages locally build we have to set up a local package repository. So install the needed packages dput and mini-dinstall.

$ sudo apt-get install dput mini-dinstall

Now we create a configuration file called .mini-dinstall.conf in our home directory.

[DEFAULT]
architectures = all, i386, amd64, powerpc
archivedir = /var/cache/archive/
use_dnotify = 0
verify_sigs = 0
extra_keyrings = ~/.gnupg/pubring.gpg
mail_on_success = 0
archive_style = flat
poll_time = 10
mail_log_level = NONE

[lucid]

To upload the packages successfully to our local repository we have to set up dput. So we create a file called .dput.cf.

[local]
method = local
incoming = /var/cache/archive/mini-dinstall/incoming
allow_non-us_software = 1
run_dinstall = 0
post_upload_command = mini-dinstall --batch
allow_unsigned_uploads = 1

It's time to create the directories and set the access rights.

$ sudo mkdir -p /var/cache/archive/mini-dinstall/incoming
$ sudo chown -R $USER /var/cache/archive/

After we successfully build a package we can upload it locally.

$ dput local my-package.changes

To use the local repository in our pBuilder environment we have to define it in the config file .pbuilderrc.my-ppa. It should look like this.

OTHERMIRROR="deb file:///var/cache/archive $DIST/"

Verwandte Artikel