diff --git a/xtask/src/install/install.rs b/xtask/src/install/install.rs index 25c69cc..08d3db4 100644 --- a/xtask/src/install/install.rs +++ b/xtask/src/install/install.rs @@ -87,7 +87,12 @@ pub enum Elevated { No, } -pub fn install(priv_exe: &Option,profile: Profile, clean_after: bool, copy: bool) -> Result { +pub fn install( + priv_exe: &Option, + profile: Profile, + clean_after: bool, + copy: bool, +) -> Result { // test if current process has CAP_DAC_OVERRIDE,CAP_CHOWN capabilities let mut state = capctl::CapState::get_current()?; if !state.permitted.has(Cap::DAC_OVERRIDE) @@ -96,29 +101,54 @@ pub fn install(priv_exe: &Option,profile: Profile, clean_after: bool, co { let bounding = capctl::bounding::probe(); // get parent process - if !bounding.has(Cap::DAC_OVERRIDE) || - !bounding.has(Cap::CHOWN) || - !bounding.has(Cap::SETFCAP) + if !bounding.has(Cap::DAC_OVERRIDE) + || !bounding.has(Cap::CHOWN) + || !bounding.has(Cap::SETFCAP) { - return Err(anyhow!("The bounding set misses DAC_OVERRIDE, CHOWN or SETFCAP capabilities")); + return Err(anyhow!( + "The bounding set misses DAC_OVERRIDE, CHOWN or SETFCAP capabilities" + )); } else if env::var("ROOTASROLE_INSTALLER_NESTED").is_ok_and(|v| v == "1") { env::remove_var("ROOTASROLE_INSTALLER_NESTED"); - return Err(anyhow!("Unable to elevate required capabilities, is LSM blocking installation?")); + return Err(anyhow!( + "Unable to elevate required capabilities, is LSM blocking installation?" + )); } let priv_bin = detect_priv_bin(); - let priv_exe = priv_exe.as_ref().or(priv_bin.as_ref()).context("Privileged binary is required").map_err(|e|{ - return anyhow::Error::msg(format!("Please run {} as an administrator.", current_exe().unwrap_or(PathBuf::from_str("the command").unwrap()).to_str().unwrap())); - })?; + let priv_exe = priv_exe + .as_ref() + .or(priv_bin.as_ref()) + .context("Privileged binary is required") + .map_err(|e| { + return anyhow::Error::msg(format!( + "Please run {} as an administrator.", + current_exe() + .unwrap_or(PathBuf::from_str("the command").unwrap()) + .to_str() + .unwrap() + )); + })?; env::set_var("ROOTASROLE_INSTALLER_NESTED", "1"); tracing::warn!("Elevating privileges..."); std::process::Command::new(priv_exe) - .arg(current_exe()?.to_str().context("Failed to get current exe path")?) + .arg( + current_exe()? + .to_str() + .context("Failed to get current exe path")?, + ) .arg("install") .status() - .context("Failed to run privileged binary").map_err(|e|{ + .context("Failed to run privileged binary") + .map_err(|e| { error!("{}", e); - return anyhow::Error::msg(format!("Failed to run privileged binary. Please run {} as an administrator.", current_exe().unwrap_or(PathBuf::from_str("the command").unwrap()).to_str().unwrap())); + return anyhow::Error::msg(format!( + "Failed to run privileged binary. Please run {} as an administrator.", + current_exe() + .unwrap_or(PathBuf::from_str("the command").unwrap()) + .to_str() + .unwrap() + )); })?; return Ok(Elevated::Yes); } diff --git a/xtask/src/install/mod.rs b/xtask/src/install/mod.rs index 8dd751f..aaca51a 100644 --- a/xtask/src/install/mod.rs +++ b/xtask/src/install/mod.rs @@ -249,12 +249,18 @@ pub(crate) fn install(opts: &InstallOptions) -> Result<(), anyhow::Error> { debug!("Building sr and chsr"); build(&opts.build_opts)?; } - if install::install(&opts.priv_bin, opts.build_opts.profile, opts.clean_after, true)?.is_yes(){ + if install::install( + &opts.priv_bin, + opts.build_opts.profile, + opts.clean_after, + true, + )? + .is_yes() + { Ok(()) } else { configure(Some(os)) } - } pub(crate) fn build(opts: &BuildOptions) -> Result<(), anyhow::Error> { diff --git a/xtask/src/postinst.rs b/xtask/src/postinst.rs index d87a3ff..d0d1244 100644 --- a/xtask/src/postinst.rs +++ b/xtask/src/postinst.rs @@ -13,7 +13,7 @@ fn main() { match action { Some(action) => match action.as_str() { "configure" => { - let res = install::install::install(&None,install::Profile::Release, false, false); + let res = install::install::install(&None, install::Profile::Release, false, false); if let Err(e) = res { warn!("{:#}", e); std::process::exit(1);