diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 35441b59f..382685019 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -234,16 +234,12 @@ pub fn is_installed_daemon(prompt: bool) -> bool { Err(e) => { log::error!("run osascript failed: {}", e); } - _ => { + Ok(status) if !status.success() => { + log::warn!("run osascript failed with status: {}", status); + } + Ok(_) => { let installed = std::path::Path::new(&agent_plist_file).exists(); log::info!("Agent file {} installed: {}", agent_plist_file, installed); - if installed { - log::info!("launch server"); - std::process::Command::new("launchctl") - .args(&["load", "-w", &agent_plist_file]) - .status() - .ok(); - } } } }); @@ -334,6 +330,16 @@ mod tests { || install.contains("launchctl kickstart -k user/$uid/$agent_label"), "install script must kickstart the agent after bootstrapping it", ); + assert!( + install.contains("quoted form of user"), + "install script must quote username-derived paths", + ); + assert!( + install.contains("test ! -f \"$user_preferences_dir/RustDesk.toml\" || cp -rf") + && install + .contains("test ! -f \"$user_preferences_dir/RustDesk2.toml\" || cp -rf"), + "install script must treat missing preference files as optional", + ); } } diff --git a/src/platform/privileges_scripts/install.scpt b/src/platform/privileges_scripts/install.scpt index 1ec34e345..efa4dbca0 100644 --- a/src/platform/privileges_scripts/install.scpt +++ b/src/platform/privileges_scripts/install.scpt @@ -6,17 +6,17 @@ on run {daemon_file, agent_file, user} set sh2 to "echo " & quoted form of agent_file & " > " & agent_plist & " && chown root:wheel " & agent_plist & ";" - set sh3 to "cp -rf /Users/" & user & "/Library/Preferences/com.carriez.RustDesk/RustDesk.toml /var/root/Library/Preferences/com.carriez.RustDesk/;" + set sh3 to "user_preferences_dir=/Users/" & quoted form of user & "/Library/Preferences/com.carriez.RustDesk; root_preferences_dir=/var/root/Library/Preferences/com.carriez.RustDesk; mkdir -p \"$root_preferences_dir\";" + set sh4 to "test ! -f \"$user_preferences_dir/RustDesk.toml\" || cp -rf \"$user_preferences_dir/RustDesk.toml\" \"$root_preferences_dir\";" + set sh5 to "test ! -f \"$user_preferences_dir/RustDesk2.toml\" || cp -rf \"$user_preferences_dir/RustDesk2.toml\" \"$root_preferences_dir\";" - set sh4 to "cp -rf /Users/" & user & "/Library/Preferences/com.carriez.RustDesk/RustDesk2.toml /var/root/Library/Preferences/com.carriez.RustDesk/;" + set sh6 to "uid=$(id -u " & quoted form of user & " 2>/dev/null || true);" + set sh7 to "launchctl load -w " & daemon_plist & ";" + set sh8 to "agent_label=$(basename " & quoted form of agent_plist & " .plist);" + set sh9 to "if [ -n \"$uid\" ]; then launchctl bootstrap gui/$uid " & quoted form of agent_plist & " 2>/dev/null || launchctl bootstrap user/$uid " & quoted form of agent_plist & " 2>/dev/null || launchctl load -w " & quoted form of agent_plist & " || true; else launchctl load -w " & quoted form of agent_plist & " || true; fi;" + set sh10 to "if [ -n \"$uid\" ]; then launchctl kickstart -k gui/$uid/$agent_label 2>/dev/null || launchctl kickstart -k user/$uid/$agent_label 2>/dev/null || true; fi;" - set sh5 to "uid=$(id -u " & quoted form of user & " 2>/dev/null || true);" - set sh6 to "launchctl load -w " & daemon_plist & ";" - set sh7 to "agent_label=$(basename " & quoted form of agent_plist & " .plist);" - set sh8 to "if [ -n \"$uid\" ]; then launchctl bootstrap gui/$uid " & quoted form of agent_plist & " 2>/dev/null || launchctl bootstrap user/$uid " & quoted form of agent_plist & " 2>/dev/null || launchctl load -w " & quoted form of agent_plist & " || true; else launchctl load -w " & quoted form of agent_plist & " || true; fi;" - set sh9 to "if [ -n \"$uid\" ]; then launchctl kickstart -k gui/$uid/$agent_label 2>/dev/null || launchctl kickstart -k user/$uid/$agent_label 2>/dev/null || true; fi;" - - set sh to "set -e;" & sh1 & sh2 & sh3 & sh4 & sh5 & sh6 & sh7 & sh8 & sh9 + set sh to "set -e;" & sh1 & sh2 & sh3 & sh4 & sh5 & sh6 & sh7 & sh8 & sh9 & sh10 do shell script sh with prompt "RustDesk wants to install daemon and agent" with administrator privileges end run