RPM upgrade uninstalls the RPM

Vidya picture Vidya · Sep 13, 2011 · Viewed 23.1k times · Source

I am upgrading our project RPM. The problem is when I upgrade from projectname-1.0-0 to projectname-1.0-1, it first installs the new project and uninstalls the old project, which, in overall view, removes my project entirely. I have used "vv" option while upgrading and the output showed the uninstallation is done after installation.

Somebody please help with this problem. Is there anything I should change specifically in the RPM spec or rpmbuild options?

Answer

Christian picture Christian · Nov 9, 2011

Yes, when an RPM upgrade occurs, RPM first installs the new version of the package and then uninstalls the old version of the package. Only the files of the old package are removed. But your scripts (i.e. %pre, %post, %preun, %postun) need to know whether they are handling an upgrade or just a plain install or uninstall.

The rpm command will pass one argument to your scripts, that is, $1, which is a count of the number of versions of the package that are installed. The table below (from the RedHat RPM Guide by Eric Foster-Johnston) provides a sample of possible values.

Install the first time:          1
Upgrade:                         2 or higher 
                                 (depending on the number of versions installed)
Remove last version of package:  0

So, in your %preun, you probably want to check if "$1 = 0" before removing any services.

For more information (and a better table) see: http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch09s04s05.html