How
to create a rpm package that i can distribute to others as intallable file ?
RHCE
is one of the prestigious certifications in open source domain.Upto my
knowledge it doesnt have any dump questions as any other famous certification
programs have,so that we can clear the examination easily.Thanks to the
non-availability of those dump questions.
I am really enjoying RHCE course presently.As for as examination
point is concerned one can practice its exercieses and gain confidence..Here in
my blog i am providing solutions which i have worked on.Please post ur doubts
as comments, i will try to clear it or come lets discuss it.
How
to create a rpm package that i can distribute to others as an intallable file ?
Let
me go in step by step order.
For
people who try this for first time,please try to do using root user or sudoers
privilages.
1.The
softwares needed to perform this exercise: rpm-build
command:
yum
install rpm-build
2.Now
write your own shell program and save it.In my case my shell program file name
is krish.
Create a tar
roll like krish-1.0.tar.gz which should contain your script .
3.Now
create spec file ,for that follow the procedure below,
note:
in my case my spec file name is krishna
vim
krishna.spec
note:
please open it in vim not vi ,because vim creates a default specification
template.
now
the spec file template and its settings are shown below.
Name: krish
Version: 1.0
Release: 1%{?dist}
Summary: just a sample echo
Group: applications
License: EULA
URL: http://douknowit.blogspot.com
Source0: krish-1.0.tar.gz
BuildRoot: %(mktemp -ud
%{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildRequires: /bin/rm,/bin/cp,/bin/mkdir
Requires: /bin/bash,/bin/date
%description
a
demo package
%prep
%setup
-q
%build
#configure
#make
%{?_smp_mflags}
%install
rm
-rf $RPM_BUILD_ROOT
#make
install DESTDIR=$RPM_BUILD_ROOT
mkdir
-p $RPM_BUILD_ROOT/usr/local/bin
cp
krish $RPM_BUILD_ROOT/usr/local/bin
%clean
rm
-rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
%doc
%attr(0755,root,root)/usr/local/bin/krish
%changelog
Note:
krish
--> script name which is contained in krish-1.0.tar.gz.
Here
Name
: krish
version:
1.0
these
two are merged and hence it expects the source to be :
krish-1.0.tar.gz.Configure this spec file with the names of ur tar file ,name
and version.
4.Now
our spec file is ready.now follow the command below,
rpmbuild -ba krishna.spec
now
it can say that it cant find ur tar.gz inside rpmbuild/SOURCES
--> move your tar.gz source file to the
path it specifies like in my case as root user,
/root/rpmbuild/SOURCES/
--> move your spec file to /root/rpmbuild/SPECS/
now
use
rpmbuild -ba
krishna.spec
Here
the package is created inside RPMS directory..we can note it from wrote keyword that is highlighted.
/root/rpmbuild/RPMS/...../*.rpm
rpm
-ivh *.rpm
Please
find the screenshot below..
you can find the screenshot the ' krish ' program can now be used as any other command.
Now
this is rpm package you can distribute.
Please post any errors you face ,we will
discuss it.Happy learning.....