Cache getInfo for linux/unix
This commit is contained in:
parent
a5d7a7293e
commit
3ab5076d9b
@ -216,6 +216,7 @@ class OSUtil {
|
|||||||
List<File> releaseFiles = new LinkedList<File>();
|
List<File> releaseFiles = new LinkedList<File>();
|
||||||
int totalLength = 0;
|
int totalLength = 0;
|
||||||
|
|
||||||
|
// looking for files like /etc/os-release
|
||||||
File file = new File("/etc");
|
File file = new File("/etc");
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
File[] list = file.listFiles();
|
File[] list = file.listFiles();
|
||||||
@ -292,17 +293,19 @@ class OSUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id the info ID to check, ie: ubuntu, arch, debian, etc... This is what the OS vendor uses to ID their OS.
|
* @param id the info ID to check, ie: ubuntu, arch, debian, etc... This is what the OS vendor uses to ID their OS.
|
||||||
*
|
|
||||||
* @return true if this OS is identified as the specified ID.
|
* @return true if this OS is identified as the specified ID.
|
||||||
*/
|
*/
|
||||||
|
private static String info = null;
|
||||||
public static
|
public static
|
||||||
boolean getInfo(String id) {
|
boolean getInfo(String id) {
|
||||||
String output = getInfo();
|
if (info == null) {
|
||||||
|
info = getInfo();
|
||||||
|
}
|
||||||
// ID=linuxmint/fedora/arch/ubuntu/etc
|
// ID=linuxmint/fedora/arch/ubuntu/etc
|
||||||
return output.contains("ID=" + id +"\n");
|
return info.contains("ID=" + id +"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static volatile Boolean isArch = null;
|
private static Boolean isArch = null;
|
||||||
public static
|
public static
|
||||||
boolean isArch() {
|
boolean isArch() {
|
||||||
if (isArch == null) {
|
if (isArch == null) {
|
||||||
@ -311,7 +314,7 @@ class OSUtil {
|
|||||||
return isArch;
|
return isArch;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static volatile Boolean isDebian = null;
|
private static Boolean isDebian = null;
|
||||||
public static
|
public static
|
||||||
boolean isDebian() {
|
boolean isDebian() {
|
||||||
if (isDebian == null) {
|
if (isDebian == null) {
|
||||||
@ -320,7 +323,7 @@ class OSUtil {
|
|||||||
return isDebian;
|
return isDebian;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static volatile Boolean isElementaryOS = null;
|
private static Boolean isElementaryOS = null;
|
||||||
public static
|
public static
|
||||||
boolean isElementaryOS() {
|
boolean isElementaryOS() {
|
||||||
if (isElementaryOS == null) {
|
if (isElementaryOS == null) {
|
||||||
@ -338,7 +341,7 @@ class OSUtil {
|
|||||||
return isElementaryOS;
|
return isElementaryOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static volatile Boolean isFedora = null;
|
private static Boolean isFedora = null;
|
||||||
public static
|
public static
|
||||||
boolean isFedora() {
|
boolean isFedora() {
|
||||||
if (isFedora == null) {
|
if (isFedora == null) {
|
||||||
@ -347,7 +350,7 @@ class OSUtil {
|
|||||||
return isFedora;
|
return isFedora;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static volatile Boolean isLinuxMint = null;
|
private static Boolean isLinuxMint = null;
|
||||||
public static
|
public static
|
||||||
boolean isLinuxMint() {
|
boolean isLinuxMint() {
|
||||||
if (isLinuxMint == null) {
|
if (isLinuxMint == null) {
|
||||||
@ -356,7 +359,7 @@ class OSUtil {
|
|||||||
return isLinuxMint;
|
return isLinuxMint;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static volatile Boolean isUbuntu = null;
|
private static Boolean isUbuntu = null;
|
||||||
public static
|
public static
|
||||||
boolean isUbuntu() {
|
boolean isUbuntu() {
|
||||||
if (isUbuntu == null) {
|
if (isUbuntu == null) {
|
||||||
@ -365,6 +368,15 @@ class OSUtil {
|
|||||||
return isUbuntu;
|
return isUbuntu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Boolean isKali = null;
|
||||||
|
public static
|
||||||
|
boolean isKali() {
|
||||||
|
if (isKali == null) {
|
||||||
|
isKali = getInfo("kali");
|
||||||
|
}
|
||||||
|
return isKali;
|
||||||
|
}
|
||||||
|
|
||||||
public static
|
public static
|
||||||
boolean isRoot() {
|
boolean isRoot() {
|
||||||
// this means we are running as sudo
|
// this means we are running as sudo
|
||||||
|
Loading…
Reference in New Issue
Block a user