Freeside:Documentation:CreatingRPMRepo

From Freeside
Jump to: navigation, search

Creating your own repository with Freeside RPMs

If you can't find an APT/yum repository for your operating system, you can create your own.

Create a build environment matching your target

If your target is CentOS 4.x or similar, be aware that the standard mod_perl is 1.99. You should install an updated httpd, mod_perl, mod_ssl, etc. from the CentOS Plus repository, which also includes an updated PostgreSQL.

yum --enablerepo=centosplus httpd mod_perl mod_ssl postgresql

Set up your development environment for building RPMs as non-root

You should always build RPMs as a non-root user.

  • First, create an account to build RPMs:
useradd bob
  • Next, create or import a GPG key with which to sign the RPMs. (Signing is optional but recommended.)
  • Next, create a .rpmmacros file in that user's home directory:
su bob
vi ~/.rpmmacros
%_topdir /home/bob/redhat
%_signature gpg
%_gpg_path /home/bob/.gnupg
%_gpg_name Yourname Here
  • Finally, create a set of directories for RPM to use:
su bob
mkdir ~/redhat/
mkdir ~/redhat/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

Create the Freeside RPMs

  • First, get the Freeside source code as a tarball
cd ~/redhat/SOURCES
wget http://www.sisd.com/freeside/freeside-1.7.3.tar.gz

Next, build the RPMs using a tarbuild:

rpmbuild -ta freeside-1.7.3.tar.gz.

You can also get tarballs from CVS using ViewVC.

Building Modified RPMs

Instead of using the tarbuild, untar the tarball:

mkdir ~/work
cd ~/work
tar zxvf ~/redhat/SOURCES/freeside-1.7.3.tar.gz

Copy your patches and supplemental files to ~/redhat/SOURCES and edit the specfile to make use of them. Next, build the RPMs:

rpmbuild -ba freeside.spec

Build the RPMs for required Perl modules

Freeside uses many Perl modules, not all of which are available as RPMs. The simplest way of generating all the required RPMs is to use Ovid, which is available from CPAN, as Ovid works recursively to build RPMs of modules that the current module depends on. Ovid also can build RPM sets from Perl bundle files. The steps below let you build all required Perl modules as RPMs. An alternate approach is to find a repository that contains most of these modules as RPMs and build the remainder using Ovid, cpan2rpm, or cpanflute2.

  • If you have not used CPAN as the build user yet, configure CPAN:
su bob
cpan # And answer all the prompts
  • Install Ovid:
cpan
install Ovid
quit
rpm -Uvh ~/redhat/RPMs/i386/ovid-0.12-1.i386.rpm

or

wget http://search.cpan.org/CPAN/authors/id/G/GY/GYEPI/Ovid-0.12.tar.gz
rpmbuild -ta Ovid-0.12.tar.gz
rpm -Uvh ~/redhat/RPMs/i386/ovid-0.12-1.i386.rpm
    • If you are using Ovid version 0.12, apply this patch to enable support for building Perl modules that use Module::Build instead of ExtUtils::MakeMaker:
--- Package.pm.orig     2007-05-25 09:54:14.000000000 -0400
+++ Package.pm  2007-07-07 15:35:20.000000000 -0400
@@ -165,6 +165,7 @@
     push @out, $self->provreq($n);
   }
 
+  return join("\n", map { "Provides: $_"; } @out) if scalar(@out) > 5;
   return join('', 'Provides: ', join ' ', @out);
 }
 
@@ -376,10 +377,15 @@
 
 %install
 
-make PREFIX=%{_prefix} \
-     DESTDIR=%{buildroot} \
-     INSTALLDIRS=@installdirs@ \
-     install
+if [ -f Build.PL -a -f Build ] ; then
+     ./Build destdir=%{buildroot} \
+          install
+else
+     make PREFIX=%{_prefix} \
+          DESTDIR=%{buildroot} \
+          INSTALLDIRS=@installdirs@ \
+          install
+fi
 
 [ -x /usr/lib/rpm/brp-compress ] && /usr/lib/rpm/brp-compress

This is applied in /usr/lib/perl5/site_perl/5.*/Ovid:

/bin/su -
cd /usr/lib/perl5/site_perl/5.*/Ovid
patch < Ovid.diff
  • Create bundle files for each of the Freeside RPMs:
