Monday 11 November 2013

How to build our own rpm

I was trying to build my own rpm package. After several testing I got the spec file. The exact steps are as follows:

====
[root@]# pwd
/home/manoj/rpmbuild
====


Make the following directories:

====
[root@rpmbuild]# mkdir BUILD SOURCES SPECS SRPMS RPMS
====
[root@ rpmbuild]# ls
BUILD  RPMS  SOURCES  SPECS  SRPMS
[root@ rpmbuild]#
=====

I have a test bash script as below:
====
[root@]# cat hello.sh
#/bin/bash
echo "This is a test bash script"
====

Create a directory as "hello-0.1" under "/home/manoj/rpmbuild/SOURCES"

Move our test script "hello.sh" to the directory "/home/manoj/rpmbuild/SOURCES/hello-0.1/"

Create a tar file with the directory "/home/manoj/rpmbuild/SOURCES/hello-0.1/"

=====
[root@SOURCES]# tar -czf  hello-0.1.tar.gz  hello-0.1
[root@SOURCES]# ll
drwxr-xr-x. 2 root root 4096 Nov 11 09:50 hello-0.1
-rw-r--r--. 1 root root  190 Nov 11 09:54 hello-0.1.tar.gz
=====

Now, comes the most important part, that is to build the spec file. Navigate through the folder "/home/manoj/rpmbuild/SPECS".


Create the spec file as below, named as "hello.spec".
==========
%define _topdir /home/manoj/rpmbuild
Name:hello
Version:0.1
Release:1%{?dist}
Summary:hello

Group:Applications/Games
License:GPL
Source0:hello-0.1.tar.gz
BuildRoot:%{_topdir}/%{name}-%{version}-root


Buildarch:noarch
Requires:bash

%description


%prep
%setup -q
%install

mkdir -p $RPM_BUILD_ROOT/home/manoj/rpmbuild
cp hello.sh $RPM_BUILD_ROOT/home/manoj/rpmbuild
%clean
rm -rf %{buildroot}


%files
%defattr(-,root,root,-)
%attr(0755,root,root)/home/manoj/rpmbuild/hello.sh
===========


 Now, run the following command to generate the RPM.
=====
[root@ SPECS]# rpmbuild -ba hello.spec

Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.bTU8uP
+ umask 022
+ cd /home/manoj/rpmbuild/BUILD
+ cd /home/manoj/rpmbuild/BUILD
+ rm -rf hello-0.1
+ /usr/bin/gzip -dc /home/manoj/rpmbuild/SOURCES/hello-0.1.tar.gz
+ /bin/tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd hello-0.1
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.ghIquq
+ umask 022
+ cd /home/manoj/rpmbuild/BUILD
+ cd hello-0.1
+ mkdir -p /home/manoj/rpmbuild/BUILDROOT/hello-0.1-1.el6.x86_64/home/manoj/rpmbuild
+ cp hello.sh /home/manoj/rpmbuild/BUILDROOT/hello-0.1-1.el6.x86_64/home/manoj/rpmbuild
+ /usr/lib/rpm/check-rpaths /usr/lib/rpm/check-buildroot
+ /usr/lib/rpm/brp-compress
+ /usr/lib/rpm/brp-strip
+ /usr/lib/rpm/brp-strip-static-archive
+ /usr/lib/rpm/brp-strip-comment-note
Processing files: hello-0.1-1.el6.noarch
Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/manoj/rpmbuild/BUILDROOT/hello-0.1-1.el6.x86_64
Wrote: /home/manoj/rpmbuild/SRPMS/hello-0.1-1.el6.src.rpm
Wrote: /home/manoj/rpmbuild/RPMS/noarch/hello-0.1-1.el6.noarch.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.XQtgTd
+ umask 022
+ cd /home/manoj/rpmbuild/BUILD
+ cd hello-0.1
+ rm -rf /home/manoj/rpmbuild/BUILDROOT/hello-0.1-1.el6.x86_64
+ exit 0
==========

 Now, an RPM package is built in
====
[root@SPECS]# ll  /home/manoj/rpmbuild/RPMS/noarch/
total 4
-rw-r--r--. 1 root root 1737 Nov 11 10:05 hello-0.1-1.el6.noarch.rpm
[root@SPECS]#
=====

 Now, you can install the rpm as below:
====
[root@noarch]# pwd
/home/manoj/rpmbuild/RPMS/noarch
[root@drbdserver1 noarch]#  rpm -ivh  hello-0.1-1.el6.noarch.rpm
Preparing...                ########################################### [100%]
   1:hello                  ########################################### [100%]
[root@noarch]#
=====


You can check whether it is installed or not as below:
====
[root@noarch]# rpm -qa | grep hello
hello-0.1-1.el6.noarch
====



Kool :)











No comments:

Post a Comment

Note: only a member of this blog may post a comment.