-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgmi
More file actions
executable file
·145 lines (131 loc) · 6.7 KB
/
gmi
File metadata and controls
executable file
·145 lines (131 loc) · 6.7 KB
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
#!/usr/bin/env bash
#########################################################################
# GMI - Get Machine Info #
# Copyright (C) 2015 Paul A. Hinchberger III #
#########################################################################
# This program is free software: you can redistribute it and/ #
# or modify it under the terms of the GNU GPLv3 as published #
# by the Free Software Foundation. #
# #
# This program is distributed in the hope that it will be #
# useful, but WITHOUT ANY WARRANTY; without even the implied #
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR #
# PURPOSE. See the GNU GPLv3 for more details. #
# #
# See <http://www.gnu.org/licenses/> for details. #
#########################################################################
if [ -e /usr/sbin/dmidecode ] && /usr/bin/sudo -n /usr/sbin/dmidecode -t 17 > /dev/null 2>&1; then
RAM=$(/usr/bin/awk "BEGIN {print ( $(/usr/bin/sudo /usr/sbin/dmidecode -t 17 | /bin/grep 'Size:' | /bin/grep -v 'No Module Installed\|Volatile Size' | /bin/sed 's/\s\+//g' | /usr/bin/cut -d: -f2 | /usr/bin/tr '\n' '+' | /bin/sed 's/+$//g;s/GB/*2^20/g;s/MB/*2^10/g') ) / 2^20}" 2> /dev/null)
[ -z "${RAM}" ] && RAM=$(/usr/bin/awk "BEGIN {print int ( $(/usr/bin/vmstat -s | /bin/grep 'total memory' | /usr/bin/cut -dK -f1 | /bin/sed 's/ *//g') / 1024 / 1024 * 100 + 0.5 ) / 100 }")
elif [ -d "/sys/devices/system/memory" ]; then
for MEMORIES in /sys/devices/system/memory/memory*; do
if [[ $(< "${MEMORIES}/online") == 1 ]]; then
((TOTALRAM+=0x$(/bin/cat /sys/devices/system/memory/block_size_bytes)))
fi
done
RAM=$(/usr/bin/awk "BEGIN {print ${TOTALRAM} / 1024 ^ 3}")
else
/bin/grep -q ARMv /proc/cpuinfo || echo "Add '%$(id -g -n $(/usr/bin/whoami)) ALL=(ALL) NOPASSWD:/usr/sbin/dmidecode -t 17' with 'visudo' to get exact RAM capacity." > /dev/stderr
RAM=$(/usr/bin/awk "BEGIN {print int ( $(/usr/bin/vmstat -s | /bin/grep 'total memory' | /usr/bin/cut -dK -f1 | /bin/sed 's/ *//g') / 1024 / 1024 * 100 + 0.5 ) / 100 }")
fi
if /usr/bin/lscpu | /bin/grep "Model name" | /bin/grep -v 'BIOS Model name' | /bin/grep -q '@'; then
SPD=$(/usr/bin/lscpu | /bin/grep "Model name" | /usr/bin/cut -d@ -f2 | /bin/sed 's/ \+//g')
elif /usr/bin/lscpu | /bin/grep -q "CPU max MHz"; then
for MHZ in $(/usr/bin/lscpu | /bin/grep "CPU max MHz" | /usr/bin/cut -d: -f2 | /usr/bin/cut -d. -f1 | /bin/sed 's/ \+//g'); do
[ -n "${SPD}" ] && SPD+=" "
SPD+="$((MHZ/1000)).$((((MHZ%1000)+5)/10))GHz"
done
else
SPD=$(/usr/bin/lscpu | /bin/grep 'BIOS Model name' | /usr/bin/cut -d@ -f2 | /bin/grep -P '[0-9\.GMHz]*')
fi
SPA=(${SPD})
NOP=$(/usr/bin/lscpu | /bin/grep -v 'BIOS' | /bin/grep -c 'Model name:')
PCC=$(/usr/bin/sort -u /proc/cpuinfo | /bin/grep -c '^core id')
PCC=${PCC/0/1} # For ARM devices which don't report core ids
LCC=$(/bin/grep -c '^processor' /proc/cpuinfo)
DST="$(/bin/uname -m | /bin/sed 's/^x86_64$/x64v1/g;s/x86_64-v/x64/g') $(/bin/grep PRETTY_NAME /etc/os-release | /usr/bin/cut -d\" -f2)"
PVN="$(/usr/bin/lscpu | /bin/grep '^Vendor ID:' | /bin/sed 's/\s//g' | /usr/bin/cut -d: -f2 | /bin/sed 's/\(Genuine\|Authentic\)//g')"
PMN="$(/usr/bin/lscpu | /bin/grep '^Model name' | /bin/sed 's/:\s\s*/:/g' | /usr/bin/cut -d: -f2 | /bin/sed 's/\s/ /g')"
PMN="${PMN//\([Tt][Mm]\)/}" # Remove (TM)
PMN="${PMN//\([Rr]\)/}" # Remove (R)
PMN="${PMN/AMD?/}" # Remove AMD (already specified in vendor string)
PMN="${PMN/Intel?/}" # Remove Intel (already specified in vendor string)
PMN="${PMN/ APU/}" # Redundant
PMN="${PMN/ CPU/}" # Redundant
PMN="${PMN/ Processor/}" # Redundant
PMN="${PMN/ @/ @}" # Condense space before @
PMN="${PMN/ @*/}" # Don't @ me ;)
PMN="${PMN/ *[GM]Hz/}" # Remove MHz speed (already specified with $GHZ)
PMN="${PMN/CentaurHauls /}" # Remove CentaurHauls
PMN="${PMN/\(/}" # Remove opening parenthesis
PMN="${PMN/\)/}" # Remove closing parenthesis
PMN="${PMN/Pentium/P-}" # Replace Pentium with P- (eg, Pentium III -> P-III)
shopt -s extglob
PMN="${PMN/ +([A-Za-z])?Core/}" # Remove [n] Core (already specified with $PCC)
PMN="${PMN/ version +([0-9]).+([0-9])/}" # Remove version string
PMN="${PMN/+( )/ }" # Reduce multiple spaces to one
shopt -u extglob
CPU=CPU
if [[ ${PMN} = *"with Radeon "*"Graphics"* ]]; then
CPU=APU
PMN="${PMN/ with Radeon *Graphics/}"
elif [[ ${PMN} = *"RADEON R"*"COMPUTE CORES"* ]]; then
CPU=APU
PMN="${PMN/ RADEON R*COMPUTE CORES*/}"
elif [[ ${PMN} = *"with Radeon R"* ]]; then
CPU=APU
PMN="${PMN/ with Radeon R?/}"
fi
PMN="${PMN// /_}"
PMA=(${PMN/$'\n'/ })
PAT="$(/usr/bin/lscpu | /bin/grep '^Architecture' | /bin/sed 's/:\s\s*/:/g' | /usr/bin/cut -d: -f2 | /bin/sed 's/\s/ /g')"
if [[ ${PAT} =~ i.86 ]] || [[ ${PAT} == x86* ]]; then
set -e
flags=$(/bin/grep '^flags\b' < /proc/cpuinfo | /usr/bin/head -n 1)
flags=" ${flags#*:} "
ckflags() {
for flag; do
case "$flags" in
*" $flag "*) :;;
*) return 1;;
esac
done
}
ckflags cx8 fpu mmx && PAT=i586 && \
ckflags cmov fxsr sse && PAT=i686 && \
ckflags sse2 && PAT=i786 && \
ckflags lm syscall && PAT=x64v1 && \
ckflags cx16 lahf_lm popcnt sse4_1 sse4_2 ssse3 && PAT=x64v2 && \
ckflags avx avx2 bmi1 bmi2 f16c fma abm movbe xsave && PAT=x64v3 && \
ckflags avx512f avx512bw avx512cd avx512dq avx512vl && PAT=x64v4
set +e
fi
if [ -z "${PAT}" ]; then
PAT="$(/usr/bin/gcc -c -Q -march=native --help=target | /bin/grep 'march= ' | /bin/sed 's/.*=\s*//;s/+.*//;s/-//g;s/arm/ARM/')"
fi
if type Xorg &> /dev/null; then
DTE="Xorg (Unkown/No DE)"
type icewm &> /dev/null && DTE="IceWM" # has to be first as it can be used stand-alone or with other DEs
type pekwm &> /dev/null && DTE="PekWM" # has to be first as it can be used stand-alone or with other DEs
type openbox-session &> /dev/null && DTE="Openbox" # has to be first as it can be used stand-alone or with other DEs
type gnome-session &> /dev/null && DTE="GNOME 3" # has to be first as it can be used by DEs based on it
type budgie-desktop &> /dev/null && DTE="Budgie"
type cinnamon-session &> /dev/null && DTE="Cinnamon"
type plasma-desktop &> /dev/null && DTE="Plasma 4"
type plasmashell &> /dev/null && DTE="Plasma 5"
type lumina-desktop &> /dev/null && DTE="Lumina"
type startdde &> /dev/null && DTE="Deepin"
type startlxde &> /dev/null && DTE="LXDE"
type startlxqt &> /dev/null && DTE="LXQt"
type mate-session &> /dev/null && DTE="MATE"
type ukui-session &> /dev/null && DTE="UKUI"
type startxfce4 &> /dev/null && DTE="XFCE"
else
DTE="CLI"
fi
/usr/bin/printf '%s %s' "${PAT}" "${PVN}${PVN//[A-Za-z]*/ }"
for (( LC=0 ; LC < ${#PMA[@]} ; LC++ )); do
[ ${LC} -gt 0 ] && /usr/bin/printf ' + '
/usr/bin/printf '%s %s' "${PMA[${LC}]//_/ }" "${SPA[${LC}]}"
done
echo " $((PCC*NOP))c/${LCC}t ${CPU} with ${RAM}GB RAM running ${DST} ${DTE}"