I noticed a likely error in one of the scriptlets in an OSCAR rpm.
Note,
additional RPMs may also have this error, but I didn't perform an
exhaustive search. The sequence of calling these scripts can be a
little
surprising at first, leading to the error.
To demonstrate, I built two test RPMs:
$ ls /usr/src/redhat/RPMS/noarch/tscript-1.2.3-*
/usr/src/redhat/RPMS/noarch/tscript-1.2.3-4.noarch.rpm
/usr/src/redhat/RPMS/noarch/tscript-1.2.3-5.noarch.rpm
They're identical, except for the release number. More importantly,
they
have the following scriptlets:
$ tail -16 /usr/src/redhat/SPECS/tscript.spec
%pre
echo pre %{name}-%{version}-%{release} $1
%post
echo post %{name}-%{version}-%{release} $1
%preun
echo preun %{name}-%{version}-%{release} $1
%postun
echo postun %{name}-%{version}-%{release} $1
As you can see, the scriptlets just identify themselves and display the
first argument they're passed. According to the docs (see below), the
argument's value "holds a count of the number of versions of the package
that are installed." The specific values are as follows:
Case Value
Install, no version currently installed 1
Upgrade, with later version or forced install
of same version >1
Erase of last version currently installed 0
You *NEED* to use this value if you want to modify files or take actions
that aren't idempotent. Here's an example showing a first install:
# rpm -ihv RPMS/noarch/tscript-1.2.3-4.noarch.rpm
Preparing... #######################################
[100%]
pre tscript-1.2.3-4 1
1:tscript #######################################
[100%]
post tscript-1.2.3-4 1
#
OK, so that was obvious enough. But, look at an upgrade:
# rpm -Uhv RPMS/noarch/tscript-1.2.3-5.noarch.rpm
Preparing... #######################################
[100%]
pre tscript-1.2.3-5 2
1:tscript #######################################
[100%]
post tscript-1.2.3-5 2
preun tscript-1.2.3-4 1
postun tscript-1.2.3-4 1
#
Notice that the pre and post scripts for the -5 version ran *BEFORE* the
preun and postun scripts of the -4 version? That is, the new version is
installed before the old version is deleted. This means that a post
script
that adds lines to a file could be wiped out by the postun script that
removes the lines from the file.
The "erase last version" operation is as expected:
# rpm --erase tscript
preun tscript-1.2.3-5 0
postun tscript-1.2.3-5 0
#
Don't forget, however, it's entirely possible to have multiple versions
(and
even multiple copies of the same version) of an RPM installed, which is
why
the "--allmatches" option exists for "rpm --erase"
So, how do you handle the upgrade problem preun and postun scripts?
Here's
an example:
%preun
if [[ $1 -eq 0 ]] ; then
do pre-stuff when deleting last copy
elif [[ $1 -ge 1 ]] ; then
do pre-stuff when UPGRADING to a newer version
Note, this runs during the erase of the OLDER version,
which happens AFTER the newer version was installed.
fi
%postun
if [[ $1 -eq 0 ]] ; then
do post-stuff when deleting last copy
elif [[ $1 -ge 1 ]] ; then
do post-stuff when UPGRADING to a newer version
Note, this runs during the erase of the OLDER version
which happens AFTER the newer version was installed.
fi
For reasonably accurate RPM documentation, see
Foster-Johnson, Eric, "Red Hat(R) RPM Guide", redhat(r) press(tm),
2003, Wiley Publishing, ISBN: 0-7645-4965-0
--
David N. Lombard
My comments represent my opinions, not those of Intel Corporation.
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id149&alloc_id�66&op=click
_______________________________________________
Oscar-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/oscar-devel