There may be cases where we need to perform
a action whenever we install a RPM. Consider a Case where we need to create a
User when a RPM is Installed or execute a Script to change the permissions on
the locations installed by a RPM.
RPM in linux provides us various options in
doing these. RPM
supports a script run prior to installation, %pre, and a script run after
installation, %post. The same concepts apply when a package is erased, or
uninstalled. The %preun script is run just before the uninstall and the %postun
script just after the uninstall.
In this post we will see how we can execute
a Shell script after the installation of the RPM. We will follow the Basic RPM
created here.
The steps are same. The only thing we need
to add was a %post element to the SPEC file. The final Spec file looks as
[root@localhost SPECS]# cat
hello.spec
Name:
hello
Version: 1
Release:
1%{?dist}
Summary: Hello
Program
Group: Utilities
License: GPL
Source: %{name}.tar.gz
BuildRoot:
%{_tmppath}/%{name}-%{version}-%{release}
%description
Test Program For Build
%prep
%setup -n hello
%install
mkdir -p
"$RPM_BUILD_ROOT/opt/hello"
cp -R *
"$RPM_BUILD_ROOT/opt/hello"
%clean
rm -rf $RPM_BUILD_ROOT
%files
/opt/hello
%post
sh
/opt/hello/hello.sh >> /tmp/hello
The %post element tells us to execute a
Shell Script and redirect the Output to /tmp/hello file.
Once the creation of the RPM , we will
install using
[root@localhost x86_64]# rpm -ivh
hello-1-1.el6.x86_64.rpm
Preparing...
########################################### [100%]
1:hello
########################################### [100%]
Once the RPM is installed check,
[root@localhost x86_64]# cat
/tmp/hello
this is hello world
The Shell Script is executed correctly once
the RPM is installed.
More to come , Happy Learning J
No comments :
Post a Comment