updater: Implement pkexec executor

This commit is contained in:
Alva Swanson 2025-02-18 21:46:32 +00:00
parent 4318c1ec14
commit 599f49dcec
No known key found for this signature in database
GPG key ID: 004760E77F753090
3 changed files with 67 additions and 0 deletions

View file

@ -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);
}
}

View file

@ -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<String> 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);
}
}
}

View file

@ -0,0 +1,7 @@
package bisq.updater.linux.pkexec;
public class PkexecAuthorizationFailedException extends RuntimeException {
public PkexecAuthorizationFailedException(String message) {
super(message);
}
}