Difference between revisions of "Freeside:Documentation:CreatingRPMRepo"

From Freeside
Jump to: navigation, search
 
Line 180: Line 180:
 
*** 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.)
 
*** 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.
 
*** 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==
+
=Create the repository=
 
* Copy all generated RPMs into your web server space:
 
* Copy all generated RPMs into your web server space:
 
<pre>
 
<pre>

Revision as of 10:03, 20 November 2007

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/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

To build Freeside RPMs as a non-root user, your build system must have a freeside user:

useradd freeside

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

(Ideally you could build the RPMs at this point using a tarbuild: rpmbuild -ta freeside.tar.gz. This doesn't work yet.) You can also get tarballs from CVS using ViewVC.

  • Next, untar the tarball and change directory to the folder containing the RPM specfile:
mkdir ~/work
cd ~/work
tar zxvf ~/redhat/SOURCES/freeside-1.7.3.tar.gz
cd freeside-1.7.3/install/rpm
  • If you are building modified RPMs, 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

About freeside-mason.deps.inc

RPM attempts to automatically determine which other pieces of software, including Perl modules, the RPM it is building is dependent on. Unfortunately, it doesn't scan Freeside's handler.pl file. The current work-around for this is creating a file freeside-mason.deps.inc in the same folder as the RPM specfile. If you believe the file is out of date, say because you modified handler.pl for a custom RPM, you can regenerate it with:

/usr/lib/rpm/perldeps.pl -requires ../BUILD/freeside-1.7.3/htetc/handler.pl \
| grep -v -E '^perl\((lib|strict|vars|RT)\)$' \
| grep -v -E '^perl\(RT::' \
| sort | uniq -u | awk '{ printf "Requires: %s\n", $1;}' > freeside-mason.deps.inc

Note that this one-liner scans the copy of handler.pl in the RPM build directory. It also strips out references to RT.

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.
  • Create the repository:
createrepo /var/www/html/fedora/7
  • 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.