Adding a local respository to pbuilder

I recently posted about backporting packages with pbuilder. Someone asked about forward porting PHP4, which is a huge task. PHP4 is out of date, and the entire set of PHP4 libraries has a lot of build dependencies, including some packages you must build yourself. I’m not going to take you through the process of backporting PHP4. If you really need it, you can install php4-cgi and php4-* from Ubuntu dapper directly on hardy. But I will show you how to enable a local repository in pbuilder. This will allow you to build a package with pbuilder, and then use that package to satisfy any build-dependencies that other packages need.

First, see my previous post and set up pbuilder using the .pbuilderrc there. Now, add the following lines to the bottom of that file.

# use previously built packages as local respository
BINDMOUNTS="$BUILDRESULT"
OTHERMIRROR="deb file:$BUILDRESULT ./"

# create local repository if it doesn't already exist,
# such as during initial 'pbuilder create'
if [ ! -d $BUILDRESULT ] ; then
        mkdir -p $BUILDRESULT
        # set permissions so I can delete files
        chgrp admin $BUILDRESULT
        chmod g+rwx $BUILDRESULT
fi
if [ ! -e $BUILDRESULT/Packages ] ; then
        touch $BUILDRESULT/Packages
fi
if [ ! -e $BUILDRESULT/Release ] ; then
        cat << EOF > $BUILDRESULT/Release
Archive: $DIST
Component: main
Origin: pbuilder
Label: pbuilder
Architecture: $ARCH
EOF

fi

These additions will cause pbuilder to add a new apt repository to each newly pbuilder base image, bind that repository into the chroot filesystem of the pbuilder environment, and create the initial apt files necessary for a basic local apt repository. This repository will be your normal result directory, where pbuilder puts completed .deb files after building, such as /var/cache/pbuilder/hardy-amd64/result/.

I also find it convenient for my user to be able to delete files from /var/cache/pbuilder/hardy-amd64/result/ without sudo, so the above script adds write permission for the “admin” group (which you probably are, if you have sudo access) to that directory.

Any new pbuilder base images made with sudo pbuilder create will use the new settings above. However, if you’ve previously created an image you’ll need to update it before proceeding.

sudo pbuilder update --override-config

Now, we need to update the /var/cache/pbuilder/hardy-amd64/result/Packages file every time we build a package. For this, we need to use a hook script. Create a script in $HOME/.pbuilder-hooks called D10apt-ftparchive, and make it executable.

touch $HOME/.pbuilder-hooks/D10apt-ftparchive
chmod a+x $HOME/.pbuilder-hooks/D10apt-ftparchive

The script should contain:

#!/bin/bash
# 2009-04-09 tyler - use previously built packages as an apt source
# http://blog.edseek.com/~jasonb/articles/pbuilder_backports/pbuilderbuild.html#pbuilderhook

echo Calling $0

: ${DIST:=$(lsb_release --short --codename)}
: ${ARCH:=$(dpkg --print-architecture)}
NAME="$DIST-$ARCH"
BUILDRESULT="/var/cache/pbuilder/$NAME/result/"

# create apt archive of previously built packages
( cd $BUILDRESULT ; apt-ftparchive packages . > $BUILDRESULT/Packages )

# see ~/.pbuilderrc for creation of $BUILDRESULT/Release

apt-get update

Now each time we call sudo pbuilder build package.dsc, pbuilder will first update /var/cache/pbuilder/hardy-amd64/result/Packages with the contents of whatever packages are already there.

As an added bonus, this allows you to satisfy build-dependencies that may be provided by hardy-backports or hardy-updates (but which aren’t in plain hardy, which is all that pbuilder uses). For instance, “debhelper >= 7” is often required for packages in intrepid or jaunty. Stock hardy only offers debhelper 6, but hardy-backports contains debhelper 7. So just download that .deb file, copy it to /var/cache/pbuilder/hardy-amd64/result/, and build your package.

pbuilder will display a warning message when using packages in your local repository, but will build anyway.

WARNING: untrusted versions of the following packages will be installed!

Untrusted packages could compromise your system's security.
You should only proceed with the installation if you are certain that
this is what you want to do.

  debhelper

*** WARNING ***   Ignoring these trust violations because
                  aptitude::CmdLine::Ignore-Trust-Violations is 'true'!

You can now build packages and meet dependencies from your local archive.

Tags: ,

  1. Bráulio’s avatar

    Nice! Thank you so much for these scripts and configurations.
    I had to add
    apt-get install -y apt-utils
    before calling apt-ftparchive on lenny

    Cheers

    Reply

  2. Jean-Michel Pouré’s avatar

    Add EXTRAPACKAGES=”apt-utils” to your config file, this will download apt-utils automatically. I also nano to make sure there is a text editor in the chroot.

    Reply

Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.