From 3bb96756ca378ecff640014c069564dd84839f31 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Tue, 18 Feb 2025 21:46:31 +0000 Subject: [PATCH 1/3] Add Slf4j constraint to platform --- platform/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/build.gradle b/platform/build.gradle index 5036fd8e6a..56008f3448 100644 --- a/platform/build.gradle +++ b/platform/build.gradle @@ -5,5 +5,6 @@ plugins { dependencies { constraints { api libs.protobuf.java + api libs.slf4j.api } } From 4318c1ec147bc50cf3285f609349ef615e838cd9 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Tue, 18 Feb 2025 21:46:31 +0000 Subject: [PATCH 2/3] Create updater module --- settings.gradle | 2 ++ updater/build.gradle | 12 ++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 updater/build.gradle diff --git a/settings.gradle b/settings.gradle index cadfe73422..ae5573c6bb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -36,6 +36,8 @@ include 'statsnode' include 'apitest' include 'platform' include 'code-coverage-report' +include 'updater' + includeBuild 'bitcoind' rootProject.name = 'bisq' diff --git a/updater/build.gradle b/updater/build.gradle new file mode 100644 index 0000000000..94b783bbe5 --- /dev/null +++ b/updater/build.gradle @@ -0,0 +1,12 @@ +plugins { + id 'bisq.java-conventions' + id 'java-library' +} + +dependencies { + implementation enforcedPlatform(project(':platform')) + annotationProcessor libs.lombok + compileOnly libs.lombok + implementation libs.logback.classic + implementation libs.logback.core +} From 599f49dcecaea2d7fba846402267dd27c6a8701c Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Tue, 18 Feb 2025 21:46:32 +0000 Subject: [PATCH 3/3] updater: Implement pkexec executor --- .../updater/InstallationFailedException.java | 11 +++++ .../bisq/updater/linux/pkexec/PkExec.java | 49 +++++++++++++++++++ .../PkexecAuthorizationFailedException.java | 7 +++ 3 files changed, 67 insertions(+) create mode 100644 updater/src/main/java/bisq/updater/InstallationFailedException.java create mode 100644 updater/src/main/java/bisq/updater/linux/pkexec/PkExec.java create mode 100644 updater/src/main/java/bisq/updater/linux/pkexec/PkexecAuthorizationFailedException.java diff --git a/updater/src/main/java/bisq/updater/InstallationFailedException.java b/updater/src/main/java/bisq/updater/InstallationFailedException.java new file mode 100644 index 0000000000..ada4ff2d7e --- /dev/null +++ b/updater/src/main/java/bisq/updater/InstallationFailedException.java @@ -0,0 +1,11 @@ +package bisq.updater; + +public class InstallationFailedException extends RuntimeException { + public InstallationFailedException(String message) { + super(message); + } + + public InstallationFailedException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/updater/src/main/java/bisq/updater/linux/pkexec/PkExec.java b/updater/src/main/java/bisq/updater/linux/pkexec/PkExec.java new file mode 100644 index 0000000000..fbd2738862 --- /dev/null +++ b/updater/src/main/java/bisq/updater/linux/pkexec/PkExec.java @@ -0,0 +1,49 @@ +package bisq.updater.linux.pkexec; + +import java.io.IOException; + +import java.util.List; +import java.util.concurrent.TimeUnit; + + +import lombok.extern.slf4j.Slf4j; + + + +import bisq.updater.InstallationFailedException; + +@Slf4j +public class PkExec { + public static final int AUTHORIZATION_FAILED = 127; + private static final int AUTHORIZATION_DIALOG_DISMISSED = 126; + + public static Process run(List args) { + try { + var processBuilder = new ProcessBuilder("pkexec"); + processBuilder.command().addAll(args); + + Process process = processBuilder + .redirectErrorStream(true) + .redirectOutput(ProcessBuilder.Redirect.DISCARD) + .start(); + + boolean isSuccess = process.waitFor(2, TimeUnit.MINUTES); + if (!isSuccess) { + throw new InstallationFailedException(processBuilder.command() + " didn't finish after 2 minutes."); + } + + int exitCode = process.exitValue(); + switch (exitCode) { + case AUTHORIZATION_FAILED: + throw new PkexecAuthorizationFailedException("Couldn't get authorization from user."); + case AUTHORIZATION_DIALOG_DISMISSED: + throw new PkexecAuthorizationFailedException("User dismissed authorization dialog."); + } + + return process; + + } catch (IOException | InterruptedException e) { + throw new InstallationFailedException("Installation failed.", e); + } + } +} diff --git a/updater/src/main/java/bisq/updater/linux/pkexec/PkexecAuthorizationFailedException.java b/updater/src/main/java/bisq/updater/linux/pkexec/PkexecAuthorizationFailedException.java new file mode 100644 index 0000000000..0a6bc27283 --- /dev/null +++ b/updater/src/main/java/bisq/updater/linux/pkexec/PkexecAuthorizationFailedException.java @@ -0,0 +1,7 @@ +package bisq.updater.linux.pkexec; + +public class PkexecAuthorizationFailedException extends RuntimeException { + public PkexecAuthorizationFailedException(String message) { + super(message); + } +}