Continued rework of networking, added root check

This commit is contained in:
Banks Troutman
2019-10-06 17:26:17 -04:00
parent 7699766091
commit 3db2f30ea7
18 changed files with 607 additions and 234 deletions

View File

@@ -1,10 +1,14 @@
package com.chameleonvision.settings;
import com.chameleonvision.util.ShellExec;
import java.io.IOException;
public enum Platform {
WINDOWS_64("Windows x64"),
LINUX_64("Linux x64"),
LINUX_RASPBIAN("Linux Raspbian"),
LINUX_AARCH64("Linux ARM 64bit"),
LINUX_AARCH64("Linux For Tegra"),
MACOS_64("Mac OS x64"),
UNSUPPORTED("Unsupported Platform");
@@ -26,6 +30,29 @@ public enum Platform {
return this == MACOS_64;
}
private static ShellExec shell = new ShellExec(true, false);
public boolean isRoot() {
if (isLinux() || isMac()) {
try {
shell.execute("id", null, true, "-u");
} catch (IOException e) {
e.printStackTrace();
}
while (!shell.isOutputCompleted()) {}
if (shell.getExitCode() == 0) {
var out = shell.getOutput();
out = out.split("\n")[0];
return out.equals("0");
}
} else if (isWindows()) {
return true;
} else {
return true;
}
return false;
}
public static Platform getCurrentPlatform() {
var osName = System.getProperty("os.name");
var osArch = System.getProperty("os.arch");