mkdir ~/.cpan/Bundle
install/rpm/rpm2Bundle ~/redhat/RPMS/noarch/freeside-1.7.3-1.noarch.rpm > ~/.cpan/Bundle/freeside.pm
install/rpm/rpm2Bundle ~/redhat/RPMS/noarch/freeside-mason-1.7.3-1.noarch.rpm > ~/.cpan/Bundle/freeside-mason.pm
install/rpm/rpm2Bundle ~/redhat/RPMS/noarch/freeside-postgresql-1.7.3-1.noarch.rpm > ~/.cpan/Bundle/freeside-postgresql.pm
  • Some of the modules Ovid will attempt to build use Module::Build instead of ExtUtils::MakeMaker. Ensure Module::Build is installed, for example by trying to find its files:
locate Module/Build
  • Install Module::Build if it's not already installed (you can build it with Ovid if it is not available prebuilt):
yum install perl-Module-Build
  • Install any prerequisites needed to build some of the modules
    • GD requires header files for JPEG, PNG, and Freetype.
yum install libjpeg-devel libpng-devel freetype-devel
    • The DBD::Pg build process also needs to know the version of PostgreSQL the module is being built for. The easiest way to do this may be to install the postgresql-devel RPM on your build machine.
  • Use Ovid to create RPMs for the main Freeside dependencies:
ovid --skip-perl-rpm-modules --packager='Yourname Here <youraddy@example.com>' \
Bundle::freeside Bundle::freeside-mason Bundle::freeside-postgresql
  • Fix up RPMs that did not build. cpan2rpm and cpanflute2 are useful when Ovid doesn't work.
    • Newer versions of DBD::Pg may require a newer version of DBI to be installed on the build computer:
ovid --skip-perl-rpm-modules --packager='Yourname Here <youraddy@example.com>' DBI # Build DBI
/bin/su - # Get root to install the RPM
rpm -Uvh  ~bob/redhat/RPMS/i386/perl-DBI-1.601-1.i386.rpm
exit
ovid --skip-perl-rpm-modules --packager='Yourname Here <youraddy@example.com>' DBD::Pg # Try a rebuild of DBD::Pg
    • Chart has inaccurate RPM "provides" information. This can be fixed by using Ovid to produce a specfile and then commenting out the lines that turn off AutoProvides. Be aware that Ovid may overwrite changes when run again.
ovid --skip-perl-rpm-modules --packager='Yourname Here <youraddy@example.com>' --nobuild Chart
vi ~/redhat/SPECS/perl-Chart.spec
rpmbuild -ba ~/redhat/SPECS/perl-Chart.spec
    • Ovid 0.12 has a bug where the version number passed to rpmbuild is incorrect for Perl modules with a trailing digit. This affects IPC::Run3 and Crypt::PasswdMD5. One workaround is to have Ovid create the specfile and hand-edit it before running rpmbuild yourself to build the RPMs:
ovid --skip-perl-rpm-modules --packager='Yourname Here <youraddy@example.com>' --nobuild IPC::Run3 Crypt::PasswdMD5
cd ~/redhat/SPECS
mv perl-IPC-Run.spec perl-IPC-Run3.spec
mv perl-Crypt-PasswdMD.spec perl-Crypt-PasswdMD5.spec
vi perl-IPC-Run3.spec # Append '3' to Run where necessary
vi perl-Crypt-PasswdMD5.spec # Append '5' to MD where necessary
rpmbuild -ba perl-IPC-Run3.spec
rpmbuild -ba perl-Crypt-PasswdMD5.spec
  • Use Ovid to create RPMs for all the Freeside dependencies you require:
ovid --skip-perl-rpm-modules --packager='Yourname Here <youraddy@example.com>' Business::OnlinePayment::AuthorizeNet
  • Fix up RPMs that have inadequate dependency information. One approach is to use Ovid to generate a specfile for the RPM, hand-edit the specfile, and then build the RPM using rpmbuild.
    • The perl-GD RPM doesn't list 'gd' as one of the dependencies.
    • The HTML::Mason RPM is troublesome as a lot of the dependencies are listed in the Bundle::HTML::Mason file inside the HTML::Mason tarball. Ovid does not build all these dependencies automatically, or add them to the dependency list of the HTML::Mason RPM.
      • First, build all the dependencies:
