2024-08-03 21:07:11 +00:00
|
|
|
use color_eyre::Result;
|
2024-08-15 10:32:02 +00:00
|
|
|
use nix::sys::utsname::UtsName;
|
|
|
|
use std::{
|
|
|
|
fs::File,
|
|
|
|
io::{self, Read},
|
|
|
|
};
|
2024-08-03 17:42:48 +00:00
|
|
|
|
2024-08-15 10:32:02 +00:00
|
|
|
pub fn get_system_info(utsname: &UtsName) -> nix::Result<String> {
|
2024-08-05 08:08:25 +00:00
|
|
|
Ok(format!(
|
|
|
|
"{} {} ({})",
|
|
|
|
utsname.sysname().to_str().unwrap_or("Unknown"),
|
|
|
|
utsname.release().to_str().unwrap_or("Unknown"),
|
|
|
|
utsname.machine().to_str().unwrap_or("Unknown")
|
|
|
|
))
|
2024-08-03 17:42:48 +00:00
|
|
|
}
|
|
|
|
|
2024-08-03 21:05:57 +00:00
|
|
|
pub fn get_os_pretty_name() -> Result<String, io::Error> {
|
2024-08-15 10:32:02 +00:00
|
|
|
let mut os_release_content = String::with_capacity(1024);
|
|
|
|
File::open("/etc/os-release")?.read_to_string(&mut os_release_content)?;
|
|
|
|
|
2024-08-03 21:05:57 +00:00
|
|
|
let pretty_name = os_release_content
|
|
|
|
.lines()
|
2024-08-03 17:42:48 +00:00
|
|
|
.find(|line| line.starts_with("PRETTY_NAME="))
|
2024-08-15 10:32:02 +00:00
|
|
|
.map(|line| line.trim_start_matches("PRETTY_NAME=").trim_matches('"'));
|
2024-08-03 17:42:48 +00:00
|
|
|
|
2024-08-15 10:32:02 +00:00
|
|
|
Ok(pretty_name.unwrap_or("Unknown").to_string())
|
2024-08-03 17:42:48 +00:00
|
|
|
}
|