apt-get for rpm

This page describes how I setup an apt-get repository for various rpm distributions that I use. I will not spend too much time on how to run apt-get; after all there is a good man page and you know how to read.
Apt comes from Debian. It was written for the Debian package management system to handle dependencies and remote installs. It was recently ported to work on top of rpm.

How to get apt working on a RedHat system?

First you will need an up-to-date apt rpm installed. I get my apt rpm the tuxfamily site. Here is the link:

ftp://apt-rpm.tuxfamily.org/apt/redhat-extra-7.2/redhat/RPMS.extra/

If you don't have RH 7.2 then read up on what you should download in the links listed at the bottom of this page

Because of the way that apt works you will never have to install updates of this package. From now on any updates of apt will come down by running upgrade; more on this later.

Once you install the apt rpm review your /etc/apt/sources.list file. It contains a list of all sites that apt-get will search for updates and new packages to be installed.

This is a sample for a RedHat 7.2 system: sources.list

Note that your sources.list can contain many repositories on many hosts. It is thus a good idea to include your own as well as other ones. Apt will determine which files are newer and use the appropriate ones. However, adding too many hosts to your list will slow down the update process as each host must be queries for it's database... so don't go overboard.

Once you get this far, you will need to update your local apt database. You do this by running:

$ apt-get update

Once complete your system is ready to act on your apt requests such as upgrade or install. It is usually a good idea to read the man page. Then upgrade your system to the latest distribution:

$ apt-get upgrade

How to clone a remote rpm site

Most mirrors do not have apt databases of their stock. In this document I will assume that this is not yet popular enough that your mirror of choice has the apt repository and you are mirroring a raw rpm base.

This is simple enough. You can use any method of obtaining your files: ftp, wget, ssh, rsync, nfs, cdrom, etc. My choice method is rsync -- you will probably already have rsync installed but if you don't...

$ apt-get install rsync

Let's start with a simple repository. We will fetch the RH 7.2 distribution. To speed up the process we can go to redhat.com and find the mirror closes to you. RedHat lists them here:

http://redhat.com/download/mirror.html To test out the location of rsync repositories you can run rsync with out any command. This will give you a list of all the repositories and a short description of each.
$ rsync ftp.crc.ca:: | grep redhat
redhat CRC's RedHat mirror redhat-contrib CRC's RedHat Contrib redhat-rawhide CRC's RedHat Rawhide redhat-beta CRC's RedHat Betas redhat-updates CRC's RedHat Updates

Say we were only interested in the i386 part of the RH 7.2 distribution. At this point it is uncertain where to locate this set of files. You can get more specific information by including the name of the archive in the command line call to rsync; repeat this several times and you will discover that you want to rsync ftp.crc.ca::redhat/redhat-7.2-en/os/i386/. The actual command to do so is:

$ rsync -avz ftp.crc.ca::redhat/redhat-7.2-en/os/i386/ redhat-7.2-en/os/i386/

Preparing an apt mirror

Apt directories require specific structure. The tools required to generate this repository come with the apt rpm package. But first a bit of preparation is required. A release file defines the type of repository; is is shown here:

Archive: stable
Component: os
Version: 7.2
Origin: RedHat
Label: RedHat
Architecture: i386

Then, a second directory tree is constructed and symlinks are generated to the actual rpm files mirrored above. Finally the genbasedir program can be ran to generate the apt database files. We will return to this in a short bit.

The genbasedir tool calls other tools in the apt distribution to generate database files for the packages listed. The main directory of an apt tree, in our case redhat-7.2-i386/redhat, is referred to as the distribution. Each distribution has its own line in the sources.list file. Parts of a distribution, such as os, are called components. Each requires its own database. The release file mentioned above is located in the base directory with the name of release.os where the suffix names the component it describes.

genbasedir expects a certain directory structure. This must be setup before genbasedir is ran. The directory redhat-7.2-i386/redhat, which bears the name of the distribution, must contain a base directory for the internal use of apt; ie database files will be generated in this dir. It also requires at least one RPMS.XXX directory where the XXX is a name of a component. In our case the component directory is called RPMS.os as our only component is the os component. RPMS.os can actually be a symlink to the redhat-7.2-en/os/i386/RedHat/RPMS directory in our mirror. Once setup we run genbasedir as follows:

$ genbasedir --topdir=/path/to/apt/tree/ --bloat --bz2only redhat-7.2-i386/redhat os

After running genbasedir, the base subdir will contain a bzipped database files with all the package information. For the above example the database file is called pkglist.os.bz2. Your repository is now ready to be used by apt-get.


My scripts

I have setup a cron job to run my scripts once per day. The items I mirror are captured by my fetch scripts. After I mirror all the repositories I run my makeapt script that is based on the TuxFamily scripts (see below).


Further reading



Bart Trojanowski
http://www.jukie.net/~bart
bart@jukie.net