From eab47e9eb8a5e0f19e038f896e94bccf89e93e6d Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Fri, 8 Nov 2024 01:53:12 -0500 Subject: [PATCH 1/5] implement a root check menu --- Cargo.lock | 21 ++++++++++++++++++++- tui/Cargo.toml | 1 + tui/src/main.rs | 5 ++++- tui/src/root.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ tui/src/state.rs | 4 ++++ 5 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 tui/src/root.rs diff --git a/Cargo.lock b/Cargo.lock index 605cd30e..cb6f2784 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -157,6 +157,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + [[package]] name = "clap" version = "4.5.20" @@ -436,6 +442,7 @@ dependencies = [ "anstyle", "clap", "linutil_core", + "nix 0.29.0", "oneshot", "portable-pty", "rand", @@ -528,6 +535,18 @@ dependencies = [ "pin-utils", ] +[[package]] +name = "nix" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" +dependencies = [ + "bitflags 2.6.0", + "cfg-if", + "cfg_aliases", + "libc", +] + [[package]] name = "nom" version = "7.1.3" @@ -598,7 +617,7 @@ dependencies = [ "lazy_static", "libc", "log", - "nix", + "nix 0.25.1", "serial", "shared_library", "shell-words", diff --git a/tui/Cargo.toml b/tui/Cargo.toml index a486e1e4..d8036618 100644 --- a/tui/Cargo.toml +++ b/tui/Cargo.toml @@ -29,6 +29,7 @@ textwrap = "0.16.1" anstyle = "1.0.8" ansi-to-tui = "7.0.0" zips = "0.1.7" +nix = { version = "0.29.0", features = [ "user" ] } [[bin]] name = "linutil" diff --git a/tui/src/main.rs b/tui/src/main.rs index 7a9f4067..44344fd9 100644 --- a/tui/src/main.rs +++ b/tui/src/main.rs @@ -3,6 +3,7 @@ mod filter; mod float; mod floating_text; mod hint; +mod root; mod running_command; pub mod state; mod theme; @@ -28,6 +29,8 @@ use ratatui::{ }; use state::AppState; +use crate::root::create_app_state; + // Linux utility toolbox #[derive(Debug, Parser)] struct Args { @@ -54,7 +57,7 @@ struct Args { fn main() -> io::Result<()> { let args = Args::parse(); - let mut state = AppState::new( + let mut state = create_app_state( args.config, args.theme, args.override_validation, diff --git a/tui/src/root.rs b/tui/src/root.rs new file mode 100644 index 00000000..5ff4c3f8 --- /dev/null +++ b/tui/src/root.rs @@ -0,0 +1,45 @@ +use crate::{ + float::Float, float::FloatContent, floating_text::FloatingText, state::AppState, theme::Theme, +}; +use std::path::PathBuf; + +#[cfg(unix)] +use nix::unistd::Uid; + +pub fn create_app_state( + config_path: Option, + theme: Theme, + override_validation: bool, + size_bypass: bool, + skip_confirmation: bool, +) -> AppState { + #[cfg(unix)] + { + if Uid::effective().is_root() { + let mut state = AppState::new( + config_path, + theme, + override_validation, + size_bypass, + skip_confirmation, + ); + + let warning = FloatingText::new( + "WARNING: You are running this utility as root!\n\nThis means you have full system access and commands can potentially damage your system if used incorrectly.\n\nPlease proceed with caution and make sure you understand what each command does before executing it.".into(), + "Root User Warning", + true, + ); + let float: Float = Float::new(Box::new(warning), 60, 40); + state.set_float_window(float); + return state; + } + } + + AppState::new( + config_path, + theme, + override_validation, + size_bypass, + skip_confirmation, + ) +} diff --git a/tui/src/state.rs b/tui/src/state.rs index 5ee34079..a5363d68 100644 --- a/tui/src/state.rs +++ b/tui/src/state.rs @@ -873,6 +873,10 @@ impl AppState { self.current_tab.select(Some(next)); self.refresh_tab(); } + + pub fn set_float_window(&mut self, float: Float) { + self.focus = Focus::FloatingWindow(float); + } } #[cfg(feature = "tips")] From 2960e0b985f2cc6319495eea43042ef353e678ef Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Fri, 8 Nov 2024 01:55:31 -0500 Subject: [PATCH 2/5] code needs to be readable --- tui/src/root.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tui/src/root.rs b/tui/src/root.rs index 5ff4c3f8..8120236a 100644 --- a/tui/src/root.rs +++ b/tui/src/root.rs @@ -25,7 +25,11 @@ pub fn create_app_state( ); let warning = FloatingText::new( - "WARNING: You are running this utility as root!\n\nThis means you have full system access and commands can potentially damage your system if used incorrectly.\n\nPlease proceed with caution and make sure you understand what each command does before executing it.".into(), + "\ + WARNING: You are running this utility as root!\n\n\ + This means you have full system access and commands can potentially damage your system if used incorrectly.\n\n\ + Please proceed with caution and make sure you understand what each command does before executing it.\ + ".into(), "Root User Warning", true, ); From 06453fabe90fbcde2e67e773614d627a75e9feb7 Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Fri, 8 Nov 2024 02:00:38 -0500 Subject: [PATCH 3/5] rephrase it a lil bit --- tui/src/root.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tui/src/root.rs b/tui/src/root.rs index 8120236a..96c70651 100644 --- a/tui/src/root.rs +++ b/tui/src/root.rs @@ -28,7 +28,7 @@ pub fn create_app_state( "\ WARNING: You are running this utility as root!\n\n\ This means you have full system access and commands can potentially damage your system if used incorrectly.\n\n\ - Please proceed with caution and make sure you understand what each command does before executing it.\ + Please proceed with caution and make sure you understand what each script does before executing it.\ ".into(), "Root User Warning", true, From 7f0d456c68c56dfa63357bd3ec3fbe0043b05dee Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Fri, 8 Nov 2024 02:06:13 -0500 Subject: [PATCH 4/5] run cargo xtask docgen --- docs/userguide.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/userguide.md b/docs/userguide.md index 11e598f8..e220e4aa 100644 --- a/docs/userguide.md +++ b/docs/userguide.md @@ -25,6 +25,8 @@ This command configures neovim from CTT's neovim configuration. https://github.com/ChrisTitusTech/neovim - **Ngrok**: Ngrok is a tool that creates secure, temporary tunnels to expose local servers to the internet for testing and development. - **Sublime Text**: Sublime Text is a fast, lightweight, and customizable text editor known for its simplicity, powerful features, and wide range of plugins for various programming languages. +- **ZapZap**: ZapZap is an open source whatsapp desktop client for Linux users developed by rafatosta. +- **Zoom**: Zoom is a widely-used video conferencing platform that allows users to host virtual meetings, webinars, and online collaboration with features like screen sharing and recording. - **VS Code**: Visual Studio Code (VS Code) is a lightweight, open-source code editor with built-in support for debugging, version control, and extensions for various programming languages and frameworks. - **VS Codium**: VSCodium is a free, open-source version of Visual Studio Code (VS Code) that removes Microsoft-specific telemetry and branding. From dcc32bca48ba9dd68d25c69472e8ed5ce00ad8e4 Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Fri, 8 Nov 2024 02:25:35 -0500 Subject: [PATCH 5/5] disregard escalation tool variable if found as root --- core/tabs/common-script.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/tabs/common-script.sh b/core/tabs/common-script.sh index f8188ac3..1584d3c7 100644 --- a/core/tabs/common-script.sh +++ b/core/tabs/common-script.sh @@ -84,7 +84,13 @@ checkAURHelper() { } checkEscalationTool() { - ## Check for escalation tools. + if [ "$(id -u)" = "0" ]; then + ESCALATION_TOOL="eval" + ESCALATION_TOOL_CHECKED=true + printf "%b\n" "${CYAN}Running as root, no escalation needed${RC}" + return 0 + fi + if [ -z "$ESCALATION_TOOL_CHECKED" ]; then ESCALATION_TOOLS='sudo doas' for tool in ${ESCALATION_TOOLS}; do