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
// Take a look at the license at the top of the repository in the LICENSE file.
pub(crate) struct ProductInner;
impl ProductInner {
pub(crate) fn family() -> Option<String> {
std::fs::read_to_string("/sys/devices/virtual/dmi/id/product_family")
.ok()
.map(|s| s.trim().to_owned())
}
pub(crate) fn name() -> Option<String> {
std::fs::read_to_string("/sys/devices/virtual/dmi/id/product_name")
.ok()
.or_else(|| {
std::fs::read_to_string("/sys/firmware/devicetree/base/model")
.ok()
.or_else(|| {
std::fs::read_to_string("/sys/firmware/devicetree/base/banner-name").ok()
})
.or_else(|| std::fs::read_to_string("/tmp/sysinfo/model").ok())
.map(|s| s.trim_end_matches('\0').to_owned())
})
.map(|s| s.trim().to_owned())
}
pub(crate) fn serial_number() -> Option<String> {
std::fs::read_to_string("/sys/devices/virtual/dmi/id/product_serial")
.ok()
.or_else(|| {
std::fs::read_to_string("/sys/firmware/devicetree/base/serial-number")
.ok()
.map(|s| s.trim_end_matches('\0').to_owned())
})
.map(|s| s.trim().to_owned())
}
pub(crate) fn stock_keeping_unit() -> Option<String> {
std::fs::read_to_string("/sys/devices/virtual/dmi/id/product_sku")
.ok()
.map(|s| s.trim().to_owned())
}
pub(crate) fn uuid() -> Option<String> {
std::fs::read_to_string("/sys/devices/virtual/dmi/id/product_uuid")
.ok()
.map(|s| s.trim().to_owned())
}
pub(crate) fn version() -> Option<String> {
std::fs::read_to_string("/sys/devices/virtual/dmi/id/product_version")
.ok()
.map(|s| s.trim().to_owned())
}
pub(crate) fn vendor_name() -> Option<String> {
std::fs::read_to_string("/sys/devices/virtual/dmi/id/sys_vendor")
.ok()
.map(|s| s.trim().to_owned())
}
}