Situation: We have to make sure certain RHEL servers have certain versions
of Java. Java version is currently specified as the version field in the RPM file
name from Oracle. However the version that the RPM feeds to the RPM database
(when installed) is different!
Example
------------
File: jdk-7u45-linux.x64.rpm
"rpm -qa" shows: jdk-1.7.0_60_fcs (First Customer Shipment, basically version 1.0 of that version)
This breaks CFEngine's packages promises and Standard Library because version
identifiers differ between the RPM-on-disk and the RPM-after-installation.
I see two possible solutions:
1. Use a two-part approach: check RPM database and install if needed.
2. Write my a custom package_method body just for Java on RHEL.
Might need several (since we have several package_method for RHEL).
Gah.
Any ideas? I'm sure I'm not the first OR the last to run into this issue.
Right now I'm inclined to go with 1 since I have it already.
Data:
Existing code base uses shell script to detect if JDK RPM is installed, so I started
out by eplacing it with native CFEngine code.
I tear filename-based version string apart using regextract() and put it back together
as the RPM-database-based version string.
There is no easy way to check if a package is installed using packages promises IIRC.
used returnszero(/bin/rpm -q jdk-ver).
{{{
bundle agent java(java_version) # e.g. 7u45-linux
{
############################################################################
# Part I - check if the package is installed
############################################################################
classes:
"ok" expression => regextract(
"^([\d]+)u([\d]+).*$", # number(s), u, number(s)
$(java_version),
"backrefs"
);
ok::
"got_it"
expression => returnszero ("/bin/rpm --quiet -q jdk-1.$(backrefs[1]).0_$(backrefs[2])", noshell);
reports:
got_it::
"detected $(java_version)";
###########################################################################
# Part II - ensure the package is installed
###########################################################################
packages:
!got_it::
"jdk"
package_policy => "addupdate",
package_method => rpm_version("/repo"),
package_select => "==",
package_version => "1.$(backrefs[1]).0_$(backrefs[2]",
package_architectures => { "x64" }; # kernel is x86_64 but JDK RPM has x64 in the file name (or i586 for 32-bit)
}
}}}
Gah!
Best,
-at
--