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.

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:

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.

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. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">