Fixes for mac

This commit is contained in:
Christopher Schnick 2022-12-27 06:54:42 +01:00
parent 560efbd345
commit 5a8a23222c
8 changed files with 71 additions and 62 deletions

View file

@ -131,7 +131,7 @@ public final class XPipeApiConnection extends BeaconConnection {
}
private void start() throws Exception {
var installation = XPipeInstallation.getLocalDefaultInstallationBasePath();
var installation = XPipeInstallation.getLocalDefaultInstallationBasePath(true);
BeaconServer.start(installation);
}

View file

@ -19,7 +19,7 @@ public class BeaconDaemonController {
if ((process = BeaconServer.tryStartCustom()) != null) {
custom = true;
} else {
var defaultBase = XPipeInstallation.getLocalDefaultInstallationBasePath();
var defaultBase = XPipeInstallation.getLocalDefaultInstallationBasePath(true);
process = BeaconServer.start(defaultBase);
}

View file

@ -1,9 +1,7 @@
package io.xpipe.core.process;
import java.nio.file.Path;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
public interface OsType {
@ -34,10 +32,6 @@ public interface OsType {
}
}
Path getBaseInstallPath();
UUID getSystemUUID(ShellProcessControl pc) throws Exception;
static class Windows implements OsType {
@Override
@ -70,20 +64,6 @@ public interface OsType {
return properties.get("OS Name") + " "
+ properties.get("OS Version").split(" ")[0];
}
@Override
public Path getBaseInstallPath() {
return Path.of(System.getenv("LOCALAPPDATA"), "X-Pipe");
}
@Override
public UUID getSystemUUID(ShellProcessControl pc) throws Exception {
try (CommandProcessControl c = pc.command(
"reg query \"Computer\\\\HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Microsoft\\\\Cryptography\" /v MachineGuid")) {
var output = c.readOnlyStdout();
return null;
}
}
}
static class Linux implements OsType {
@ -110,16 +90,14 @@ public interface OsType {
@Override
public String determineOperatingSystemName(ShellProcessControl pc) throws Exception {
try (CommandProcessControl c =
pc.command("lsb_release -a").start()) {
try (CommandProcessControl c = pc.command("lsb_release -a").start()) {
var text = c.readOnlyStdout();
if (c.getExitCode() == 0) {
return PropertiesFormatsParser.parse(text, ":").getOrDefault("Description", null);
}
}
try (CommandProcessControl c =
pc.command("cat /etc/*release").start()) {
try (CommandProcessControl c = pc.command("cat /etc/*release").start()) {
var text = c.readOnlyStdout();
if (c.getExitCode() == 0) {
return PropertiesFormatsParser.parse(text, "=").getOrDefault("PRETTY_NAME", null);
@ -144,23 +122,13 @@ public interface OsType {
return type + " " + version;
}
@Override
public Path getBaseInstallPath() {
return Path.of("/opt/xpipe");
}
@Override
public UUID getSystemUUID(ShellProcessControl pc) throws Exception {
return null;
}
}
static class Mac implements OsType {
@Override
public String getTempDirectory(ShellProcessControl pc) throws Exception {
return pc.executeStringSimpleCommand(pc.getShellType().getPrintVariableCommand("TEMP"));
return pc.executeStringSimpleCommand(pc.getShellType().getPrintVariableCommand("TMPDIR"));
}
@Override
@ -175,22 +143,21 @@ public interface OsType {
@Override
public Map<String, String> getProperties(ShellProcessControl pc) throws Exception {
return null;
try (CommandProcessControl c =
pc.subShell(ShellTypes.BASH).command("sw_vers").start()) {
var text = c.readOrThrow();
return PropertiesFormatsParser.parse(text, ":");
}
}
@Override
public String determineOperatingSystemName(ShellProcessControl pc) throws Exception {
return null;
}
@Override
public Path getBaseInstallPath() {
return Path.of(System.getProperty("user.home"), "Application Support", "X-Pipe");
}
@Override
public UUID getSystemUUID(ShellProcessControl pc) throws Exception {
return null;
var properties = getProperties(pc);
var name = pc.executeStringSimpleCommand(
"awk '/SOFTWARE LICENSE AGREEMENT FOR macOS/' '/System/Library/CoreServices/Setup " +
"Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf' | " +
"awk -F 'macOS ' '{print $NF}' | awk '{print substr($0, 0, length($0)-1)}'");
return properties.get("ProductName") + " " + name + " " + properties.get("ProductVersion");
}
}
}

View file

@ -19,17 +19,20 @@ public class ShellTypes {
public static final ShellType CMD = new Cmd();
public static final ShellType SH = new Sh();
public static final ShellType BASH = new Bash();
public static final ShellType ZSH = new Zsh();
public static ShellType getPlatformDefault() {
if (OsType.getLocal().equals(OsType.WINDOWS)) {
return CMD;
} else {
} else if (OsType.getLocal().equals(OsType.LINUX)) {
return BASH;
} else {
return ZSH;
}
}
public static ShellType[] getAllShellTypes() {
return new ShellType[] {CMD, POWERSHELL, BASH, SH};
return new ShellType[] {CMD, POWERSHELL, ZSH, BASH, SH};
}
@JsonTypeName("cmd")
@ -328,7 +331,7 @@ public class ShellTypes {
@Override
public String createFileReadCommand(String file) {
return "cmd /c type \""+ file + "\"";
return "cmd /c type \"" + file + "\"";
}
@Override
@ -359,7 +362,8 @@ public class ShellTypes {
@Override
public Charset determineCharset(ShellProcessControl control) throws Exception {
var r = new BufferedReader(new InputStreamReader(control.getStdout(), StandardCharsets.US_ASCII));
control.writeLine("If (Get-Command -erroraction 'silentlycontinue' chcp) {chcp} Else {echo \"Not Windows\"}");
control.writeLine(
"If (Get-Command -erroraction 'silentlycontinue' chcp) {chcp} Else {echo \"Not Windows\"}");
// Read echo of command
r.readLine();
@ -583,4 +587,25 @@ public class ShellTypes {
return "bash";
}
}
@JsonTypeName("zsh")
@Value
@EqualsAndHashCode(callSuper = false)
public static class Zsh extends PosixBase {
@Override
public String getExecutable() {
return "/bin/zsh";
}
@Override
public String getDisplayName() {
return "/bin/zsh";
}
@Override
public String getName() {
return "zsh";
}
}
}

View file

@ -1,5 +1,6 @@
package io.xpipe.core.store;
import io.xpipe.core.charsetter.Charsetter;
import io.xpipe.core.impl.LocalStore;
import io.xpipe.core.process.ShellProcessControl;
import io.xpipe.core.process.ShellType;
@ -10,6 +11,12 @@ public interface ShellStore extends DataStore {
return new LocalStore();
}
static void withLocal(Charsetter.FailableConsumer<ShellProcessControl, Exception> c) throws Exception {
try (var l = local().create().start()) {
c.accept(l);
}
}
static boolean isLocal(ShellStore s) {
return s instanceof LocalStore;
}

View file

@ -70,7 +70,7 @@ public class Deobfuscator {
file.toString())
.redirectErrorStream(true);
var active = proc.start();
var out = new String(active.getInputStream().readAllBytes()).replaceAll("\\r\\n", NewLine.LF.getNewLineString());
var out = new String(active.getInputStream().readAllBytes()).replaceAll("\r\n", NewLine.LF.getNewLineString());
var code = active.waitFor();
if (code == 0) {
return out;

View file

@ -64,9 +64,9 @@ public class XPipeInstallation {
}
}
public static String getLocalDefaultInstallationBasePath() {
public static String getLocalDefaultInstallationBasePath(boolean acceptCustomHome) {
var customHome = System.getenv("XPIPE_HOME");
if (!customHome.isEmpty()) {
if (!customHome.isEmpty() && acceptCustomHome) {
return customHome;
}
@ -74,8 +74,10 @@ public class XPipeInstallation {
if (OsType.getLocal().equals(OsType.WINDOWS)) {
var base = System.getenv("LOCALAPPDATA");
path = FileNames.join(base, "X-Pipe");
} else {
} else if (OsType.getLocal().equals(OsType.LINUX)) {
path = "/opt/xpipe";
} else {
path = "~/Applications/X-Pipe.app";
}
return path;
@ -93,8 +95,10 @@ public class XPipeInstallation {
if (p.getOsType().equals(OsType.WINDOWS)) {
var base = p.executeStringSimpleCommand(p.getShellType().getPrintVariableCommand("LOCALAPPDATA"));
path = FileNames.join(base, "X-Pipe");
} else {
} else if (p.getOsType().equals(OsType.LINUX)) {
path = "/opt/xpipe";
} else {
path = "~/Applications/X-Pipe.app";
}
return path;
@ -103,24 +107,30 @@ public class XPipeInstallation {
public static String getDaemonDebugScriptPath(OsType type) {
if (type.equals(OsType.WINDOWS)) {
return FileNames.join("app", "scripts", "xpiped_debug.bat");
} else {
} else if (type.equals(OsType.LINUX)) {
return FileNames.join("app", "scripts", "xpiped_debug.sh");
} else {
return FileNames.join("Content", "scripts", "xpiped_debug.sh");
}
}
public static String getDaemonDebugAttachScriptPath(OsType type) {
if (type.equals(OsType.WINDOWS)) {
return FileNames.join("app", "scripts", "xpiped_debug_attach.bat");
} else {
} else if (type.equals(OsType.LINUX)) {
return FileNames.join("app", "scripts", "xpiped_debug_attach.sh");
} else {
return FileNames.join("Content", "scripts", "xpiped_debug_attach.sh");
}
}
public static String getDaemonExecutablePath(OsType type) {
if (type.equals(OsType.WINDOWS)) {
return FileNames.join("app", "xpiped.exe");
} else {
} else if (type.equals(OsType.LINUX)) {
return FileNames.join("app", "bin", "xpiped");
} else {
return FileNames.join("Content", "MacOS", "xpiped");
}
}
}

View file

@ -23,7 +23,7 @@ public class XPipeTempDirectory {
throw new IOException("Unable to access or create temporary directory " + dir);
}
if (proc.getOsType().equals(OsType.LINUX)) {
if (proc.getOsType().equals(OsType.LINUX) || proc.getOsType().equals(OsType.MAC)) {
proc.executeSimpleCommand("(chmod -f 777 \"" + dir + "\" || true)");
}