fix: bootstrap install LaunchAgent in user session
Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
This commit is contained in:
parent
e0427bdc77
commit
ed182b8b54
2 changed files with 35 additions and 4 deletions
|
|
@ -312,6 +312,31 @@ fn correct_app_name(s: &str) -> String {
|
|||
s
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{correct_app_name, PRIVILEGES_SCRIPTS_DIR};
|
||||
|
||||
#[test]
|
||||
fn install_script_bootstraps_agent_into_user_domain() {
|
||||
let install = PRIVILEGES_SCRIPTS_DIR
|
||||
.get_file("install.scpt")
|
||||
.and_then(|file| file.contents_utf8())
|
||||
.map(correct_app_name)
|
||||
.expect("install.scpt should be embedded");
|
||||
|
||||
assert!(
|
||||
install.contains("launchctl bootstrap gui/$uid")
|
||||
|| install.contains("launchctl bootstrap user/$uid"),
|
||||
"install script must bootstrap the agent into a user launchd domain",
|
||||
);
|
||||
assert!(
|
||||
install.contains("launchctl kickstart -k gui/$uid/$agent_label")
|
||||
|| install.contains("launchctl kickstart -k user/$uid/$agent_label"),
|
||||
"install script must kickstart the agent after bootstrapping it",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn uninstall_service(show_new_window: bool, sync: bool) -> bool {
|
||||
// to-do: do together with win/linux about refactory start/stop service
|
||||
if !is_installed_daemon(false) {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,22 @@
|
|||
on run {daemon_file, agent_file, user}
|
||||
set daemon_plist to "/Library/LaunchDaemons/com.carriez.RustDesk_service.plist"
|
||||
set agent_plist to "/Library/LaunchAgents/com.carriez.RustDesk_server.plist"
|
||||
|
||||
set sh1 to "echo " & quoted form of daemon_file & " > /Library/LaunchDaemons/com.carriez.RustDesk_service.plist && chown root:wheel /Library/LaunchDaemons/com.carriez.RustDesk_service.plist;"
|
||||
set sh1 to "echo " & quoted form of daemon_file & " > " & daemon_plist & " && chown root:wheel " & daemon_plist & ";"
|
||||
|
||||
set sh2 to "echo " & quoted form of agent_file & " > /Library/LaunchAgents/com.carriez.RustDesk_server.plist && chown root:wheel /Library/LaunchAgents/com.carriez.RustDesk_server.plist;"
|
||||
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 sh4 to "cp -rf /Users/" & user & "/Library/Preferences/com.carriez.RustDesk/RustDesk2.toml /var/root/Library/Preferences/com.carriez.RustDesk/;"
|
||||
|
||||
set sh5 to "launchctl load -w /Library/LaunchDaemons/com.carriez.RustDesk_service.plist;"
|
||||
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 sh1 & sh2 & sh3 & sh4 & sh5
|
||||
set sh to "set -e;" & sh1 & sh2 & sh3 & sh4 & sh5 & sh6 & sh7 & sh8 & sh9
|
||||
|
||||
do shell script sh with prompt "RustDesk wants to install daemon and agent" with administrator privileges
|
||||
end run
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue