Scenario : There are 3 rpms A,B and C.
When we are installing rpm A we are installing rpm B and C as well.So first time installation is working fine.When we install a newer version of rpm A that's during upgradation we want to delete rpm B and C which were installed by previous rpm A.
Requirement : Before installing new rpm A, check if B and C are installed . If yes uninstall B and C.So that new rpm A can install new rpm B and C.
What we tried :
A's spec file %pre section:
%pre
if rpm -qa | grep B; then
rpm -e B;
fi
if rpm -qa | grep C; then
rpm -e C;
fi
We are using puppet. When we run puppet agent -t --debug, before installing rpm A it's getting hanged at below line!
Debug: Executing '/usr/bin/yum -d 0 -e 0 -y install A'
Any idea why we aren't able to uninstall those rpms?
Edit : Let me explain the proper scenario :
Its a legacy code where we are fixing an issue which happens during upgradation !
In puppet we have mentioned if we are installing rpm A, ensure rpm B and C are present.
Steps :
1. We upload rpm A,B and C to our puppet server.
2. Run puppet agent –t
in our puppet client.
3. It installs all the rpms
4. Rpm A’s .spec file : in %pre
section they are doing rm –rf /m/n/current
and in %install
section they are doing mkdir /m/n
and extracting contents of rpm A in this folder.
5. Rpm B’s .spec file : in %install
section they are doing mkdir /m/n/current/filesofBAndC
and and extracting a file from rpm B in this folder
6. Rpm C’s .spec file : in %install
section they are doing mkdir /m/n/current/filesofBAnd
C and and extracting a file from rpm C in this folder
7. Everything works fine in below scenarios
• First time installation
• Uninstalling rpm A and installing newer version of A (nothing but fresh installation)
• Upgrading A (there is version change in B and C )
8. Problem is if we are installing newer version of A(withough unistalling previous version of A) without any version change in rpm B and C, it’ll install only rpm A (since there are no version change in rpm B and C). During rpm A installation we are deleting folder /m/n/current which means our /m/n/current/filesofBAndC is also getting deleted.
Deletion of folder filesofBAndC is creating issue. So if we uninstall rpm B and C before installing rpm A, puppet will take care of installing those rpms again during installation of rpm A and/m/n/current/filesofBAndC
will be created again with the required files.
We should not modify the folder structure ( like /m/n/filesofBAndC
) due to some dependencies.
Because this isn't how you should be doing this and yum is transactional and the database is likely locked during the installation.
The way you do this is by listing the B and C RPMs on the Requires:
lines of your A
package's .spec
file so that yum handles this automatically for you when you ask it to install the A
package.
Additionally, if you have specific version requirements you can include those in the Requires
lines as well and yum
will check (and enforce those) for you.
You can, also, add Conflicts
entries which tell yum
that these two packages cannot be installed at the same time and Obsoletes
entries that tell yum
that this package replaces the other package and so it can be removed.
Do all that correctly and yum
just handles all this for you.