RPM Building

Following are the packages which are required to build rpm package with shell script inside.

[ bob @ leolinux ~]$  sudo yum install rpmdevtools rpmlint


Run following commands to create necessary directories which are written below. ( BUILD, RPMS ,SOURCES, SPECS, SRPMS , BUILDROOT )

[ bob @ leolinux ~]$   rpmdev-setuptree

[ bob @ leolinux ~]$  cd  ~/rpmbuild/

[ bob @ leolinux ~]$  mkdir  ~/rpmbuild/BUILDROOT

[ bob @ leolinux ~]$  ls


Create a directory with version no in suffix where we will create or save our script.

[ bob @ leolinux ~]$  mkdir ~/rpmbuild/BUILD/MYSCRIPT-0.1


Create your script.

[ bob @ leolinux ~]$  vim ~/rpmbuild/BUILD/MYSCRIPT-0.1/myscript


read -p "Enter Your Name : " name

echo "$name"



Create Doc "README" file
[ bob @ leolinux ~]$   vim   ~/rpmbuild/BUILD/MYSCRIPT-0.1/README
Write Script related help and its description.
Run following commands step by step because its necessary and compress MYSCRIPT-0.1 .
[ bob @ leolinux ~]$   cd   ~/rpmbuild/BUILD/
[ bob @ leolinux ~]$   tar   -cvzf    ../SOURCES/MYSCRIPT-0.1.tar.gz    MYSCRIPT-0.1
Create specfile with default parameters
[ bob @ leolinux ~]$  cd   ~/rpmbuild/SPECS
[ bob @ leolinux ~]$  rpmdev-newspec
[ bob @ leolinux ~]$  mv newpackage.spec    myscript.spec

Edit myscript.spec file with the following information.

[ bob @ leolinux ~]$  vim ~/rpmbuild/SPEC/myscript.spec


%define PNAME myscript

Name: %{PNAME}

Version: 0.1

Release: el6

Summary: Draw chess board

Group: System Environment/Base

License: GPLv2

Source0: MYSCRIPT-0.1.tar.gz

BuildArch: noarch


Displays user name


%setup -q


echo "Build Complete"



mkdir -p $RPM_BUILD_ROOT/usr/local/bin

cp myscript $RPM_BUILD_ROOT/usr/local/bin

mkdir -p  $RPM_BUILD_ROOT/usr/share/doc/MYSCRIPT-0.1

cp README $RPM_BUILD_ROOT/usr/share/doc/MYSCRIPT-0.1






%attr(0755,root,root) /usr/local/bin/myscript





*    Sun   May   7  2012  leoxian <Leoxian@leolinux.in 0.1 

-    initial build for version 1






Run following command to build rpm package.It builds binary package .rpm in ~/rpmbuild/noarch/RPMS directory and .src.rpm in ~/rpmbuild/SRPMS directory)
[ bob @ leolinux ~]$  cd   ~/rpmbuild/
[ bob @ leolinux ~]$  rpmbuild -ba SPECS/myip.spec
Cheer !!!