more intelligent way of uninstalling a RPM

Hi all,

I'm writing an uninstaller for a bespoke piece of software that we deploy to our Linux terminals.

One of the packages we install is the JDK (Java Development Kit). Now over the years we have quite a number of different versions installed with different package names. In my uninstaller I want to give the option to uninstall this package. The obvious way, but not very intelligent is just go through a nice long if/else loop of all the different package names it could be until it finds a match. It will work but it's not very intelligent and every time the package name changes I need to update my uninstaller.

So I guess I'm looking for a clever way to query the rpm database or some other way that will give me the package name of the JDK installed so I can just pass this to the rpm -e command.

If I do "rpm -aqi | grep Name" this is provides me with a basic list of every package name installed. I could go further and add "| java" on the end but this would only return results where the word java appeared in the Name line which it doesn't in all JDK distributions. I can use the rpm -q to query if the package exists but this relies on me knowing the package name in the first place.

Anyone got any good suggestions? I'm probably missing something blindingly obvious but I've had a good look through the man page for rpm and I can't see to find anything.

Thanks for any help.