From f1560261074a1910835cbc7961e0fd3a11572fee Mon Sep 17 00:00:00 2001 From: Cody Bloemhard Date: Fri, 10 Mar 2023 15:26:59 +0100 Subject: [PATCH] Add support for Artix Linux --- README.md | 1 + os_info/src/info.rs | 9 +++++++++ os_info/src/linux/file_release.rs | 13 ++++++++++++- os_info/src/linux/lsb_release.rs | 17 +++++++++++++++++ os_info/src/linux/mod.rs | 1 + os_info/src/linux/tests/Artix/etc/os-release | 9 +++++++++ os_info/src/os_type.rs | 4 ++++ 7 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 os_info/src/linux/tests/Artix/etc/os-release diff --git a/README.md b/README.md index c81754ac..186e998c 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ Right now, the following operating system types can be returned: - Amazon Linux AMI - Android - Arch Linux +- Artix Linux - CentOS - Debian - DragonFly BSD diff --git a/os_info/src/info.rs b/os_info/src/info.rs index 9ae5fe55..1eba0fea 100644 --- a/os_info/src/info.rs +++ b/os_info/src/info.rs @@ -213,6 +213,7 @@ mod tests { Type::Amazon, Type::Android, Type::Arch, + Type::Artix, Type::CentOS, Type::Debian, Type::Emscripten, @@ -281,6 +282,14 @@ mod tests { }, "Arch Linux Rolling Release [unknown bitness]", ), + ( + Info { + os_type: Type::Artix, + version: Version::Rolling(None), + ..Default::default() + }, + "Artix Linux Rolling Release [unknown bitness]", + ), ( Info { os_type: Type::Manjaro, diff --git a/os_info/src/linux/file_release.rs b/os_info/src/linux/file_release.rs index 64393904..e276b58a 100644 --- a/os_info/src/linux/file_release.rs +++ b/os_info/src/linux/file_release.rs @@ -97,7 +97,7 @@ static DISTRIBUTIONS: [ReleaseInfo; 6] = [ //"aosc" => AOSC "arch" => Some(Type::Arch), "archarm" => Some(Type::Arch), - //"artix" => Artix + "artix" => Some(Type::Artix), "centos" => Some(Type::CentOS), //"clear-linux-os" => ClearLinuxOS //"clearos" => ClearOS @@ -264,6 +264,17 @@ mod tests { assert_eq!(info.codename, None); } + #[test] + fn artix_os_release() { + let root = "src/linux/tests/Artix"; + + let info = retrieve(&DISTRIBUTIONS, root).unwrap(); + assert_eq!(info.os_type(), Type::Artix); + assert_eq!(info.version, Version::Unknown); + assert_eq!(info.edition, None); + assert_eq!(info.codename, None); + } + #[test] fn centos_7_os_release() { let root = "src/linux/tests/CentOS_7"; diff --git a/os_info/src/linux/lsb_release.rs b/os_info/src/linux/lsb_release.rs index 028dae55..a2456e98 100644 --- a/os_info/src/linux/lsb_release.rs +++ b/os_info/src/linux/lsb_release.rs @@ -18,6 +18,7 @@ pub fn get() -> Option { let os_type = match release.distribution.as_ref().map(String::as_ref) { Some("Amazon") | Some("AmazonAMI") => Type::Amazon, Some("Arch") => Type::Arch, + Some("Artix") => Type::Artix, Some("CentOS") => Type::CentOS, Some("Debian") => Type::Debian, Some("EndeavourOS") => Type::EndeavourOS, @@ -119,6 +120,14 @@ mod tests { assert_eq!(parse_results.codename, None); } + #[test] + fn artix() { + let parse_results = parse(artix_file()); + assert_eq!(parse_results.distribution, Some("Artix".to_string())); + assert_eq!(parse_results.version, Some("rolling".to_string())); + assert_eq!(parse_results.codename, None); + } + #[test] fn fedora() { let parse_results = parse(fedora_file()); @@ -307,6 +316,14 @@ mod tests { Codename: n/a" } + fn artix_file() -> &'static str { + "\nLSB Version: n/a\n\ + Distributor ID: Artix\n\ + Description: Artix Linux\n\ + Release: rolling\n\ + Codename: n/a" + } + fn fedora_file() -> &'static str { "\nLSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch\n\ Distributor ID: Fedora\n\ diff --git a/os_info/src/linux/mod.rs b/os_info/src/linux/mod.rs index 71aaf17f..7b92d23c 100644 --- a/os_info/src/linux/mod.rs +++ b/os_info/src/linux/mod.rs @@ -29,6 +29,7 @@ mod tests { Type::Alpine | Type::Amazon | Type::Arch + | Type::Artix | Type::CentOS | Type::Debian | Type::EndeavourOS diff --git a/os_info/src/linux/tests/Artix/etc/os-release b/os_info/src/linux/tests/Artix/etc/os-release new file mode 100644 index 00000000..26279cec --- /dev/null +++ b/os_info/src/linux/tests/Artix/etc/os-release @@ -0,0 +1,9 @@ +NAME="Artix Linux" +PRETTY_NAME="Artix Linux" +ID=artix +BUILD_ID=rolling +ANSI_COLOR="38;2;23;147;209" +HOME_URL="https://artixlinux.org/" +DOCUMENTATION_URL="https://wiki.artixlinux.org/" +SUPPORT_URL="https://forum.artixlinux.org/" +BUG_REPORT_URL="https://gitea.artixlinux.org/artix" diff --git a/os_info/src/os_type.rs b/os_info/src/os_type.rs index 420c8dcc..414e77fb 100644 --- a/os_info/src/os_type.rs +++ b/os_info/src/os_type.rs @@ -14,6 +14,8 @@ pub enum Type { Android, /// Arch Linux (). Arch, + /// Artix Linux (). + Artix, /// CentOS (). CentOS, /// Debian (). @@ -98,6 +100,7 @@ impl Display for Type { Type::Alpine => write!(f, "Alpine Linux"), Type::Amazon => write!(f, "Amazon Linux AMI"), Type::Arch => write!(f, "Arch Linux"), + Type::Artix => write!(f, "Artix Linux"), Type::DragonFly => write!(f, "DragonFly BSD"), Type::Garuda => write!(f, "Garuda Linux"), Type::Gentoo => write!(f, "Gentoo Linux"), @@ -131,6 +134,7 @@ mod tests { (Type::Amazon, "Amazon Linux AMI"), (Type::Android, "Android"), (Type::Arch, "Arch Linux"), + (Type::Artix, "Artix Linux"), (Type::CentOS, "CentOS"), (Type::Debian, "Debian"), (Type::DragonFly, "DragonFly BSD"),