-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.sh
177 lines (149 loc) · 4.14 KB
/
bench.sh
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
#!/bin/bash
# constant
date_time_str="$(TZ="UST-8" date +%Y-%m-%d_%H-%M-%S)"
markdown_log_file="BenchResult_${date_time_str}.md"
api_url="https://bench.nodeloc.com/up2.php"
function green_color(){
echo -ne "\e[1;32m"
}
function white_color(){
echo -ne "\e[m"
}
function yellow_color(){
echo -ne "\e[1;33m"
}
function print_help(){
green_color
cat <<- EOF
BenchScript: 主机测试脚本,用于在NodeLoc.com发表测评文章
Author: [email protected]
EOF
white_color
}
function install(){
if [ -n "$(command -v apt)" ] ; then
cmd1="apt-get"
cmd2="apt-get install -y"
elif [ -n "$(command -v yum)" ] ; then
cmd1="yum"
cmd2="yum install -y"
elif [ -n "$(command -v dnf)" ] ; then
cmd1="dnf"
cmd2="dnf install -y"
elif [ -n "$(command -v apk)" ] ; then
cmd1="apk"
cmd2="apk add"
else
echo "Error: OS Not Support"
exit 1
fi
if [ -z "$updated" ] ; then
$cmd1 update
updated=1
fi
$cmd2 "$@"
}
function pre_install(){
if [ -z "$(command -v wget)" ] ; then
install wget
fi
if [ -z "$(command -v curl)" ] ; then
install curl
fi
}
function fetch(){
download_url="$1"
if [ -n "$(command -v wget)" ] ; then
wget -qO- $download_url
elif [ -n "$(command -v curl)" ] ; then
curl -sLo- $download_url
else
install wget
wget -qO- $download_url
fi
}
function print_header(){
header=$1
if [ -n "$2" ] ; then
title_level=$2
else
title_level=1
fi
title_prefix=" "
for _ in $(seq 1 $title_level) ; do
title_prefix="#"$title_prefix
done
green_color | tee -a $markdown_log_file
echo -ne "$title_prefix" | tee -a $markdown_log_file
echo -ne $header | tee -a $markdown_log_file
white_color | tee -a $markdown_log_file
echo -e '\n' | tee -a $markdown_log_file
}
function print_code_block(){
echo '```' >> $markdown_log_file
tee -a $markdown_log_file
echo '```' >> $markdown_log_file
}
function print_markdown_block(){
print_header $1
print_code_block
}
function yabs(){
fetch 'https://yabs.sh' | bash -s -- -5 -6 | print_markdown_block Yabs测试
}
function backtrace(){
fetch 'https://raw.githubusercontent.com/zhucaidan/mtr_trace/main/mtr_trace.sh' | \
bash 2>&1 | print_markdown_block 三网回程路由测试
}
function RegionRestrictionCheck(){
num=0 bash <(fetch https://raw.githubusercontent.com/lmc999/RegionRestrictionCheck/main/check.sh | \
sed -E '/请输入正确数字或直接按回车:/d') | sed -n '/正在测试/,/测试已结束/p' | \
print_markdown_block 流媒体平台及游戏区域限制测试
}
function IPCheck(){
fetch https://raw.githubusercontent.com/spiritLHLS/ecs/main/qzcheck.sh | \
bash 2>&1 | print_markdown_block IP质量测试
}
function hyperspeed(){
bash <(fetch https://bench.im/hyperspeed) | \
print_markdown_block 单线程测速
}
function benchsh(){
fetch bench.sh | bash | \
print_markdown_block bench.sh测试
}
function main(){
print_help
pre_install
yabs
backtrace
RegionRestrictionCheck
echo -ne "\e[1;33m是否进行IP质量测试(Y/n) default Y: \e[m"
read ans
if [[ -z "$ans" ]]; then
ans=y
fi
if [[ "$ans" == 'y' ]] || [[ "$ans" == 'Y' ]]; then
IPCheck
fi
echo -ne "\e[1;33m是否进行单线程测速(Y/n) default Y: \e[m"
read ans
if [[ -z "$ans" ]]; then
ans=y
fi
if [[ "$ans" == 'y' ]] || [[ "$ans" == 'Y' ]]; then
hyperspeed
fi
echo -ne "\e[1;33m是否补充测试bench.sh(y/N) default n: \e[m"
read ans
if [[ "$ans" == 'y' ]] || [[ "$ans" == 'Y' ]]; then
benchsh
fi
if [ -n "$(command -v wget)" ] ; then
wget -qO- --post-file "$markdown_log_file" --header="Content-Disposition: attachment; filename=\"$markdown_log_file\"" $api_url | cat
else
curl -X POST --header "Content-Disposition: attachment; filename=\"$markdown_log_file\"" --data-binary @"$markdown_log_file" $api_url?filename=$markdown_log_file
fi
echo
}
main