Merge branch 'main' into add_readme

This commit is contained in:
Orhun Parmaksız 2022-03-24 23:42:10 +03:00
commit 0e8e7e1328
No known key found for this signature in database
GPG key ID: F83424824B3E4B90
5 changed files with 397 additions and 29 deletions

146
man/systeroid-tui.8 Normal file
View file

@ -0,0 +1,146 @@
.\" Manpage for systeroid-tui
.TH SYSTEROID-TUI "8" "2022-03-22" "systeroid-tui" "System Administration"
.SH NAME
systeroid-tui \- manage kernel parameters with a terminal user interface
.SH SYNOPSIS
.B systeroid-tui
[options]
.SH DESCRIPTION
.B systeroid-tui
is used to configure and view kernel parameters with a terminal user interface.
.SH PARAMETERS
.TP
\fB\-t\fR, \fB\-\-tick\-rate\fR <ms>
Use this option to set the tick rate of the terminal. [default: 250]
.TP
\fB\-D\fR, \fB\-\-docs\fR <path>
Use this option to set a custom path for the kernel documentation.
.TP
\fB\-s\fR, \fB\-\-section\fR <section>
Use this option to set the section to filter.
.HP
\fB\-q\fR, \fB\-\-query\fR <query> set the query to search.
.TP
\fB\-\-bg\-color\fR <color>
Use this option to set the background color. [default: black]
.TP
\fB\-\-fg\-color\fR <color>
Use this option to set the foreground color. [default: white]
.TP
\fB\-n\fR, \fB\-\-no\-docs\fR
Do not show the kernel documentation.
.TP
\fB\-h\fR, \fB\-\-help\fR
Display help text and exit.
.TP
\fB\-V\fR, \fB\-\-version\fR
Display version information and exit.
.SH EXAMPLES
systeroid-tui \-t 500
.br
systeroid-tui \-s kernel
.br
systeroid-tui \-q "fs.quota"
.br
systeroid-tui \-\-fg-color blue
.br
systeroid-tui \-\-bg-color ffff99 \-\-fg-color 003366
.br
systeroid-tui \-D /usr/share/doc/linux
.br
systeroid-tui -n
.SH KEY BINDINGS
.TS
tab(@);
l l.
T{
Key
T}@T{
Action
T}
_
T{
?, f1
T}@T{
show help
T}
T{
up/down, k/j, pgup/pgdown
T}@T{
scroll list
T}
T{
t/b
T}@T{
scroll to top/bottom
T}
T{
left/right, h/l
T}@T{
scroll documentation
T}
T{
tab, \[ga]
T}@T{
next/previous section
T}
T{
:
T}@T{
command
T}
T{
/, s
T}@T{
search
T}
T{
enter
T}@T{
select / set parameter value
T}
T{
c
T}@T{
copy to clipboard
T}
T{
r, f5
T}@T{
refresh
T}
T{
esc
T}@T{
cancel / exit
T}
T{
q, ctrl-c/ctrl-d
T}@T{
exit
T}
.TE
.SH SEE ALSO
.BR systeroid (8)
.SH AUTHOR
.UR orhunparmaksiz@gmail.com
Orhun Parmaksız
.UE
.SH COPYRIGHT
Copyright © 2022 Orhun Parmaksız
.RS 0
Licensed under either of Apache License Version 2.0 or The MIT License at your option.
.SH REPORTING BUGS
Report bugs at <https://github.com/orhun/systeroid/issues> or contact the author via email.
.RS 0
See the project homepage at <https://github.com/orhun/systeroid> for full documentation.

221
man/systeroid.8 Normal file
View file

@ -0,0 +1,221 @@
.\" Manpage for systeroid
.TH SYSTEROID "8" "2022-03-22" "systeroid" "System Administration"
.SH NAME
systeroid \- configure kernel parameters at runtime
.SH SYNOPSIS
.B systeroid
[options] [variable[=value] ...] --load[=<file>]
.SH DESCRIPTION
.B systeroid
is used to modify kernel parameters at runtime. The parameters available
are those listed under /proc/sys/. Procfs is required for
.B systeroid
support in Linux. You can use
.B systeroid
to both read and write sysctl data.
.SH PARAMETERS
.TP
.I variable
The name of a key to read from. An example is kernel.ostype. The '/'
separator is also accepted in place of a '.'.
.TP
.IR variable = value
To set a key, use the form
.IR variable = value
where
.I variable
is the key and
.I value
is the value to set it to. If the value contains quotes or characters
which are parsed by the shell, you may need to enclose the value in double
quotes.
.TP
\fB\-a\fR, \fB\-\-all\fR
Display all variables currently available. (\fB\-A\fR,\fB\-X\fR)
.TP
\fB\-T\fR, \fB\-\-tree\fR
Display the variables in a tree\-like format.
.TP
\fB\-J\fR, \fB\-\-json\fR
Display the variables in JSON format.
.TP
\fB\-\-deprecated\fR
Include deprecated parameters to
.B \-\-all
values listing.
.TP
\fB\-e\fR, \fB\-\-ignore\fR
Use this option to ignore errors about unknown keys.
.TP
\fB\-N\fR, \fB\-\-names\fR
Use this option to only print the names. It may be useful with shells that
have programmable completion.
.TP
\fB\-n\fR, \fB\-\-values\fR
Use this option to disable printing of the key name when printing values.
.TP
\fB\-b\fR, \fB\-\-binary\fR
Print only variable values without new line.
.TP
\fB\-p\fR[\fIFILE\fR], \fB\-\-load\fR[=\fIFILE\fR]
Load in sysctl settings from the file specified or /etc/sysctl.conf if none
given. Specifying \- as filename means reading data from standard input.
.TP
\fB\-S\fR, \fB\-\-system\fR
Load settings from all system configuration files. See the
.B CONFIGURATION
section below.
.TP
\fB\-r\fR, \fB\-\-pattern\fR <expr>
Only apply settings that match
.IR pattern .
The
.I pattern
uses extended regular expression syntax.
.TP
\fB\-q\fR, \fB\-\-quiet\fR
Use this option to not display the values set to stdout.
.TP
\fB\-w\fR, \fB\-\-write\fR
Use this option when all arguments prescribe a key to be set.
.TP
\fB\-E\fR, \fB\-\-explain\fR
Use this option to print a detailed explanation of a variable.
.TP
\fB\-D\fR, \fB\-\-docs\fR <path>
Use this option to set a custom path for the kernel documentation.
.TP
\fB\-P\fR, \fB\-\-no\-pager\fR
Use this option to disable piping output into a pager.
.TP
\fB\-v\fR, \fB\-\-verbose\fR
Use this option to enable verbose logging.
.TP
\fB\-\-tui\fR
Use this option to show the terminal user interface.
.B systeroid-tui
binary should be present in $PATH. See
.B systeroid-tui(8)
for more information.
.TP
\fB\-h\fR, \fB\-\-help\fR
Display help text and exit. (\fB\-d\fR)
.TP
\fB\-V\fR, \fB\-\-version\fR
Display version information and exit.
.SH EXAMPLES
systeroid \-a
.br
systeroid \-t
.br
systeroid vm user
.br
systeroid \-n kernel.hostname
.br
systeroid kernel.domainname="example.com"
.br
systeroid dmesg_restrict=0
.br
systeroid \-p /etc/sysctl.conf
.br
systeroid \-r 'net.ipv4.conf.(eth|wlan)0.arp'
.br
systeroid \-\-names \-\-tree \-\-pattern 'kernel.*_max$'
.br
systeroid \-\-explain oom_dump_tasks
.br
systeroid \-E user.max_user_namespaces \-\-docs /usr/share/doc/linux
.br
systeroid \-\-no-pager \-E kernel.ctrl-alt-del
.br
systeroid \-\-tui
.SH DEPRECATED PARAMETERS
The
.B base_reachable_time
and
.B retrans_time
are deprecated. The
.B systeroid
command does not allow changing values of these
parameters. Users who insist to use deprecated kernel interfaces should push values
to /proc file system by other means. For example:
.PP
echo 256 > /proc/sys/net/ipv6/neigh/eth0/base_reachable_time
.SH CONFIGURATION
.B sysctl.conf
is a simple file containing sysctl values to be read in and set by
.BR systeroid .
The syntax is simply as follows:
.RS
.sp
.nf
.ne 7
# comment
; comment
token = value
.fi
.RE
.PP
Note that blank lines are ignored, and whitespace before and after a token or
value is ignored, although a value can contain whitespace within. Lines which
begin with a \fI#\fR or \fI;\fR are considered comments and ignored.
If a line begins with a single \-, any attempts to set the value that fail will be
ignored.
.SS EXAMPLE
.RS
.sp
.nf
.ne 7
# sysctl.conf sample
#
kernel.domainname = example.com
; this one has a space which will be written to the sysctl!
kernel.modprobe = /sbin/mod probe
.fi
.RE
.SS FILES
When using the \fB\-\-system\fR option,
.B systeroid
will read files from directories in the following list.
/etc/sysctl.d/*.conf
.br
/run/sysctl.d/*.conf
.br
/usr/local/lib/sysctl.d/*.conf
.br
/usr/lib/sysctl.d/*.conf
.br
/lib/sysctl.d/*.conf
.br
/etc/sysctl.conf
.SH SEE ALSO
.BR systeroid-tui (8)
.SH AUTHOR
.UR orhunparmaksiz@gmail.com
Orhun Parmaksız
.UE
.SH COPYRIGHT
Copyright © 2022 Orhun Parmaksız
.RS 0
Licensed under either of Apache License Version 2.0 or The MIT License at your option.
.SH REPORTING BUGS
Report bugs at <https://github.com/orhun/systeroid/issues> or contact the author via email.
.RS 0
See the project homepage at <https://github.com/orhun/systeroid> for full documentation.

View file

@ -87,7 +87,7 @@ impl Sysctl {
for path in KERNEL_DOCS_PATH {
if let Some(mut path) = globwalk::glob(path).ok().and_then(|glob| {
glob.filter_map(StdResult::ok)
.filter(|entry| entry.file_type().is_file())
.filter(|entry| entry.file_type().is_dir())
.map(|entry| entry.into_path())
.next()
}) {
@ -143,20 +143,16 @@ impl Sysctl {
.iter()
.filter(|document| Section::from(document.path.as_path()) == param.section)
{
if let Some(paragraph) = document
.paragraphs
.par_iter()
.find_first(|paragraph| param.get_absolute_name() == Some(&paragraph.title))
.or_else(|| {
document.paragraphs.par_iter().find_first(|paragraph| {
match param.get_absolute_name() {
Some(absolute_name) => {
absolute_name.len() > 2
if let Some(paragraph) =
document.paragraphs.par_iter().find_first(|paragraph| {
match param.get_absolute_name() {
Some(absolute_name) => {
absolute_name == paragraph.title
|| absolute_name.len() > 2
&& paragraph.title.contains(absolute_name)
}
_ => false,
}
})
None => false,
}
})
{
param.description = Some(paragraph.contents.to_owned());

View file

@ -1,6 +1,6 @@
use crate::output::OutputType;
use std::env;
use std::io::Write;
use std::io::{self, BufRead, Write};
use std::path::PathBuf;
use std::process::{Command, Stdio};
use systeroid_core::cache::Cache;
@ -189,8 +189,15 @@ impl<'a, Output: Write> App<'a, Output> {
}
/// Processes the parameters in the given file.
pub fn preload_from_file(&mut self, file: String) -> Result<()> {
let path = PathBuf::from(file);
pub fn preload_from_file(&mut self, path: PathBuf) -> Result<()> {
if path == PathBuf::from("-") {
for line in io::stdin().lock().lines() {
if let Err(e) = self.process_parameter(line?, true, false) {
println!("{}: {}", env!("CARGO_PKG_NAME"), e);
}
}
return Ok(());
}
if !path.exists() {
eprintln!(
"{}: cannot open {:?}: No such file or directory",
@ -202,9 +209,15 @@ impl<'a, Output: Write> App<'a, Output> {
let contents = reader::read_to_string(path)?;
for parameter in contents
.lines()
.filter(|v| !(v.starts_with('#') || v.is_empty()))
.filter(|v| !(v.starts_with('#') || v.starts_with(';') || v.is_empty()))
{
self.process_parameter(parameter.to_string(), false, false)?;
let process_result =
self.process_parameter(parameter.trim_start_matches('-').to_string(), false, false);
if !parameter.starts_with('-') {
process_result?;
} else if let Err(e) = process_result {
eprintln!("{}: {}", env!("CARGO_PKG_NAME"), e);
}
}
Ok(())
}
@ -218,16 +231,7 @@ impl<'a, Output: Write> App<'a, Output> {
if let Ok(glob_walker) = globwalk::glob(preload_path.to_string_lossy()) {
for file in glob_walker.filter_map(|v| v.ok()) {
println!("* Applying {} ...", file.path().display());
let contents = reader::read_to_string(file.path())?;
for parameter in contents
.lines()
.filter(|v| !(v.starts_with('#') || v.is_empty()))
{
if let Err(e) = self.process_parameter(parameter.to_string(), false, false)
{
eprintln!("{}: {}", env!("CARGO_PKG_NAME"), e);
}
}
self.preload_from_file(file.path().to_path_buf())?;
}
}
}

View file

@ -12,6 +12,7 @@ pub mod output;
use crate::app::App;
use crate::args::Args;
use std::io::Write;
use std::path::PathBuf;
use systeroid_core::config::Config;
use systeroid_core::error::Result;
use systeroid_core::sysctl::controller::Sysctl;
@ -39,7 +40,7 @@ pub fn run<Output: Write>(args: Args, output: &mut Output) -> Result<()> {
}
} else if args.preload_files {
for file in args.values {
app.preload_from_file(file)?;
app.preload_from_file(PathBuf::from(file))?;
}
} else {
for param in args.values {