-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7398 from alvasw/updater_Implement_pkexec_executor
updater: Implement pkexec executor
- Loading branch information
Showing
6 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ plugins { | |
dependencies { | ||
constraints { | ||
api libs.protobuf.java | ||
api libs.slf4j.api | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
11 changes: 11 additions & 0 deletions
11
updater/src/main/java/bisq/updater/InstallationFailedException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
updater/src/main/java/bisq/updater/linux/pkexec/PkExec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
updater/src/main/java/bisq/updater/linux/pkexec/PkexecAuthorizationFailedException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package bisq.updater.linux.pkexec; | ||
|
||
public class PkexecAuthorizationFailedException extends RuntimeException { | ||
public PkexecAuthorizationFailedException(String message) { | ||
super(message); | ||
} | ||
} |