From 3be6f702729d819b3d5499e3486ad4f2bac08328 Mon Sep 17 00:00:00 2001 From: crschnick Date: Tue, 19 Nov 2024 10:15:11 +0000 Subject: [PATCH] Improvements for proxmox connections --- .../java/io/xpipe/app/issue/SentryErrorHandler.java | 2 +- .../main/java/io/xpipe/app/util/CommandSupport.java | 10 ++++++++++ .../main/java/io/xpipe/core/process/ShellControl.java | 8 ++++++++ .../java/io/xpipe/core/process}/StubShellControl.java | 4 +--- .../io/xpipe/core/process}/WrapperShellControl.java | 3 +-- 5 files changed, 21 insertions(+), 6 deletions(-) rename {app/src/main/java/io/xpipe/app/ext => core/src/main/java/io/xpipe/core/process}/StubShellControl.java (74%) rename {app/src/main/java/io/xpipe/app/ext => core/src/main/java/io/xpipe/core/process}/WrapperShellControl.java (99%) diff --git a/app/src/main/java/io/xpipe/app/issue/SentryErrorHandler.java b/app/src/main/java/io/xpipe/app/issue/SentryErrorHandler.java index 638235d2f..db30c2dfe 100644 --- a/app/src/main/java/io/xpipe/app/issue/SentryErrorHandler.java +++ b/app/src/main/java/io/xpipe/app/issue/SentryErrorHandler.java @@ -199,7 +199,7 @@ public class SentryErrorHandler implements ErrorHandler { options.setProguardUuid(AppProperties.get().getBuildUuid().toString()); options.setTag("os", System.getProperty("os.name")); options.setTag("osVersion", System.getProperty("os.version")); - options.setTag("arch", System.getProperty("os.arch")); + options.setTag("arch", AppProperties.get().getArch()); options.setDist(XPipeDistributionType.get().getId()); options.setTag("staging", String.valueOf(AppProperties.get().isStaging())); options.setSendModules(false); diff --git a/app/src/main/java/io/xpipe/app/util/CommandSupport.java b/app/src/main/java/io/xpipe/app/util/CommandSupport.java index 21107dbea..15de5b5ba 100644 --- a/app/src/main/java/io/xpipe/app/util/CommandSupport.java +++ b/app/src/main/java/io/xpipe/app/util/CommandSupport.java @@ -2,6 +2,7 @@ package io.xpipe.app.util; import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.storage.DataStoreEntry; +import io.xpipe.core.process.OsType; import io.xpipe.core.process.ShellControl; import io.xpipe.core.util.FailableSupplier; @@ -10,6 +11,15 @@ import java.util.Optional; public class CommandSupport { + public static boolean isRoot(ShellControl shellControl) throws Exception { + if (shellControl.getOsType() == OsType.WINDOWS) { + return false; + } + + var isRoot = shellControl.executeSimpleBooleanCommand("test \"${EUID:-$(id -u)}\" -eq 0"); + return isRoot; + } + public static Optional findProgram(ShellControl processControl, String name) throws Exception { var out = processControl .command(processControl.getShellDialect().getWhichCommand(name)) diff --git a/core/src/main/java/io/xpipe/core/process/ShellControl.java b/core/src/main/java/io/xpipe/core/process/ShellControl.java index 948ed80df..e2bbebf3d 100644 --- a/core/src/main/java/io/xpipe/core/process/ShellControl.java +++ b/core/src/main/java/io/xpipe/core/process/ShellControl.java @@ -199,6 +199,14 @@ public interface ShellControl extends ProcessControl { return sc; } + default ShellControl elevateIfNeeded(ElevationFunction function) throws Exception { + if (function.apply(this)) { + return identicalSubShell().elevated(ElevationFunction.elevated(function.getPrefix())); + } else { + return new StubShellControl(this); + } + } + default T enforceDialect(@NonNull ShellDialect type, FailableFunction sc) throws Exception { if (isRunning() && getShellDialect().equals(type)) { diff --git a/app/src/main/java/io/xpipe/app/ext/StubShellControl.java b/core/src/main/java/io/xpipe/core/process/StubShellControl.java similarity index 74% rename from app/src/main/java/io/xpipe/app/ext/StubShellControl.java rename to core/src/main/java/io/xpipe/core/process/StubShellControl.java index 65bf18a2a..bcbf2fb69 100644 --- a/app/src/main/java/io/xpipe/app/ext/StubShellControl.java +++ b/core/src/main/java/io/xpipe/core/process/StubShellControl.java @@ -1,6 +1,4 @@ -package io.xpipe.app.ext; - -import io.xpipe.core.process.ShellControl; +package io.xpipe.core.process; public class StubShellControl extends WrapperShellControl { diff --git a/app/src/main/java/io/xpipe/app/ext/WrapperShellControl.java b/core/src/main/java/io/xpipe/core/process/WrapperShellControl.java similarity index 99% rename from app/src/main/java/io/xpipe/app/ext/WrapperShellControl.java rename to core/src/main/java/io/xpipe/core/process/WrapperShellControl.java index 5d56d5601..7b54eaf91 100644 --- a/app/src/main/java/io/xpipe/app/ext/WrapperShellControl.java +++ b/core/src/main/java/io/xpipe/core/process/WrapperShellControl.java @@ -1,6 +1,5 @@ -package io.xpipe.app.ext; +package io.xpipe.core.process; -import io.xpipe.core.process.*; import io.xpipe.core.store.DataStore; import io.xpipe.core.store.FilePath; import io.xpipe.core.util.FailableConsumer;