mirror of
https://github.com/NotAShelf/microfetch.git
synced 2025-11-25 16:52:50 +00:00
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I0351e5753996e6d0391fc9e2f329878a6a6a6964
37 lines
964 B
Rust
37 lines
964 B
Rust
use std::{
|
|
fs::File,
|
|
io::{self, BufRead, BufReader},
|
|
};
|
|
|
|
use nix::sys::utsname::UtsName;
|
|
|
|
#[must_use]
|
|
#[cfg_attr(feature = "hotpath", hotpath::measure)]
|
|
pub fn get_system_info(utsname: &UtsName) -> String {
|
|
format!(
|
|
"{} {} ({})",
|
|
utsname.sysname().to_str().unwrap_or("Unknown"),
|
|
utsname.release().to_str().unwrap_or("Unknown"),
|
|
utsname.machine().to_str().unwrap_or("Unknown")
|
|
)
|
|
}
|
|
|
|
#[cfg_attr(feature = "hotpath", hotpath::measure)]
|
|
pub fn get_os_pretty_name() -> Result<String, io::Error> {
|
|
let file = File::open("/etc/os-release")?;
|
|
let reader = BufReader::new(file);
|
|
|
|
for line in reader.lines() {
|
|
let line = line?;
|
|
if let Some(pretty_name) = line.strip_prefix("PRETTY_NAME=") {
|
|
if let Some(trimmed) = pretty_name
|
|
.strip_prefix('"')
|
|
.and_then(|s| s.strip_suffix('"'))
|
|
{
|
|
return Ok(trimmed.to_owned());
|
|
}
|
|
return Ok(pretty_name.to_owned());
|
|
}
|
|
}
|
|
Ok("Unknown".to_owned())
|
|
}
|