Skip to content

Commit

Permalink
feat(launchpad): ensure start mac launchapd with sudo only if not set
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuef committed May 7, 2024
1 parent d07baf6 commit fa6ffe2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion node-launchpad/src/bin/tui/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async fn main() -> Result<()> {
local
.run_until(async {
if let Err(e) = tokio_main().await {
eprintln!("{} error: Something went wrong", env!("CARGO_PKG_NAME"));
eprintln!("{} failed:", env!("CARGO_PKG_NAME"));
Err(e)
} else {
Ok(())
Expand Down
22 changes: 18 additions & 4 deletions node-launchpad/src/bin/tui/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
// permissions and limitations relating to use of the SAFE Network Software.

use clap::Parser;
use color_eyre::{eyre::eyre, eyre::Result};
use std::{path::PathBuf, process::Command};
use color_eyre::eyre::{bail, eyre, Result};
use std::{
path::PathBuf,
process::{Command, Stdio},
};
use which::which;

#[derive(Debug)]
Expand Down Expand Up @@ -39,7 +42,7 @@ fn is_running_root() -> bool {

pub(crate) fn detect_and_setup_terminal() -> Result<TerminalType> {
if !is_running_root() {
#[cfg(windows)]
#[cfg(target_os = "windows")]
{
// todo: There is no terminal to show this error message when double clicking on the exe.
color_eyre::eyre::bail!("Admin privileges required to run");
Expand Down Expand Up @@ -133,7 +136,18 @@ pub(crate) fn launch_terminal(terminal_type: &TerminalType) -> Result<()> {
Ok(())
}
TerminalType::MacOS(_path) | TerminalType::ITerm2(_path) => {
// Nothing necessary at the moment
// We need to detect here to avoid a loop on mac
// as the terminal is booted by default
if !is_running_root() {
let status = Command::new("sudo")
.arg(launchpad_path)
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.status()?;
if !status.success() {
bail!("Failed to run as root");
}
}
Ok(())
}
TerminalType::WindowsCmd(path)
Expand Down

0 comments on commit fa6ffe2

Please sign in to comment.