Reputation: 1030
In %post, I am running few tests that will validate the rpm installation. But If tests got failed or post script failed, How can I revert the rpm installation ?
Upvotes: 4
Views: 3626
Reputation: 288
This is the hack I used in %post
to roll-back:
if [ ! -d %{basedeploymentpath} ]; then
echo "ERROR: %{basedeploymentpath} does not exist or is inaccessible. I will uninstall myself."
rpm -ev ${APP_NAME} &
exit 1
fi
In the above snippet, if variable %{basedeploymentpath}
, which represents a directory, is not found, then call rpm -ev
on the name of the package, using the &
to fork the process. The %post
script exits with code 1
upon the condition mentioned.
If the install process is then run at the command line (rpm -ivh
) and the error condition exists at post-install, this result will appear: warning: %post(...) scriptlet failed, exit status 1
It is an ugly hack but it works. NOTE: the exit status of the rpm -ivh
command will still appear as successful (exit 0
) if you execute echo $?
after running the rpm -ivh
operation.
Upvotes: 0
Reputation: 80921
You can't really and you shouldn't.
You should be asserting everything you possibly can via `Requires: lines in your spec file to prevent you from even getting that far.
%post
is much too late to abort. All your files have already been put on disk/etc.
You can disable yourself so you don't run but that's about it.
If these are things that you really can't allow to fail then the best you can do is test during %pre
and abort there (but even that is evil).
Upvotes: 2