-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathhardware.sh
More file actions
executable file
·209 lines (169 loc) · 4.68 KB
/
hardware.sh
File metadata and controls
executable file
·209 lines (169 loc) · 4.68 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env bash
#
# Hardware Information - Interactive Demo Script
# Run: ./hardware.sh [section]
# Note: Some commands require root privileges or Linux-specific tools
#
set -euo pipefail
readonly NC='\033[0m'
readonly BOLD='\033[1m'
readonly GREEN='\033[0;32m'
readonly CYAN='\033[0;36m'
readonly YELLOW='\033[0;33m'
readonly RED='\033[0;31m'
section() { echo -e "\n${BOLD}${GREEN}=== $1 ===${NC}\n"; }
code() { echo -e "${CYAN}$ $1${NC}"; }
output() { echo -e "${YELLOW}$1${NC}"; }
warn() { echo -e "${RED}(requires: $1)${NC}"; }
check_cmd() { command -v "$1" &>/dev/null; }
is_linux() { [[ "$OSTYPE" == "linux"* ]]; }
is_macos() { [[ "$OSTYPE" == "darwin"* ]]; }
# -----------------------------------------------------------------------------
demo_cpu() {
section "CPU Information"
if check_cmd nproc; then
code 'nproc'
output "$(nproc)"
fi
if is_macos; then
code 'sysctl -n hw.logicalcpu'
output "$(sysctl -n hw.logicalcpu)"
code 'sysctl -n hw.physicalcpu'
output "$(sysctl -n hw.physicalcpu)"
code 'sysctl -n machdep.cpu.brand_string'
output "$(sysctl -n machdep.cpu.brand_string)"
fi
if check_cmd lscpu; then
code 'lscpu | head -15'
lscpu | head -15
fi
if is_linux && [[ -f /proc/cpuinfo ]]; then
code 'grep "model name" /proc/cpuinfo | head -1'
grep "model name" /proc/cpuinfo | head -1
echo
code 'grep -c ^processor /proc/cpuinfo'
output "$(grep -c ^processor /proc/cpuinfo) logical CPUs"
fi
}
# -----------------------------------------------------------------------------
demo_memory() {
section "Memory Information"
if check_cmd free; then
code 'free -h'
free -h
echo
fi
if is_macos; then
code 'sysctl -n hw.memsize | awk "{print \$1/1024/1024/1024 \" GB\"}"'
sysctl -n hw.memsize | awk '{print $1/1024/1024/1024 " GB"}'
echo
code 'vm_stat | head -10'
vm_stat | head -10
fi
if is_linux && [[ -f /proc/meminfo ]]; then
code 'head -5 /proc/meminfo'
head -5 /proc/meminfo
fi
}
# -----------------------------------------------------------------------------
demo_disk() {
section "Disk and Storage"
code 'df -h'
df -h
echo
code 'df -h / | tail -1'
df -h / | tail -1
echo
code 'du -sh ~/* 2>/dev/null | sort -h | tail -5'
du -sh ~/* 2>/dev/null | sort -h | tail -5 || echo "(permission denied on some dirs)"
echo
if check_cmd lsblk; then
code 'lsblk'
lsblk
elif is_macos; then
code 'diskutil list | head -20'
diskutil list | head -20
fi
}
# -----------------------------------------------------------------------------
demo_pci() {
section "PCI Devices"
if ! check_cmd lspci; then
if is_macos; then
code 'system_profiler SPPCIDataType | head -30'
system_profiler SPPCIDataType 2>/dev/null | head -30 || echo "(no PCI data)"
else
warn "lspci (install with: apt install pciutils)"
fi
return
fi
code 'lspci | head -15'
lspci | head -15
echo
code 'lspci | grep -i vga'
lspci | grep -i vga || echo "(no VGA device found)"
echo
code 'lspci | grep -i network'
lspci | grep -i network || echo "(no network device found)"
echo
code 'lspci -nn | head -10'
lspci -nn | head -10
}
# -----------------------------------------------------------------------------
demo_summary() {
section "System Summary"
code 'uname -a'
output "$(uname -a)"
if is_macos; then
code 'system_profiler SPHardwareDataType | grep -E "Model|Processor|Memory|Serial"'
system_profiler SPHardwareDataType | grep -E "Model|Processor|Memory|Serial"
fi
if check_cmd hostnamectl; then
code 'hostnamectl'
hostnamectl
fi
if check_cmd lshw; then
echo
echo "lshw available - run with: sudo lshw -short"
fi
if check_cmd dmidecode; then
echo
echo "dmidecode available - run with: sudo dmidecode -t system"
fi
}
# -----------------------------------------------------------------------------
run_all() {
demo_cpu
demo_memory
demo_disk
demo_pci
demo_summary
}
# -----------------------------------------------------------------------------
usage() {
cat <<EOF
Hardware Information - Interactive Demo
Usage: $0 [section]
Sections:
cpu CPU information
memory Memory information
disk Disk and storage
pci PCI devices
summary System summary
all Run all demos (default)
Note: Some commands require root privileges or Linux-specific tools.
For GPU information, see gpu.sh
EOF
}
# Main
case "${1:-all}" in
cpu) demo_cpu ;;
memory) demo_memory ;;
disk) demo_disk ;;
pci) demo_pci ;;
gpu) demo_gpu ;;
summary) demo_summary ;;
all) run_all ;;
-h|--help) usage ;;
*) echo "Unknown section: $1"; usage; exit 1 ;;
esac