Setting up a private RPM repo

By jbayer - Last updated: Tuesday, August 9, 2011 - Save & Share - Leave a Comment

I had a local need for a private repo, for some of our locally-built RPMS.

Since I’ve previously set up a private mirror, I decided to write a script which would both setup the directory structure I needed, and to do whatever rsyncing would be needed for a mirror.

  privaterepo.sh (2.8 KiB, 570 hits)

To install, just copy it into /usr/local/bin, and update the variables in the beginning to support what you want.  The variables and their explanations are:

VERSIONS=”5.5 5.6 6 6.0 6.1″  Put the versions of the OS you want to be a repo for
DIRS=”os updates”  The directories you want to mirror
OS=CentOS  OS this is a repo for
ARCH=”x86_64 i386″  Architectures
ROOT=/var/www/html  Document root for the repository, as referred to by Apache
MIRROR=rsync://mirror.trouble-free.net/centosr  Rsync mirror
 sync=0  Set to 1 if you want to rsync

 

The first time you run it, it will create all the necessary directories and the initial repo files.  If you are rsyncing as well, it will take a while to sync all the files.

The script will also create a repo file which you can install into /etc/yum.repos.d.  Call it as follows:

/usr/local/bin/privaterepo.sh  releasever basearch serverip

where:

releasever    OS release the repo file is for
basearch     Architecture the repo file is for
serverip     Either the IP address or the DNS name of the server

For example:

# /usr/local/bin/privaterepo.sh 5.6 x86_64 192.168.100.91

would produce the following output:

[os]
name=CentOS-5.6 - Base
baseurl=http://192.168.100.91/centos/5.6/os/x86_64/

gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

[updates]
name=CentOS-5.6 - Updates
baseurl=http://192.168.100.91/centos/5.6/updates/x86_64/

gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

You could either redirect it into a file, or simply do a copy/paste.

Finally, add the following to cron to automatically run it once a day:

0 * * * *     /usr/local/bin/privaterepo.sh

Posted in Administration, Bash, Open Source • • Top Of Page
1,004 views

Write a comment

asd