Check if running as root during install and uninstall
This commit is contained in:
parent
b123bbf285
commit
9c0dd087c3
|
@ -40,3 +40,7 @@ impl CommandExecute for HarmonicCli {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_root() -> bool {
|
||||
nix::unistd::getuid() == nix::unistd::Uid::from_raw(0)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::{path::PathBuf, process::ExitCode};
|
||||
|
||||
use crate::BuiltinPlanner;
|
||||
use crate::{cli::is_root, BuiltinPlanner};
|
||||
use clap::{ArgAction, Parser};
|
||||
use eyre::{eyre, WrapErr};
|
||||
|
||||
|
@ -43,6 +43,12 @@ impl CommandExecute for Install {
|
|||
explain,
|
||||
} = self;
|
||||
|
||||
if !is_root() {
|
||||
return Err(eyre!(
|
||||
"`harmonic install` must be run as `root`, try `sudo harmonic install`"
|
||||
));
|
||||
}
|
||||
|
||||
let mut plan = match &plan {
|
||||
Some(plan_path) => {
|
||||
let install_plan_string = tokio::fs::read_to_string(&plan_path)
|
||||
|
|
|
@ -9,11 +9,11 @@ use crate::cli::CommandExecute;
|
|||
|
||||
/// Plan an install that can be repeated on an identical host later
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(args_conflicts_with_subcommands = true, arg_required_else_help = true)]
|
||||
#[command(arg_required_else_help = true)]
|
||||
pub struct Plan {
|
||||
#[clap(subcommand)]
|
||||
pub planner: Option<BuiltinPlanner>,
|
||||
#[clap(env = "HARMONIC_PLAN")]
|
||||
#[clap(env = "HARMONIC_PLAN", default_value = "/dev/stdout")]
|
||||
pub output: PathBuf,
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use std::{path::PathBuf, process::ExitCode};
|
||||
|
||||
use crate::InstallPlan;
|
||||
use crate::{cli::is_root, InstallPlan};
|
||||
use clap::{ArgAction, Parser};
|
||||
use eyre::WrapErr;
|
||||
use eyre::{eyre, WrapErr};
|
||||
|
||||
use crate::{cli::CommandExecute, interaction};
|
||||
|
||||
|
@ -37,6 +37,12 @@ impl CommandExecute for Uninstall {
|
|||
explain,
|
||||
} = self;
|
||||
|
||||
if !is_root() {
|
||||
return Err(eyre!(
|
||||
"`harmonic install` must be run as `root`, try `sudo harmonic install`"
|
||||
));
|
||||
}
|
||||
|
||||
let install_receipt_string = tokio::fs::read_to_string(receipt)
|
||||
.await
|
||||
.wrap_err("Reading receipt")?;
|
||||
|
|
Loading…
Reference in a new issue