From ee8f814e738205b1d416194c4c7559d986c944c6 Mon Sep 17 00:00:00 2001 From: Ikey Doherty Date: Thu, 1 Aug 2024 01:01:34 +0000 Subject: [PATCH] lichen_cli: Require root to run Signed-off-by: Ikey Doherty --- Cargo.lock | 23 +++++++++++++++++++++-- lichen_cli/Cargo.toml | 1 + lichen_cli/src/main.rs | 7 +++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0155d7b..6892855 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -113,6 +113,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + [[package]] name = "chrono" version = "0.4.38" @@ -708,6 +714,7 @@ dependencies = [ "futures", "indicatif", "installer", + "nix 0.29.0", "tokio", ] @@ -802,7 +809,19 @@ checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" dependencies = [ "bitflags", "cfg-if", - "cfg_aliases", + "cfg_aliases 0.1.1", + "libc", +] + +[[package]] +name = "nix" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" +dependencies = [ + "bitflags", + "cfg-if", + "cfg_aliases 0.2.1", "libc", ] @@ -1437,7 +1456,7 @@ source = "git+https://github.com/serpent-os/blsforme.git#0aaece601fe4d11025382fa dependencies = [ "gpt", "log", - "nix", + "nix 0.28.0", "superblock", "thiserror", ] diff --git a/lichen_cli/Cargo.toml b/lichen_cli/Cargo.toml index 6779392..237e118 100644 --- a/lichen_cli/Cargo.toml +++ b/lichen_cli/Cargo.toml @@ -13,3 +13,4 @@ futures.workspace = true tokio.workspace = true installer = { path = "../crates/installer" } console = "0.15.8" +nix = "0.29" diff --git a/lichen_cli/src/main.rs b/lichen_cli/src/main.rs index d287b0f..42d49b9 100644 --- a/lichen_cli/src/main.rs +++ b/lichen_cli/src/main.rs @@ -11,11 +11,13 @@ use std::{ time::Duration, }; +use color_eyre::eyre::bail; use console::{set_colors_enabled, style}; use crossterm::style::Stylize; use dialoguer::theme::ColorfulTheme; use indicatif::ProgressStyle; use installer::{selections, steps::Context, systemd, Account, BootPartition, Installer, Locale, SystemPartition}; +use nix::libc::geteuid; use tokio::io::AsyncWriteExt; use tokio::process::Command; @@ -151,6 +153,11 @@ async fn main() -> color_eyre::Result<()> { color_eyre::install().unwrap(); set_colors_enabled(true); + let euid = unsafe { geteuid() }; + if euid != 0 { + bail!("lichen must be run as root. Re-run with sudo") + } + // Test selection management, force GNOME let selections = selections::Manager::new().with_groups([ selections::Group::from_str(include_str!("../../selections/base.json"))?,