A.2. Dealing with upgrades

The fact that a package may be upgraded, and not simply installed or removed, makes the think a little bit tougher... The problem is that the %postun script of the update is run after the %post of the old version. So all %post stuff is lost...

The solution is brought by a parameter passed to each of the four scripts. That parameter is the number of packages with the same name that will normaly be present after total installation/upgrade.

Table A-1. Value of the parameter passed to pre and post scripts

Parameter \ Script%pre%post%preun%postun
for a first time install11N/CN/C
for an upgrade2222
for a removalN/CN/C00

This will allow the programmer to distinguish different attitudes of his scripts depending on the operation: install or upgrade.

A single test is therefore enough, to call the right action at the right time.