mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-12-03 10:16:02 +00:00
implement a root check menu (#927)
* implement a root check menu * code needs to be readable * rephrase it a lil bit * disregard escalation tool variable if found as root * refactor: Call root check from within AppState constructor (#7) * remove duplicate check * add comment back --------- Co-authored-by: Liam <33645555+lj3954@users.noreply.github.com>
This commit is contained in:
parent
fab3415c48
commit
7147ed93e9
21
Cargo.lock
generated
21
Cargo.lock
generated
|
@ -113,6 +113,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"
|
||||
|
@ -393,6 +399,7 @@ dependencies = [
|
|||
"anstyle",
|
||||
"clap",
|
||||
"linutil_core",
|
||||
"nix 0.29.0",
|
||||
"oneshot",
|
||||
"portable-pty",
|
||||
"rand",
|
||||
|
@ -486,6 +493,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"
|
||||
|
@ -571,7 +590,7 @@ dependencies = [
|
|||
"lazy_static",
|
||||
"libc",
|
||||
"log",
|
||||
"nix",
|
||||
"nix 0.25.1",
|
||||
"serial",
|
||||
"shared_library",
|
||||
"shell-words",
|
||||
|
|
|
@ -86,6 +86,13 @@ checkAURHelper() {
|
|||
checkEscalationTool() {
|
||||
## Check for escalation tools.
|
||||
if [ -z "$ESCALATION_TOOL_CHECKED" ]; then
|
||||
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
|
||||
|
||||
ESCALATION_TOOLS='sudo doas'
|
||||
for tool in ${ESCALATION_TOOLS}; do
|
||||
if command_exists "${tool}"; then
|
||||
|
|
|
@ -30,6 +30,7 @@ textwrap = { version = "0.16.1", default-features = false }
|
|||
anstyle = { version = "1.0.8", default-features = false }
|
||||
ansi-to-tui = { version = "7.0.0", default-features = false }
|
||||
zips = "0.1.7"
|
||||
nix = { version = "0.29.0", features = [ "user" ] }
|
||||
|
||||
[[bin]]
|
||||
name = "linutil"
|
||||
|
|
|
@ -3,6 +3,7 @@ mod filter;
|
|||
mod float;
|
||||
mod floating_text;
|
||||
mod hint;
|
||||
mod root;
|
||||
mod running_command;
|
||||
pub mod state;
|
||||
mod theme;
|
||||
|
|
17
tui/src/root.rs
Normal file
17
tui/src/root.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
use crate::floating_text::FloatingText;
|
||||
|
||||
#[cfg(unix)]
|
||||
use nix::unistd::Uid;
|
||||
|
||||
const ROOT_WARNING: &str = "WARNING: You are running this utility as root!\n
|
||||
This means you have full system access and commands can potentially damage your system if used incorrectly.\n
|
||||
Please proceed with caution and make sure you understand what each script does before executing it.";
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn check_root_status() -> Option<FloatingText> {
|
||||
(Uid::effective().is_root()).then_some(FloatingText::new(
|
||||
ROOT_WARNING.into(),
|
||||
"Root User Warning",
|
||||
true,
|
||||
))
|
||||
}
|
|
@ -4,6 +4,7 @@ use crate::{
|
|||
float::{Float, FloatContent},
|
||||
floating_text::FloatingText,
|
||||
hint::{create_shortcut_list, Shortcut},
|
||||
root::check_root_status,
|
||||
running_command::RunningCommand,
|
||||
theme::Theme,
|
||||
};
|
||||
|
@ -124,6 +125,11 @@ impl AppState {
|
|||
skip_confirmation,
|
||||
};
|
||||
|
||||
#[cfg(unix)]
|
||||
if let Some(root_warning) = check_root_status() {
|
||||
state.spawn_float(root_warning, 60, 40);
|
||||
}
|
||||
|
||||
state.update_items();
|
||||
if let Some(auto_execute_commands) = auto_execute_commands {
|
||||
state.handle_initial_auto_execute(&auto_execute_commands);
|
||||
|
|
Loading…
Reference in New Issue
Block a user