Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
fix: use sudo when pkexec not found
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzgydi committed Aug 12, 2023
1 parent 241b22a commit 38a9a92
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src-tauri/src/core/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,19 @@ pub fn grant_permission(core: String) -> anyhow::Result<()> {
let output = {
let path = path.replace(' ', "\\ "); // 避免路径中有空格
let shell = format!("setcap cap_net_bind_service,cap_net_admin=+ep {path}");
Command::new("pkexec")
.arg("sh")
.arg("-c")
.arg(shell)
.output()?

let sudo = match Command::new("which").arg("pkexec").output() {
Ok(output) => {
if output.stdout.is_empty() {
"sudo"
} else {
"pkexec"
}
}
Err(_) => "sudo",
};

Command::new(sudo).arg("sh").arg("-c").arg(shell).output()?
};

if output.status.success() {
Expand Down

0 comments on commit 38a9a92

Please sign in to comment.