]>
Commit | Line | Data |
---|---|---|
82068881 MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # firmware-update - IPFire Firmware Update Tool # | |
5 | # Copyright (C) 2019 IPFire Development Team # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
af9ef5f2 MT |
22 | PACKAGE_NAME="@PACKAGE_NAME@" |
23 | PACKAGE_VERSION="@PACKAGE_VERSION@" | |
24 | ||
f2b32736 MT |
25 | read_dmi() { |
26 | local what="${1}" | |
27 | ||
28 | # Return an error when what is empty | |
29 | [ -z "${what}" ] && return 2 | |
30 | ||
31 | local file="/sys/class/dmi/id/${what}" | |
32 | ||
33 | # Read file | |
34 | if [ -r "${file}" ]; then | |
35 | printf "%s" "$(<${file})" | |
36 | return 0 | |
37 | fi | |
38 | ||
39 | # File could not be read | |
40 | return 1 | |
41 | } | |
42 | ||
43 | board_string() { | |
44 | printf "%s %s\n" \ | |
45 | "$(read_dmi "board_vendor")" \ | |
46 | "$(read_dmi "board_name")" | |
47 | } | |
48 | ||
49 | board_version() { | |
50 | read_dmi "board_version" | |
51 | } | |
52 | ||
53 | board_serial() { | |
54 | read_dmi "board_serial" | |
55 | } | |
56 | ||
57 | bios_version() { | |
58 | read_dmi "bios_version" | |
59 | } | |
60 | ||
61 | bios_date() { | |
62 | read_dmi "bios_date" | |
63 | } | |
64 | ||
af9ef5f2 MT |
65 | main() { |
66 | local action="${1}" | |
67 | shift | |
68 | ||
69 | case "${action}" in | |
f2b32736 MT |
70 | info) |
71 | printf "%-12s: %s\n" "Board" "$(board_string)" | |
72 | printf "%-12s: %s\n" "HW Version" "$(board_version)" | |
73 | printf "%-12s: %s\n" "Serial" "$(board_serial)" | |
74 | printf "%-12s: %s (%s)\n" "BIOS Version" \ | |
75 | "$(bios_version)" "$(bios_date)" | |
76 | return 0 | |
77 | ;; | |
78 | ||
af9ef5f2 MT |
79 | version) |
80 | echo "${PACKAGE_NAME}: Version ${PACKAGE_VERSION}" | |
81 | return 0 | |
82 | ;; | |
babb073d MT |
83 | |
84 | "") | |
85 | echo "No command given" >&2 | |
86 | return 2 | |
87 | ;; | |
88 | ||
89 | *) | |
90 | echo "Invalid command: ${action}" >&2 | |
91 | return 2 | |
92 | ;; | |
af9ef5f2 MT |
93 | esac |
94 | } | |
95 | ||
96 | # Call main | |
babb073d | 97 | main "$@" || exit ${?} |