1
votes

RPM is taking care of installing older version and also same version scenario.

If I do update instead of installing new version when old is existing then it updates the package so no problem here.

But When I try to install a new version when an older version exists RPM installs the new version separately thus two versions will exist.

I would like to stop the new version installation when an older exists in my spec file by checking in %pre section. How can I know that rpm -ivh is called or rpm -Uvh is called in my spec file?

if [ "$1" = "1" ]; then
  echo Perform tasks to prepare for the initial installation
elif [ "$1" = "2" ]; then
  echo You already have old version Please use -U to upgrade. 
fi

"$1" = "2" true for both new installation when old is present and for upgrade.

Please let me know how to solve this.

3
Wouldn't it be better to do it in %post and then check that if they have installed it before, then you do the Upgrade tasks and if not - install tasks? - favoretti
how to achieve watever u r telling me to do in %post. Could u pls let me know specifically how to check and update or install the new if older exist - user1234
Well, same as what you posted. If you don't have an old version [ "$1" = "1" ], if you have [ "$1" = "2" ]... Same as in pre, but you don't check whether you have an upgrade or install in pre. It won't stop installing new version, but it will prevent from making any changes to configuration or whatnot. - favoretti

3 Answers

0
votes

From what I can see, you can't. Find some other way. For example trying to use -i when both already-existing and to-be-installed packages have conflicting files usually stops the installation.

0
votes

RPM will never install two versions of the same rpm packages that only differ in versions/releases (unless you have some old/buggy version). Now I will assume this is what you wanted:

I have rpm package that should do something a bit different after installation and after upgrade. For example install database on first install, but update it otherwise.

That would mean one of a few things:

  1. You are trying to upgrade automatically something that should be updated by the administrator and/or the program itself. Files generated by the program should not be touched by packages. Ever
  2. You should mark those files as %config in %files section and leave administrator to merge xxx.rpmnew files with the files edited by user

In other words rpms should only touch things it created itself, knows what they contain and can compare it with the database/other source or reliable information. This doesn't seem to be your case

0
votes

The correct answer is: yum _____ --nogpgchech

have a nice day!