Skip to content
Snippets Groups Projects
Unverified Commit 38a9a924 authored by GyDi's avatar GyDi
Browse files

fix: use sudo when pkexec not found

parent 241b22a4
No related branches found
No related tags found
No related merge requests found
...@@ -28,11 +28,19 @@ pub fn grant_permission(core: String) -> anyhow::Result<()> { ...@@ -28,11 +28,19 @@ pub fn grant_permission(core: String) -> anyhow::Result<()> {
let output = { let output = {
let path = path.replace(' ', "\\ "); // 避免路径中有空格 let path = path.replace(' ', "\\ "); // 避免路径中有空格
let shell = format!("setcap cap_net_bind_service,cap_net_admin=+ep {path}"); let shell = format!("setcap cap_net_bind_service,cap_net_admin=+ep {path}");
Command::new("pkexec")
.arg("sh") let sudo = match Command::new("which").arg("pkexec").output() {
.arg("-c") Ok(output) => {
.arg(shell) if output.stdout.is_empty() {
.output()? "sudo"
} else {
"pkexec"
}
}
Err(_) => "sudo",
};
Command::new(sudo).arg("sh").arg("-c").arg(shell).output()?
}; };
if output.status.success() { if output.status.success() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment