forked from ChrisTitusTech/linutil
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f472ab9
commit f631441
Showing
4 changed files
with
95 additions
and
88 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use ratatui::{ | ||
backend::CrosstermBackend, | ||
crossterm::event::{self, Event, KeyCode, KeyEvent}, | ||
layout::{Alignment, Constraint, Layout}, | ||
style::{Style, Stylize}, | ||
widgets::{Paragraph, Wrap}, | ||
Terminal, | ||
}; | ||
use std::io; | ||
|
||
pub fn check_root(terminal: &mut Terminal<CrosstermBackend<io::Stdout>>) -> io::Result<bool> { | ||
if nix::unistd::geteuid().is_root() { | ||
terminal.draw(|frame| { | ||
let root_warn = Paragraph::new( | ||
r#" | ||
!!!!!!!!!!!!!! YOU ARE ABOUT TO RUN LINUTIL AS ROOT !!!!!!!!!!!!!! | ||
This utility prioritizes compatibility with non-root environments. | ||
Some scripts may work without any issues, some may not. | ||
You have been warned! | ||
!!!!!!!!!!!!!!!!!!!!!! PROCEED WITH CAUTION !!!!!!!!!!!!!!!!!!!!!! | ||
Press [y] to continue, [n] to abort | ||
"#, | ||
) | ||
.white() | ||
.on_black() | ||
.alignment(Alignment::Center) | ||
.style(Style::default().bold()) | ||
.wrap(Wrap { trim: true }); | ||
|
||
let rects = Layout::vertical([ | ||
Constraint::Fill(1), | ||
Constraint::Length(10), | ||
Constraint::Fill(1), | ||
]) | ||
.split(frame.area()); | ||
|
||
let centered = rects[1]; | ||
|
||
frame.render_widget(root_warn, centered); | ||
})?; | ||
|
||
loop { | ||
match event::read()? { | ||
Event::Key( | ||
KeyEvent { | ||
code: KeyCode::Char('y'), | ||
.. | ||
} | ||
| KeyEvent { | ||
code: KeyCode::Char('Y'), | ||
.. | ||
}, | ||
) => break, | ||
Event::Key( | ||
KeyEvent { | ||
code: KeyCode::Char('n'), | ||
.. | ||
} | ||
| KeyEvent { | ||
code: KeyCode::Char('N'), | ||
.. | ||
}, | ||
) => return Ok(false), | ||
_ => {} | ||
} | ||
} | ||
} | ||
Ok(true) | ||
} |