Some of the folks down stream from me think that tar archives and customized install scripts were too difficult to deal with. Thus they requested that I begin migrating my install packages to RPMs. I felt that this was not an unreasonable request, thus began a research project trying to learn everything I could. I decided to start with two small projects the first simply two files and the second about twelve. I found many examples and some good write ups but even the simple examples were more complicated than what I needed. I eventually figured it out and have simplified the process to the following 5 steps, for the most basic install.
Step1: Create a linux user called "rpmbuild "
For various reasons it is best not to do this as the root user.
Step2: Create required directories under the rpmbuild user account
Because I have used this account to create multiple packages I've setup the following directory structure
Shell> mkdir -p /home/rpmbuild/packages/mygreatrpm
Shell> cd /home/rpmbuild/packages/mygreatrpm
Shell> mkdir BUILD RPMS SOURCES SPECS SRPMS
Step3: Copy your Shell scripts to the SOURCES directory
Step4: Create your spec file in the SPECS directory
Shell> vi SPECS/MyScript.spec
#
%define _topdir /home/rpmbuild/packages/mygreatrpm
Name : MyScript
Summary : Does something REALLY great
Version : %{VERSION}
Release : %{REV}
Group: : Applications/Databases
License: : (c) MyCompany
BuildArch : noarch
BuildRoot : %{_topdir}/%{name}-%{version}-root
# Use "Requires" for any dependencies, for example:
# Requires : tomcat6
# Description gives information about the rpm package. This can be expanded up to multiple lines.
%description
This tool is designed to watch your kids, take out the trash, feed the cat and clean the refridgerator.
# Prep is used to set up the environment for building the rpm package
# Expansion of source tar balls are done in this section
%prep
# Used to compile and to build the source
%build
# The installation.
# We actually just put all our install files into a directory structure that
# mimics a server directory structure here
%install
rm -rf $RPM_BUILD_ROOT
install -d -m 755 $RPM_BUILD_ROOT/opt/MyTools
cp ../SOURCES/myscript.dat $RPM_BUILD_ROOT/opt/MyTools/.
cp ../SOURCES/myscript.sh $RPM_BUILD_ROOT/opt/MyTools/.
%post
echo "Installed %{name} scripts to /opt/MyTools"
# Contains a list of the files that are part of the package
# See useful directives such as attr here: http://www.rpm.org/max-rpm-snapshot/s1-rpm-specref-files-list-directives.html
%files
%defattr(755, root, root)
/opt/MyTools/myscript.dat
/opt/MyTools/myscript.sh
# Used to store any changes between versions
%changelog
* Fri Aug 31 2012 firstname lastname
- Initial release.
STEP 5: Create the package
Shell> cd /home/rpmbuild/packages/mygreatrpm
Shell> rpmbuild -bb --define 'VERSION 1.0' --define 'REV 1234' SPECS/MyScript.spec
...snip...
/home/rpmbuild/packages/mygreatrpm/RPMS/noarch/MyScript-1.0-1234.noarch.rpm
Nice article. it worked for me.
ReplyDeleteThanks a lot.
Mahesh Saga,
www.weluvlinux.com