I have created a new OSVersion class as shown below. This class has the variable "IS_REDHAT_LINUX_7" which returns true if the server is RHEL7.
Note :- The Osversion class which is provided as a part of izpack doesnot have the logic to check the version of RHEL and it can be used only to determine if the server is Rhel or not or other os.
public class OsVersion {
public final static String LINUX = "Linux";
public final static String REDHAT = "RedHat";
public final static String RED_HAT = "Red Hat";
public final static String OS_NAME = System.getProperty("os.name");
/**
* True if this is Linux.
*/
public static final boolean IS_LINUX = StringTool.startsWithIgnoreCase(OS_NAME, LINUX);
/**
* True if RedHat Linux was detected
*/
public static final boolean IS_REDHAT_LINUX = IS_LINUX && ((FileUtil.fileContains(getReleaseFileNamesList(), REDHAT)
|| FileUtil.fileContains(getReleaseFileNamesList(), RED_HAT)));
/**
* True if RHEL7 server.
*/
public static final boolean IS_REDHAT_LINUX_7 = IS_REDHAT_LINUX && ((getRedHatReleaseVersion() == 7));
/**
* True if RHEL6 server.
*/
public static final boolean IS_REDHAT_LINUX_6 = IS_REDHAT_LINUX && ((getRedHatReleaseVersion() == 6));
/**
* Gets the etc Release Filename
*
* @return name of the file the release info is stored in for Linux
* distributions
*/
private static String getReleaseFileName() {
String result = "";
File[] etcList = new File("/etc").listFiles();
if (etcList != null)
for (int idx = 0; idx < etcList.length; idx++) {
File etcEntry = etcList[idx];
if (etcEntry.isFile()) {
if (etcEntry.getName().endsWith("-release")) {
// match :-)
return result = etcEntry.toString();
}
}
}
return result;
}
/**
* Gets the list of etc Release Filenames
*
* @return name of the file the release info is stored in for Linux
* distributions
*/
private static List<String> getReleaseFileNamesList() {
List<String> result = new ArrayList<String>();
File[] etcList = new File("/etc").listFiles();
if (etcList != null)
for (int idx = 0; idx < etcList.length; idx++) {
File etcEntry = etcList[idx];
if (etcEntry.isFile()) {
if (etcEntry.getName().endsWith("redhat-release")) {
result.add(etcEntry.toString());
}
}
}
return result;
}
/**
* Gets the RedHat Release Version
*
* @return the major release version number
*/
private static Integer getRedHatReleaseVersion() {
String releaseDetails = "Red Hat Enterprise Linux Server release";
String relaseFile = getReleaseFileName();
BufferedReader br = null;
FileReader fr = null;
Integer redhatVersion = 0;
try {
fr = new FileReader(relaseFile);
br = new BufferedReader(fr);
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null) {
if (sCurrentLine.trim().startsWith(releaseDetails)) {
String s[] = sCurrentLine.split("release");
char version = s[1].trim().charAt(0);
redhatVersion = Character.getNumericValue(version);
}
}
} catch (IOException e) {
//Do Nothing.
} finally {
try {
if (br != null)
br.close();
if (fr != null)
fr.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return redhatVersion;
}
Moreover now you have to create a new condition as shown below :-
<condition type="java" id="IS_REDHAT_LINUX_7">
<java>
<class>OsVersion</class>
<field>IS_REDHAT_LINUX_7</field>
</java>
<returnvalue type="boolean">true</returnvalue>
</condition>
Now you can use this id="IS_REDHAT_LINUX_7" to perform actions specific to RHE7.