From 38a9a9240df0aad888a1764b7b407fa929e5378c Mon Sep 17 00:00:00 2001 From: GyDi Date: Sat, 12 Aug 2023 15:58:37 +0800 Subject: [PATCH] fix: use sudo when pkexec not found --- src-tauri/src/core/manager.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/core/manager.rs b/src-tauri/src/core/manager.rs index d15e6f5..fdb9269 100644 --- a/src-tauri/src/core/manager.rs +++ b/src-tauri/src/core/manager.rs @@ -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() {