View Javadoc
1   /*
2    * Copyright 2020-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.driver.linux;
6   
7   import oshi.annotation.concurrent.ThreadSafe;
8   import oshi.util.ExecutingCommand;
9   import oshi.util.ParseUtil;
10  
11  /**
12   * Utility to read info from {@code lshal}
13   */
14  @ThreadSafe
15  public final class Lshal {
16  
17      private Lshal() {
18      }
19  
20      /**
21       * Query the serial number from lshal
22       *
23       * @return The serial number if available, null otherwise
24       */
25      public static String querySerialNumber() {
26          // if lshal command available (HAL deprecated in newer linuxes)
27          String marker = "system.hardware.serial =";
28          for (String checkLine : ExecutingCommand.runNative("lshal")) {
29              if (checkLine.contains(marker)) {
30                  return ParseUtil.getSingleQuoteStringValue(checkLine);
31              }
32          }
33          return null;
34      }
35  
36      /**
37       * Query the UUID from lshal
38       *
39       * @return The UUID if available, null otherwise
40       */
41      public static String queryUUID() {
42          // if lshal command available (HAL deprecated in newer linuxes)
43          String marker = "system.hardware.uuid =";
44          for (String checkLine : ExecutingCommand.runNative("lshal")) {
45              if (checkLine.contains(marker)) {
46                  return ParseUtil.getSingleQuoteStringValue(checkLine);
47              }
48          }
49          return null;
50      }
51  }