ovid --skip-perl-rpm-modules --packager='Yourname Here <youraddy@example.com>' Bundle::HTML::Mason
      • Next, create the HTML::Mason specfile and hand-edit it to insert all these dependencies. (There is no perl-Bundle-HTML-Mason RPM, so you have to list all the dependencies individually.)
      • Finally, rebuild the HTML::Mason RPM using rpmbuild. Be aware that Ovid will overwrite your customized specfile if it thinks it needs to build HTML::Mason again.

Create the repository

  • Copy all generated RPMs into your web server space:
mkdir /var/www/html/fedora/7/
cp ~/redhat/RPMS/*/*.rpm /var/www/html/fedora/7
  • Remove any files that are present on any other repositories you intend to use. (This is left as an exercise for the reader.)
  • Sign all the RPMs with your GPG key:
cd /var/www/html/fedora/7
rpm --addsign *.rpm
  • Download any programs needed to build the repository. For newer, XML-based versions of yum, you'll need createrepo. If it's in a yum repository, this can be as simple as:
    yum install createrepo
    . On distros using older versions of yum (e.g. FC2 and earlier), you'll need to use yum-arch instead of createrepo to generate the repository metadata. yum-arch should be installed as part of the yum RPM, so there's no need to install another RPM. You should also use yum-arch when creating a new-style repository if you intend for it to be accessed from official RHEL v4 using up2date.
  • Create the repository:
createrepo /var/www/html/fedora/7
yum-arch /var/www/html/fedora/7/freeside-1.7/testing/$basearch
  • Make sure the web server is started

At this point your web server is acting as a yum repository with a URL of http://localhost/fedora/7/

  • Create a file defining the repository in /etc/yum.repos.d/freeside.repo, or put it up on your web server so it can be downloaded to machines that Freeside will be installed on.
#Packages used in Freeside
[freeside]
name=Freeside-$releasever
#mirrorlist=http://localhost/mirrors/fedora/$releasever/$basearch
baseurl=http://localhost/fedora/$releasever/
gpgcheck=1
enabled=0
gpgkey=http://localhost/RPM-GPG-KEY-yourname

Once this file is installed in /etc/yum.repos.d, you can proceed to install Freeside from the repository.

The short version

One-time setup

  • Create a build environment matching your target.
  • Set up your development environment for building RPMs as non-root.
  • If you think you're going to add Perl dependencies, install one of Ovid (modified as in the wiki), cpan2rpm (see the installation instructions for CentOS 4.4 for details on installing this), or RPM::Specfile (for cpanflute2). Not necessary if you're just doing minor bug fixes.
  • If you think you're going to distribute the revised Freeside RPMs via a repository, install createrepo using yum.
  • Checkout the 1.7 branch from CVS into the build user's working area.

Updates

Build the new RPMs

  • Do a CVS update on the working copy.
  • Create a new tarball and copy it to the SOURCES directory.
  • cd to the working copy's install/rpm directory.
  • run rpmbuild --define='release RELEASE' -ba freeside.spec

Example script to build from a local CVS working tree:

#!/bin/sh
VERSION=1.7
RELEASE=`date +%Y%m%d`
cd freeside-${VERSION}
cvs update
cd ..
tar zcvf /home/rsiddall/redhat/SOURCES/freeside-${VERSION}.tar.gz \
--exclude CVS freeside-${VERSION}
cd freeside-${VERSION}/install/rpm
rpmbuild --define="version $VERSION" --define="release $RELEASE" -ba \
freeside.spec

Your RPMs should build successfully. About 6 to 12 lines before the end of the build output you should see a bunch of lines like: Wrote: /home/bob/redhat/SRPMS/freeside-1.7-20071113.src.rpm Wrote: /home/bob/redhat/RPMS/noarch/freeside-1.7-20071113.noarch.rpm which tells you the RPMs were created.

Additional checks

You can do some optional checking at this point with "rpm -q", for example:

 rpm -qlp /path/to/RPM # List of all the files packaged in the RPM
 rpm -qp --requires /path/to/RPM # List of dependencies
 rpm -qip /path/to/RPM # Cataloging data.
 rpm -qp --scripts /path/to/RPM # Dump all the RPM-related scripts.

This is mainly useful for checking against the previous RPM to see nothing unexpected changed.

Sign the RPMs

 rpm --addsign <list of rpms>

Upload to repository

Put them in a folder in web server space and run createrepo <folder> to update the yum metadata for the repo. (Also yum-arch if the target system is RHEL rather then CentOS)

Update target system

Update the target system with up2date or yum.