The first thing is to install the rpmdevtools package:
yum install rpmdevtools -yYou now need to create the source tree, which you can do manually (You'll need BUILD,BUILDROOT, RPMS, SPECS,SOURCE,SRPMS) or you can just use:
rpmdev-setuptreeSince the objective calls for a least one file to be packaged, let's just create a script, say greetings.sh, and copy it to its own folder in the home/user/rpmbuild/SOURCES directory:
echo 'echo "hello `whoami`";' >> greetings.sh; chmod +x greetings.sh ; mkdir /home/user/rpmbuild/SOURCES/greet-1.0; cp greetings.sh /home/user/rpmbuild/SOURCES/greet-1.0Create a tarball out of the directory with the greetings.sh script, from SOURCES directory:
tar -czvf greet.tar.gz greet-1.0Now, you need a spec file and you can create a sample spec file with, again from SOURCES directory:
rpmdev-newspec ../SPECS/greet.specYou can now edit this file to this:
Name: greetYou can build this file with from the SPECS directory:
Version: 1.0
Release: 1%{?dist}
Summary: Greets the invoker
Group: Greetings Group
License: GPL
URL: http://www.sgniteerg.com
Source0: greet.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
%description
%prep
%setup -q
%build
%install
install -m 0755 -d $RPM_BUILD_ROOT/opt/greet
install -m 0777 greetings.sh $RPM_BUILD_ROOT/opt/greet/greetings.sh
%clean
#rm -rf $RPM_BUILD_ROOT
%files
%dir /opt/greet
/opt/greet/greetings.sh
%defattr(-,root,root,-)
%doc
%changelog
rpmbuild -bb greet.specThis will create an rpm, greet-1.0-1.el6.x86_64.rpm, in the RPMS/x86_64 directory of your buildtree, which you can then proceed to install. If you are not using the x86_64 architecture, the directory will be different. You could add BuildArch: noarch to the spec file.
You can now package all your scripts and pass them to your friends as an rpm file. How cool is that?
Thanks bro. Good work.
ReplyDelete