Hosting a yum Repository
Hosting a yum repository allows you to easily distribute and automatically update your own packages. The recipe below describes how to configure a yum repository for Fedora Core 5. The first three sections explain how to create a proper directory structure on your web server, sign your RPMs, and move them to the appropriate locations. The final section explains how to create a RPM which users can download and install to begin using your repository with yum.
The steps in this tutorial may be easily modified to work with other distributions.
Create directories
Run the following commands to set up the repository structure on your web server:
1 2 3 4 5 6 7 8 9 | yum install createrepo cd mkdir yum mkdir yum/fedora mkdir yum/fedora/5 mkdir yum/fedora/5/SRPMS mkdir yum/fedora/5/i386 mkdir yum/fedora/5/x86_64 ... |
Feel free to create more folders named after all the architectures you intend to support.
Create a private key
Create a GPG key to sign the packages using a GUI program like Seahorse on GNOME or the command line GPG tools. Configure rpm to use this key to sign all packages by adding the following lines to ~/.rpmmacros. Replace my name with the name on your key:
%_signature gpg %_gpg_name Peter Parente
Initialize the repository
Copy RPMs into appropriate directories and sign them. Run createrepo in each architecture directory and SRPMS. For instance:
1 2 3 4 5 | cp /usr/src/redhat/RPMS /yum/fedora/5/i386 cd /yum/fedora/5/i386 rpm --resign * createrepo Create a repo RPM |
Write a RPM spec file like the following. Replace any fields that contain the word trove with your own information:
Name: trove-repo
Version: 5
Release: 1
Summary: Trove Repository Configuration
Group: System Environment/Base
License: MIT
URL: http://trove.wordpress.com
Source0: RPM-GPG-KEY-TROVE
Source1: trove.repo
BuildRoot: %{_builddir}/%{name}-%{version}-rpmroot
BuildArch: noarch
Requires: fedora-release >= %{version}
%description
This package installs the repository GPG and repo files for the Trove software repository.
%prep
%setup -c -T
%build
%install
rm -rf $RPM_BUILD_ROOT
# gpg
install -Dpm 644 %{SOURCE0}
$RPM_BUILD_ROOT%{_sysconfdir}/pki/rpm-gpg/RPM-GPG-KEY-TROVE
# yum
install -dm 755 $RPM_BUILD_ROOT%{_sysconfdir}/yum.repos.d
install -pm 644 %{SOURCE1}
$RPM_BUILD_ROOT%{_sysconfdir}/yum.repos.d
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
%{_sysconfdir}/pki/rpm-gpg/*
%config %{_sysconfdir}/yum.repos.d/*
%changelog
* Sun Aug 03 2006 Peter Parente - 5-1
- First spec file based on those used by other repositories.
Create a repo file like the following. Replace the repository name and web server with your own information:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [trove] name=Trove for Fedora Core $releasever - $basearch baseurl=http://trove.com/yum/fedora/$releasever/$basearch/ failovermethod=priority enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-TROVE [trove-source] name=Trove for Fedora Core $releasever - Source baseurl=http://trove.com/yum/fedora/$releasever/SRPMS/ failovermethod=priority enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-TROVE |
Export the public key for the private key you used to sign your packages. Copy the repo and GPG public key files to the RPM build location:
1 2 | sudo cp trove.repo /usr/src/redhat/SOURCES/ sudo cp RPM-GPG-KEY-* /usr/src/redhat/SOURCES/ |
Build the rpm using the spec file:
1 | sudo rpmbuild -bb trove-repo.spec |
Have your users to install the RPM you just created in /usr/src/redhat/RPMS/. The easiest approach is to post the RPM on your web server with instructions for your user to run the following command:
1 | sudo rpm -i http://trove.com/yum/trove-repo-5-1.noarch.rpm |