Creating a Personal Apt Repository - Debian Delving

Ever wanted your own apt-repo? If not hit the back button about…. now.

My new employers are going to be very Debian heavy on the systems side of the project I’m on so I’m currently in the process of sharpening my Debian specific skills (I’ve always tried to avoid Unix solutions that were tied to a single OS or distro but in this case we might as well do it The Debian Way).

One of the first things to come up was the need for a local apt repository - for internal packages, third party ones we wanted to use, some backported from other Debian releases and even some rebuilt ones. In this, the first of who knows how many, Debian focused blog post I’ll be describing my first pass at setting up a repo for holding these and how I’m using it. I should probably say that this is all from bits and pieces I’ve picked up across the web so be careful before you blindly follow my advice.

First of all let’s set a victory condition - I want to be able to apt-get install puppet and have it install the version currently from testing (Lenny as I write this) under a stable system (Etch) without any pinning, apt magic etc. Before we start, run apt-get install -s puppet | grep 'Inst puppet' and see what version you get back - I get ‘Inst puppet (0.20.1-1 Debian:4.0r3/stable)’ so it’ll be pretty easy for me to see if this works; when it does the version number will change.

We’re going to serve packages over http so you’ll need a webserver (apt-get install apache2 in my experiments) and a couple of other debian packages (apt-utils and bzip2). Rather than go in to a line by line description grab my simple make-repo.sh Debian Repository creation script and my sample apt-ftparchive.conf.

Once you’ve got local copies of both, had a quick look at them (you wouldn’t run arbitrary shell scripts you’ve downloaded from the net would you?) and made any config adjustments run make-repo.sh and watch as it adds directories to your system. You now have a skeleton repo on your machine; but without any packages it’s about as much use as a Westham fan at a cup final. So let’s add a package.

$ cd dists/pool/main/ # this is under your repo base

# grab the puppet version from lenny (at time of writing)
$ wget http://ftp.de.debian.org/debian/pool/main/p/puppet/puppet_0.24.4-3_all.deb

# generate the index files
$ cd /var/www/debian # my repo base
$ apt-ftparchive generate /var/www/debian/apt-ftparchive.conf

On the client side edit /etc/apt/sources.list and add a line that looks like deb http://apt-repo.example.com/debian/ etch main - replacing apt-repo.example.com with your web host. Do an apt-get update and you should get a couple of ‘Ign’ warnings but all should work. If not, then get debugging. Now for the moment of truth, on the client -

$ apt-get install -s puppet | grep 'Inst puppet'
Inst puppet (0.24.4-3 apt-repo.example.com)

You now have a local apt repository with a sensible version of puppet ready for use by all your Etch hosts. It’s also a good building block for fulfilling some of our other requirements. But well get to those in other blog posts. Now go and add the process and website checks to Nagios.

Notes - while you can pull the packages down and dpkg -i them one by one on each machine this requires you to copy them to each host and (this is the annoying part) install the dependencies by hand (yes, you can frig this with apt-get -f and let it try to do this for you but that’s horrible). I should also say that if I’m doing any of this horribly wrong then feel free to mail me with corrections. I’d love to know how the Debian pros do it. (don’t send me emails with the word “Alone”).