-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpawprint.sh
More file actions
1577 lines (1444 loc) · 60.3 KB
/
pawprint.sh
File metadata and controls
1577 lines (1444 loc) · 60.3 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# System Profiler (PawPrint)
# Comprehensive system information tool
# Tiger Computing LTD
# https://github.com/tiger-computing/pawprint
set -u
#──────────────────────────────
# SCRIPT RELATED CONFIGURATION
#──────────────────────────────
# Colors
if [ -n "${NO_COLOR:-}" ]; then
RED=''
GREEN=''
YELLOW=''
BLUE=''
NC=''
else
RED=$'\033[0;31m'
GREEN=$'\033[0;32m'
YELLOW=$'\033[1;33m'
BLUE=$'\033[0;34m'
NC=$'\033[0m' # No Color
fi
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "${RED}This script must be run as root.${NC}"
exit 1
fi
# Check if system is Linux
if [ "$(uname -s)" != "Linux" ]; then
echo "${RED}$(uname -s) systems are not supported.${NC}"
exit 1
fi
# Check for --debug or --full flag
DEBUG=false
FULL=false
if [ "${1:-}" = "--debug" ]; then
DEBUG=true
FULL=true # automatically enable FULL as well
elif [ "${1:-}" = "--full" ]; then
FULL=true
fi
# Spinner frames from loading.sh
frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏')
# Initial message
echo "${BLUE}┌─────────────────────────────────────────┐"
echo "│ PawPrint System Profiler │"
echo "│ Tiger Computing LTD │"
echo "│ https://tiger-computing.co.uk/pawprint/ │"
echo "└─────────────────────────────────────────┘${NC}"
echo
# EOL dates for common distros
declare -A DISTRO_EOL
# Ubuntu LTS versions (including EOL'd)
DISTRO_EOL["Ubuntu 12.04 LTS"]="April 2017"
DISTRO_EOL["Ubuntu 14.04 LTS"]="April 2019"
DISTRO_EOL["Ubuntu 16.04 LTS"]="April 2021"
DISTRO_EOL["Ubuntu 18.04 LTS"]="April 2023"
DISTRO_EOL["Ubuntu 20.04 LTS"]="April 2025"
DISTRO_EOL["Ubuntu 22.04 LTS"]="April 2027"
DISTRO_EOL["Ubuntu 24.04 LTS"]="April 2029"
# Debian versions (including EOL'd)
DISTRO_EOL["Debian 7"]="May 2018"
DISTRO_EOL["Debian 8"]="June 2020"
DISTRO_EOL["Debian 9"]="June 2022"
DISTRO_EOL["Debian 10"]="June 2024"
DISTRO_EOL["Debian 11"]="August 2026"
DISTRO_EOL["Debian GNU/Linux 12 (bookworm)"]="June 2028"
DISTRO_EOL["Debian 12"]="June 2028"
# Red Hat Enterprise Linux (including EOL'd)
DISTRO_EOL["Red Hat Enterprise Linux 5"]="March 2017"
DISTRO_EOL["Red Hat Enterprise Linux 6"]="November 2020"
DISTRO_EOL["Red Hat Enterprise Linux 7"]="June 2024"
DISTRO_EOL["Red Hat Enterprise Linux 8"]="May 2029"
DISTRO_EOL["Red Hat Enterprise Linux 9"]="May 2032"
# CentOS versions (including EOL'd)
DISTRO_EOL["CentOS 5"]="March 2017"
DISTRO_EOL["CentOS 6"]="November 2020"
DISTRO_EOL["CentOS 7"]="June 2024"
DISTRO_EOL["CentOS 8"]="December 2021"
DISTRO_EOL["CentOS Stream 8"]="May 2024"
DISTRO_EOL["CentOS Stream 9"]="May 2027"
# Rocky Linux
DISTRO_EOL["Rocky Linux 8"]="May 2029"
DISTRO_EOL["Rocky Linux 9"]="May 2032"
# AlmaLinux
DISTRO_EOL["AlmaLinux 8"]="May 2029"
DISTRO_EOL["AlmaLinux 9"]="May 2032"
# SUSE Linux Enterprise (including EOL'd)
DISTRO_EOL["SUSE Linux Enterprise Server 11"]="March 2019"
DISTRO_EOL["SUSE Linux Enterprise Server 12"]="October 2027"
DISTRO_EOL["SUSE Linux Enterprise Server 15"]="July 2031"
# Fedora (shorter support cycles, including recent EOL'd)
DISTRO_EOL["Fedora 35"]="December 2022"
DISTRO_EOL["Fedora 36"]="May 2023"
DISTRO_EOL["Fedora 37"]="November 2023"
DISTRO_EOL["Fedora 38"]="May 2024"
DISTRO_EOL["Fedora 39"]="November 2024"
DISTRO_EOL["Fedora 40"]="May 2025"
# Global error counter and message arrays
CHECK_ERRORS=0
CHECK_WARNINGS=0
declare -a ERROR_MESSAGES
declare -a WARNING_MESSAGES
# Enhanced run_check function that works with bash functions
run_check() {
local description=$1
local check_func=$2
local i=0 status=0
local temp_output
temp_output=$(mktemp)
if [ "$DEBUG" = true ]; then
# Run the check synchronously with no spinner
(
[ -n "${TRACE:-}" ] && set -x
$check_func
) > "$temp_output" || status=$?
else
# Run the check function in background with error capture
(
[ -n "${TRACE:-}" ] && set -x
$check_func
) > "$temp_output" &
pid=$!
# Show spinner while check runs
while kill -0 $pid 2>/dev/null; do
printf "\r${YELLOW}${frames[i]}${NC} %s..." "$description"
(( i = (i + 1) % ${#frames[@]} ))
sleep 0.1
done
wait $pid || status=$?
fi
if [ "$status" -ne 0 ]; then
# Check failed - capture error
(( CHECK_ERRORS++ ))
ERROR_MESSAGES+=("$description failed (exit code: $status)")
echo "${RED}ERROR: $description failed (exit code: $status)${NC}" >> "$temp_output"
fi
# Clear the spinner line and show result
printf "\r\033[K"
# Check for empty output: if check succeeded (status=0) with no output, silently skip
# If check failed (status!=0) with no output, show warning
if [ ! -s "$temp_output" ]; then
if [ "$status" -eq 0 ]; then
# Successful check with no output = silent skip (don't show anything)
rm -f "$temp_output"
return 0
else
# Failed check with no output = warning
(( CHECK_WARNINGS++ ))
WARNING_MESSAGES+=("$description produced no output")
echo "${YELLOW}WARNING: $description produced no output${NC}" > "$temp_output"
fi
fi
# Output the check result with debug mode column if enabled
if [ "$DEBUG" = true ]; then
while IFS= read -r line; do
[ -n "$line" ] && printf "%-20s | %s\n" "$check_func" "$line"
done < "$temp_output"
else
cat "$temp_output"
fi
# Cleanup temp files
rm -f "$temp_output"
}
#─────────────
# SYSTEM INFO
#─────────────
# Check hostname and FQDN, validate hostname format
check_hostname() {
local host fqdn
host=$(hostname 2>/dev/null || echo "Unknown")
fqdn=$(hostname -f 2>/dev/null || echo "Unknown")
if [[ "$host" =~ ^[.a-z0-9-]+$ ]]; then
echo "Hostname: ${GREEN}$host${NC} (${BLUE}$fqdn${NC})"
else
echo "Hostname: ${RED}$host${NC} (${BLUE}$fqdn${NC})"
fi
}
# Check if system is a VM or bare metal, best effort to identify provider if VM
# Display ipmi info if bare metal
check_systype() {
if systemd-detect-virt >/dev/null 2>&1 && [[ $(systemd-detect-virt) != none ]]; then
virt=$(systemd-detect-virt)
# Try to determine cloud provider
if [[ -f /sys/class/dmi/id/product_name ]]; then
read -r name < /sys/class/dmi/id/product_name
case $name in
*Amazon*) provider="AWS" ;;
*Google*) provider="GCP" ;;
*Azure*|*microsoft*) provider="Azure" ;;
*Linode*) provider="Linode" ;;
*DigitalOcean*) provider="DigitalOcean" ;;
*) provider="" ;;
esac
fi
# Fallback - additional hints
[[ -z $provider && -f /sys/class/dmi/id/sys_vendor ]] &&
read -r vendor < /sys/class/dmi/id/sys_vendor &&
[[ $vendor == *Hetzner* ]] && provider="Hetzner"
output="Type: VM (${BLUE}$virt${NC})"
[[ $provider ]] && output+=" likely ${BLUE}$provider${NC}"
else
local ipmi=""
if command -v ipmitool >/dev/null; then
ipmi=$(ipmitool -I open mc info 2>/dev/null | awk '/Firmware Revision/ {print "IPMI: " $NF}')
fi
output="Type: ${YELLOW}Bare Metal${NC}${ipmi:+ (${BLUE}$ipmi${NC})}"
fi
echo "$output"
}
# Retrieve BIOS details from dmidecode
check_bios() {
local manufacturer product version serial
local output=""
manufacturer=$(dmidecode -s system-manufacturer 2>/dev/null || echo "Unknown")
product=$(dmidecode -s system-product-name 2>/dev/null || echo "Unknown")
version=$(dmidecode -s system-version 2>/dev/null || echo "Unknown")
serial=$(dmidecode -s system-serial-number 2>/dev/null || echo "Unknown")
[ "$manufacturer" != "Unknown" ] && output="${NC}Manufacturer: ${BLUE}$manufacturer${NC} | ${NC}Product: ${BLUE}$product${NC} | ${NC}Version: ${BLUE}$version${NC} | ${NC}Serial: ${BLUE}$serial${NC}"
if [ -n "$output" ]; then
echo "$output"
else
echo "${YELLOW}BIOS: No data available${NC}"
fi
}
# Display CPU details
check_cpu() {
local chips model cores
chips=$(grep "physical id" /proc/cpuinfo 2>/dev/null | sort -u | wc -l || echo "Unknown")
model=$(grep "model name" /proc/cpuinfo 2>/dev/null | head -1 | cut -d':' -f2 | sed 's/^\s*//' || echo "Unknown")
cores=$(nproc 2>/dev/null || echo "Unknown")
if [ "$chips" != "Unknown" ] && [ "$model" != "Unknown" ] && [ "$cores" != "Unknown" ]; then
echo "Processor: $chips CPU(s), Model: ${BLUE}$model${NC}, $cores Cores/Threads"
else
echo "${YELLOW}Processor: No data available${NC}"
fi
}
# Memory and swap usage
check_memory() {
local total used swap_total swap_used mem_percent
local swap_percent=0
total=$(free -h 2>/dev/null | awk '/^Mem:/ {print $2}' || echo "Unknown")
used=$(free -h 2>/dev/null | awk '/^Mem:/ {print $3}' || echo "Unknown")
swap_total=$(free -h 2>/dev/null | awk '/^Swap:/ {print $2}' || echo "Unknown")
swap_used=$(free -h 2>/dev/null | awk '/^Swap:/ {print $3}' || echo "Unknown")
mem_percent=$(free 2>/dev/null | awk '/^Mem:/ {print ($3/$2)*100}' | awk '{printf "%.0f", $1}' || echo "N/A")
if [ "$swap_total" != "0B" ] && [ "$swap_total" != "Unknown" ]; then
swap_percent=$(free 2>/dev/null | awk '/^Swap:/ {print ($3/$2)*100}' | awk '{printf "%.0f", $1}' || echo "N/A")
fi
if [ "$total" = "Unknown" ] || [ "$used" = "Unknown" ]; then
echo "${YELLOW}Memory: No data available${NC}"
return
fi
local mem_color=""
if [ "$mem_percent" != "N/A" ] && [ "$mem_percent" -lt 70 ]; then
mem_color="${GREEN}"
elif [ "$mem_percent" != "N/A" ] && [ "$mem_percent" -ge 71 ] && [ "$mem_percent" -le 88 ]; then
mem_color="${YELLOW}"
else
mem_color="${RED}"
fi
if [ "$swap_total" != "0B" ] && [ "$swap_total" != "Unknown" ]; then
if [ "$swap_percent" != "N/A" ] && [ "$swap_percent" -gt 30 ]; then
echo "Memory: ${BLUE}Total RAM: $total ${mem_color}(Used: $used), Swap: $swap_total (Used: $swap_used)${RED} (Swap usage: ${swap_percent}%)${NC}"
else
echo "Memory: ${BLUE}Total RAM: $total ${mem_color}(Used: $used), Swap: $swap_total (Used: $swap_used)${GREEN} (Swap usage: ${swap_percent}%)${NC}"
fi
else
echo "Memory: ${BLUE}Total RAM: $total ${mem_color}(Used: $used), ${RED}No Swap${NC}"
fi
}
# Display current time in UTC and time synchronization service
check_time() {
local time_output
local sync=""
[ -n "$(command -v ntpq)" ] && ntpq -p >/dev/null 2>&1 && sync+="NTP "
[ -n "$(systemctl is-active systemd-timesyncd 2>/dev/null)" ] && sync+="timesyncd "
[ -n "$(command -v chronyc)" ] && chronyc tracking >/dev/null 2>&1 && sync+="chrony "
time_output=$(date -u +"%Y %b %d (%a) %H:%M" 2>/dev/null || echo "Unknown")
if [ "$time_output" = "Unknown" ]; then
echo "${YELLOW}Time: No data available${NC}"
return
fi
if [ -n "$sync" ]; then
echo "${NC}Time: ${BLUE}$time_output${NC}, Service: ${BLUE}$sync${NC}"
else
echo "${NC}Time: ${BLUE}$time_output${NC}, ${RED}Service: No Time Service${NC}"
fi
}
# Report system uptime
check_uptime() {
local uptime_seconds
uptime_seconds=$(cut -d. -f1 /proc/uptime 2>/dev/null || echo "Unknown")
if [ "$uptime_seconds" = "Unknown" ]; then
echo "${YELLOW}Uptime: No data available${NC}"
return
fi
if [ "$uptime_seconds" -lt 600 ]; then
echo "${NC}Uptime: ${GREEN}Freshly rebooted${NC}"
else
echo "${NC}Uptime: ${BLUE}$(uptime -p 2>/dev/null | sed 's/up //' || echo "Unknown")${NC}"
fi
}
# Display system load averages
check_load() {
local load load_output
load=$(uptime 2>/dev/null | awk -F'load average:' '{print $2}' | awk '{print $1}' | tr -d ',' || echo "N/A")
load_output=$(uptime 2>/dev/null | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//' || echo "Unknown")
if [ "$load" = "N/A" ] || [ "$load_output" = "Unknown" ]; then
echo "${YELLOW}Load: No data available${NC}"
return
fi
if awk "BEGIN {exit !($load < 1.0)}"; then
echo "${NC}Load: ${GREEN}$load_output${NC}"
else
echo "${NC}Load: ${RED}$load_output${NC}"
fi
}
# Show distribution name and EOL date if available
check_distro() {
local distro
distro=$(cat /etc/os-release 2>/dev/null | grep PRETTY_NAME | cut -d'"' -f2 || echo "Unknown")
if [ "$distro" = "Unknown" ]; then
echo "${YELLOW}OS: No data available${NC}"
return
fi
local eol="${DISTRO_EOL["$distro"]:-}"
if [ -n "$eol" ]; then
echo "${NC}OS: ${BLUE}$distro${NC} ${GREEN}(EOL: $eol)${NC}"
else
echo "${NC}OS: ${BLUE}$distro${NC}"
fi
}
# Check for active Pro subscriptions (only on distros with subscription systems)
check_sub() {
local output="" details="" subscription="" status="" expiry="" distro="" color=""
# Red Hat Enterprise Linux (RHEL) or Oracle Linux with subscription-manager
if [ -f "/etc/redhat-release" ] && command -v subscription-manager >/dev/null 2>&1; then
# Check if it's actually RHEL or Oracle Linux (not Rocky/Alma/CentOS which are free)
if grep -qiE 'Red Hat Enterprise|Oracle Linux' /etc/redhat-release 2>/dev/null; then
distro="Red Hat"
status=$(subscription-manager status 2>/dev/null | grep -i "Overall Status" | awk '{print $NF}' || echo "Unknown")
expiry=$(subscription-manager list --installed 2>/dev/null | grep -i "Ends" | awk '{print $NF}' | head -1 || echo "Unknown")
else
# Rocky/Alma/CentOS don't have subscriptions
if [ "$DEBUG" = true ] || [ "$FULL" = true ]; then
echo "${NC}Subscription: ${BLUE}N/A${NC} ${GREEN}(distro doesn't use subscriptions)${NC}"
fi
return 0
fi
# Ubuntu Pro (ESM) - only if ua tool is installed
elif grep -qi ubuntu /etc/os-release 2>/dev/null && command -v ua >/dev/null 2>&1; then
distro="Ubuntu Pro"
status=$(ua status --format json 2>/dev/null | grep -oP '(?<="esm-apps":\{"status":")[^"]+' || echo "Unknown")
expiry=$(ua status 2>/dev/null | grep -oP 'expires:\s*\K\S+' | head -1 || echo "Unknown")
# SUSE Linux Enterprise Server (SLES) - not openSUSE
elif [ -f "/etc/os-release" ] && grep -qi "SUSE Linux Enterprise" /etc/os-release && command -v SUSEConnect >/dev/null 2>&1; then
distro="SUSE"
if SUSEConnect --status-text 2>/dev/null | grep -qi "Product.*Registered"; then
status="enabled"
expiry=$(SUSEConnect -s 2>/dev/null | grep -oP '\d{4}-\d{2}-\d{2}' | sort | tail -1 || echo "Unknown")
else
status="disabled"
expiry="Unknown"
fi
else
# Skip check silently for distros without subscriptions (Debian, Rocky, Alma, etc.)
# But show message in debug/full mode
if [ "$DEBUG" = true ] || [ "$FULL" = true ]; then
echo "${NC}Subscription: ${BLUE}N/A${NC} ${GREEN}(distro doesn't use subscriptions)${NC}"
fi
return 0
fi
# Build output message
if [ "$status" = "Current" ] || [ "$status" = "enabled" ]; then
subscription="Active ($distro, expires: $expiry)"
color="${YELLOW}"
elif [ "$status" != "Unknown" ]; then
subscription="Expired/inactive ($distro, status: $status, last valid: $expiry)"
color="${RED}"
fi
# Final output control
if [ -n "$subscription" ]; then
if [ "$DEBUG" = true ] || [ "$FULL" = true ]; then
echo "${NC}Subscription: ${color}$subscription${NC}"
echo "Status: $status"
echo "Expiry: $expiry"
else
echo "${NC}Subscription: ${color}$subscription${NC}"
fi
fi
}
# Check for cluster/HA software
check_cluster() {
local cluster_tech=()
local details=()
# Check for Pacemaker
if command -v crm >/dev/null 2>&1 || command -v pcs >/dev/null 2>&1 || [ -d "/var/lib/pacemaker" ]; then
cluster_tech+=("Pacemaker")
details+=("Pacemaker")
fi
# Check for Corosync
if command -v corosync-quorumtool >/dev/null 2>&1 || [ -f "/etc/corosync/corosync.conf" ]; then
cluster_tech+=("Corosync")
details+=("Corosync")
fi
# Check for DRBD
if command -v drbdadm >/dev/null 2>&1 || [ -f "/proc/drbd" ] || [ -f "/etc/drbd.conf" ]; then
cluster_tech+=("DRBD")
details+=("DRBD")
fi
# Check for Keepalived
if command -v keepalived >/dev/null 2>&1 || [ -f "/etc/keepalived/keepalived.conf" ]; then
cluster_tech+=("Keepalived")
details+=("Keepalived")
fi
# Check for Heartbeat (legacy)
if command -v heartbeat >/dev/null 2>&1 || [ -d "/etc/ha.d" ]; then
cluster_tech+=("Heartbeat")
details+=("Heartbeat")
fi
# Check for cluster filesystems
if command -v gfs2_tool >/dev/null 2>&1 || lsmod 2>/dev/null | grep -q gfs2; then
cluster_tech+=("GFS2")
details+=("GFS2")
fi
if command -v ocfs2 >/dev/null 2>&1 || lsmod 2>/dev/null | grep -q ocfs2; then
cluster_tech+=("OCFS2")
details+=("OCFS2")
fi
# Check for Galera (MySQL/MariaDB clustering)
if command -v mysql >/dev/null 2>&1 && mysql -V 2>/dev/null | grep -qi galera; then
cluster_tech+=("Galera")
details+=("Galera")
fi
# Check for Redis Cluster/Sentinel
if command -v redis-cli >/dev/null 2>&1; then
if redis-cli --version 2>/dev/null | grep -q redis; then
if systemctl is-active redis-sentinel >/dev/null 2>&1 || [ -f "/etc/redis/sentinel.conf" ]; then
cluster_tech+=("Redis Sentinel")
details+=("Redis Sentinel")
fi
fi
fi
# Check for MongoDB Replica Set
if command -v mongod >/dev/null 2>&1 && grep -q "replSet" /etc/mongod.conf 2>/dev/null; then
cluster_tech+=("MongoDB Replica Set")
details+=("MongoDB Replica Set")
fi
# Check for etcd
if command -v etcd >/dev/null 2>&1 || command -v etcdctl >/dev/null 2>&1; then
cluster_tech+=("etcd")
details+=("etcd")
fi
# Check for Consul
if command -v consul >/dev/null 2>&1; then
cluster_tech+=("Consul")
details+=("Consul")
fi
# Check for ZooKeeper
if command -v zkServer.sh >/dev/null 2>&1 || [ -d "/etc/zookeeper" ]; then
cluster_tech+=("ZooKeeper")
details+=("ZooKeeper")
fi
# Check for HAProxy (often used with clusters)
if command -v haproxy >/dev/null 2>&1 || [ -f "/etc/haproxy/haproxy.cfg" ]; then
cluster_tech+=("HAProxy")
details+=("HAProxy")
fi
# Check for Kubernetes (any variant, worker or control plane)
if command -v kubectl >/dev/null 2>&1 || command -v kubelet >/dev/null 2>&1 || [ -d "/etc/kubernetes" ] || [ -f "/var/lib/kubelet/config.yaml" ]; then
local k8s_role=""
cluster_tech+=("Kubernetes")
if [ "$DEBUG" = true ] || [ "$FULL" = true ]; then
# Determine role
if [ -f "/etc/kubernetes/manifests/kube-apiserver.yaml" ] || [ -f "/etc/kubernetes/admin.conf" ]; then
k8s_role="control-plane"
else
k8s_role="worker"
fi
details+=("Kubernetes ($k8s_role)")
fi
fi
# Check for K3s (lightweight Kubernetes)
if command -v k3s >/dev/null 2>&1 || [ -f "/etc/rancher/k3s/k3s.yaml" ]; then
if [ -z "${cluster_tech##*Kubernetes*}" ]; then
: # Already detected as Kubernetes
else
cluster_tech+=("K3s")
fi
if [ "$DEBUG" = true ] || [ "$FULL" = true ]; then
local k3s_role="unknown"
if systemctl is-active k3s >/dev/null 2>&1; then
k3s_role="server"
elif systemctl is-active k3s-agent >/dev/null 2>&1; then
k3s_role="agent"
fi
details+=("K3s ($k3s_role)")
fi
fi
# Check for MicroK8s
if command -v microk8s >/dev/null 2>&1 || [ -d "/var/snap/microk8s" ]; then
if printf '%s\0' "${cluster_tech[@]}" | grep -Fxqz -- Kubernetes; then
: # Already detected as Kubernetes
else
cluster_tech+=("MicroK8s")
fi
details+=("MicroK8s")
fi
# Check for Docker Swarm
if command -v docker >/dev/null 2>&1; then
local swarm_status
swarm_status=$(docker info --format '{{.Swarm.LocalNodeState}}' 2>/dev/null)
if [ "$swarm_status" != "inactive" ]; then
cluster_tech+=("Docker Swarm")
if [ "$DEBUG" = true ] || [ "$FULL" = true ]; then
local swarm_role
swarm_role=$(docker info --format '{{.Swarm.ControlAvailable}}' 2>/dev/null)
if [ "$swarm_role" = "true" ]; then
details+=("Docker Swarm (manager)")
else
details+=("Docker Swarm (worker)")
fi
fi
fi
fi
# Check for Nomad (HashiCorp orchestrator)
if command -v nomad >/dev/null 2>&1; then
cluster_tech+=("Nomad")
details+=("Nomad")
fi
# Check for RKE (Rancher Kubernetes Engine)
if command -v rke >/dev/null 2>&1 || [ -f "/etc/kubernetes/ssl/kube-ca.pem" ] || [ -d "/opt/rke" ]; then
cluster_tech+=("RKE")
details+=("RKE")
fi
# Check for Rancher (management platform)
if command -v rancher >/dev/null 2>&1 || systemctl is-active rancher >/dev/null 2>&1 || [ -d "/var/lib/rancher" ]; then
cluster_tech+=("Rancher")
details+=("Rancher")
fi
# Check for Longhorn (distributed block storage for Kubernetes)
if kubectl get ns longhorn-system >/dev/null 2>&1 || [ -d "/var/lib/longhorn" ] || systemctl is-active longhorn-manager >/dev/null 2>&1; then
cluster_tech+=("Longhorn")
details+=("Longhorn")
fi
# Output results
if [ "${#cluster_tech[@]}" -gt 0 ]; then
if [ "$DEBUG" = true ] || [ "$FULL" = true ]; then
echo "Cluster/HA: ${YELLOW}Detected${NC}"
echo "Details:"
printf " - ${YELLOW}%s${NC}\n" "${details[@]}"
else
echo "Cluster/HA: ${YELLOW}${cluster_tech[*]}${NC}"
fi
else
echo "Cluster/HA: ${GREEN}None detected${NC}"
fi
}
# List disk usage for physical filesystems, including RAID, ZFS, Btrfs, and network mounts
check_disks() {
local dev mount size used avail use_percent fstype
# Obtain filesystem types from /proc/mounts
local -A fstypes
while read -r dev mount fstype _; do
fstypes[$mount]="$fstype"
done < /proc/mounts
# Print filesystem overview using df
df -hl -x overlay -x tmpfs -x devtmpfs -x proc -x sysfs -x efivarfs 2>/dev/null | while read -r dev size used avail use_percent mount; do
[ "${dev}" = "Filesystem" ] && continue # skip header
fstype="${fstypes[$mount]:-unknown}"
if [ "${use_percent%%\%}" -gt 75 ]; then
echo "Disk: $dev @ $mount (${fstype}, size: $size, used: $used, avail: ${RED}$avail / ${use_percent}${NC})"
else
echo "Disk: $dev @ $mount (${fstype}, size: $size, used: $used, avail: ${GREEN}$avail / ${use_percent}${NC})"
fi
done
# RAID devices
lsblk -fln 2>/dev/null | while read -r dev fstype _; do
[[ "${fstype,,}" == *raid* ]] || continue # only RAID
echo "RAID: ${dev} (${fstype})"
done
# ZFS
zfs list -H -o name,used,avail 2>/dev/null | while read -r dev used avail; do
echo "ZFS: ${dev} (used: ${used}, avail: ${avail})"
done
# btrfs
btrfs filesystem show -m 2>/dev/null | grep devid | while read -r _ mount _ size _ used _ dev; do
echo "btrfs: ${dev} (devid: ${mount}, size: ${size}, used: ${used})"
done
# Network file systems
while read -r dev mount fstype _; do
case "$fstype" in
cifs|nfs) ;;
*) continue;;
esac
echo "Network: ${dev} @ ${mount} (${fstype})"
done < /proc/mounts
}
#────────────────
# NETWORK CHECKS
#────────────────
# Check network interfaces for speed and errors
check_network() {
local output=""
local details=()
local sysdev
for sysdev in /sys/class/net/*; do
local state carrier
[ -h "$sysdev" ] || continue
# Skip operationally down interfaces
state="$(< "${sysdev}/operstate")"
[ "$state" = "down" ] && continue
# Skip interfaces with no carrier
carrier="$(< "${sysdev}/carrier")"
[ "$carrier" != "1" ] && continue
local nic="${sysdev##*/}"
local speed mtu address
for attr in speed mtu address; do
declare "${attr}=$(< "${sysdev}/${attr}")"
done
local rx_errors tx_errors rx_packets rx_bytes tx_packets tx_bytes
for stat in rx_errors tx_errors rx_packets rx_bytes tx_packets tx_bytes; do
declare "${stat}=$(< "${sysdev}/statistics/${stat}")"
done
local speed_color="${BLUE}"
case "$speed" in
-1|'') speed="n/a"; speed_color="${YELLOW}";;
esac
local error_color="${GREEN}"
if [ "$rx_errors" -gt 0 ] || [ "$tx_errors" -gt 0 ]; then
error_color="${RED}"
fi
# Only include physical NICs (eth* or en*) in standard mode
if [ "$DEBUG" = true ] || [ "$FULL" = true ]; then
local ip_addr ip6_addr
ip_addr=$(ip -4 -o addr show "$nic" 2>/dev/null | awk '{print $4}' | xargs -n1)
ip6_addr=$(ip -6 -o addr show "$nic" scope global 2>/dev/null | awk '{print $4}' | xargs -n1)
echo "NIC: ${nic}"
echo " Speed: ${speed_color}${speed}${NC}"
echo " RX/TX Errors: ${error_color}${rx_errors}/${tx_errors}${NC}"
echo " RX/TX Packets: ${rx_packets}/${tx_packets}"
echo " RX/TX Bytes: ${rx_bytes}/${tx_bytes}"
echo " MTU: ${mtu}"
echo " Address: ${address}"
echo " IP: ${ip_addr:-None}"
echo " IPv6: ${ip6_addr:-None}"
elif [[ "$nic" =~ ^eth[0-9]+$ || "$nic" =~ ^e[nm][a-z0-9]+ ]]; then
echo "NIC: $nic (${speed_color}speed: $speed${NC}, ${error_color}errors: ${rx_errors}/${tx_errors}${NC})"
fi
done
}
# Check ping latency
check_ping() {
local host="thames.tiger-computing.co.uk"
local ipv4_result ipv6_result ipv4_avg ipv6_avg
# Test IPv4
ipv4_result=$(ping -4 -i 0.2 -c 20 "$host" 2>/dev/null | tail -1 || echo "")
if [ -n "$ipv4_result" ]; then
ipv4_avg=$(echo "$ipv4_result" | awk -F'/' '{print $5}' | grep -E '^[0-9.]+' || echo "N/A")
else
ipv4_avg="FAILED"
fi
# Test IPv6
ipv6_result=$(ping -6 -i 0.2 -c 20 "$host" 2>/dev/null | tail -1 || echo "")
if [ -n "$ipv6_result" ]; then
ipv6_avg=$(echo "$ipv6_result" | awk -F'/' '{print $5}' | grep -E '^[0-9.]+' || echo "N/A")
else
ipv6_avg="FAILED"
fi
# Output results
echo -n "Ping: "
# IPv4 status
if [ "$ipv4_avg" = "FAILED" ]; then
echo -n "IPv4: ${RED}Failed${NC}"
elif [ "$ipv4_avg" = "N/A" ]; then
echo -n "IPv4: ${RED}Error${NC}"
elif awk "BEGIN {exit !($ipv4_avg < 100)}"; then
echo -n "IPv4: ${GREEN}OK (${ipv4_avg}ms)${NC}"
else
echo -n "IPv4: ${YELLOW}High latency (${ipv4_avg}ms)${NC}"
fi
echo -n " | "
# IPv6 status
if [ "$ipv6_avg" = "FAILED" ]; then
echo -n "IPv6: ${RED}Failed${NC}"
elif [ "$ipv6_avg" = "N/A" ]; then
echo -n "IPv6: ${RED}Error${NC}"
elif awk "BEGIN {exit !($ipv6_avg < 100)}"; then
echo -n "IPv6: ${GREEN}OK (${ipv6_avg}ms)${NC}"
else
echo -n "IPv6: ${YELLOW}High latency (${ipv6_avg}ms)${NC}"
fi
echo " ($host)"
# Show detailed results in debug/full mode
if [ "$DEBUG" = true ] || [ "$FULL" = true ]; then
echo "Details:"
if [ "$ipv4_avg" != "FAILED" ]; then
echo " IPv4: $ipv4_result"
else
echo " IPv4: ${RED}No response${NC}"
fi
if [ "$ipv6_avg" != "FAILED" ]; then
echo " IPv6: $ipv6_result"
else
echo " IPv6: ${RED}No response${NC}"
fi
fi
}
# Check contents of /etc/hosts file
check_hosts() {
# Check /etc/hosts
local hosts_count=0
local hosts_content=""
if [ -f /etc/hosts ]; then
hosts_content=$(grep -vE '^[[:space:]]*(#|$)' /etc/hosts 2>/tmp/hosts_error || echo "")
hosts_count=$(printf '%s' "$hosts_content" | grep -c '^' || true)
if [ -s /tmp/hosts_error ]; then
error=$(cat /tmp/hosts_error)
rm -f /tmp/hosts_error
echo "${RED}Hosts: Error accessing /etc/hosts${NC}"
if [ "$DEBUG" = true ] || [ "$FULL" = true ]; then
echo "Details: ${RED}$error${NC}"
fi
return
fi
fi
# Check /etc/hosts.allow
local allow_count=0
local allow_content=""
if [ -f /etc/hosts.allow ]; then
allow_content=$(grep -vE '^[[:space:]]*(#|$)' /etc/hosts.allow 2>/tmp/allow_error || echo "")
allow_count=$(printf '%s' "$allow_content" | grep -c '^' || true)
if [ -s /tmp/allow_error ]; then
error=$(cat /tmp/allow_error)
rm -f /tmp/allow_error
echo "${RED}Hosts: Error accessing /etc/hosts.allow${NC}"
if [ "$DEBUG" = true ] || [ "$FULL" = true ]; then
echo "Details: ${RED}$error${NC}"
fi
return
fi
fi
# Check /etc/hosts.deny
local deny_count=0
local deny_content=""
if [ -f /etc/hosts.deny ]; then
deny_content=$(grep -vE '^[[:space:]]*(#|$)' /etc/hosts.deny 2>/tmp/deny_error || echo "")
deny_count=$(printf '%s' "$deny_content" | grep -c '^' || true)
if [ -s /tmp/deny_error ]; then
error=$(cat /tmp/deny_error)
rm -f /tmp/deny_error
echo "${RED}Hosts: Error accessing /etc/hosts.deny${NC}"
if [ "$DEBUG" = true ] || [ "$FULL" = true ]; then
echo "Details: ${RED}$error${NC}"
fi
return
fi
fi
# Standard mode output
if [ "$hosts_count" -gt 0 ]; then
echo "Hosts: ${BLUE}$hosts_count configured entries${NC} (hosts.allow: ${BLUE}$allow_count rules${NC}, hosts.deny: ${BLUE}$deny_count rules${NC})"
else
echo "${RED}Hosts: None configured${NC} (hosts.allow: ${BLUE}$allow_count rules${NC}, hosts.deny: ${BLUE}$deny_count rules${NC})"
fi
# Full or debug mode output
if [ "$DEBUG" = true ] || [ "$FULL" = true ]; then
echo "Details:"
if [ "$hosts_count" -gt 0 ]; then
echo "/etc/hosts:"
printf '%s' "$hosts_content" | while IFS= read -r line; do
echo " $line"
done
else
echo "${RED}/etc/hosts is empty or not found${NC}"
fi
if [ "$allow_count" -gt 0 ]; then
echo "/etc/hosts.allow:"
printf '%s' "$allow_content" | while IFS= read -r line; do
echo " $line"
done
else
echo "${BLUE}/etc/hosts.allow is empty or not found${NC}"
fi
if [ "$deny_count" -gt 0 ]; then
echo "/etc/hosts.deny:"
printf '%s' "$deny_content" | while IFS= read -r line; do
echo " $line"
done
else
echo "${BLUE}/etc/hosts.deny is empty or not found${NC}"
fi
fi
}
#────────────────────────
# SOFTWARE STACK CHECKS
#────────────────────────
# Check for installed panels
check_panels() {
local panels=()
[ -d "/usr/local/psa" ] && panels+=("Plesk")
[ -d "/usr/local/cpanel" ] && panels+=("cPanel")
[ -d "/usr/local/directadmin" ] && panels+=("DirectAdmin")
[ -d "/usr/local/CyberCP" ] || command -v cyberpanel >/dev/null 2>&1 && panels+=("CyberPanel")
[ -d "/www/server/panel" ] && panels+=("aaPanel")
[ -d "/usr/local/hestia" ] && panels+=("HestiaCP")
[ -d "/usr/local/vesta" ] && panels+=("VestaCP")
[ -d "/etc/webmin" ] || command -v webmin >/dev/null 2>&1 && panels+=("Webmin")
[ -d "/etc/virtualmin-license" ] || [ -d "/usr/share/virtualmin" ] && panels+=("Virtualmin")
[ -d "/usr/local/ispconfig" ] && panels+=("ISPConfig")
[ -d "/usr/local/cwpsrv" ] && panels+=("CentOS Web Panel")
[ -d "/usr/local/mgr5" ] && panels+=("ISPmanager")
[ -d "/usr/local/interworx" ] && panels+=("InterWorx")
[ -d "/usr/local/webuzo" ] && panels+=("Webuzo")
[ -d "/opt/fastpanel" ] && panels+=("FastPanel")
[ -d "/var/www/froxlor" ] && panels+=("Froxlor")
[ -d "/var/lib/ajenti" ] || command -v ajenti >/dev/null 2>&1 && panels+=("Ajenti")
[ -d "/home/forge" ] && [ -f "/home/forge/.forge" ] && panels+=("Laravel Forge")
[ -f "/root/.ploi" ] && panels+=("Ploi")
systemctl is-active orchd >/dev/null 2>&1 && panels+=("Enhance")
[ -d "/usr/local/openpanel" ] && panels+=("OpenPanel")
[ -d "/usr/local/panel" ] && panels+=("CloudPanel")
[ -d "/usr/local/hpanel" ] && panels+=("hPanel")
[ -d "/RunCloud" ] || systemctl is-active runcloud-agent >/dev/null 2>&1 && panels+=("RunCloud")
[ -d "/usr/local/gridpane" ] || systemctl is-active gp-agent >/dev/null 2>&1 && panels+=("GridPane")
[ -d "/opt/serverpilot" ] || [ -d "/opt/sp" ] && panels+=("ServerPilot")
[ -d "/home/moss" ] || systemctl is-active moss >/dev/null 2>&1 && panels+=("Moss.sh")
systemctl is-active cleavr >/dev/null 2>&1 && panels+=("Cleavr")
[ -f "/opt/spinupwp/spinupwp" ] || systemctl is-active spinupwp >/dev/null 2>&1 && panels+=("SpinupWP")
if [ "${#panels[@]}" -gt 0 ]; then
echo "Hosting Panels: ${YELLOW}${panels[*]}${NC}"
else
echo "Hosting Panels: ${GREEN}None${NC}"
fi
}
# Check for installed hypervisors
check_hypervisors() {
local hyper=()
[ -f "/etc/pve/.version" ] && hyper+=("Proxmox")
[ -f "/usr/local/bin/truenas" ] || [ -d "/data/zfs" ] && hyper+=("TrueNAS")
[ -n "$(command -v qemu-system-x86_64)" ] && hyper+=("QEMU/KVM")
[ -n "$(command -v vboxmanage)" ] && hyper+=("VirtualBox")
if [ "${#hyper[@]}" -gt 0 ]; then
echo "Hypervisors: ${BLUE}${hyper[*]}${NC}"
else
echo "Hypervisors: ${GREEN}None${NC}"
fi
}
# Check for available software updates
check_updates() {
local package_manager="None"
local count=0
if command -v apt >/dev/null; then
package_manager="apt"
count=$(apt-get --simulate --ignore-hold dist-upgrade | awk 'BEGIN { c=0 } /^Inst/ && $3 ~ /\[/ { c++ } END { print c }')
elif command -v yum >/dev/null; then
package_manager="yum"
count=$({ yum check-update 2>/dev/null || :; } | awk 'BEGIN { c=0 } /^[a-zA-Z0-9]/ { c++ } END { print c }')
elif command -v dnf >/dev/null; then
package_manager="dnf"
count=$(dnf repoquery --upgrades --qf '%{name}' 2>/dev/null | wc -l)
fi
if [ "$count" -gt 0 ]; then
echo "Updates: ${YELLOW}$count packages available ($package_manager)${NC}"
else
echo "Updates: ${GREEN}None ($package_manager)${NC}"
fi
}
# Check for containers (Docker, Podman, or LXC), including stopped ones
check_containers() {
local runtime=""
local containers=""
local version=""
local active_count=0
local inactive_count=0
local error=""
if command -v docker >/dev/null; then
runtime="Docker"
version=$(docker info --format '{{.ServerVersion}}' || echo "Unknown")
containers=$(docker ps -a --format '{{.State}} {{.Names}}' 2>/tmp/docker_error || true)
if [ -s /tmp/docker_error ]; then
error=$(cat /tmp/docker_error)
rm -f /tmp/docker_error
echo "${RED}Containers: Error accessing runtime ($runtime)${NC}"
if [ "$DEBUG" = true ] || [ "$FULL" = true ]; then
echo "Details: ${RED}Failed to access Docker: $error${NC}"
fi
return
fi
active_count=$(printf '%s' "$containers" | grep -c '^running ' || true)
inactive_count=$(printf '%s' "$containers" | grep -cv '^running ' || true)
elif command -v podman >/dev/null; then
runtime="Podman"
version=$(podman info --format '{{.Version.Version}}' || echo "Unknown")
containers=$(podman ps -a --format '{{.State}} {{.Names}}' 2>/tmp/podman_error || true)
if [ -s /tmp/podman_error ]; then
error=$(cat /tmp/podman_error)
rm -f /tmp/podman_error