星期三, 3月 14, 2007

RPM Tips English Version

RPM Tips

Traditional Chinese Version

Be forewarned, I am not going to write anything on how to create an RPM spec file. There are enough howtos in the Internet on this regard. Writing an RPM spec file can be very simple, but it can also be very complicated, depending on the program you want to write an RPM spec file for. No matter what, this requires quite a lot of time.

When I do write an RPM spec file, my main references are:

http://www.rpm.org/max-rpm/
http://www.rpm.org/RPM-HOWTO/

I never ever want to install a program from source. It is not because it is difficult. On the contrary, it is quite easy to install from source. It is just that I do not want to mess up my system. When I update a program installed from source, quite often enough, there are old files around not deleted. And sometimes, this may cause some problems. If I want to uninstall this program, where do you go to make sure that all the installed files are really removed?

If at all possible, I would rather install an RPM. RPM updates and uninstalls programs very cleanly.

So, what I want to talk about is when you only have a source program available, are there ways to convert it to an RPM package?

If I need a particular program, I would first go to the installation CD to check if this program is already available. If not, I would then go to freshmeat, to sourceforge.net or maybe google.

If there is no RPM package available, I would search rpmfind.

But, if I am unable to find an RPM package of the program, what to do then? The following discussion might solve the problem, i.e., building the RPM package is possible after all.

But before you can build or rebuild an RPM, you need to install the rpm-build package:

rpm -Uvh rpm-build-4.3.2-21.i386.rpm

Note: I am using Fedora Core 3, so I will be using RPM packages available in this distribution.

It is always recommended to build/rebuild an RPM package as a regular, not root, user. You also need to create the RPM build directories. Now login as a regular user and do the following:

mkdir rpmbuild
mkdir rpmbuild/BUILD
mkdir rpmbuild/RPMS
mkdir rpmbuild/RPMS/athlon
mkdir rpmbuild/RPMS/i386
mkdir rpmbuild/RPMS/i486
mkdir rpmbuild/RPMS/i586
mkdir rpmbuild/RPMS/i686
mkdir rpmbuild/RPMS/noarch
mkdir rpmbuild/SOURCES
mkdir rpmbuild/SPECS
mkdir rpmbuild/SRPMS

Now create the file .rpmmacros (look closely it is a dot file, i.e., the filename is preceded by a period) and the content is:

%_topdir /home/username/rpmbuild

Replace username with the actual user account name.

We are ready ready to build an RPM package.

Source RPM

If you want to install ClamAV anti-virus program, you may download the RPM package from crash-hat. It also provides a source rpm (.src.rpm). I prefer to download the source RPM and then rebuild it against my own server.

To do this, just execute the following command:

rpmbuild --rebuild clamav-0.83-1.src.rpm

After rebuilding the source RPM, you have the RPM files in:

rpmbuild/RPMS/i386/clamav-0.83-1.i386.rpm
rpmbuild/RPMS/i386/clamav-milter-0.83-1.i386.rpm
rpmbuild/RPMS/i386/clamav-devel-0.83-1.i386.rpm

Source Tarball with spec file

If, for example, you want to install SpamAssassin. No RPM package is made available. But what is provided contains the RPM spec file (Mail-SpamAssassin-3.0.2.tar.bz2 and Mail-SpamAssassin-3.0.2.tar.gz).

How do you know if an RPM spec file is included in the source tarball? Taking the two files above as an example, execute the following:

tar fzt Mail-SpamAssassin-3.0.2.tar.gz | grep .spec
tar fjt Mail-SpamAssassin-3.0.2.tar.bz2 | grep .spec

Build the RPM packaged this way:

rpmbuild -tb Mail-SpamAssassin-3.0.2.tar.gz
rpmbuild -tb --define "srcext .bz2" Mail-SpamAssassin-3.0.2.tar.bz2

Source tarball without spec file

I mentioned above that I do not want to install from source. So, what to do? Install CheckInstall and let it make an RPM for you.

The procedure for creating an RPM program is as follows:

tar xvfz program_name-version.tar.gz
cd program_name-version
./configure
make

Now instead of executing:

make install

Execute instead:

checkinstall

Perl Modules

How I hate perl! It is very difficult to manage the perl module packages installed in your system. I absolutely refuse to install perl modules from source. It has been a cause of many problems. If you upgrade to a newer version from source, you might find that your application does not work anymore.

But I need a particular perl module package. What can I do? For example, we are using OpenWebMail in our school to access our emails. It requires a perl module Text-Iconv. As I do not want to install from source, I searched the Internet and found an RPM perl-Text-Iconv package. I downloaded and installed it. But OpenWebMail was still complaining that it could not find Text-Iconv. After a few days of scratching my head, I found out that the RPM perl-Text-Iconv that I downloaded and installed was compiled against a different version of perl. So it does not work. Now what to do?

I finally found the program cpan2rpm that solved my problem. Download and install it. And then just execute:

cpan2rpm Text-Iconv-1.4.tar.gz

And it will create the following files:

rpmbuild/RPMS/i386/perl-Text-Iconv-1.4-1.i386.rpm
rpmbuild/SRPMS/perl-Text-Iconv-1.4.1.src.rpm

Now you can install the RPM package without any problem.

Fr. Visminlu Vicente L. Chua, S.J.
2005/03/21