Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 60 additions & 6 deletions NodeQuality.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,40 @@

current_time="$(date +%Y_%m_%d_%H_%M_%S)"
work_dir=".nodequality$current_time"

# GitHub 镜像代理前缀(为空表示不使用代理)
# 使用 -p/--proxy <url> 传入,例如:
# -p https://ghfast.top
# --proxy https://mirror.ghproxy.com
# 设置后所有 github.com / raw.githubusercontent.com 的下载都会被加上代理前缀
gh_proxy=""
bench_os_url="https://github.com/LloydAsp/NodeQuality/releases/download/v0.0.2/BenchOs.tar.gz"
raw_file_prefix="https://raw.githubusercontent.com/LloydAsp/NodeQuality/refs/heads/main"

if uname -m | grep -Eq 'arm|aarch64'; then
bench_os_url="https://github.com/LloydAsp/NodeQuality/releases/download/v0.0.2/BenchOs-arm.tar.gz"
fi

# 给 github.com / raw.githubusercontent.com / objects.githubusercontent.com
# 这类 URL 加上镜像代理前缀;其它 URL 原样返回
# 用法: gh_url <原 URL>
gh_url(){
local url="$1"
# 没设置代理就不动
[[ -z "$gh_proxy" ]] && { echo "$url"; return; }
# 只对 github 相关域名生效
case "$url" in
https://github.com/*|https://raw.githubusercontent.com/*|https://objects.githubusercontent.com/*|https://codeload.github.com/*)
# 去掉代理末尾的斜杠,避免拼出双斜杠
local p="${gh_proxy%/}"
echo "${p}/${url}"
;;
*)
echo "$url"
;;
esac
}

header_info_filename=header_info.log
ip_quality_filename=ip_quality.log
ip_quality_json_filename=ip_quality.json
Expand Down Expand Up @@ -140,7 +167,31 @@ function _green_bold() {
}

function get_opts(){
while getopts "D:d:46Ee" opt; do
# 先解析长选项 --proxy / --help
local argv=()
while [[ $# -gt 0 ]]; do
case "$1" in
--proxy)
if [[ -z "$2" ]]; then
echo "Error: --proxy 需要一个参数"
exit 1
fi
gh_proxy="$2"
shift 2
;;
--proxy=*)
gh_proxy="${1#--proxy=}"
shift
;;
*)
argv+=("$1")
shift
;;
esac
done
set -- "${argv[@]}"

while getopts "D:d:46Eep:" opt; do
case $opt in
4)
if [[ "$opt_ipv" == "-6" ]]; then
Expand Down Expand Up @@ -169,7 +220,10 @@ function get_opts(){
lang="en"
opt_lang="-E"
;;
\?)
p)
gh_proxy="$OPTARG"
;;
\?)
echo "$(L err02)"
;;
esac
Expand Down Expand Up @@ -205,7 +259,7 @@ function load_bench_os(){
cd $work_dir
rm -rf BenchOs

curl "-L#o" BenchOs.tar.gz $bench_os_url
curl "-L#o" BenchOs.tar.gz "$(gh_url $bench_os_url)"
tar -xzf BenchOs.tar.gz
cd $work_dir/BenchOs

Expand All @@ -224,16 +278,16 @@ function chroot_run(){

function load_part(){
# gb5-test.sh, swap part
. <(curl -sL "$raw_file_prefix/part/swap.sh")
. <(curl -sL "$(gh_url "$raw_file_prefix/part/swap.sh")")
}

function load_3rd_program(){
chroot_run wget https://github.com/nxtrace/NTrace-core/releases/download/v1.3.7/nexttrace_linux_amd64 -qO /usr/local/bin/nexttrace
chroot_run wget "$(gh_url https://github.com/nxtrace/NTrace-core/releases/download/v1.3.7/nexttrace_linux_amd64)" -qO /usr/local/bin/nexttrace
chroot_run chmod u+x /usr/local/bin/nexttrace
}

function run_header(){
chroot_run bash <(curl -Ls "$raw_file_prefix/part/header.sh")
chroot_run bash <(curl -Ls "$(gh_url "$raw_file_prefix/part/header.sh")")
}

function detect_virt() {
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@
```
bash <(curl -sL https://run.NodeQuality.com)
```

## GitHub 加速(镜像代理)
当 vps 访问 GitHub 困难时,可用 `-p` / `--proxy` 参数指定一个 GitHub 镜像加速前缀,脚本会把 `github.com`、`raw.githubusercontent.com`、`objects.githubusercontent.com`、`codeload.github.com` 等域名的下载全部走该代理,第三方测试接口(`*.Check.Place`、`api.nodequality.com`)不受影响。

```bash
# 短选项
bash NodeQuality.sh -p https://ghfast.top

# 长选项(两种写法等价)
bash NodeQuality.sh --proxy https://ghfast.top
bash NodeQuality.sh --proxy=https://ghfast.top

# 与其他参数混用
bash NodeQuality.sh -E -4 -p https://ghfast.top
```

常用镜像前缀(任选其一,可用性因地区和网络而异):
- `https://ghfast.top`
- `https://mirror.ghproxy.com`
- `https://ghproxy.net`

> 注:代理前缀末尾的 `/` 可加可不加,脚本会自动处理。该参数仅对 GitHub 资源生效,不会影响 IP/网络质量检测的真实结果。
## 沙箱隔离,无痕测试
测试脚本往往需要加载很多软件和工具,符合**把各种专用工具串起来解决问题的linux哲学**。 为了减少测试过程中安装的软件和产生的临时文件占用空间,将所有测试放在**BenchOS**内。 chroot特别适合作为测试脚本的沙箱工具,因为其**不用额外安装、极致的轻量、只有文件隔离而没有网络和内存隔离**。

Expand Down