1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//! A parser and data structures for the `/etc/os-release` file.
//!
//! os-release file is used by systemd and other tools to store information about the
//! operating system distribution.
//!
//! The file is formatted as a list of environment-like shell-compatible
//! variable assignments.
//!
//! For more information, see [`os-release(5)`]
//!
//! [`os-release(5)`]: https://www.freedesktop.org/software/systemd/man/os-release.html
//!
//! # Usage
//!
//! Add this to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! etc-os-release = "0.1.1"
//! ```
//!
//! # Examples
//!
//! Open the os-release file and print the OS name and version:
//!
//! ```rust,no_run
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use etc_os_release::OsRelease;
//!
//! let os_release = OsRelease::open()?;
//! println!("{}-{}", os_release.id(), os_release.version_id().unwrap_or_default());
//! # Ok(())
//! # }
//! ```
//!
//! Parse a string containing the contents of the os-release file:
//!
//! ```rust
//! use std::str::FromStr;
//!
//! use etc_os_release::OsRelease;
//!
//! let os_release = OsRelease::from_str(r#"
//! NAME=Fedora
//! VERSION="32 (Workstation Edition)"
//! ID=fedora
//! VERSION_ID=32
//! PRETTY_NAME="Fedora 32 (Workstation Edition)"
//! ANSI_COLOR="0;38;2;60;110;180"
//! LOGO=fedora-logo-icon
//! CPE_NAME="cpe:/o:fedoraproject:fedora:32"
//! HOME_URL="https://fedoraproject.org/"
//! DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f32/system-administrators-guide/"
//! SUPPORT_URL="https://fedoraproject.org/wiki/Communicating_and_getting_help"
//! BUG_REPORT_URL="https://bugzilla.redhat.com/"
//! REDHAT_BUGZILLA_PRODUCT="Fedora"
//! REDHAT_BUGZILLA_PRODUCT_VERSION=32
//! REDHAT_SUPPORT_PRODUCT="Fedora"
//! REDHAT_SUPPORT_PRODUCT_VERSION=32
//! PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy"
//! VARIANT="Workstation Edition"
//! VARIANT_ID=workstation
//! "#).unwrap();
//!
//! assert_eq!(os_release.id(), "fedora");
//! assert_eq!(os_release.version_id(), Some("32"));
//! ```
use IndexMap;
pub use crate::;
/// The parsed contents of the os-release file.
///
/// This structure is a map of the fields in the os-release file.
///
/// For more information, see [`os-release(5)`].
///
/// [`os-release(5)`]: https://www.freedesktop.org/software/systemd/man/os-release.html
///
/// # Notes
///
/// If you are using this crate to determine the OS or a specific version of it, use the [`Self::id()`]
/// and [`Self::version_id()`] methods, possibly with [`Self::id_like()`] as fallback for [`Self::id()`].
/// When looking for an OS identification string for presentation to the user, use the [`Self::pretty_name()`] method.
///
/// Note that operating system vendors may choose not to provide version information, for example to accommodate for rolling releases.
/// In this case, [`Self::version()`] and [`Self::version_id()`] may be `None`.
/// Application should not rely on these fields to be set.
///
/// # Examples
///
/// Open the os-release file and print the OS name and version:
///
/// ```rust,no_run
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use etc_os_release::OsRelease;
///
/// let os_release = OsRelease::open()?;
/// println!("{}-{}", os_release.id(), os_release.version_id().unwrap_or_default());
/// # Ok(())
/// # }
/// ```
///
/// Parse a string containing the contents of the os-release file:
///
/// ```rust
/// use std::str::FromStr;
///
/// use etc_os_release::OsRelease;
///
/// let os_release = OsRelease::from_str(r#"
/// NAME=Fedora
/// VERSION="32 (Workstation Edition)"
/// ID=fedora
/// VERSION_ID=32
/// PRETTY_NAME="Fedora 32 (Workstation Edition)"
/// ANSI_COLOR="0;38;2;60;110;180"
/// LOGO=fedora-logo-icon
/// CPE_NAME="cpe:/o:fedoraproject:fedora:32"
/// HOME_URL="https://fedoraproject.org/"
/// DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f32/system-administrators-guide/"
/// SUPPORT_URL="https://fedoraproject.org/wiki/Communicating_and_getting_help"
/// BUG_REPORT_URL="https://bugzilla.redhat.com/"
/// REDHAT_BUGZILLA_PRODUCT="Fedora"
/// REDHAT_BUGZILLA_PRODUCT_VERSION=32
/// REDHAT_SUPPORT_PRODUCT="Fedora"
/// REDHAT_SUPPORT_PRODUCT_VERSION=32
/// PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy"
/// VARIANT="Workstation Edition"
/// VARIANT_ID=workstation
/// "#).unwrap();
///
/// assert_eq!(os_release.id(), "fedora");
/// assert_eq!(os_release.version_id(), Some("32"));
/// ```