fscarmen【Sing-box 全家桶】
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
test/speed.sh

277 lines
14 KiB

#!/usr/bin/env bash
# 当前脚本版本号和新增功能
VERSION=1.00
E[0]="Language:\n 1.English (default) \n 2.简体中文"
C[0]="${E[0]}"
E[1]="Speed test and unlocking test is for reference only and does not represent the actual usage, due to network changes, Netflix blocking and ip replacement. Speed test is time-sensitive."
C[1]="测速及解锁测试仅供参考,不代表实际使用情况,由于网络情况变化、Netflix 封锁及 ip 更换,测速具有时效性"
E[2]="New Features: "
C[2]="新特性: "
E[3]="Choose:"
C[3]="请选择:"
E[4]="!!! This cannot be empty!!!"
C[4]="!!!此处不能为空!!!"
E[5]="More than 5 errors have been entered, and the script exits."
C[5]="输入错误超过5次, 脚本退出"
E[6]="Please input a subscription url or a single node supported by v2ray (VLESS is not supported):"
C[6]="请输入订阅链接或者v2ray支持的单节点 (不支持 VLESS):"
E[7]="If there are more than 2 filters below, you can separate the keywords by spaces."
C[7]="以下筛选条件如超过2个, 可以通过空格分隔关键词."
E[8]="Filter nodes by remarks using keyword:"
C[8]="使用关键字通过注释筛选节点:"
E[9]="Exclude nodes by remarks using keyword:"
C[9]="通过使用关键字的注释排除节点:"
E[10]="Manually set group:"
C[10]="请输入测速组名:"
E[11]="Set the colors when exporting images:\n 1. origin (default)\n 2. poor"
C[11]="导出图像时设置颜色:\n 1. origin (默认)\n 2. poor"
E[12]="Select sort method, default not sorted:\n 1. speed\n 2. rspeed\n 3. ping\n 4. rping"
C[12]="请选择排序方法, 默认不排序, 如默认请跳过:\n 1. speed\n 2. rspeed\n 3. ping\n 4. rping"
E[13]="This script only supports macOS."
C[13]="本脚本只支持 macOS "
E[14]="Step 1/3: Detect and install brew, python3 and git."
C[14]="进度 1/3: 检测并安装 brew, python3 和 git"
E[15]="Step 2/3: Update SSRSpeedN and dependencies."
C[15]="进度 2/3: 更新 SSRSpeedN 和依赖"
E[16]="Step 3/3: SSRSpeedN speed test."
C[16]="进度 3/3: SSRSpeedN 测速"
E[17]="Installing"
C[17]="安装"
E[18]="Failed to download the client zip package."
C[18]="下载客户端压缩包失败"
E[19]="Client decompression failed."
C[19]="客户端解压失败"
E[20]="Whether to uninstall the following python3 dependencies:"
C[20]="是否卸载以下 python3 依赖:"
E[21]="Whether to uninstall the following environment dependencies:\n git and python3."
C[21]="是否卸载以下环境依赖:\n git 和 python3"
E[22]="Whether to uninstall brew, a package management tool for Mac?"
C[22]="是否卸载 Mac下的一个包管理工具 brew"
E[23]="To uninstall the above dependencies, please press [y]. The default is not to uninstall:"
C[23]="卸载以上依赖请按[y],默认为不卸载:"
E[24]="Uninstallation of SSRSpeedN is complete."
C[24]="卸载 SSRSpeedN 已完成"
E[25]="The SSRSpeedN installation folder cannot be found in the current path. Please check if it is already installed or the installation path."
C[25]="当前路径下找不到 SSRSpeedN 安装文件夹。请确认是否已安装或安装路径"
# 自定义字体彩色,read 函数,友道翻译函数
red(){ echo -e "\033[31m\033[01m$1\033[0m"; }
green(){ echo -e "\033[32m\033[01m$1\033[0m"; }
yellow(){ echo -e "\033[33m\033[01m$1\033[0m"; }
reading(){ read -rp "$(green "$1")" "$2"; }
translate(){ [[ -n "$1" ]] && curl -ksm8 "http://fanyi.youdao.com/translate?&doctype=json&type=AUTO&i=${1//[[:space:]]/}" | cut -d \" -f18 2>/dev/null; }
# 选择语言,先判断 /etc/wireguard/language 里的语言选择,没有的话再让用户选择,默认英语
select_language(){
if [[ "$T" != [CE] ]]; then
if [ -e SSRSpeedN/language ]; then
T=$(cat SSRSpeedN/language 2>&1)
else
T=E && yellow "\n $(eval echo "\${${T}[0]}") \n" && reading " $(eval echo "\${${T}[3]}") " CHOOSE_LANGUAGE
[[ $CHOOSE_LANGUAGE = 2 ]] && T=C
fi
fi
}
help(){
if [[ "$T" = C ]] || grep -q 'C' SSRSpeedN/languag; then
echo "
用法: ssrspeed [-h] [--version] [-c GUICONFIG] [-u URL] [-m TEST_METHOD]
[-M TEST_MODE] [--include FILTER [FILTER ...]]
[--include-remark REMARKS [REMARKS ...]]
[--include-group GROUP [GROUP ...]]
[--exclude EFLITER [EFLITER ...]]
[--exclude-group EGFILTER [EGFILTER ...]]
[--exclude-remark ERFILTER [ERFILTER ...]] [--use-ssr-cs]
[-g GROUP_OVERRIDE] [-y] [-C RESULT_COLOR] [-s SORT_METHOD]
[-i IMPORT_FILE] [--skip-requirements-check] [--debug]
[--paolu]
选项:
--version 显示程序的版本号并退出
-h,--help 显示此帮助消息并退出
-c GUICONFIG,--config = GUICONFIG 加载由 shadowsocksr-csharp 生成的配置。
-u URL,--url = URL 从订阅 URL 加载 ssr 配置。
-m TEST_METHOD,--method = TEST_METHOD 在 [speedtestnet, fast, socket, stasync] 中选择测试方法。
-M TEST_MODE,--mode = TEST_MODE 在 [all, pingonly, wps] 中选择测试模式。
--include 按组过滤节点,并使用关键字注释。
--include-remark 使用关键字通过注释过滤节点。
--include-group 使用关键字按组名过滤节点。
--exclude 按组排除节点,并使用关键字进行注释。
--exclude-group 使用关键字按组排除节点。
--exclude-remark 通过使用关键字的注释排除节点。
--use-ssr-cs 用 ShadowsocksR-C# 替换 ShadowsocksR-libev(仅 Windows)
-g GROUP 手动设置组。
-y,--yes 测试前跳过节点列表确认。
-C RESULT_COLOR,--color = RESULT_COLOR 导出图像时设置颜色。
-S SORT_METHOD,--sort = SORT_METHOD 在 [speed, rspeed, ping, rping] 中选择排序方法,默认不排序。
-i IMPORT_FILE,--import = IMPORT_FILE 从 json 文件导入测试结果并导出。
-skip-requirements-check 跳过要求检查。
--debug 在调试模式下运行程序。
测试模式
模式 备注
TCP_PING 仅 tcp ping,无速度测试
WEB_PAGE_SIMULATION 网页模拟测试
ALL 全速测试(不包括网页模拟)
测试方法
方法 备注
ST_ASYNC 单线程异步下载
SOCKET 具有多线程的原始套接字
SPEED_TEST_NET SpeedTest.Net 速度测试
FAST Fast.com 速度测试
"
else
echo "
usage: ssrspeed [-h] [--version] [-c GUICONFIG] [-u URL] [-m TEST_METHOD]
[-M TEST_MODE] [--include FILTER [FILTER ...]]
[--include-remark REMARKS [REMARKS ...]]
[--include-group GROUP [GROUP ...]]
[--exclude EFLITER [EFLITER ...]]
[--exclude-group EGFILTER [EGFILTER ...]]
[--exclude-remark ERFILTER [ERFILTER ...]] [--use-ssr-cs]
[-g GROUP_OVERRIDE] [-y] [-C RESULT_COLOR] [-s SORT_METHOD]
[-i IMPORT_FILE] [--skip-requirements-check] [--debug]
[--paolu]
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-c GUICONFIG, --config=GUICONFIG Load config generated by shadowsocksr-csharp.
-u URL, --url=URL Load ssr config from subscription url.
-m TEST_METHOD, --method=TEST_METHOD Select test method in in [speedtestnet, fast, socket, stasync].
-M TEST_MODE, --mode=TEST_MODE Select test mode in [all, pingonly, wps].
--include Filter nodes by group and remarks using keyword.
--include-remark Filter nodes by remarks using keyword.
--include-group Filter nodes by group name using keyword.
--exclude Exclude nodes by group and remarks using keyword.
--exclude-group Exclude nodes by group using keyword.
--exclude-remark Exclude nodes by remarks using keyword.
--use-ssr-cs Replace the ShadowsocksR-libev with the ShadowsocksR-C# (Only Windows)
-g GROUP Manually set group.
-y, --yes Skip node list confirmation before test.
-C RESULT_COLOR, --color=RESULT_COLOR Set the colors when exporting images..
-S SORT_METHOD, --sort=SORT_METHOD Select sort method in [speed, rspeed, ping, rping], default not sorted.
-i IMPORT_FILE, --import=IMPORT_FILE Import test result from json file and export it.
--skip-requirements-check Skip requirements check.
--debug Run program in debug mode.
Test Modes
Mode Remark
TCP_PING Only tcp ping, no speed test
WEB_PAGE_SIMULATION Web page simulation test
ALL Full speed test (exclude web page simulation)
Test Methods
Methods Remark
ST_ASYNC Asynchronous download with single thread
SOCKET Raw socket with multithreading
SPEED_TEST_NET Speed Test Net speed test
FAST Fast.com speed test
"
fi
exit 0
}
input(){
local i=0
while [ -z $URL ]; do
((i++)) || true
[ $i -gt 1 ] && NOT_BLANK="$(eval echo "\${${T}[4]}") " && [ $i = 6 ] && red "\n $(eval echo "\${${T}[5]}") " && exit 1
reading "\n ${NOT_BLANK}$(eval echo "\${${T}[6]}") " URL
done
[ -n "$URL" ] && URL="-u $URL"
yellow "\n $(eval echo "\${${T}[7]}") "
reading "\n $(eval echo "\${${T}[8]}") " INCLUDE_REMARK
[ -n "$INCLUDE_REMARK" ] && INCLUDE_REMARK="--include-remark $INCLUDE_REMARK"
reading "\n $(eval echo "\${${T}[9]}") " EXCLUDE_REMARK
[ -n "$EXCLUDE_REMARK" ] && EXCLUDE_REMARK="--exclude-remark $EXCLUDE_REMARK"
reading "\n $(eval echo "\${${T}[10]}") " GROUP
[ -n "$GROUP" ] && GROUP="-g $GROUP"
RESULT_COLOR="--color=origin" && yellow "\n $(eval echo "\${${T}[11]}") " && reading " $(eval echo "\${${T}[3]}") " CHOOSE_COLOR && [ "$CHOOSE_COLOR" = 2 ] && RESULT_COLOR="--color=poor"
yellow "\n $(eval echo "\${${T}[12]}") " && reading " $(eval echo "\${${T}[3]}") " CHOOSE_METHOD
case "$CHOOSE_METHOD" in 1 ) SORT_METHOD="--sort=speed";; 2 ) SORT_METHOD="--sort=rspeed";; 3 ) SORT_METHOD="--sort=ping";; 4 ) SORT_METHOD="--sort=rping";; esac
}
check_operating_system(){
sw_vesrs 2>/dev/null | grep -qvi macos && red " $(eval echo "\${${T}[13]}") " && exit 1
}
check_brew(){
green "\n $(eval echo "\${${T}[14]}") \n"
! type -p brew >/dev/null 2>&1 && yellow " $(eval echo "\${${T}[17]}") brew " && sudo /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
! type -p pip3 >/dev/null 2>&1 && yellow " $(eval echo "\${${T}[17]}") python3 " && sudo brew install python3
! type -p git >/dev/null 2>&1 && yellow " $(eval echo "\${${T}[17]}") git " && sudo brew install git
}
check_ssrspeedn(){
green "\n $(eval echo "\${${T}[15]}") \n"
[ ! -e SSRSpeedN ] && sudo git clone https://github.com/Oreomeow/SSRSpeedN
if [ ! -e SSRSpeedN/resources/clients ]; then
local LATEST=$(sudo curl -fsSL "https://api.github.com/repos/Oreomeow/SSRSpeedN/releases/latest" | grep "tag_name" | head -n 1 | cut -d : -f2 | sed 's/[ \"v,]//g')
local LATEST=${LATEST:-'1.1.1'}
sudo curl -Lo SSRSpeedN/resources/clients_darwin_64.zip https://github.com/OreosLab/SSRSpeedN/releases/download/v$LATEST/clients_darwin_64.zip
[ ! -e SSRSpeedN/resources/clients_darwin_64.zip ] && red " $(eval echo "\${${T}[18]}") " && exit 1 || sudo unzip -d SSRSpeedN/resources/ SSRSpeedN/resources/clients_darwin_64.zip
[ ! -e SSRSpeedN/resources/clients ] && red " $(eval echo "\${${T}[19]}") " && exit 1 || sudo rm -f SSRSpeedN/resources/clients_darwin_64.zip
fi
sudo chmod -R +x SSRSpeedN
cd SSRSpeedN
sudo git pull
echo "$T" | sudo tee language >/dev/null 2>&1
sudo pip3 install --upgrade setuptools
sudo pip3 install six
sudo pip3 install -r requirements.txt
[ ! -e data/ssrspeed.json ] && sudo cp -f data/ssrspeed.example.json data/ssrspeed.json
}
test(){
green "\n $(eval echo "\${${T}[16]}") \n"
sudo python3 -m ssrspeed $URL $INCLUDE_REMARK $EXCLUDE_REMARK $GROUP $RESULT_COLOR $SORT_METHOD --yes --skip-requirements-check
}
uninstall(){
if [ -e SSRSpeedN ]; then
REQUIREMENTS=$(cat SSRSpeedN/requirements.txt | sed "/^$/d")
REQUIREMENTS="${REQUIREMENTS//[[:space:]]/, }"
yellow "\n $(eval echo "\${${T}[20]}")\n $REQUIREMENTS " && reading " $(eval echo "\${${T}[23]}") " UNINSTALL_REQUIREMENTS
# yellow "\n $(eval echo "\${${T}[21]}") " && reading " $(eval echo "\${${T}[23]}") " UNINSTALL_GIT_PYTHON3
# yellow "\n $(eval echo "\${${T}[22]}") " && reading " $(eval echo "\${${T}[23]}") " UNINSTALL_BREW
cd SSRSpeedN
[[ $UNINSTALL_REQUIREMENTS = [Yy] ]] && sudo pip3 uninstall -yr requirements.txt
cd ..
sudo rm -rf SSRSpeedN
# [[ $UNINSTALL_GIT_PYTHON3 = [Yy] ]] && brew uninstall git
# [[ $UNINSTALL_BREW = [Yy] ]] && sudo
green " $(eval echo "\${${T}[24]}") "
exit 0
else
red " $(eval echo "\${${T}[25]}") "
exit 1
fi
}
# 传参 1/2
[[ "$@" =~ -[Ee] ]] && T=E
[[ "$@" =~ -[Cc] ]] && T=C
select_language
# 传参 2/2
while getopts ":HhUuR:r:" OPTNAME; do
case "$OPTNAME" in
[Hh] ) help;;
[Uu] ) uninstall;;
[Rr] ) URL=$OPTARG;;
esac
done
input
check_operating_system
check_brew
check_ssrspeedn
test