Monday, February 22, 2010

Building RPMs Part 3

Now for part 3 of 'Building RPMs' we will be looking at how to determine what dependencies the package needs. In most cases, you would have installed software on your computer that may already have downloaded the libraries required to install your present application. For this reason it is best to use some sort of bare bone environment to install the software under that will than prompt you what libraries need to be installed. To setup a PC with a clean installation can be very time consuming. So instead we use a program called mock that chroots an environment that we could use to test what dependencies are required.

Lets install and configure mock. The best thing to do is create a user to do the mock builds because you don't want people to have access to your files while they test with mock. Add this also gives the user permissions to use mock using group permissions
adduser -m -G mock build
if your the only user on this system than you can just add your username to the mock group
usermod -a -G mock username

Once that's all done, it's time to test with mock. Let's assume you are building on a 64bit architecture and you're running Fedora 12 on that machine. If so this would be the command you would run:
#mock rebuild -r fedora-12-x86_64 --rebuild rpmbuild/SRPM/packagename*.src.rpm
#cat /var/lib/mock/fedora-12-x86_64/result/build.log

First command builds the source rpm package and the second will allow you to see the output of the build so you can determine what dependencies are needed.

When you find the required libraries than you have to find out the names for them to install them with 'yum' which than you would include them to the line in the spec file that says 'BuildRequires: " and add the library package name there. Now run mock again until you get no errors. Let's move to 'Koji'.

TO BE CONTINUED... (Build testing with Koji)

Saturday, February 20, 2010

Building RPMs Part 2

So, lets continue with the rpm creation process. (part1)

Part 1 covers how to download and check the files involved with most packages.

NOW the fun begins!!!

I'm going to explain how I created a package rpm for Irssi.


First I downloaded the tarball from http://www.irssi.org/files/irssi-0.8.14.tar.gz
which I than put it in the rpmbuild/SOURCE/ and created a new blank spec file using

rpmbuild-newspec irssi

First thing we need to do is fill in the fields on the top like Name, Version, etc... they are pretty straight forward and require very little google'ing to find the answers.

We need to understand how the file would install using just the source. Would you use a make and make install? Or ./configure, make, make install? This will affect the spec file depending on the procedure required to make the rpm package.

Here is my spec file:
Name: irssi
Version: 0.8.14
Release: 1%{?dist}
Summary: Command Line IRC Client
Group: Applications/Communications
License: GPLv2+
URL: http://www.irssi.org/
Source0: http://www.irssi.org/files/irssi-0.8.14.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: glib2-devel
BuildRequires: ncurses-devel
%description
Irssi is a terminal based IRC client for UNIX systems.

%prep
%setup -q

%build
%configure
make %{?_smp_mflags}

%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT
rm -rf $RPM_BUILD_ROOT/%{_docdir}/%{name}

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root,-)
%doc docs/*.txt docs/*.html AUTHORS COPYING NEWS README TODO
%config(noreplace) %{_sysconfdir}/%{name}.conf
%{_bindir}/%{name}
%{_datadir}/%{name}
%{_includedir}/%{name}/
%{_mandir}/man1/%{name}.1*

%changelog
* Wed Feb 3 2010 - Dave - 0.8.14-1
- Initial build..
I'm not going to explain everything in a spec file because I'm still learning. Hopefully from looking at my spec file you can determine what everything does. My Irssi spec file is really basic so it's good to learn from.

Now we try testing the spec file by using

rpmbuild -ba ~/rpmbuild/SPECS/irssi.spec
Issuing this command will try to build using the spec file above. Which had no problems and the exit code was 0. And to even test the spec file further we can try using rpmlint.

rpmlint ~/rpmbuild/SPECS/irssi.spec
If you have no problems than we move on to 'mock' to test what the package requires.


TO BE CONTINUED...(Using Mock to test RPM requirements)

Wednesday, February 3, 2010

Building RPMs

Creating a RPM in Fedora 12.

RPMs are the binary packages that Red Hat, Fedora, Suse and other distros use to install software. In most cases you can find a rpm packages somewhere on the web but for those rare occasions where you can only find the tar.gz source code than you can simply compile it using ./configure, make, make install. However, that isn't always the best way! It makes it harder to keep a rpm package list of all software installed if some apps are installed using 'make install' or what if you had a bunch of server racks that need to be running the same software and need the same updates? Wouldn't it be easier to use a rpm repository than to manually install on each computer?

So in a rpm package there are two files that are essential.
1) The actual software that needs installed or data that needs to be placed on the machine.
2) The SPEC file which holds the meta data of where everything goes.

I'm learning the in and outs of how to create/maintain rpm packages but I'll share with the web what I've learned so far.

So lets begin with the procedure required to creating a rpm package.

Needed packages
  • rpm-build
  • rpmdevtools
  • rpmlint
yum install rpm-build rpmdevtools rpmlint

After the packages are downloaded and installed we can start creating/editing rpm packages.
First we create a directory to do all the work in.

rpmdev-setuptree


In that directory there are subdirectories such as SPECS, SOURCE and BUILD.
If your interested in editing a rpm than the easiest way would be to download a src.rpm.

yumdownloader --source packagename


This downloads a *.src.rpm which you can disassemble the rpm and see how they do it.

rpm -i packagename*.src.rpm
This installs the files in the packagename.src.rpm into ~/rpmbuild which you can find the tarball and the spec file for most packages.

TO BE CONTINUED...