I was pointed to the following:

When the rpm command executes the scriptlets in a package it indicates if
the action preformed is an install, erase, upgrade or reinstall by passing
an integer argument to the script in question according to the following:
          install   erase   upgrade  reinstall
%pre         1        -         2         2
%post        1        -         2         2
%preun       -        0         1         -
%postun      -        0         1         -

This means that for example a package that installs an init script with
the chkconfig command should uninstall it only on erase and not upgrade with
the following snippet:

%preun
if [ $1 -eq 0 ] ; then
/sbin/chkconfig --del %{name}
fi

https://fedoraproject.org/wiki/Packaging:Guidelines#Scriptlets

Although I found I had to do:

if [ $1 -eq 0 ]; then   \
   groupdel ....;       \
fi

On 10/14/10 11:57 AM, "Rich Smrcina" <[email protected]> wrote:

>   While %postun is running do you have any context of the rpm command line
> options?
> 
> On 10/14/2010 10:34 AM, Neale Ferguson wrote:
>> I have built an RPM that during installation needs to add an entry to
>> /etc/passwd and /etc/group. This is easy to do using the %pre section:
>> 
>> %pre
>> egrep -q "^njeanon" /etc/group;                         \
>> if [ $? != 0  ]; then                                   \
>>      groupadd nje 2>/dev/null;                           \
>>      groupadd njeanon 2>/dev/null;                       \
>>      useradd njeanon -g njeanon;                         \
>> fi
>> 
>> Similarly, when the RPM is being uninstalled I need to get rid of those
>> entries. Again, easily done with %postun:
>> 
>> %postun
>> rm -rf %{nobodyhome}
>> userdel njeanon 2>/dev/null
>> groupdel njeanon 2>/dev/null
>> groupdel nje 2>/dev/null
>> 
>> However, if I am upgrading using -Uhv then I get the %pre and %postun
>> sections run as part of the upgrade. This means that the work done in %pre
>> gets undone by %postun. If I was simply doing a rpm --erase I would be
>> satisfied but doing -U then this is not what I want.
>> 
>> So my question is, how do I prevent -Uhv undoing the %pre work (to be
>> pedantique if it's doing an upgrade then the groupadds aren't issued because
>> the check tells me the entries are already there).
>> 
>> Neale
>> 
>> ----------------------------------------------------------------------
>> For LINUX-390 subscribe / signoff / archive access instructions,
>> send email to [email protected] with the message: INFO LINUX-390 or
>> visit
>> http://www.marist.edu/htbin/wlvindex?LINUX-390
>> ----------------------------------------------------------------------
>> For more information on Linux on System z, visit
>> http://wiki.linuxvm.org/
>> 
>> 
> 
> 
> --
> Rich Smrcina
> Velocity Software, Inc.
> Mobile: 414-491-6001
> Office: 262-392-3717
> http://www.velocitysoftware.com
> 
> Catch the WAVV! http://www.wavv.org
> WAVV 2011 - April 15-19, 2011 Colorado Springs, CO
> 
> ----------------------------------------------------------------------
> For LINUX-390 subscribe / signoff / archive access instructions,
> send email to [email protected] with the message: INFO LINUX-390 or visit
> http://www.marist.edu/htbin/wlvindex?LINUX-390
> ----------------------------------------------------------------------
> For more information on Linux on System z, visit
> http://wiki.linuxvm.org/
> 

----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
----------------------------------------------------------------------
For more information on Linux on System z, visit
http://wiki.linuxvm.org/

Reply via email to