From ae90c421f66af09120e841939c456fada77b79bb Mon Sep 17 00:00:00 2001 From: Stanislav Tkach Date: Tue, 12 Mar 2024 19:09:14 +0100 Subject: [PATCH] Release the 3.8.0 version (#368) * Release the 3.8.0 version --- CHANGELOG.md | 29 +++++++++++++++++++++++- README.md | 11 ++++++++- cli/Cargo.toml | 2 +- cspell-dictionary.txt | 1 + os_info/Cargo.toml | 2 +- os_info/src/aix/mod.rs | 37 +++++-------------------------- os_info/src/architecture.rs | 2 +- os_info/src/freebsd/mod.rs | 37 +++++++++++++++++++++---------- os_info/src/illumos/mod.rs | 28 ++++------------------- os_info/src/linux/file_release.rs | 1 + os_info/src/os_type.rs | 17 +++++++++++--- os_info/src/uname.rs | 6 ++--- 12 files changed, 95 insertions(+), 78 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29762e0a..bdd96f24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,32 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +## [3.8.0] (2024-03-12) + +- The `windows-sys` crate instead of `winapi` is now used internally. (#341) + +- Architecture information for Windows targets has been added. (#345) + +- Artix Linux detection has been fixed. (#348) + +- AIX support has been added. (#348) + +- Kali Linux support has been added. (#350) + +- openSUSE Tumbleweed detection has been fixed. (#353) + +- Version parsing from `lsb_release` has been added. (#354) + +- HardenedBSD detection has been fixed. (#358) + +- Ultramarine Linux support has been added. (#359) + +- AlmaLinux and Rocky Linux support has been added. (#360) + +- Ultramarine Linux support has been added. (#363) + +- Void Linux support has been added. (#365) + ## [3.7.0] (2023-03-20) - Information about a processor's architecture has been added. (#336) @@ -291,7 +317,8 @@ All notable changes to this project will be documented in this file. The first release containing only minor infrastructural changes and based on [os_type](https://github.com/schultyy/os_type). -[Unreleased]: https://github.com/stanislav-tkach/os_info/compare/v3.7.0...HEAD +[Unreleased]: https://github.com/stanislav-tkach/os_info/compare/v3.8.0...HEAD +[3.8.0]: https://github.com/stanislav-tkach/os_info/compare/v3.7.0...v3.8.0 [3.7.0]: https://github.com/stanislav-tkach/os_info/compare/v3.6.0...v3.7.0 [3.6.0]: https://github.com/stanislav-tkach/os_info/compare/v3.5.1...v3.6.0 [3.5.1]: https://github.com/stanislav-tkach/os_info/compare/v3.5.0...v3.5.1 diff --git a/README.md b/README.md index 6e34f2df..a87dcd04 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,8 @@ os_info --help Right now, the following operating system types can be returned: +- AIX +- AlmaLinux - Alpaquita Linux - Alpine Linux - Amazon Linux AMI @@ -95,8 +97,10 @@ Right now, the following operating system types can be returned: - Garuda Linux - Gentoo Linux - HardenedBSD -- Illumos +- illumos +- Kali Linux - Linux +- Mabox - macOS (Mac OS X or OS X) - Manjaro - Mariner @@ -105,6 +109,8 @@ Right now, the following operating system types can be returned: - NetBSD - NixOS - OpenBSD +- OpenCloudOS +- openEuler (EulerOS) - openSUSE - Oracle Linux - Pop!_OS @@ -112,10 +118,13 @@ Right now, the following operating system types can be returned: - Red Hat Linux - Red Hat Enterprise Linux - Redox +- Rocky Linux - Solus - SUSE Linux Enterprise Server - Ubuntu +- Ultramarine Linux - Unknown +- Void Linux - Windows If you need support for more OS types, I am looking forward to your Pull Request. diff --git a/cli/Cargo.toml b/cli/Cargo.toml index b568c6ad..83f47df7 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -18,7 +18,7 @@ name = "os_info" path = "src/main.rs" [dependencies] -os_info = { version = "3.7.0", default-features = false, path = "../os_info" } +os_info = { version = "3.8.0", default-features = false, path = "../os_info" } log.workspace = true env_logger = "0.11" clap = { version = "4", features = ["derive"] } diff --git a/cspell-dictionary.txt b/cspell-dictionary.txt index 8a9a66f2..1eefc932 100644 --- a/cspell-dictionary.txt +++ b/cspell-dictionary.txt @@ -43,6 +43,7 @@ raspbian redhat rhel rustdoc +sbin serde structopt toml diff --git a/os_info/Cargo.toml b/os_info/Cargo.toml index 8bc141e7..12adeb85 100644 --- a/os_info/Cargo.toml +++ b/os_info/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "os_info" -version = "3.7.0" +version = "3.8.0" authors = ["Jan Schulte ", "Stanislav Tkach "] description = "Detect the operating system type and version." documentation = "https://docs.rs/os_info" diff --git a/os_info/src/aix/mod.rs b/os_info/src/aix/mod.rs index 24ddff53..b02bdca1 100644 --- a/os_info/src/aix/mod.rs +++ b/os_info/src/aix/mod.rs @@ -1,5 +1,4 @@ -use std::process::Command; -use std::str; +use std::{process::Command, str}; use log::{error, trace}; @@ -24,39 +23,15 @@ pub fn current_platform() -> Info { } fn get_version() -> Option { - fn parse_uname(arg: &str) -> Option { - Command::new("uname") - .arg(arg) - .output() - .map_err(|e| { - error!("Failed to invoke 'uname': {:?}", e); - }) - .ok() - .and_then(|out| { - if out.status.success() { - Some(String::from_utf8_lossy(&out.stdout).trim_end().to_owned()) - } else { - log::error!("'uname' invocation error: {:?}", out); - None - } - }) - } - - let major = parse_uname("-v")?; - let minor = parse_uname("-r").unwrap_or(String::from("0")); + let major = uname("-v")?; + let minor = uname("-r").unwrap_or(String::from("0")); Some(format!("{}.{}", major, minor)) } fn get_os() -> Type { - let os = Command::new("uname") - .arg("-o") - .output() - .expect("Failed to get OS"); - - match str::from_utf8(&os.stdout) { - Ok("AIX\n") => Type::AIX, - Ok(_) => Type::Unknown, - Err(_) => Type::Unknown, + match uname("-o") { + Some("AIX") => Type::AIX, + None => Type::Unknown, } } diff --git a/os_info/src/architecture.rs b/os_info/src/architecture.rs index d6de08b2..4e2272b3 100644 --- a/os_info/src/architecture.rs +++ b/os_info/src/architecture.rs @@ -26,7 +26,7 @@ mod tests { #[test] fn uname_nonempty() { - let val = get().expect("uname failed"); + let val = get().expect("architecture::get() failed"); assert!(!val.is_empty()); } } diff --git a/os_info/src/freebsd/mod.rs b/os_info/src/freebsd/mod.rs index 14c769fb..5f1319c9 100644 --- a/os_info/src/freebsd/mod.rs +++ b/os_info/src/freebsd/mod.rs @@ -24,26 +24,39 @@ pub fn current_platform() -> Info { } fn get_os() -> Type { - let os = Command::new("uname") - .arg("-s") - .output() - .expect("Failed to get OS"); - - match str::from_utf8(&os.stdout) { - Ok("FreeBSD\n") => { - let check_hardening = Command::new("/sbin/sysctl") + let os = match uname("-s") { + Some(o) => o, + None => return Type::Unknown, + }; + + let os = match Command::new("uname").arg("-s").output() { + Ok(o) => o, + Err(e) => { + error!("Failed to invoke 'uname': {:?}", e); + return Type::Unknown; + } + }; + + match uname("-s") { + None => Type::Unknown, + Some("MidnightBSD") => Type::MidnightBSD, + Some("FreeBSD") => { + let check_hardening = match Command::new("/sbin/sysctl") .arg("hardening.version") .output() - .expect("Failed to check if is hardened"); + { + Ok(o) => o, + Err(e) => { + error!("Failed to invoke '/sbin/sysctl': {:?}", e); + return Type::FreeBSD; + } + }; match str::from_utf8(&check_hardening.stderr) { Ok("0\n") => Type::HardenedBSD, Ok(_) => Type::FreeBSD, Err(_) => Type::FreeBSD, } } - Ok("MidnightBSD\n") => Type::MidnightBSD, - Ok(_) => Type::Unknown, - Err(_) => Type::Unknown, } } diff --git a/os_info/src/illumos/mod.rs b/os_info/src/illumos/mod.rs index 1f23771f..66b55d84 100644 --- a/os_info/src/illumos/mod.rs +++ b/os_info/src/illumos/mod.rs @@ -24,33 +24,13 @@ pub fn current_platform() -> Info { } fn get_version() -> Option { - Command::new("uname") - .arg("-v") - .output() - .map_err(|e| { - error!("Failed to invoke 'uname': {:?}", e); - }) - .ok() - .and_then(|out| { - if out.status.success() { - Some(String::from_utf8_lossy(&out.stdout).trim_end().to_owned()) - } else { - log::error!("'uname' invocation error: {:?}", out); - None - } - }) + uname("-v") } fn get_os() -> Type { - let os = Command::new("uname") - .arg("-o") - .output() - .expect("Failed to get OS"); - - match str::from_utf8(&os.stdout) { - Ok("illumos\n") => Type::Illumos, - Ok(_) => Type::Unknown, - Err(_) => Type::Unknown, + match uname("-o") { + Some("illumos") => Type::Illumos, + None => Type::Unknown, } } diff --git a/os_info/src/linux/file_release.rs b/os_info/src/linux/file_release.rs index 54b36030..e4917c94 100644 --- a/os_info/src/linux/file_release.rs +++ b/os_info/src/linux/file_release.rs @@ -43,6 +43,7 @@ fn retrieve(distributions: &[ReleaseInfo], root: &str) -> Option { let version = (release_info.version)(&file_content); return Some(Info { + // Unwrap is OK here because of the `os_type.is_none()` check above. os_type: os_type.unwrap(), version: version.unwrap_or(Version::Unknown), bitness: Bitness::Unknown, diff --git a/os_info/src/os_type.rs b/os_info/src/os_type.rs index fecfc93c..a7e596b6 100644 --- a/os_info/src/os_type.rs +++ b/os_info/src/os_type.rs @@ -125,6 +125,8 @@ impl Display for Type { Type::Macos => write!(f, "Mac OS"), Type::MidnightBSD => write!(f, "Midnight BSD"), Type::Mint => write!(f, "Linux Mint"), + Type::openEuler => write!(f, "EulerOS"), + Type::OracleLinux => write!(f, "Oracle Linux"), Type::Pop => write!(f, "Pop!_OS"), Type::Raspbian => write!(f, "Raspberry Pi OS"), Type::Redhat => write!(f, "Red Hat Linux"), @@ -151,6 +153,7 @@ mod tests { fn display() { let data = [ (Type::AIX, "AIX"), + (Type::AlmaLinux, "AlmaLinux"), (Type::Alpaquita, "Alpaquita Linux"), (Type::Alpine, "Alpine Linux"), (Type::Amazon, "Amazon Linux AMI"), @@ -163,30 +166,38 @@ mod tests { (Type::Emscripten, "Emscripten"), (Type::EndeavourOS, "EndeavourOS"), (Type::Fedora, "Fedora"), + (Type::FreeBSD, "FreeBSD"), (Type::Garuda, "Garuda Linux"), (Type::Gentoo, "Gentoo Linux"), - (Type::FreeBSD, "FreeBSD"), + (Type::HardenedBSD, "HardenedBSD"), + (Type::Illumos, "illumos"), (Type::Kali, "Kali Linux"), (Type::Linux, "Linux"), + (Type::Mabox, "Mabox"), (Type::Macos, "Mac OS"), (Type::Manjaro, "Manjaro"), + (Type::Mariner, "Mariner"), + (Type::MidnightBSD, "Midnight BSD"), (Type::Mint, "Linux Mint"), (Type::NetBSD, "NetBSD"), (Type::NixOS, "NixOS"), + (Type::OpenCloudOS, "OpenCloudOS"), (Type::OpenBSD, "OpenBSD"), + (Type::openEuler, "EulerOS"), (Type::openSUSE, "openSUSE"), - (Type::OracleLinux, "OracleLinux"), + (Type::OracleLinux, "Oracle Linux"), (Type::Pop, "Pop!_OS"), (Type::Raspbian, "Raspberry Pi OS"), (Type::Redhat, "Red Hat Linux"), (Type::RedHatEnterprise, "Red Hat Enterprise Linux"), (Type::Redox, "Redox"), + (Type::RockyLinux, "Rocky Linux"), (Type::Solus, "Solus"), (Type::SUSE, "SUSE Linux Enterprise Server"), (Type::Ubuntu, "Ubuntu"), (Type::Ultramarine, "Ultramarine Linux"), - (Type::Void, "Void Linux"), (Type::Unknown, "Unknown"), + (Type::Void, "Void Linux"), (Type::Windows, "Windows"), ]; diff --git a/os_info/src/uname.rs b/os_info/src/uname.rs index f4417e88..242c8ad7 100644 --- a/os_info/src/uname.rs +++ b/os_info/src/uname.rs @@ -2,12 +2,12 @@ use std::process::Command; use log::error; -pub fn uname() -> Option { +pub fn uname(arg: &str) -> Option { Command::new("uname") - .arg("-r") + .arg(arg) .output() .map_err(|e| { - error!("Failed to invoke 'uname': {:?}", e); + error!("Failed to invoke 'uname {}': {:?}", arg, e); }) .ok() .and_then(|out| {