use crate::version::{MAJOR, MINOR, PATCH, SUFFIX};
use hostname::get;
use whoami;
pub fn get_known_host_id() -> String {
let host = get()
.expect("Failed to get hostname")
.into_string()
.expect("Failed to convert hostname to string");
let user = whoami::username();
format!("{}@{}", user, host)
}
pub fn get_os() -> String {
if cfg!(windows) {
return "Windows".to_string();
}
if cfg!(target_os = "macos") {
return "macOS".to_string();
}
if cfg!(unix) {
return "Unix".to_string();
}
"Unknown".to_string()
}
pub fn get_os_version() -> String {
let os_release =
std::fs::read_to_string("/etc/os-release").expect("Failed to read /etc/os-release");
let version_id = os_release
.lines()
.find(|line| line.starts_with("VERSION_ID="))
.expect("Failed to find VERSION_ID in /etc/os-release");
version_id.to_string()
}
pub fn get_cot_version() -> String {
let version = format!("{}.{}.{}{}", MAJOR, MINOR, PATCH, SUFFIX);
version
}