=======================================================
Using cowbuilder and reprepro with unreleased libraries
=======================================================

.. warning::
   There exists a superior solution to this problem, which is documented in
   `Enrico Zini's pbuilder tips`__. See there for how to do this using the
   ``OTHERMIRROR`` option.

   My current workflow is having my reprepro available over HTTPS and running ::

       cowbuilder --update --othermirror 'deb [ allow-insecure=yes trusted=yes ] https://archive.amsuess.com unstable main' --override-config

   before any cowbuilder builds which need local repositories; a ::

       cowbuilder --update --override-config

   restores the original builder (probably limited to situations where an
   update of the base system doesn't actually install packages from the local
   repository).

   The text below is being kept online for reference only.

  .. __: http://www.enricozini.org/2006/tips/pbuilder-tips/

The problem
-----------

When you are packaging new software for Debian_ and a library it depends on, you probably want to build it in a clean environment before publishing it. An easy way to get such an environment is cowbuilder_.

For testing new packages before uploading them, it is sometimes useful to have an own repository, maintaining which is quite easy with reprepro_.

If there are dependencies between a bunch of new packages, they can't easily be built in cowbuilder as cowbuilder per default only queries Debian's main repository and area_.

Additionally, when building packages from the contrib area, the packages built can build-depend on packge from non-free or contrib. These dependencies can't be satisfied from the default configuration either. 

The solution
------------

Create a pbuilder_ configuration (as cowbuilder is based on pbuilder), let's call it ``~/.config/pbuilder/rc-myrepo``::

    HOOKDIR="/home/<user>/.config/pbuilder/rc-myrepo-hooks"
    BINDMOUNTS="<path to your repository> $HOOKDIR"

When this configuration is included in a cowbuilder run, the repository and the ``HOOKDIR`` will be bind-mounted into the build environment, and scripts from the ``rc-myrepo-hooks`` directory will be executed at appropriate places during the build run.

Next, create a directory ``~/.config/pbuilder/rc-myrepo-hooks`` and a file ``~/.config/pbuilder/rc-myrepo-hooks/D10-myrepo`` (and set it executable)::

    #!/bin/sh
    echo "adding own repository"
    echo "deb file://<path to your repository> unstable main contrib" >> /etc/apt/sources.list

    echo "updating index"
    apt-get update

(In this example, both the main and the contrib areas are used from the reprepro repository.)

If you want to build contrib packages, put the following two lines below the #! line::

    echo "adding non-free to sources.list"
    sed -i 's/main/main contrib non-free/g' /etc/apt/sources.list

Now, you can build your packges using::

    sudo cowbuilder --build <package>-<version>.dsc --configfile ~/.config/pbuilder/rc-myrepo



.. _cowbuilder: http://wiki.debian.org/cowbuilder
.. _reprepro: http://mirrorer.alioth.debian.org/
.. _Debian: http://www.debian.org/
.. _pbuilder: http://packages.debian.org/sid/pbuilder
.. _area: http://www.debian.org/doc/debian-policy/ch-archive.html#s-sections
