-
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathhardware.sh
More file actions
5229 lines (5226 loc) · 159 KB
/
Copy pathhardware.sh
File metadata and controls
5229 lines (5226 loc) · 159 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
script_version="v2026-05-21"
check_bash(){
current_bash_version=$(bash --version|head -n 1|awk -F ' ' '{for (i=1; i<=NF; i++) if ($i ~ /^[0-9]+\.[0-9]+\.[0-9]+/) {print $i; exit}}'|cut -d . -f 1)
if [ "$current_bash_version" = "0" ]||[ "$current_bash_version" = "1" ]||[ "$current_bash_version" = "2" ]||[ "$current_bash_version" = "3" ];then
echo "ERROR: Bash version is lower than 4.0!"
echo "Tips: Run the following script to automatically upgrade Bash."
echo "bash <(curl -sL https://raw.githubusercontent.com/xykt/HardwareQuality/main/ref/upgrade_bash.sh)"
exit 0
fi
}
check_bash
Font_B="\033[1m"
Font_D="\033[2m"
Font_I="\033[3m"
Font_U="\033[4m"
Font_Black="\033[30m"
Font_Red="\033[31m"
Font_Green="\033[32m"
Font_Yellow="\033[33m"
Font_Blue="\033[34m"
Font_Purple="\033[35m"
Font_Cyan="\033[36m"
Font_White="\033[37m"
Back_Black="\033[40m"
Back_Red="\033[41m"
Back_Green="\033[42m"
Back_Yellow="\033[43m"
Back_Blue="\033[44m"
Back_Purple="\033[45m"
Back_Cyan="\033[46m"
Back_White="\033[47m"
Font_Suffix="\033[0m"
Font_LineClear="\033[2K"
Font_LineUp="\033[1A"
declare ADLines
declare -A aad
declare IP=""
declare IPhide
declare fullinfo=0
declare YY="cn"
declare IPV4
declare IPV6
declare ERRORcode=0
declare shelp
declare -A osinfo
declare -A mbinfo
declare -A cpuinfo
declare -A gpuinfo
declare -A meminfo
declare -A diskinfo
declare -A markinfo
declare -A sinfo
declare -A shead
declare -A sos
declare -A smb
declare -A scpu
declare -A sgpu
declare -A smem
declare -A sdisk
declare -A smark
declare -A stail
declare mode_no=0
declare mode_yes=0
declare mode_json=0
declare mode_menu=0
declare mode_disk=0
declare mode_fast=0
declare mode_fast_dep=" sysbench"
declare mode_skip=""
declare mode_output=0
declare mode_privacy=0
declare mode_verbose=0
declare outputfile=""
declare workdir="$PWD"
declare hwjson
declare ibar=0
declare bar_pid
declare ibar_step=0
declare main_pid=$$
declare PADDING=""
declare rawgithub
shelp_lines=(
"HARDWARE QUALITY CHECK SCRIPT IP质量体检脚本"
"Interactive Interface: bash <(curl -sL Hardware.Check.Place) -EM"
"交互界面: bash <(curl -sL Hardware.Check.Place) -M"
"Parameters 参数运行: bash <(curl -sL Hardware.Check.Place) [-d testdir] [-f] [-h] [-j] [-l language] [-n] [-o outputpath] [-p] [-x proxy] [-y] [-D] [-E] [-F] [-M] [-S chapters] [-V]"
" -d /path/to/testdir/ Specify fio disk test directory 设置fio硬盘测试路径"
" -f No mask sensitive info on reports 报告不隐藏敏感信息"
" -h Help information 帮助信息"
" -j JSON output JSON输出"
" -l cn|en|jp|es|de|fr|ru|pt Specify script language 指定报告语言"
" -n No OS or dependencies check 跳过系统检测及依赖安装"
" -o /path/to/file.ansi Output ANSI report to file 输出ANSI报告至文件"
" /path/to/file.json Output JSON result to file 输出JSON结果至文件"
" /path/to/file.anyother Output plain text report to file 输出纯文本报告至文件"
" -p Privacy mode - no generate report link 隐私模式:不生成报告链接"
" -y Install dependencies without interupt 自动安装依赖"
" -D Disk mode 硬盘模式"
" -E Specify English Output 指定英文输出"
" -F Fast mode with no benchmarks 快速检测模式不测试成绩"
" -M Run with Interactive Interface 交互界面方式运行"
" -S 123456 Skip sections by number 跳过相应章节"
" -V Verbose mode to show benchmark details 深度模式:展示全部测试细节")
shelp=$(printf "%s\n" "${shelp_lines[@]}")
set_language(){
case "$YY" in
"en")swarn[1]="ERROR: Unsupported parameters!"
swarn[3]="ERROR: Dependent programs are missing. Please run as root or install sudo!"
swarn[9]="ERROR: It is not allowed to skip all funcions!"
swarn[10]="ERROR: Output file already exist!"
swarn[11]="ERROR: Output file is not writable!"
swarn[12]="ERROR: Test directory is not exist!"
swarn[13]="ERROR: Test directory is not readable or writable!"
sinfo[virt]="Detecting Virtualization Information "
sinfo[os]="Detecting OS Information "
sinfo[mb]="Detecting Matherboard Information "
sinfo[cpu]="Detecting CPU Information "
sinfo[cpubench]="Sysbench CPU Running Test "
sinfo[cpumark]="Geekbench5 CPU "
sinfo[gpu]="Detecting Graphic Information "
sinfo[gpumark]="Geekbench5 GPU "
sinfo[mem]="Detecting Memory Information "
sinfo[membench]="Sysbench Memory Running Test "
sinfo[disk]="Detecting Disk Information "
sinfo[fio]="Fio Test "
sinfo[lvirt]=37
sinfo[los]=25
sinfo[lmb]=34
sinfo[lcpu]=26
sinfo[lcpubench]=26
sinfo[lcpumark]=15
sinfo[lgpu]=30
sinfo[lgpumark]=15
sinfo[lmem]=29
sinfo[lmembench]=29
sinfo[ldisk]=27
sinfo[lfio]=9
shead[title]="HARDWARE QUALITY CHECK REPORT: "
shead[ver]="Version: $script_version"
shead[bash]="bash <(curl -sL https://Check.Place) -EH"
shead[git]="https://github.com/xykt/HardwareQuality"
shead[time_raw]=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
shead[time]="Report Time: ${shead[time_raw]}"
shead[ltitle]=31
shead[ptime]=$(printf '%11s' '')
sos[docker]="Docker container"
sos[podman]="Podman container"
sos[lxc]="LXC container"
sos[lxc-libvirt]="LXC (libvirt) container"
sos[systemd-nspawn]="systemd-nspawn container"
sos[openvz]="OpenVZ container"
sos[rkt]="rkt container"
sos[proot]="proot container"
sos[pouch]="Pouch container"
sos[kvm]="KVM virtual machine"
sos[qemu]="QEMU virtual machine"
sos[amazon]="Amazon EC2 (Nitro/KVM)"
sos[vmware]="VMware virtual machine"
sos[microsoft]="Hyper-V virtual machine"
sos[xen]="Xen virtual machine"
sos[oracle]="VirtualBox virtual machine"
sos[parallels]="Parallels virtual machine"
sos[bhve]="bhyve virtual machine"
sos[uml]="User-Mode Linux"
sos[bochs]="Bochs emulator"
sos[zvm]="IBM z/VM"
sos[powervm]="IBM PowerVM"
sos[qnx]="QNX hypervisor"
sos[acrn]="ACRN hypervisor"
sos[apple]="Apple virtualization framework"
sos[sre]="LMHS SRE hypervisor"
sos[google]="Google Compute Engine"
sos[wsl]="Windows Subsystem for Linux (WSL)"
sos[virtual-machine]="Virtual machine"
sos[physical-machine]="Physical machine"
sos[unknown]="Unknown environment"
sos[title]="1. Operating System Information"
sos[virt]="Virt type: "
sos[arch]="Architecture: "
sos[os]="OS / Kernel: "
sos[uptime]="Uptime: "
sos[load]="Load: "
sos[status]="Processes: "
sos[loc]="Regional setting: "
sos[d]="days"
sos[h]="hours"
sos[m]="minutes"
sos[q]=", "
sos[user]="Users"
sos[proc]="Procs"
sos[svc]="Run/All services"
smb[title]="2. Motherboard Information"
smb[mb]="MB: "
smb[bios]="BIOS: "
smb[chip]="Chipset: "
smb[audio]="Audio: "
smb[net]="Ethernet: "
smb[ver]="Ver:"
smb[s]=""
scpu[title]="3. CPU Review"
scpu[cpu]="CPU: "
scpu[cache]="Cache: "
scpu[flag]="Features: "
scpu[temp]="Temp: "
scpu[sysbench]="Sysbench: "
scpu[base]="GB5 Base: "
scpu[single]="Single: "
scpu[multi]="Multi: "
scpu[url]="Details: "
scpu[singlet]="Single Thread"
scpu[multit]="Multi Threads"
scpu[num]=""
scpu[step]="Step "
scpu[gen]=" Gen"
scpu[core]=" Core"
scpu[thread]=" Thread"
scpu[limit1]=" Limit "
scpu[limit2]=" Procs"
scpu[usage]="Usage "
scpu[min]="Idle "
scpu[max]="Load "
scpu[lnum]=0
scpu[lstep]=0
scpu[lgen]=0
scpu[lcore]=0
scpu[lthread]=0
scpu[llimit]=0
scpu[lusage]=0
sgpu[title]="4. GPU Review"
sgpu[gpu]="Graphics: "
sgpu[ft]="Features: "
sgpu[temp]="Temp: "
sgpu[base]="GB5Base: "
sgpu[score]="GB5Score: "
sgpu[url]="Details: "
sgpu[1]="Discrete"
sgpu[0]="Integrated"
sgpu[driver]="Driver"
sgpu[min]="Idle "
sgpu[max]="Load "
smem[title]="5. Memory Review"
smem[mem]="Memory: "
smem[swap]="Swap: "
smem[reuse]="Overcmmt: "
smem[nb]="Neighbor: "
smem[sysbench]="Sysbench: "
smem[total]="Total"
smem[used]="Used"
smem[avail]="Available"
smem[balloon]="Balloon"
smem[ksm]="KSM Reuse"
smem[nbnum]="Containers"
smem[read]="Read"
smem[write]="Write"
smem[lat]="Latency"
smem[ltotal]=0
sdisk[title]="6. Disk Review"
sdisk[disk]="Disks: "
sdisk[dir]="Test Dev: "
sdisk[fio]="Fio Test: "
sdisk[crystal]="Crystal: "
sdisk[atto]="ATTO: "
sdisk[read]="Read: "
sdisk[write]="Write: "
sdisk[count]="Count "
sdisk[total]="Total "
sdisk[used]="Used "
sdisk[avail]="Available "
sdisk[po]="PwrOn "
sdisk[times]=""
sdisk[lf]="Lf"
sdisk[sp]="Sp"
sdisk[lcount]=0
sdisk[ltotal]=0
sdisk[lused]=0
sdisk[lavail]=0
sdisk[lpo]=0
sdisk[llf]=0
sdisk[lsp]=0
smark[title]="7. HQ Weighted Hardware Benchmark"
smark[item]="Items: "
smark[mark]="Score: "
smark[pct]="Ranking: "
smark[total]="Total"
smark[mem]="Memory"
smark[disk]="Disk"
smark[ltotal]=5
smark[lmem]=6
smark[ldisk]=4
stail[stoday]="Hardware Checks Today: "
stail[stotal]="; Total: "
stail[thanks]=". Thanks for running xy scripts!"
stail[link]="${Font_I}Report Link: $Font_U"
;;
"cn")swarn[1]="错误:不支持的参数!"
swarn[3]="错误:未安装依赖程序,请以root执行此脚本,或者安装sudo命令!"
swarn[9]="错误: 不允许跳过所有功能!"
swarn[10]="错误:输出文件已存在!"
swarn[11]="错误:输出文件不可写!"
swarn[12]="错误:测试目录不存在!"
swarn[13]="错误:测试目录不可读写!"
sinfo[virt]="正在获取虚拟化信息"
sinfo[os]="正在获取操作系统信息"
sinfo[mb]="正在获取主板信息"
sinfo[cpu]="正在获取CPU信息"
sinfo[cpubench]="Sysbench CPU测试 "
sinfo[cpumark]="Geekbench5 CPU "
sinfo[gpu]="正在获取显卡信息"
sinfo[gpumark]="Geekbench5 GPU "
sinfo[mem]="正在获取内存信息"
sinfo[membench]="Sysbench 内存测试 "
sinfo[disk]="正在获取硬盘信息"
sinfo[fio]="Fio测试 "
sinfo[lvirt]=18
sinfo[los]=20
sinfo[lmb]=16
sinfo[lcpu]=15
sinfo[lcpubench]=17
sinfo[lcpumark]=15
sinfo[lgpu]=16
sinfo[lgpumark]=15
sinfo[lmem]=16
sinfo[lmembench]=18
sinfo[ldisk]=16
sinfo[lfio]=8
shead[title]="硬件质量体检报告:"
shead[title_lite]="IP质量体检报告(Lite):"
shead[ver]="脚本版本:$script_version"
shead[bash]="bash <(curl -sL https://Check.Place) -H"
shead[git]="https://github.com/xykt/HardwareQuality"
shead[time_raw]=$(TZ="Asia/Shanghai" date +"%Y-%m-%d %H:%M:%S CST")
shead[time]="报告时间:${shead[time_raw]}"
shead[ltitle]=18
shead[ptime]=$(printf '%12s' '')
sos[virt]="容器/虚拟化: "
sos[arch]="架构: "
sos[os]="操作系统/内核: "
sos[uptime]="运行时间: "
sos[load]="负载: "
sos[status]="进程: "
sos[loc]="区域设置: "
sos[docker]="Docker 容器"
sos[podman]="Podman 容器"
sos[lxc]="LXC 容器"
sos[lxc-libvirt]="LXC(libvirt) 容器"
sos[systemd-nspawn]="systemd-nspawn 容器"
sos[openvz]="OpenVZ 容器"
sos[rkt]="rkt 容器"
sos[proot]="proot 容器"
sos[pouch]="Pouch 容器"
sos[kvm]="KVM 虚拟机"
sos[qemu]="QEMU 虚拟机"
sos[amazon]="Amazon EC2(Nitro/KVM)"
sos[vmware]="VMware 虚拟机"
sos[microsoft]="Hyper-V 虚拟机"
sos[xen]="Xen 虚拟机"
sos[oracle]="VirtualBox 虚拟机"
sos[parallels]="Parallels 虚拟机"
sos[bhve]="bhyve 虚拟机"
sos[uml]="User-Mode Linux"
sos[bochs]="Bochs 模拟器"
sos[zvm]="IBM z/VM"
sos[powervm]="IBM PowerVM"
sos[qnx]="QNX Hypervisor"
sos[acrn]="ACRN Hypervisor"
sos[apple]="Apple Virtualization"
sos[sre]="LMHS SRE Hypervisor"
sos[google]="Google Compute Engine"
sos[wsl]="WSL(Windows Subsystem for Linux)"
sos[virtual-machine]="虚拟机"
sos[physical-machine]="物理机"
sos[unknown]="未知环境"
sos[title]="一、操作系统信息"
sos[d]="天"
sos[h]="小时"
sos[m]="分钟"
sos[q]=","
sos[user]="用户"
sos[proc]="进程"
sos[svc]="活跃/总服务"
smb[title]="二、主板信息"
smb[mb]="主板: "
smb[bios]="BIOS: "
smb[chip]="芯片组: "
smb[audio]="声卡: "
smb[net]="网卡: "
smb[ver]="版本"
smb[s]="个"
scpu[title]="三、CPU测评"
scpu[cpu]="CPU: "
scpu[cache]="缓存: "
scpu[flag]="指令集: "
scpu[temp]="温度: "
scpu[sysbench]="Sysbench:"
scpu[geekbench]="GB5成绩: "
scpu[url]="详细结果:"
scpu[singlet]="单线程"
scpu[multit]="多线程"
scpu[base]="GB5基准: "
scpu[single]="GB5单核: "
scpu[multi]="GB5多核: "
scpu[num]="颗"
scpu[step]="步进"
scpu[gen]="代"
scpu[core]="核心"
scpu[thread]="线程"
scpu[limit1]="限制"
scpu[limit2]="进程"
scpu[usage]="利用率"
scpu[min]="待机 "
scpu[max]="负载 "
scpu[lnum]=1
scpu[lstep]=2
scpu[lgen]=1
scpu[lcore]=2
scpu[lthread]=2
scpu[llimit]=4
scpu[lusage]=3
sgpu[title]="四、显卡测评"
sgpu[gpu]="显卡: "
sgpu[ft]="特性: "
sgpu[temp]="温度: "
sgpu[base]="GB5基准: "
sgpu[score]="GB5成绩: "
sgpu[url]="详细结果:"
sgpu[1]="独显"
sgpu[0]="集显"
sgpu[driver]="驱动程序"
sgpu[min]="待机 "
sgpu[max]="负载 "
smem[title]="五、内存测评"
smem[mem]="内存: "
smem[swap]="交换: "
smem[reuse]="超开指标:"
smem[nb]="邻居数量:"
smem[sysbench]="Sysbench:"
smem[total]="总容量"
smem[used]="已用"
smem[avail]="可用"
smem[balloon]="气球回收"
smem[ksm]="KSM 复用"
smem[nbnum]="个容器"
smem[read]="读取"
smem[write]="写入"
smem[lat]="延迟"
smem[ltotal]=7
sdisk[title]="六、硬盘测评"
sdisk[disk]="硬盘: "
sdisk[dir]="测试设备:"
sdisk[fio]="Fio测试: "
sdisk[crystal]="Crystal: "
sdisk[atto]="ATTO: "
sdisk[read]="读取: "
sdisk[write]="写入: "
sdisk[count]="数量 "
sdisk[total]="总容量 "
sdisk[used]="已用容量 "
sdisk[avail]="可用容量 "
sdisk[po]="通电"
sdisk[times]="次"
sdisk[lf]="寿"
sdisk[sp]="备"
sdisk[lcount]=2
sdisk[ltotal]=3
sdisk[lused]=4
sdisk[lavail]=4
sdisk[lpo]=3
sdisk[llf]=1
sdisk[lsp]=1
smark[title]="七、HQ硬件加权评分"
smark[item]="项目: "
smark[mark]="分数: "
smark[pct]="排名: "
smark[total]="总 分"
smark[mem]="内 存"
smark[disk]="硬 盘"
smark[ltotal]=5
smark[lmem]=5
smark[ldisk]=5
stail[stoday]="今日硬件检测量:"
stail[stotal]=";总检测量:"
stail[thanks]="。感谢使用xy系列脚本!"
stail[link]="$Font_I报告链接:$Font_U"
;;
*)echo -ne "ERROR: Language not supported!"
esac
}
countRunTimes(){
local RunTimes=$(curl $CurlARG -s --max-time 10 "https://hits.xykt.de/hardware?action=hit" 2>&1)
stail[today]=$(echo "$RunTimes"|jq '.daily')
stail[total]=$(echo "$RunTimes"|jq '.total')
}
show_progress_bar(){
show_progress_bar_ "$@" 1>&2
}
show_progress_bar_(){
local bar="\u280B\u2819\u2839\u2838\u283C\u2834\u2826\u2827\u2807\u280F"
local n=${#bar}
local tmpinfo=""
local tmplen=$(($2))
local last_stage=""
local upload_seen=0
while sleep 0.1;do
if ! kill -0 "$main_pid" 2>/dev/null;then
echo -ne ""
exit
fi
if ((upload_seen==0))&&[[ -n $3 ]];then
while IFS= read -r -t 0.05 line;do
[[ -z $line ]]&&continue
if [[ $3 -eq 1 ]];then
if [[ $line == *"Uploading results"* ]];then
upload_seen=1
break
fi
case "$line" in
*"Running"*)last_stage="${line#"${line%%[![:space:]]*}"}"
esac
elif [[ $3 -eq 2 ]];then
last_stage="$line"
fi
done
fi
if ((upload_seen==0))&&[[ -n $last_stage ]];then
tmpinfo="$last_stage"
else
tmpinfo=""
fi
tmplen=$(($2-${#tmpinfo}))
((tmplen<0))&&tmplen=0
echo -ne "\r$Font_Cyan$Font_B[$IP]# $1$tmpinfo""$Font_Cyan$Font_B$(printf '%*s' "$tmplen" ''|tr ' ' '.') ""${bar:ibar++*6%n:6} $(printf '%02d%%' $ibar_step) $Font_Suffix"
done
}
kill_progress_bar(){
kill "$bar_pid" 2>/dev/null&&echo -ne "\r"
}
install_dependencies(){
local is_dep=1
local is_geekbench5=1
local is_curl_impersonate=1
local is_darwin=0
[[ "$(uname)" == "Darwin" ]]&&is_darwin=1
if ! tar --version >/dev/null 2>&1||! jq --version >/dev/null 2>&1||! curl --version >/dev/null 2>&1||! bc --version >/dev/null 2>&1||(! dmidecode --version >/dev/null 2>&1&&[ "$is_darwin" -eq 0 ])||(! sensors --version >/dev/null 2>&1&&[ "$is_darwin" -eq 0 ])||(! lspci --version >/dev/null 2>&1&&[ "$is_darwin" -eq 0 ])||(! lscpu --version >/dev/null 2>&1&&[ "$is_darwin" -eq 0 ])||! smartctl --version >/dev/null 2>&1||! fio --version >/dev/null 2>&1||(! sysbench --version >/dev/null 2>&1&&[ "${mode_fast:-0}" -eq 0 ])||(! command -v update-ca-certificates >/dev/null 2>&1&&[ "${mode_verbose:-0}" -eq 1 ]);then
is_dep=0
fi
if ! command -v geekbench5 >/dev/null 2>&1&&[[ ${mode_fast:-0} -eq 0 && ${mode_privacy:-0} -eq 0 ]];then
is_geekbench5=0
fi
if ! command -v curl-impersonate >/dev/null 2>&1&&[[ ${mode_fast:-0} -eq 0 && ${mode_privacy:-0} -eq 0 && ${mode_verbose:-0} -eq 1 ]];then
is_curl_impersonate=0
fi
if [[ $is_dep -eq 0 || $is_geekbench5 -eq 0 || $is_curl_impersonate -eq 0 ]];then
echo -e "Lacking necessary dependencies."
[[ $is_dep -eq 0 ]]&&echo -e "Packages $Font_I${Font_Cyan}tar jq curl bc dmidecode sensors pciutils util-linux smartmontools fio$mode_fast_dep$Font_Suffix will be installed using package manager$Font_Suffix."
[[ $is_geekbench5 -eq 0 ]]&&echo -e "Application $Font_I${Font_Cyan}Geekbench5$Font_Suffix will be downloaded from ${Font_B}Geekbench.com$Font_Suffix and installed to folder $Font_U/usr/local/bin$Font_Suffix."
[[ $is_curl_impersonate -eq 0 ]]&&echo -e "Application $Font_I${Font_Cyan}curl-impersonate$Font_Suffix will be installed using ${Font_B}github.com/lexiforest/curl-impersonate$Font_Suffix release ${Font_U}v1.5.6$Font_Suffix to folder $Font_U/usr/local/bin$Font_Suffix."
if [[ $mode_yes -eq 0 ]];then
prompt=$(printf "Continue? (${Font_Green}y$Font_Suffix/${Font_Red}n$Font_Suffix): ")
read -p "$prompt" choice
case "$choice" in
y|Y|yes|Yes|YES)echo "Continue to install dependencies..."
;;
n|N|no|No|NO)echo "Script exited."
exit 0
;;
*)echo "Invalid input, script exited."
exit 1
esac
else
echo -e "Detected parameter $Font_Green-y$Font_Suffix. Continue installation..."
fi
if [[ $is_dep -eq 0 ]];then
if [ "$(uname)" == "Darwin" ];then
install_packages "brew" "brew install" "no_sudo"
elif [ -f /etc/os-release ];then
. /etc/os-release
if [ $(id -u) -ne 0 ]&&! command -v sudo >/dev/null 2>&1;then
ERRORcode=3
fi
case $ID in
ubuntu|debian|linuxmint)install_packages "apt" "apt-get install -y"
;;
rhel|centos|almalinux|rocky|anolis)if
[ "$(echo $VERSION_ID|cut -d '.' -f1)" -ge 8 ]
then
install_packages "dnf" "dnf install -y"
else
install_packages "yum" "yum install -y"
fi
;;
arch|manjaro)install_packages "pacman" "pacman -S --noconfirm"
;;
alpine)install_packages "apk" "apk add"
;;
fedora)install_packages "dnf" "dnf install -y"
;;
alinux)install_packages "yum" "yum install -y"
;;
suse|opensuse*)install_packages "zypper" "zypper install -y"
;;
void)install_packages "xbps" "xbps-install -Sy"
;;
*)echo "Unsupported distribution: $ID"
exit 1
esac
elif [ -n "$PREFIX" ];then
install_packages "pkg" "pkg install"
else
echo "Cannot detect distribution because /etc/os-release is missing."
exit 1
fi
fi
if [[ $is_geekbench5 -eq 0 ]];then
install_geekbench5
fi
if [[ $is_curl_impersonate -eq 0 ]];then
install_curl_impersonate
fi
fi
}
install_packages(){
local package_manager=$1
local install_command=$2
local no_sudo=$3
if [ "$no_sudo" == "no_sudo" ]||[ $(id -u) -eq 0 ];then
local usesudo=""
else
local usesudo="sudo"
fi
case $package_manager in
apt)$usesudo apt update
$usesudo $install_command tar jq curl bc dmidecode lm-sensors pciutils util-linux smartmontools fio ca-certificates $mode_fast_dep
;;
dnf|yum)$usesudo $install_command epel-release
$usesudo $package_manager makecache
$usesudo $install_command tar jq curl bc dmidecode lm-sensors pciutils util-linux smartmontools fio ca-certificates $mode_fast_dep
;;
pacman)$usesudo pacman -Sy
$usesudo $install_command tar jq curl bc dmidecode lm-sensors pciutils util-linux smartmontools fio ca-certificates $mode_fast_dep
;;
apk)$usesudo apk update
$usesudo $install_command tar jq curl bc dmidecode lm-sensors pciutils util-linux smartmontools fio ca-certificates $mode_fast_dep
;;
pkg)$usesudo $package_manager update
$usesudo $package_manager $install_command tar jq curl bc dmidecode lm-sensors pciutils util-linux smartmontools fio ca-certificates $mode_fast_dep
;;
brew)eval "$(/opt/homebrew/bin/brew shellenv)"
$install_command tar jq curl bc smartmontools fio ca-certificates $mode_fast_dep
;;
zypper)$usesudo zypper refresh
$usesudo $install_command tar jq curl bc dmidecode sensors pciutils util-linux smartmontools fio ca-certificates $mode_fast_dep
;;
xbps)$usesudo xbps-install -Sy
$usesudo $install_command tar jq curl bc dmidecode lm-sensors pciutils util-linux smartmontools fio ca-certificates $mode_fast_dep
esac
}
install_geekbench5(){
local GB_VER="5.5.1"
local GB_BASE_URL="https://cdn.geekbench.com"
local tmpdir arch pkg url
local usesudo=""
if [ "$(id -u)" -ne 0 ];then
if command -v sudo >/dev/null 2>&1;then
usesudo="sudo"
else
echo "Error: need root privileges to install Geekbench5."
return 1
fi
fi
case "$(uname -m)" in
x86_64|amd64|i386|i686)arch="i386/amd64"
pkg_arch="Linux"
;;
aarch64|arm64|armv7l|armv6l)arch="ARM"
pkg_arch="LinuxARMPreview"
;;
*)echo "Unsupported architecture: $(uname -m)"
return 1
esac
pkg="Geekbench-$GB_VER-$pkg_arch.tar.gz"
url="$GB_BASE_URL/$pkg"
echo "Downloading Geekbench 5 ($arch) ..."
tmpdir="$(mktemp -d)"||return 1
cleanup_local(){
if [[ -n $tmpdir ]];then
rm -f "$tmpdir/$pkg" 2>/dev/null
rmdir "$tmpdir" 2>/dev/null
fi
}
on_int(){
cleanup_local
echo ""
exit 130
}
on_term(){
cleanup_local
echo ""
exit 143
}
trap cleanup_local RETURN
trap on_int INT
trap on_term TERM
if ! curl -L --fail -o "$tmpdir/$pkg" "$url";then
echo "Failed to download Geekbench5."
return 1
fi
if ! $usesudo tar -xf "$tmpdir/$pkg" -C /usr/local/bin;then
echo "Failed to extract Geekbench5 to /usr/local/bin."
return 1
fi
local dst_dir="/usr/local/bin/Geekbench-$GB_VER-$pkg_arch"
if [ ! -d "$dst_dir" ];then
echo "Geekbench directory not found after extraction."
return 1
fi
case "$(uname -m)" in
aarch64|arm64)rm -f "/usr/local/bin/Geekbench-$GB_VER-$pkg_arch/geekbench_armv7"
;;
armv7l|armv6l)rm -f "/usr/local/bin/Geekbench-$GB_VER-$pkg_arch/geekbench_aarch64"
esac
$usesudo chmod +x "$dst_dir/geekbench5"
if [ ! -e /usr/local/bin/geekbench5 ];then
$usesudo ln -s "$dst_dir/geekbench5" /usr/local/bin/geekbench5
fi
}
install_curl_impersonate(){
local arch
local sys_type
arch=$(uname -m)
case "$arch" in
x86_64)if
[[ "$(getconf LONG_BIT)" == "32" ]]
then
sys_type="i386"
else
sys_type="x86_64"
fi
;;
aarch64|arm64)sys_type="aarch64"
;;
i386|i486|i586|i686)sys_type="i386"
;;
riscv64)sys_type="riscv64"
;;
*)return 1
esac
$usesudo curl -sL -o /usr/local/bin/curl-impersonate "${rawgithub}main/ref/curl-impersonate/curl-impersonate-$sys_type"
$usesudo chmod +x /usr/local/bin/curl-impersonate
}
adaptoslocale(){
local ifunicode=$(printf '\u2800')
[[ ${#ifunicode} -gt 3 ]]&&export LC_CTYPE=en_US.UTF-8 2>/dev/null
}
check_connectivity(){
local url="https://www.google.com/generate_204"
local timeout=2
local http_code
http_code=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout "$timeout" "$url" 2>/dev/null)
if [[ $http_code == "204" ]];then
rawgithub="https://github.com/xykt/HardwareQuality/raw/"
return 0
else
rawgithub="https://testingcf.jsdelivr.net/gh/xykt/HardwareQuality@"
return 1
fi
}
get_ipv4(){
local response
IPV4=""
local API_NET=("myip.check.place" "ip.sb" "ping0.cc" "icanhazip.com" "api64.ipify.org" "ifconfig.co" "ident.me")
for p in "${API_NET[@]}";do
response=$(curl $CurlARG -s4 --max-time 2 "$p")
if [[ $? -eq 0 && ! $response =~ error && -n $response ]];then
IPV4="$response"
break
fi
done
}
hide_ipv4(){
if [[ -n $1 ]];then
IFS='.' read -r -a ip_parts <<<"$1"
IPhide="${ip_parts[0]}.${ip_parts[1]}.*.*"
else
IPhide=""
fi
}
get_ipv6(){
local response
IPV6=""
local API_NET=("myip.check.place" "ip.sb" "ping0.cc" "icanhazip.com" "api64.ipify.org" "ifconfig.co" "ident.me")
for p in "${API_NET[@]}";do
response=$(curl $CurlARG -s6k --max-time 2 "$p")
if [[ $? -eq 0 && ! $response =~ error && -n $response ]];then
IPV6="$response"
break
fi
done
}
hide_ipv6(){
if [[ -n $1 ]];then
local expanded_ip=$(echo "$1"|sed 's/::/:0000:0000:0000:0000:0000:0000:0000:0000:/g'|cut -d ':' -f1-8)
IFS=':' read -r -a ip_parts <<<"$expanded_ip"
while [ ${#ip_parts[@]} -lt 8 ];do
ip_parts+=(0000)
done
IPhide="${ip_parts[0]:-0}:${ip_parts[1]:-0}:${ip_parts[2]:-0}:*:*:*:*:*"
IPhide=$(echo "$IPhide"|sed 's/:0\{1,\}/:/g'|sed 's/::\+/:/g')
else
IPhide=""
fi
}
calculate_display_width(){
local string="$1"
local length=0
local char
for ((i=0; i<${#string}; i++));do
char=$(echo "$string"|od -An -N1 -tx1 -j $((i))|tr -d ' ')
if [ "$(printf '%d\n' 0x$char)" -gt 127 ];then
length=$((length+2))
i=$((i+1))
else
length=$((length+1))
fi
done
echo "$length"
}
calc_padding(){
local input_text="$1"
local total_width=$2
local title_length=$(calculate_display_width "$input_text")
local left_padding=$(((total_width-title_length)/2))
if [[ $left_padding -gt 0 ]];then
PADDING=$(printf '%*s' $left_padding)
else
PADDING=""
fi
}
kill_test(){
kill "$1" 2>/dev/null
}
detect_virt(){
local dv_os dv_sdv dv_env1 _pn
local dv_virt="physical-machine"
dv_os="$(uname -s 2>/dev/null)"
if [[ $dv_os == "Linux" ]];then
[[ -f /.dockerenv ]]&&{
echo "docker"
return 0
}
[[ -f /run/.containerenv ]]&&{
echo "podman"
return 0
}
if command -v systemd-detect-virt >/dev/null 2>&1;then
dv_sdv="$(systemd-detect-virt 2>/dev/null)"
case "$dv_sdv" in
none|"");;
*)echo "$dv_sdv"
return 0
esac
fi
if [[ -r /proc/1/environ ]];then
dv_env1="$(tr '\0' '\n' </proc/1/environ 2>/dev/null)"
case "$dv_env1" in
*container=lxc*)echo "lxc"
return 0
;;
*container=lxd*)echo "lxd"
return 0
;;
*container=systemd-nspawn*)echo "systemd-nspawn"
return 0
esac
fi
if grep -qw hypervisor /proc/cpuinfo 2>/dev/null;then
if [[ -r /sys/devices/virtual/dmi/id/product_name ]];then
_pn="$(cat /sys/devices/virtual/dmi/id/product_name 2>/dev/null)"
case "$_pn" in
*VMware*)echo "vmware"
return 0
;;
*VirtualBox*)echo "oracle"
return 0
;;
*Parallels*)echo "parallels"
return 0
;;
*HVM*domU*|*Xen*)echo "xen"
return 0
;;
*Amazon*EC2*)echo "amazon"
return 0
;;
*Google*Compute*Engine*)echo "google"
return 0
;;
*KVM*|*Standard\ PC*|*Q35*|*i440FX*)echo "kvm"
return 0
;;
*Microsoft*|*Virtual\ Machine*)echo "microsoft"
return 0
;;
*BHYVE*)echo "bhve"
return 0
;;
*Bochs*)echo "bochs"
return 0
esac
fi
echo "virtual-machine"
return 0
fi
echo "$dv_virt"
return 0
fi
if [[ $dv_os == "Darwin" ]];then
if sysctl -n kern.hv_vmm_present 2>/dev/null|grep -q '^1$';then
echo "virtual-machine"
else
echo "$dv_virt"
fi
return 0
fi
echo "unknown"
return 0
}
classify_virt_kind(){
case "$1" in
docker|podman|lxc|lxd|systemd-nspawn|openvz|rkt|proot|pouch)echo "container"
;;
kvm|qemu|vmware|wsl|microsoft|xen|oracle|parallels|bhve|bochs|amazon|google|virtual-machine)echo "virtual-machine"
;;
physical-machine)echo "physical-machine"
;;
*)echo "unknown"
esac
}
get_virt(){
local temp_info="$Font_Cyan$Font_B${sinfo[virt]}$Font_Suffix"
((ibar_step+=1))
show_progress_bar "$temp_info" $((55-${sinfo[lvirt]}))&
bar_pid="$!"&&disown "$bar_pid"
trap "kill_progress_bar" RETURN
osinfo[virt]="$(detect_virt)"
osinfo[virt_kind]="$(classify_virt_kind "${osinfo[virt]}")"
}
calc_uptime(){
local total_sec
total_sec="$(awk '{print int($1)}' /proc/uptime 2>/dev/null)"
[[ -z $total_sec ]]&&total_sec=0
osinfo[d]=$((total_sec/86400))
osinfo[h]=$(((total_sec%86400)/3600))
osinfo[m]=$(((total_sec%3600)/60))
}
colorize_load(){
local lv="$1"
local cores="$2"
awk -v l="$lv" -v c="$cores" \
-v R="$Font_Red" -v Y="$Font_Yellow" -v G="$Font_Green" -v S="$Font_Suffix" '
BEGIN {
if (l < c)
printf "%s%.2f%s", G, l, S
else if (l < 2*c)
printf "%s%.2f%s", Y, l, S
else
printf "%s%.2f%s", R, l, S
}'
}
get_os(){
local temp_info="$Font_Cyan$Font_B${sinfo[os]}$Font_Suffix"
((ibar_step+=2))
show_progress_bar "$temp_info" $((55-${sinfo[los]}))&
bar_pid="$!"&&disown "$bar_pid"
trap "kill_progress_bar" RETURN
osinfo[os]="$(grep '^PRETTY_NAME=' /etc/os-release 2>/dev/null|cut -d= -f2|tr -d '"')"
osinfo[kernel]="$(uname -r)"
osinfo[arch]="$(uname -m)"
calc_uptime
read osinfo[load1] osinfo[load5] osinfo[load15] <<<"$(uptime|awk -F'load average:' '{gsub(/^[[:space:]]+/, "", $2); gsub(/,/, "", $2); print $2}')"
local cpu_cores="$(getconf _NPROCESSORS_ONLN 2>/dev/null)"
[[ -z $cpu_cores || ! $cpu_cores =~ ^[0-9]+$ ]]&&cpu_cores=1
sos[load1]="$(colorize_load "${osinfo[load1]}" "$cpu_cores")"
sos[load5]="$(colorize_load "${osinfo[load5]}" "$cpu_cores")"
sos[load15]="$(colorize_load "${osinfo[load15]}" "$cpu_cores")"
if [[ -z ${osinfo[user]} ]];then
local tmpuc=""
if command -v loginctl >/dev/null 2>&1;then
tmpuc="$(loginctl list-users 2>/dev/null|tail -n +2|wc -l|tr -d ' ')"
[[ $tmpuc -gt 0 ]]&&osinfo[user]="$tmpuc"
elif [[ "$(uname -s)" == "Darwin" ]];then
tmpuc="$(stat -f '%Su' /dev/console 2>/dev/null|wc -l|tr -d ' ')"
[[ $tmpuc -gt 0 ]]&&osinfo[user]="$tmpuc"
else
tmpuc="$(who 2>/dev/null|wc -l|tr -d ' ')"
[[ $tmpuc -gt 0 ]]&&osinfo[user]="$tmpuc"
fi
fi
[[ -z ${osinfo[proc]} ]]&&osinfo[proc]=$(ps -e 2>/dev/null|wc -l|tr -d ' ')
[[ ${osinfo[proc]} -gt 0 ]]&&osinfo[proc]=$((osinfo[proc]-1))