Hi i have a problem with code duplication while building rpm package.
I have a spec like this:
Summary : ${product.id} ${rpmType}
Name : ${product.id}_${rpmType}
.....
%build
%install
%files
%defattr(-,root,java,750)
%{home}
%clean
rm -rf %{buildroot}
%pre
CHECK_PAUSE=2;
echo -n "Stopping tomcat";
sh %{binary}/shutdown.sh
rc=0
while [ "$rc" == 0 ]; do
sleep $CHECK_PAUSE;
wget -q -O /dev/null -S http://localhost:8080/some-server/test;
rc=$?;
done;
echo "Tomcat: STOPPED"
mv %{home}/%{warname} %{home}/%{warname}.`date +%Y%d%m`
rm -rf %{home}/some-server
echo done.
%post
CHECK_PAUSE=2;
echo -n "Starting tomcat";
sh %{binary}/startup.sh
rc=1
while [ "$rc" -ne 0 ]; do
sleep $CHECK_PAUSE
wget -q -O /dev/null -S http://localhost:8080/some-server/test
rc=$?
done
echo "Tomcat: STARTED"
%preun
if [ "$1" == "0" ]; then
#STOP TOMCAT HERE SAME WAY AS IN PRE
fi
%postun
if [ "$1" == "0" ]; then
#START TOMCAT HERE SAME WAY AS IN POST
fi
The scripts which are going to be executed in preun and postun sections are the same as in pre and post sections. But I don't want just copy/paste them. Is there some sophisticated solution to avoid code duplication here?