Compare commits

...

21 Commits

Author SHA1 Message Date
spiritlhl
ebce9e493d v0.0.86 增加GooglePlay流媒体检测 2024-11-23 21:01:20 +08:00
spiritlhl
176899d3e9 Update 2024-11-18 13:19:11 +08:00
spiritlhl
e58da9e921 Update 2024-11-18 13:09:43 +08:00
spiritlhl
651bbb94d0 Add noninteractive option 2024-11-18 12:54:09 +08:00
spiritlhl
91ffbfa417 v0.0.85 更新分区模块,更新shell相关脚本修复隐藏BUG 2024-11-18 11:24:36 +08:00
spiritlhl
84b0303468 2024.11.17 2024-11-17 08:58:14 +00:00
spiritlhl
f3e10a999b 2024.11.17 更新shell相关内容,支持epel安装回退和可选是否更新包管理器 2024-11-17 08:38:52 +00:00
spiritlhl
76a6e09d97 2024.11.17 更新shell相关内容,支持epel安装回退和可选是否更新包管理器 2024-11-17 08:37:32 +00:00
spiritsoul
9c9dbc6200 增加对应的子网掩码检测调用 2024-11-08 22:19:57 +08:00
spiritsoul
20c8063e5e v0.0.83 增加IPV6子网掩码检测所需的依赖 2024-11-08 20:55:14 +08:00
spiritsoul
fbe5eb8e58 v0.0.83 增加IPV6子网掩码检测 2024-11-08 20:21:17 +08:00
spiritlhl
290f0d8d8c Update 2024-10-20 11:37:06 +08:00
spiritlhl
140347c2a6 v0.0.81
优化在按ctrl+c终止程序时依然生成分享链接
2024-10-06 21:22:14 +08:00
spiritlhl
aeda7a6e88 Update goecs.sh 2024-10-06 21:04:23 +08:00
spiritlhl
a205ca38be v0.0.80
修复选项识别错误以及测速识别错误的问题
修正终止命令的检测和退出机制
pingtest优化日志记录
2024-10-06 20:41:36 +08:00
spiritlhl
43bf9c81ed Update goecs.sh 2024-10-06 19:13:22 +08:00
spiritlhl
d47f8987a7 Update goecs.sh 2024-10-06 19:00:18 +08:00
spiritlhl
ffbe5a539a Update goecs.sh 2024-10-06 16:09:26 +08:00
spiritsoul
4b8ae06df8 v0.0.79 2024-10-06 00:50:52 +08:00
spiritsoul
859e783241 v0.0.78 2024-10-06 00:03:28 +08:00
spiritsoul
3cd912219e v0.0.77 临时修复测速BUG,未完全修复
v0.0.77 临时修复测速BUG,未完全修复
2024-10-05 23:26:09 +08:00
9 changed files with 326 additions and 179 deletions

View File

@@ -4,9 +4,9 @@ FROM alpine:latest
# 安装必要的工具 # 安装必要的工具
RUN apk add --no-cache wget curl bash RUN apk add --no-cache wget curl bash
RUN apk add --no-cache bind-tools --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main RUN apk add --no-cache bind-tools --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main
RUN apk add --no-cache grep openssl ca-certificates uuidgen RUN apk add --no-cache grep openssl ca-certificates uuidgen
RUN export noninteractive=true
# 下载并执行 goecs.sh 脚本 # 下载并执行 goecs.sh 脚本
RUN curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && \ RUN curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && \
chmod +x goecs.sh && \ chmod +x goecs.sh && \

View File

@@ -47,13 +47,13 @@ Shell版本 https://github.com/spiritLHLS/ecs
### 一键命令 ### 一键命令
``` ```
curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh && bash goecs.sh env && bash goecs.sh install && goecs export noninteractive=true && curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh && bash goecs.sh env && bash goecs.sh install && goecs
``` ```
``` ```
curl -L https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh && bash goecs.sh env && bash goecs.sh install && goecs export noninteractive=true && curl -L https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh && bash goecs.sh env && bash goecs.sh install && goecs
``` ```
### 详细说明 ### 详细说明
@@ -70,12 +70,14 @@ curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o go
curl -L https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh curl -L https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh
``` ```
安装环境 更新包管理器(可选择)和安装环境
``` ```
./goecs.sh env ./goecs.sh env
``` ```
如果不想要互动,可使用```export noninteractive=true```再执行```env```命令
安装goecs 安装goecs
``` ```
@@ -99,18 +101,28 @@ shell脚本的说明
``` ```
可用命令: 可用命令:
./goecs.sh env 检查并安装的包: ./goecs.sh env 检查并安装依赖包
sudo (几乎所有类 Unix 系统都有。) 警告: 此命令会执行系统更新(可选择),可能:
tar (几乎所有类 Unix 系统都有。) 1. 耗时较长
unzip (几乎所有类 Unix 系统都有。) 2. 导致网络短暂中断
dd (几乎所有类 Unix 系统都有。) 3. 影响系统稳定性
fio (几乎所有类 Unix 系统可以通过系统的包管理器安装。) 4. 影响后续系统启动
sysbench (几乎所有类 Unix 系统可以通过系统的包管理器安装。) 对于内存小于1GB的系统还可能导致:
geekbench (geekbench5) (仅支持 IPV4 环境,且内存大于 1GB 并需要持续联网,仅支持 amd64 和 arm64 架构。) 1. 系统卡死
speedtest (使用官方提供的二进制文件以获得更准确的测试结果。) 2. SSH连接中断
ping (使用官方提供的二进制文件以获得更准确的测试结果。) 3. 关键服务失败
systemd-detect-virt 或 dmidecode (几乎所有类 Unix 系统都有,安装以获得更准确的测试结果。) 推荐:
事实上sysbench/geekbench 是上述依赖项中唯一必须安装的,没有它们无法测试 CPU 分数。 环境依赖安装过程中挂起执行
必需组件:
sysbench/geekbench (CPU性能测试必需)
可选组件:
sudo, tar, unzip, dd, fio
speedtest (网络测试)
ping (网络连通性测试)
systemd-detect-virt/dmidecode (系统信息检测)
./goecs.sh install 安装 goecs 命令 ./goecs.sh install 安装 goecs 命令
./goecs.sh upgrade 升级 goecs 命令 ./goecs.sh upgrade 升级 goecs 命令
./goecs.sh uninstall 卸载 goecs 命令 ./goecs.sh uninstall 卸载 goecs 命令

View File

@@ -47,7 +47,7 @@ Systems to be supported (hardware testing bugs not yet fixed): MacOS、FreeBSD
### one-click command ### one-click command
``` ```
curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh && bash goecs.sh env && bash goecs.sh install && goecs -l en export noninteractive=true && curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh && bash goecs.sh env && bash goecs.sh install && goecs -l en
``` ```
### explain in detail ### explain in detail
@@ -64,6 +64,8 @@ Install environment
./goecs.sh env ./goecs.sh env
``` ```
If you don't want interaction, use ```export noninteractive=true``` and then execute the ```env``` command
Install goecs Install goecs
``` ```
@@ -87,18 +89,28 @@ Explanation of the shell script
``` ```
Available commands: Available commands:
./goecs.sh env Check and Install package: ./goecs.sh env Check and Install dependencies
sudo (Almost all unix-like systems have it.) Warning: This command performs system update(optional), which may:
tar (Almost all unix-like systems have it.) 1. Take considerable time
unzip (Almost all unix-like systems have it.) 2. Cause temporary network interruptions
dd (Almost all unix-like systems have it.) 3. Impact system stability
fio (Almost all unix-like systems can be installed through the system's package manager.) 4. Affect subsequent system startups
sysbench (Almost all unix-like systems can be installed through the system's package manager.) For systems with less than 1GB RAM, additional risks:
geekbench (geekbench5)(Only support IPV4 environment, and memory greater than 1GB network detection, only support amd64 and arm64 architecture.) 1. System freeze
speedtest (Use the officially provided binaries for more accurate test results.) 2. SSH connection loss
ping (Use the officially provided binaries for more accurate test results.) 3. Critical service failures
systemd-detect-virt OR dmidecode (Almost all unix-like systems have it, for more accurate test results.) Recommended:
In fact, sysbench/geekbench is the only one of the above dependencies that must be installed, without which the CPU score cannot be tested. Hanging execution during environment dependency installation
Required components:
sysbench/geekbench (Required for CPU testing)
Optional components:
sudo, tar, unzip, dd, fio
speedtest (Network testing)
ping (Network connectivity)
systemd-detect-virt/dmidecode (System info detection)
./goecs.sh install Install goecs command ./goecs.sh install Install goecs command
./goecs.sh upgrade Upgrade goecs command ./goecs.sh upgrade Upgrade goecs command
./goecs.sh uninstall Uninstall goecs command ./goecs.sh uninstall Uninstall goecs command

View File

@@ -7,7 +7,7 @@ import (
"strings" "strings"
) )
// 本包不在main中使用仅做测试使用 // 本包不在main中使用仅做测试使用,真正调用的在 utils 中的 BasicsAndSecurityCheck
func Basic(language string) { func Basic(language string) {
ipInfo, _, _ := network.NetworkCheck("both", false, language) ipInfo, _, _ := network.NetworkCheck("both", false, language)
systemInfo := system.CheckSystemInfo(language) systemInfo := system.CheckSystemInfo(language)

8
go.mod
View File

@@ -5,19 +5,19 @@ go 1.22.4
require ( require (
github.com/imroc/req/v3 v3.43.7 github.com/imroc/req/v3 v3.43.7
github.com/oneclickvirt/CommonMediaTests v0.0.4-20240704024502 github.com/oneclickvirt/CommonMediaTests v0.0.4-20240704024502
github.com/oneclickvirt/UnlockTests v0.0.16-20240823051211 github.com/oneclickvirt/UnlockTests v0.0.19-20241123125400
github.com/oneclickvirt/backtrace v0.0.4-20240702140722 github.com/oneclickvirt/backtrace v0.0.4-20240702140722
github.com/oneclickvirt/basics v0.0.7-20240821160408 github.com/oneclickvirt/basics v0.0.8-20241108124433
github.com/oneclickvirt/cputest v0.0.8-20240702070215 github.com/oneclickvirt/cputest v0.0.8-20240702070215
github.com/oneclickvirt/defaultset v0.0.2-20240624082446 github.com/oneclickvirt/defaultset v0.0.2-20240624082446
github.com/oneclickvirt/disktest v0.0.4-20240809053456 github.com/oneclickvirt/disktest v0.0.4-20240809053456
github.com/oneclickvirt/gostun v0.0.3-20240702054621 github.com/oneclickvirt/gostun v0.0.3-20240702054621
github.com/oneclickvirt/memorytest v0.0.4-20240820095126 github.com/oneclickvirt/memorytest v0.0.4-20240820095126
github.com/oneclickvirt/nt3 v0.0.3-20240809100110 github.com/oneclickvirt/nt3 v0.0.3-20240809100110
github.com/oneclickvirt/pingtest v0.0.5-20240804134050 github.com/oneclickvirt/pingtest v0.0.5-20241006123443
github.com/oneclickvirt/portchecker v0.0.2-20240803151204 github.com/oneclickvirt/portchecker v0.0.2-20240803151204
github.com/oneclickvirt/security v0.0.4-20240729065854 github.com/oneclickvirt/security v0.0.4-20240729065854
github.com/oneclickvirt/speedtest v0.0.7-20240704023701 github.com/oneclickvirt/speedtest v0.0.8-20241005164804
) )
require ( require (

16
go.sum
View File

@@ -104,12 +104,12 @@ github.com/nxtrace/NTrace-core v1.3.2 h1:8aU/IQFmPnwbaWGVBIJHwwVIWk+roo+9+lG+U0O
github.com/nxtrace/NTrace-core v1.3.2/go.mod h1:qCVsgSs982jw02BVjTtN8mjSg5OIXW9TaUdISQrMnTw= github.com/nxtrace/NTrace-core v1.3.2/go.mod h1:qCVsgSs982jw02BVjTtN8mjSg5OIXW9TaUdISQrMnTw=
github.com/oneclickvirt/CommonMediaTests v0.0.4-20240704024502 h1:hRIYJ2uEp2N3AH5bP5X6bwfdwWfZQO/2WoqpUJ8+WsY= github.com/oneclickvirt/CommonMediaTests v0.0.4-20240704024502 h1:hRIYJ2uEp2N3AH5bP5X6bwfdwWfZQO/2WoqpUJ8+WsY=
github.com/oneclickvirt/CommonMediaTests v0.0.4-20240704024502/go.mod h1:DAmFPRjFV5p9fEzUUSml5jJGn2f1NZJQCzTxITHDjc4= github.com/oneclickvirt/CommonMediaTests v0.0.4-20240704024502/go.mod h1:DAmFPRjFV5p9fEzUUSml5jJGn2f1NZJQCzTxITHDjc4=
github.com/oneclickvirt/UnlockTests v0.0.16-20240823051211 h1:oDYlAXbUSt6JYTC+wcFDVWTacGuyBtWNfJhpKkrqNkU= github.com/oneclickvirt/UnlockTests v0.0.19-20241123125400 h1:grW8HzS4v0mRQ2ZBtR7CNg+k9he5QtgW/CQ86Ux0rdg=
github.com/oneclickvirt/UnlockTests v0.0.16-20240823051211/go.mod h1:UELwZDDiddSxe38boYOPl1FlrL0ptEZYSQwdE3MYvUM= github.com/oneclickvirt/UnlockTests v0.0.19-20241123125400/go.mod h1:UELwZDDiddSxe38boYOPl1FlrL0ptEZYSQwdE3MYvUM=
github.com/oneclickvirt/backtrace v0.0.4-20240702140722 h1:UJ/VWf+ZbhGarc9HcHMIyenpmX+b2LxkXu0hlLk3Gxs= github.com/oneclickvirt/backtrace v0.0.4-20240702140722 h1:UJ/VWf+ZbhGarc9HcHMIyenpmX+b2LxkXu0hlLk3Gxs=
github.com/oneclickvirt/backtrace v0.0.4-20240702140722/go.mod h1:zvsC7xY/WZqs5KL2JB967OVnuqjNbxu9bW6wXRLo5h8= github.com/oneclickvirt/backtrace v0.0.4-20240702140722/go.mod h1:zvsC7xY/WZqs5KL2JB967OVnuqjNbxu9bW6wXRLo5h8=
github.com/oneclickvirt/basics v0.0.7-20240821160408 h1:IOqa7bBAkjhfru6arDsOTKB7qZ36ojfOP73kE+cDaqc= github.com/oneclickvirt/basics v0.0.8-20241108124433 h1:eKZcoNoa9uLWmfisk+qN/QOvSGT4ajCmZdZfIAcHG+o=
github.com/oneclickvirt/basics v0.0.7-20240821160408/go.mod h1:fUdVpU8gdjaZsTCyqnQBAbHc9BbbN8Fxr3sGPKooUpU= github.com/oneclickvirt/basics v0.0.8-20241108124433/go.mod h1:fUdVpU8gdjaZsTCyqnQBAbHc9BbbN8Fxr3sGPKooUpU=
github.com/oneclickvirt/cputest v0.0.8-20240702070215 h1:CcFpyVPlQkJ6vjFP17BRuJhh/afiJhOhZ0BW+TtfVDg= github.com/oneclickvirt/cputest v0.0.8-20240702070215 h1:CcFpyVPlQkJ6vjFP17BRuJhh/afiJhOhZ0BW+TtfVDg=
github.com/oneclickvirt/cputest v0.0.8-20240702070215/go.mod h1:MmaHN9+XMntI3rLycwj8Ne31fG18IfNoa8N2utDK1CY= github.com/oneclickvirt/cputest v0.0.8-20240702070215/go.mod h1:MmaHN9+XMntI3rLycwj8Ne31fG18IfNoa8N2utDK1CY=
github.com/oneclickvirt/defaultset v0.0.2-20240624082446 h1:5Pg3mK/u/vQvSz7anu0nxzrNdELi/AcDAU1mMsmPzyc= github.com/oneclickvirt/defaultset v0.0.2-20240624082446 h1:5Pg3mK/u/vQvSz7anu0nxzrNdELi/AcDAU1mMsmPzyc=
@@ -122,14 +122,14 @@ github.com/oneclickvirt/memorytest v0.0.4-20240820095126 h1:Il3rvWkrZy/6B2iO3HRe
github.com/oneclickvirt/memorytest v0.0.4-20240820095126/go.mod h1:+YNzy+NeVg61d0kNwSyVDqHyVtKzjuRe1NvMzsDLg0I= github.com/oneclickvirt/memorytest v0.0.4-20240820095126/go.mod h1:+YNzy+NeVg61d0kNwSyVDqHyVtKzjuRe1NvMzsDLg0I=
github.com/oneclickvirt/nt3 v0.0.3-20240809100110 h1:UyF0jBDP0xpxSV9L/GYG83SKUMPSjHPru+3iPZHYG7U= github.com/oneclickvirt/nt3 v0.0.3-20240809100110 h1:UyF0jBDP0xpxSV9L/GYG83SKUMPSjHPru+3iPZHYG7U=
github.com/oneclickvirt/nt3 v0.0.3-20240809100110/go.mod h1:4SDl5o83wbixk9YJqvG0eNo2w8aWt/QgntfPBi9wEpY= github.com/oneclickvirt/nt3 v0.0.3-20240809100110/go.mod h1:4SDl5o83wbixk9YJqvG0eNo2w8aWt/QgntfPBi9wEpY=
github.com/oneclickvirt/pingtest v0.0.5-20240804134050 h1:ASiYr+IgWIPDhTiXEN1dbm1AEcxRkPnKi3NNn4mCkDE= github.com/oneclickvirt/pingtest v0.0.5-20241006123443 h1:Ywrh0Yd/PYXOKGE8VaNiKGWlIqdgLLgsthAzxy0t7s8=
github.com/oneclickvirt/pingtest v0.0.5-20240804134050/go.mod h1:d3Ntx5m9lMll3a/k3+2B+5emj//vgDh4/NHTxs2qQE8= github.com/oneclickvirt/pingtest v0.0.5-20241006123443/go.mod h1:d3Ntx5m9lMll3a/k3+2B+5emj//vgDh4/NHTxs2qQE8=
github.com/oneclickvirt/portchecker v0.0.2-20240803151204 h1:ZruxRgyIv3d6Y8n0Ney5FHhQtcQLxCvs+xJmGsh9/7E= github.com/oneclickvirt/portchecker v0.0.2-20240803151204 h1:ZruxRgyIv3d6Y8n0Ney5FHhQtcQLxCvs+xJmGsh9/7E=
github.com/oneclickvirt/portchecker v0.0.2-20240803151204/go.mod h1:HQxSTrqM8/QFqHMTBZ7S8H9eEO5FkUXU1eb7ZX5Mk+k= github.com/oneclickvirt/portchecker v0.0.2-20240803151204/go.mod h1:HQxSTrqM8/QFqHMTBZ7S8H9eEO5FkUXU1eb7ZX5Mk+k=
github.com/oneclickvirt/security v0.0.4-20240729065854 h1:I27XtMUEHmXw1RN0jNDQmFqNdu6vL4v1g8UZtXiCuBY= github.com/oneclickvirt/security v0.0.4-20240729065854 h1:I27XtMUEHmXw1RN0jNDQmFqNdu6vL4v1g8UZtXiCuBY=
github.com/oneclickvirt/security v0.0.4-20240729065854/go.mod h1:384ZpNE3H6T6rtl0QhA4eQn8xGw7tc0rLD8ZH47qNGc= github.com/oneclickvirt/security v0.0.4-20240729065854/go.mod h1:384ZpNE3H6T6rtl0QhA4eQn8xGw7tc0rLD8ZH47qNGc=
github.com/oneclickvirt/speedtest v0.0.7-20240704023701 h1:F8ChZXf3U1/bUk+dCFt0Gc01LSPLhbBhCeHjkEJ6K88= github.com/oneclickvirt/speedtest v0.0.8-20241005164804 h1:qguczGucxyRCRaeI2Av7+QpgYb6o8lTJJmOjPkmGiSg=
github.com/oneclickvirt/speedtest v0.0.7-20240704023701/go.mod h1:zd5ZgIGslmtQLQehEfRjyumlvgDHTpCSMchKfKXoASI= github.com/oneclickvirt/speedtest v0.0.8-20241005164804/go.mod h1:zd5ZgIGslmtQLQehEfRjyumlvgDHTpCSMchKfKXoASI=
github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA= github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA=
github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To= github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk= github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=

View File

@@ -39,7 +39,7 @@ import (
) )
var ( var (
ecsVersion = "v0.0.76" ecsVersion = "v0.0.86"
menuMode bool menuMode bool
onlyChinaTest bool onlyChinaTest bool
input, choice string input, choice string
@@ -61,23 +61,21 @@ var (
enabelUpload = true enabelUpload = true
help bool help bool
goecsFlag = flag.NewFlagSet("goecs", flag.ContinueOnError) goecsFlag = flag.NewFlagSet("goecs", flag.ContinueOnError)
finish bool
) )
func getMenuChoice(language string) string { func getMenuChoice(language string) string {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
sigChan := make(chan os.Signal, 1) sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) signal.Notify(sigChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(sigChan) defer signal.Stop(sigChan)
inputChan := make(chan string, 1) inputChan := make(chan string, 1)
go func() { go func() {
select { select {
case <-sigChan: case <-sigChan:
fmt.Println("\n程序在选择过程中被用户中断") fmt.Println("\n程序在选择过程中被用户中断")
os.Exit(1) os.Exit(0)
case <-ctx.Done(): case <-ctx.Done():
return return
} }
@@ -96,15 +94,14 @@ func getMenuChoice(language string) string {
return return
} }
}() }()
select { select {
case input := <-inputChan: case input := <-inputChan:
re := regexp.MustCompile(`^\d+$`) // 正则表达式匹配纯数字 re := regexp.MustCompile(`^\d+$`) // 正则表达式匹配纯数字
if re.MatchString(input) { if re.MatchString(input) {
choice := input inChoice := input
switch choice { switch inChoice {
case "1", "2", "3", "4", "5", "6", "7", "8", "9", "10": case "1", "2", "3", "4", "5", "6", "7", "8", "9", "10":
return choice return inChoice
default: default:
if language == "zh" { if language == "zh" {
fmt.Println("无效的选项") fmt.Println("无效的选项")
@@ -210,7 +207,7 @@ func main() {
} }
Loop: Loop:
for { for {
choice := getMenuChoice(language) choice = getMenuChoice(language)
switch choice { switch choice {
case "1": case "1":
basicStatus = true basicStatus = true
@@ -319,19 +316,21 @@ func main() {
startTime = time.Now() startTime = time.Now()
// 等待信号 // 等待信号
<-sig <-sig
endTime := time.Now() if !finish {
duration := endTime.Sub(startTime) endTime := time.Now()
minutes := int(duration.Minutes()) duration := endTime.Sub(startTime)
seconds := int(duration.Seconds()) % 60 minutes := int(duration.Minutes())
currentTime := time.Now().Format("Mon Jan 2 15:04:05 MST 2006") seconds := int(duration.Seconds()) % 60
output = utils.PrintAndCapture(func() { currentTime := time.Now().Format("Mon Jan 2 15:04:05 MST 2006")
utils.PrintCenteredTitle("", width) output = utils.PrintAndCapture(func() {
fmt.Printf("Cost Time : %d min %d sec\n", minutes, seconds) utils.PrintCenteredTitle("", width)
fmt.Printf("Current Time : %s\n", currentTime) fmt.Printf("Cost Time : %d min %d sec\n", minutes, seconds)
utils.PrintCenteredTitle("", width) fmt.Printf("Current Time : %s\n", currentTime)
}, tempOutput, output) utils.PrintCenteredTitle("", width)
utils.ProcessAndUpload(output, filePath, enabelUpload) }, tempOutput, output)
os.Exit(1) // 使用非零状态码退出,表示意外退出 utils.ProcessAndUpload(output, filePath, enabelUpload)
}
os.Exit(0)
}() }()
switch language { switch language {
case "zh": case "zh":
@@ -341,7 +340,7 @@ func main() {
if basicStatus { if basicStatus {
utils.PrintCenteredTitle("系统基础信息", width) utils.PrintCenteredTitle("系统基础信息", width)
} }
basicInfo, securityInfo, nt3CheckType = utils.SecurityCheck(language, nt3CheckType, securityTestStatus) basicInfo, securityInfo, nt3CheckType = utils.BasicsAndSecurityCheck(language, nt3CheckType, securityTestStatus)
if basicStatus { if basicStatus {
fmt.Printf(basicInfo) fmt.Printf(basicInfo)
} else if (input == "6" || input == "9") && securityTestStatus { } else if (input == "6" || input == "9") && securityTestStatus {
@@ -451,14 +450,16 @@ func main() {
if speedTestStatus { if speedTestStatus {
utils.PrintCenteredTitle("就近节点测速", width) utils.PrintCenteredTitle("就近节点测速", width)
speedtest.ShowHead(language) speedtest.ShowHead(language)
if (menuMode && choice == "1") || !menuMode { if choice == "1" || !menuMode {
speedtest.NearbySP() speedtest.NearbySP()
speedtest.CustomSP("net", "global", 2, language) speedtest.CustomSP("net", "global", 2, language)
speedtest.CustomSP("net", "cu", spNum, language) speedtest.CustomSP("net", "cu", spNum, language)
speedtest.CustomSP("net", "ct", spNum, language) speedtest.CustomSP("net", "ct", spNum, language)
speedtest.CustomSP("net", "cmcc", spNum, language) speedtest.CustomSP("net", "cmcc", spNum, language)
} else if menuMode && choice == "2" || choice == "3" || choice == "4" || choice == "5" { } else if choice == "2" || choice == "3" || choice == "4" || choice == "5" {
speedtest.CustomSP("net", "global", 4, language) speedtest.CustomSP("net", "global", 4, language)
} else if choice == "6" {
speedtest.CustomSP("net", "global", 11, language)
} }
} }
}, tempOutput, output) }, tempOutput, output)
@@ -480,7 +481,7 @@ func main() {
if basicStatus { if basicStatus {
utils.PrintCenteredTitle("System-Basic-Information", width) utils.PrintCenteredTitle("System-Basic-Information", width)
} }
basicInfo, securityInfo, nt3CheckType = utils.SecurityCheck(language, nt3CheckType, securityTestStatus) basicInfo, securityInfo, nt3CheckType = utils.BasicsAndSecurityCheck(language, nt3CheckType, securityTestStatus)
if basicStatus { if basicStatus {
fmt.Printf(basicInfo) fmt.Printf(basicInfo)
} else if (input == "6" || input == "9") && securityTestStatus { } else if (input == "6" || input == "9") && securityTestStatus {
@@ -574,6 +575,7 @@ func main() {
fmt.Println("Unsupported language") fmt.Println("Unsupported language")
} }
utils.ProcessAndUpload(output, filePath, enabelUpload) utils.ProcessAndUpload(output, filePath, enabelUpload)
finish = true
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" { if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
fmt.Println("Press Enter to exit...") fmt.Println("Press Enter to exit...")
fmt.Scanln() fmt.Scanln()

295
goecs.sh
View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
#From https://github.com/oneclickvirt/ecs # From https://github.com/oneclickvirt/ecs
#2024.07.21 # 2024.11.18
# curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh # curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh
@@ -24,6 +24,7 @@ _red() { echo -e "\033[31m\033[01m$@\033[0m"; }
_green() { echo -e "\033[32m\033[01m$@\033[0m"; } _green() { echo -e "\033[32m\033[01m$@\033[0m"; }
_yellow() { echo -e "\033[33m\033[01m$@\033[0m"; } _yellow() { echo -e "\033[33m\033[01m$@\033[0m"; }
_blue() { echo -e "\033[36m\033[01m$@\033[0m"; } _blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
reading() { read -rp "$(_green "$1")" "$2"; }
check_cdn() { check_cdn() {
local o_url=$1 local o_url=$1
@@ -59,6 +60,32 @@ download_file() {
return 0 return 0
} }
get_memory_size() {
if [ -f /proc/meminfo ]; then
local mem_kb=$(grep MemTotal /proc/meminfo | awk '{print $2}')
echo $((mem_kb / 1024)) # Convert to MB
return
fi
if command -v free >/dev/null 2>&1; then
local mem_kb=$(free -m | awk '/^Mem:/ {print $2}')
echo "$mem_kb" # Already in MB
return
fi
if command -v sysctl >/dev/null 2>&1; then
local mem_bytes=$(sysctl -n hw.memsize 2>/dev/null || sysctl -n hw.physmem 2>/dev/null)
if [ -n "$mem_bytes" ]; then
echo $((mem_bytes / 1024 / 1024)) # Convert to MB
return
fi
fi
}
cleanup_epel() {
_yellow "Cleaning up EPEL repositories..."
rm -f /etc/yum.repos.d/*epel*
yum clean all
}
goecs_check() { goecs_check() {
os=$(uname -s) os=$(uname -s)
arch=$(uname -m) arch=$(uname -m)
@@ -145,7 +172,7 @@ goecs_check() {
download_file "${cdn_success_url}https://github.com/oneclickvirt/ecs/releases/download/v${ECS_VERSION}/goecs_amd64.zip" "goecs.zip" download_file "${cdn_success_url}https://github.com/oneclickvirt/ecs/releases/download/v${ECS_VERSION}/goecs_amd64.zip" "goecs.zip"
;; ;;
"armv7l" | "armv8" | "armv8l" | "aarch64" | "arm64") "armv7l" | "armv8" | "armv8l" | "aarch64" | "arm64")
download_file "${cdn_success_url}https://github.com/oneclickvirt/ecs/releases/download/v${ECS_VERSION}/goecs_arm64.zip" "goecs.zip" download_file "${cdn_success_url}https://github.com/oneclickvirt/ ecs/releases/download/v${ECS_VERSION}/goecs_arm64.zip" "goecs.zip"
;; ;;
*) *)
_red "Unsupported architecture: $arch , please check https://github.com/oneclickvirt/ecs/releases to download the zip for yourself and unzip it to use the binary for testing." _red "Unsupported architecture: $arch , please check https://github.com/oneclickvirt/ecs/releases to download the zip for yourself and unzip it to use the binary for testing."
@@ -158,6 +185,7 @@ goecs_check() {
exit 1 exit 1
;; ;;
esac esac
unzip goecs.zip unzip goecs.zip
rm -rf goecs.zip rm -rf goecs.zip
rm -rf README.md rm -rf README.md
@@ -187,7 +215,9 @@ goecs_check() {
} }
InstallSysbench() { InstallSysbench() {
if [ -f "/etc/centos-release" ]; then # CentOS if [ -f "/etc/opencloudos-release" ]; then # OpenCloudOS
Var_OSRelease="opencloudos"
elif [ -f "/etc/centos-release" ]; then # CentOS
Var_OSRelease="centos" Var_OSRelease="centos"
elif [ -f "/etc/fedora-release" ]; then # Fedora elif [ -f "/etc/fedora-release" ]; then # Fedora
Var_OSRelease="fedora" Var_OSRelease="fedora"
@@ -203,7 +233,6 @@ InstallSysbench() {
Var_OSRelease="alpinelinux" Var_OSRelease="alpinelinux"
elif [ -f "/etc/almalinux-release" ]; then # almalinux elif [ -f "/etc/almalinux-release" ]; then # almalinux
Var_OSRelease="almalinux" Var_OSRelease="almalinux"
# rockylinux
elif [ -f "/etc/arch-release" ]; then # archlinux elif [ -f "/etc/arch-release" ]; then # archlinux
Var_OSRelease="arch" Var_OSRelease="arch"
elif [ -f "/etc/freebsd-update.conf" ]; then # freebsd elif [ -f "/etc/freebsd-update.conf" ]; then # freebsd
@@ -211,15 +240,70 @@ InstallSysbench() {
else else
Var_OSRelease="unknown" # 未知系统分支 Var_OSRelease="unknown" # 未知系统分支
fi fi
case "$Var_OSRelease" in local mem_size=$(get_memory_size)
ubuntu | debian | astra) ! apt-get install -y sysbench && apt-get --fix-broken install -y && apt-get install --no-install-recommends -y sysbench ;; if [ -z "$mem_size" ] || [ "$mem_size" -eq 0 ]; then
centos | rhel | almalinux | redhat) (yum -y install epel-release && yum -y install sysbench) || (dnf install epel-release -y && dnf install sysbench -y) ;; echo "Error: Unable to determine memory size or memory size is zero."
fedora) dnf -y install sysbench ;; elif [ $mem_size -lt 1024 ]; then
arch) pacman -S --needed --noconfirm sysbench && pacman -S --needed --noconfirm libaio && ldconfig ;; _red "Warning: Your system has less than 1GB RAM (${mem_size}MB)"
freebsd) pkg install -y sysbench ;; if [ "$noninteractive" != "true" ]; then
alpinelinux) echo -e "${Msg_Warning}Sysbench Module not found, installing ..." && echo -e "${Msg_Warning}SysBench Current not support Alpine Linux, Skipping..." && Var_Skip_SysBench="1" ;; reading "Do you want to continue with EPEL installation? (y/N): " confirm
*) _red "Sysbench Install Error: Unknown OS release: $os_release" ;; if [[ ! $confirm =~ ^[Yy]$ ]]; then
esac _yellow "Skipping EPEL installation"
return 1
fi
fi
case "$Var_OSRelease" in
ubuntu | debian | astra)
! apt-get install -y sysbench && apt-get --fix-broken install -y && apt-get install --no-install-recommends -y sysbench ;;
centos | rhel | almalinux | redhat | opencloudos)
(yum -y install epel-release && yum -y install sysbench) || (dnf install epel-release -y && dnf install sysbench -y) ;;
fedora)
dnf -y install sysbench ;;
arch)
pacman -S --needed --noconfirm sysbench && pacman -S --needed --noconfirm libaio && ldconfig ;;
freebsd)
pkg install -y sysbench ;;
alpinelinux)
if [ "$noninteractive" != "true" ]; then
reading "Do you want to continue with sysbench installation? (y/N): " confirm
if [[ ! $confirm =~ ^[Yy]$ ]]; then
_yellow "Skipping sysbench installation"
return 1
fi
fi
ALPINE_VERSION=$(grep -o '^[0-9]\+\.[0-9]\+' /etc/alpine-release)
COMMUNITY_REPO="http://dl-cdn.alpinelinux.org/alpine/v${ALPINE_VERSION}/community"
if grep -q "^${COMMUNITY_REPO}" /etc/apk/repositories; then
echo "Community repository is already enabled."
else
echo "Enabling community repository..."
echo "${COMMUNITY_REPO}" >> /etc/apk/repositories
echo "Community repository has been added."
echo "Updating apk package index..."
apk update && echo "Package index updated successfully."
fi
if apk info sysbench >/dev/null 2>&1; then
echo -e "${Msg_Info}Sysbench already installed."
else
apk add --no-cache sysbench
if [ $? -ne 0 ]; then
echo -e "${Msg_Warning}Sysbench Module not found, installing ..." && echo -e "${Msg_Warning}SysBench Current not support Alpine Linux, Skipping..." && Var_Skip_SysBench="1"
else
echo -e "${Msg_Success}Sysbench installed successfully."
fi
fi ;;
*)
_red "Sysbench Install Error: Unknown OS release: $Var_OSRelease" ;;
esac
if [[ $SYSTEM =~ ^(CentOS|RHEL|AlmaLinux)$ ]]; then
_yellow "Installing EPEL repository..."
if ! yum -y install epel-release; then
_red "EPEL installation failed!"
cleanup_epel
_yellow "Attempting to continue without EPEL..."
fi
fi
fi
} }
Check_SysBench() { Check_SysBench() {
@@ -248,6 +332,9 @@ Check_Sysbench_InstantBuild() {
if [ "$os_sysbench" = "astra" ]; then if [ "$os_sysbench" = "astra" ]; then
os_sysbench="debian" os_sysbench="debian"
fi fi
if [ "$os_sysbench" = "opencloudos" ]; then
os_sysbench="centos"
fi
echo -e "${Msg_Info}Release Detected: ${os_sysbench}" echo -e "${Msg_Info}Release Detected: ${os_sysbench}"
echo -e "${Msg_Info}Preparing compile enviorment ..." echo -e "${Msg_Info}Preparing compile enviorment ..."
prepare_compile_env "${os_sysbench}" prepare_compile_env "${os_sysbench}"
@@ -282,15 +369,15 @@ prepare_compile_env() {
} }
env_check() { env_check() {
REGEX=("debian|astra" "ubuntu" "centos|red hat|kernel|oracle linux|alma|rocky" "'amazon linux'" "fedora" "arch" "freebsd" "alpine" "openbsd") REGEX=("debian|astra" "ubuntu" "centos|red hat|kernel|oracle linux|alma|rocky" "'amazon linux'" "fedora" "arch" "freebsd" "alpine" "openbsd" "opencloudos")
RELEASE=("Debian" "Ubuntu" "CentOS" "CentOS" "Fedora" "Arch" "FreeBSD" "Alpine" "OpenBSD") RELEASE=("Debian" "Ubuntu" "CentOS" "CentOS" "Fedora" "Arch" "FreeBSD" "Alpine" "OpenBSD" "OpenCloudOS")
PACKAGE_UPDATE=("apt-get update" "apt-get update" "yum -y update" "yum -y update" "yum -y update" "pacman -Sy" "pkg update" "apk update" "pkg_add -u") PACKAGE_UPDATE=("apt-get update" "apt-get update" "yum -y update" "yum -y update" "yum -y update" "pacman -Sy" "pkg update" "apk update" "pkg_add -qu" "yum -y update")
PACKAGE_INSTALL=("apt-get -y install" "apt-get -y install" "yum -y install" "yum -y install" "yum -y install" "pacman -Sy --noconfirm --needed" "pkg install -y" "apk add") PACKAGE_INSTALL=("apt-get -y install" "apt-get -y install" "yum -y install" "yum -y install" "yum -y install" "pacman -Sy --noconfirm --needed" "pkg install -y" "apk add --no-cache" "pkg_add -I" "yum -y install")
PACKAGE_REMOVE=("apt-get -y remove" "apt-get -y remove" "yum -y remove" "yum -y remove" "yum -y remove" "pacman -Rsc --noconfirm" "pkg delete" "apk del") PACKAGE_REMOVE=("apt-get -y remove" "apt-get -y remove" "yum -y remove" "yum -y remove" "yum -y remove" "pacman -Rsc --noconfirm" "pkg delete" "apk del" "pkg_delete -I" "yum -y remove")
PACKAGE_UNINSTALL=("apt-get -y autoremove" "apt-get -y autoremove" "yum -y autoremove" "yum -y autoremove" "yum -y autoremove" "" "pkg autoremove" "apk autoremove") PACKAGE_UNINSTALL=("apt-get -y autoremove" "apt-get -y autoremove" "yum -y autoremove" "yum -y autoremove" "yum -y autoremove" "pacman -Rns --noconfirm" "pkg autoremove" "apk autoremove" "pkg_delete -a" "yum -y autoremove")
# 检查系统信息 # 检查系统信息
if [ -f /etc/alpine-release ]; then if [ -f /etc/opencloudos-release ]; then
SYS="alpine" SYS="opencloudos"
elif [ -s /etc/os-release ]; then elif [ -s /etc/os-release ]; then
SYS="$(grep -i pretty_name /etc/os-release | cut -d \" -f2)" SYS="$(grep -i pretty_name /etc/os-release | cut -d \" -f2)"
elif [ -x "$(type -p hostnamectl)" ]; then elif [ -x "$(type -p hostnamectl)" ]; then
@@ -307,6 +394,7 @@ env_check() {
SYS="$(uname -s)" SYS="$(uname -s)"
fi fi
[[ -n $SYS ]] || exit 1 [[ -n $SYS ]] || exit 1
# 匹配操作系统 # 匹配操作系统
for ((int = 0; int < ${#REGEX[@]}; int++)); do for ((int = 0; int < ${#REGEX[@]}; int++)); do
if [[ $(echo "$SYS" | tr '[:upper:]' '[:lower:]') =~ ${REGEX[int]} ]]; then if [[ $(echo "$SYS" | tr '[:upper:]' '[:lower:]') =~ ${REGEX[int]} ]]; then
@@ -314,68 +402,57 @@ env_check() {
[[ -n $SYSTEM ]] && break [[ -n $SYSTEM ]] && break
fi fi
done done
# 检查是否成功匹配 # 检查是否成功匹配
[[ -n $SYSTEM ]] || exit 1 [[ -n $SYSTEM ]] || exit 1
# 根据 SYSTEM 设置相应的包管理命令 # 根据 SYSTEM 设置相应的包管理命令
UPDATE_CMD=${PACKAGE_UPDATE[int]} UPDATE_CMD=${PACKAGE_UPDATE[int]}
INSTALL_CMD=${PACKAGE_INSTALL[int]} INSTALL_CMD=${PACKAGE_INSTALL[int]}
REMOVE_CMD=${PACKAGE_REMOVE[int]} REMOVE_CMD=${PACKAGE_REMOVE[int]}
UNINSTALL_CMD=${PACKAGE_UNINSTALL[int]} UNINSTALL_CMD=${PACKAGE_UNINSTALL[int]}
echo "System: $SYSTEM" echo "System: $SYSTEM"
echo "Update command: $UPDATE_CMD" echo "Update command: $UPDATE_CMD"
echo "Install command: $INSTALL_CMD" echo "Install command: $INSTALL_CMD"
echo "Remove command: $REMOVE_CMD" echo "Remove command: $REMOVE_CMD"
echo "Uninstall command: $UNINSTALL_CMD" echo "Uninstall command: $UNINSTALL_CMD"
cdn_urls=("https://cdn0.spiritlhl.top/" "http://cdn3.spiritlhl.net/" "http://cdn1.spiritlhl.net/" "http://cdn2.spiritlhl.net/") cdn_urls=("https://cdn0.spiritlhl.top/" "http://cdn3.spiritlhl.net/" "http://cdn1.spiritlhl.net/" "http://cdn2.spiritlhl.net/")
check_cdn_file check_cdn_file
_green "Update system manager." _yellow "Warning: System update will be performed"
${PACKAGE_UPDATE[int]} 2>/dev/null _yellow "This operation may:"
if ! command -v sudo >/dev/null 2>&1; then _yellow "1. Take significant time to complete"
_green "Installing sudo" _yellow "2. Cause temporary network interruptions"
${PACKAGE_INSTALL[int]} sudo _yellow "3. Impact system stability"
fi _yellow "4. Affect future system startup"
if ! command -v wget >/dev/null 2>&1; then if [ "$noninteractive" != "true" ]; then
_green "Installing wget" reading "Do you want to proceed with system update? (y/N): " update_confirm
${PACKAGE_INSTALL[int]} wget if [[ ! $update_confirm =~ ^[Yy]$ ]]; then
fi _yellow "Skipping system update"
if ! command -v tar >/dev/null 2>&1; then _yellow "Note: Some package installations may fail"
_green "Installing tar" else
${PACKAGE_INSTALL[int]} tar _green "Updating system package manager..."
fi if ! ${PACKAGE_UPDATE[int]} 2>/dev/null; then
if ! command -v unzip >/dev/null 2>&1; then _red "System update failed!"
_green "Installing unzip"
${PACKAGE_INSTALL[int]} unzip
fi
if ! command -v systemd-detect-virt >/dev/null 2>&1; then
_green "Installing systemd-detect-virt"
${PACKAGE_INSTALL[int]} systemd-detect-virt
if [ $? -ne 0 ]; then
if ! command -v dmidecode >/dev/null 2>&1; then
_green "Installing dmidecode"
${PACKAGE_INSTALL[int]} dmidecode
fi fi
fi fi
fi fi
if ! command -v dd >/dev/null 2>&1; then
_green "Installing dd" # 安装必要的命令
${PACKAGE_INSTALL[int]} coreutils for cmd in sudo wget tar unzip iproute2 systemd-detect-virt dd fio; do
if [ $? -ne 0 ]; then if ! command -v "$cmd" >/dev/null 2>&1; then
${PACKAGE_INSTALL[int]} man _green "Installing $cmd"
${PACKAGE_INSTALL[int]} "$cmd"
fi fi
fi done
if ! command -v fio >/dev/null 2>&1; then
_green "Installing fio" if ! command -v sysbench >/dev/null 2>&1; then
${PACKAGE_INSTALL[int]} fio
fi
if ! command -v sysbench >/dev/null 2>&1 && [ "${REGEX[int]}" != "freebsd" ]; then
_green "Installing sysbench" _green "Installing sysbench"
${PACKAGE_INSTALL[int]} sysbench ${PACKAGE_INSTALL[int]} sysbench
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Unable to download sysbench through the system's package manager, speak to try compiling and installing it..." echo "Unable to download sysbench through the system's package manager, trying to compile and install it..."
if ! wget -O /tmp/sysbench.zip "${cdn_success_url}https://github.com/akopytov/sysbench/archive/1.0.20.zip"; then wget -O /tmp/sysbench.zip "${cdn_success_url}https://github.com/akopytov/sysbench/archive/1.0.20.zip" || curl -Lk -o /tmp/sysbench.zip "${cdn_success_url}https://github.com/akopytov/sysbench/archive/1.0.20.zip"
echo "wget failed, trying with curl"
curl -Lk -o /tmp/sysbench.zip "${cdn_success_url}https://github.com/akopytov/sysbench/archive/1.0.20.zip"
fi
if [ ! -f /tmp/sysbench.zip ]; then if [ ! -f /tmp/sysbench.zip ]; then
wget -q -O /tmp/sysbench.zip "https://hub.fgit.cf/akopytov/sysbench/archive/1.0.20.zip" wget -q -O /tmp/sysbench.zip "https://hub.fgit.cf/akopytov/sysbench/archive/1.0.20.zip"
fi fi
@@ -384,11 +461,12 @@ env_check() {
Check_SysBench Check_SysBench
fi fi
fi fi
if ! command -v geekbench >/dev/null 2>&1; then if ! command -v geekbench >/dev/null 2>&1; then
_green "Installing geekbench" _green "Installing geekbench"
curl -L "${cdn_success_url}https://raw.githubusercontent.com/oneclickvirt/cputest/main/dgb.sh" -o dgb.sh && chmod +x dgb.sh curl -L "${cdn_success_url}https://raw.githubusercontent.com/oneclickvirt/cputest/main/dgb.sh" -o dgb.sh && chmod +x dgb.sh
bash dgb.sh -v gb5 bash dgb.sh -v gb5
_blue "If you not want to use geekbench5, you can use" _blue "If you do not want to use geekbench5, you can use"
echo "bash dgb.sh -v gb6" echo "bash dgb.sh -v gb6"
echo "bash dgb.sh -v gb4" echo "bash dgb.sh -v gb4"
_blue "to change version, or use" _blue "to change version, or use"
@@ -396,26 +474,28 @@ env_check() {
_blue "to uninstall geekbench" _blue "to uninstall geekbench"
rm -rf dgb.sh rm -rf dgb.sh
fi fi
if ! command -v speedtest >/dev/null 2>&1; then if ! command -v speedtest >/dev/null 2>&1; then
_green "Installing geekbench" _green "Installing speedtest"
curl -L "${cdn_success_url}https://raw.githubusercontent.com/oneclickvirt/speedtest/main/dspt.sh" -o dspt.sh && chmod +x dspt.sh curl -L "${cdn_success_url}https://raw.githubusercontent.com/oneclickvirt/speedtest/main/dspt.sh" -o dspt.sh && chmod +x dspt.sh
bash dspt.sh bash dspt.sh
rm -rf dspt.sh rm -rf dspt.sh
rm -rf speedtest.tar.gz rm -rf speedtest.tar.gz
_blue "if you want to use golang origin speedtest, you can use" _blue "if you want to use golang original speedtest, you can use"
echo "rm -rf /usr/bin/speedtest" echo "rm -rf /usr/bin/speedtest"
echo "rm -rf /usr/bin/speedtest-go" echo "rm -rf /usr/bin/speedtest-go"
_blue "to uninstall speedtest and speedtest-go" _blue "to uninstall speedtest and speedtest-go"
fi fi
if ! command -v ping >/dev/null 2>&1; then if ! command -v ping >/dev/null 2>&1; then
_green "Installing ping" _green "Installing ping"
${PACKAGE_INSTALL[int]} iputils-ping >/dev/null 2>&1 ${PACKAGE_INSTALL[int]} iputils-ping >/dev/null 2>&1
${PACKAGE_INSTALL[int]} ping >/dev/null 2>&1 ${PACKAGE_INSTALL[int]} ping >/dev/null 2>&1
fi fi
if [ "$(uname -s)" = "Darwin" ]; then if [ "$(uname -s)" = "Darwin" ]; then
echo "Detected MacOS. Installing sysbench and fio..." echo "Detected MacOS. Installing sysbench iproute2mac fio..."
brew install --force sysbench fio dd brew install --force sysbench iproute2mac fio
# 有问题需要修复root环境不能brewbrew安装完毕后可能路径不在环境变量中
else else
if ! grep -q "^net.ipv4.ping_group_range = 0 2147483647$" /etc/sysctl.conf; then if ! grep -q "^net.ipv4.ping_group_range = 0 2147483647$" /etc/sysctl.conf; then
echo "net.ipv4.ping_group_range = 0 2147483647" >> /etc/sysctl.conf echo "net.ipv4.ping_group_range = 0 2147483647" >> /etc/sysctl.conf
@@ -427,46 +507,68 @@ env_check() {
} }
uninstall_goecs() { uninstall_goecs() {
rm -rf /root/goecs rm -rf /root/goecs
rm -rf /usr/bin/goecs rm -rf /usr/bin/goecs
_green "The command (goecs) has been uninstalled." _green "The command (goecs) has been uninstalled."
} }
show_help() { show_help() {
cat <<"EOF" cat <<"EOF"
可用命令: 可用命令:
./goecs.sh env 检查并安装的包: ./goecs.sh env 检查并安装依赖包
sudo (几乎所有类 Unix 系统都有。) 警告: 此命令会执行系统更新(可选择),可能:
tar (几乎所有类 Unix 系统都有。) 1. 耗时较长
unzip (几乎所有类 Unix 系统都有。) 2. 导致网络短暂中断
dd (几乎所有类 Unix 系统都有。) 3. 影响系统稳定性
fio (几乎所有类 Unix 系统可以通过系统的包管理器安装。) 4. 影响后续系统启动
sysbench (几乎所有类 Unix 系统可以通过系统的包管理器安装。) 对于内存小于1GB的系统还可能导致:
geekbench (geekbench5) (仅支持 IPV4 环境,且内存大于 1GB 并需要持续联网,仅支持 amd64 和 arm64 架构。) 1. 系统卡死
speedtest (使用官方提供的二进制文件以获得更准确的测试结果。) 2. SSH连接中断
ping (使用官方提供的二进制文件以获得更准确的测试结果。) 3. 关键服务失败
systemd-detect-virt 或 dmidecode (几乎所有类 Unix 系统都有,安装以获得更准确的测试结果。) 推荐:
事实上sysbench/geekbench 是上述依赖项中唯一必须安装的,没有它们无法测试 CPU 分数。 环境依赖安装过程中挂起执行
必需组件:
sysbench/geekbench (CPU性能测试必需)
可选组件:
sudo, tar, unzip, dd, fio
speedtest (网络测试)
ping (网络连通性测试)
systemd-detect-virt/dmidecode (系统信息检测)
./goecs.sh install 安装 goecs 命令 ./goecs.sh install 安装 goecs 命令
./goecs.sh upgrade 升级 goecs 命令 ./goecs.sh upgrade 升级 goecs 命令
./goecs.sh uninstall 卸载 goecs 命令 ./goecs.sh uninstall 卸载 goecs 命令
./goecs.sh help 显示此消息 ./goecs.sh help 显示此消息
[English version follows...]
Available commands: Available commands:
./goecs.sh env Check and Install package: ./goecs.sh env Check and Install dependencies
sudo (Almost all unix-like systems have it.) Warning: This command performs system update(optional), which may:
tar (Almost all unix-like systems have it.) 1. Take considerable time
unzip (Almost all unix-like systems have it.) 2. Cause temporary network interruptions
dd (Almost all unix-like systems have it.) 3. Impact system stability
fio (Almost all unix-like systems can be installed through the system's package manager.) 4. Affect subsequent system startups
sysbench (Almost all unix-like systems can be installed through the system's package manager.) For systems with less than 1GB RAM, additional risks:
geekbench (geekbench5)(Only support IPV4 environment, and memory greater than 1GB network detection, only support amd64 and arm64 architecture.) 1. System freeze
speedtest (Use the officially provided binaries for more accurate test results.) 2. SSH connection loss
ping (Use the officially provided binaries for more accurate test results.) 3. Critical service failures
systemd-detect-virt OR dmidecode (Almost all unix-like systems have it, for more accurate test results.) Recommended:
In fact, sysbench/geekbench is the only one of the above dependencies that must be installed, without which the CPU score cannot be tested. Hanging execution during environment dependency installation
Required components:
sysbench/geekbench (Required for CPU testing)
Optional components:
sudo, tar, unzip, dd, fio
speedtest (Network testing)
ping (Network connectivity)
systemd-detect-virt/dmidecode (System info detection)
./goecs.sh install Install goecs command ./goecs.sh install Install goecs command
./goecs.sh upgrade Upgrade goecs command ./goecs.sh upgrade Upgrade goecs command
./goecs.sh uninstall Uninstall goecs command ./goecs.sh uninstall Uninstall goecs command
@@ -493,3 +595,4 @@ case "$1" in
show_help show_help
;; ;;
esac esac

View File

@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"github.com/imroc/req/v3" "github.com/imroc/req/v3"
"github.com/oneclickvirt/UnlockTests/uts" "github.com/oneclickvirt/UnlockTests/uts"
"github.com/oneclickvirt/basics/ipv6"
"github.com/oneclickvirt/basics/system" "github.com/oneclickvirt/basics/system"
. "github.com/oneclickvirt/defaultset" . "github.com/oneclickvirt/defaultset"
"github.com/oneclickvirt/security/network" "github.com/oneclickvirt/security/network"
@@ -128,12 +129,12 @@ func CheckChina(enableLogger bool) bool {
return selectChina return selectChina
} }
// SecurityCheck 执行安全检查 // BasicsAndSecurityCheck 执行安全检查
func SecurityCheck(language, nt3CheckType string, securtyCheckStatus bool) (string, string, string) { func BasicsAndSecurityCheck(language, nt3CheckType string, securtyCheckStatus bool) (string, string, string) {
var wgt sync.WaitGroup var wgt sync.WaitGroup
var ipInfo, securityInfo, systemInfo string var ipInfo, securityInfo, systemInfo string
var err error var err error
wgt.Add(2) wgt.Add(1)
go func() { go func() {
defer wgt.Done() defer wgt.Done()
ipInfo, securityInfo, err = network.NetworkCheck("both", securtyCheckStatus, language) ipInfo, securityInfo, err = network.NetworkCheck("both", securtyCheckStatus, language)
@@ -141,12 +142,17 @@ func SecurityCheck(language, nt3CheckType string, securtyCheckStatus bool) (stri
fmt.Println(err.Error()) fmt.Println(err.Error())
} }
}() }()
wgt.Add(1)
go func() { go func() {
defer wgt.Done() defer wgt.Done()
systemInfo = system.CheckSystemInfo(language) systemInfo = system.CheckSystemInfo(language)
}() }()
wgt.Wait() wgt.Wait()
ipv6Info, errv6 := ipv6.GetIPv6Mask(language)
basicInfo := systemInfo + ipInfo basicInfo := systemInfo + ipInfo
if errv6 == nil && ipv6Info != "" {
basicInfo += ipv6Info
}
if strings.Contains(ipInfo, "IPV4") && strings.Contains(ipInfo, "IPV6") { if strings.Contains(ipInfo, "IPV4") && strings.Contains(ipInfo, "IPV6") {
uts.IPV4 = true uts.IPV4 = true
uts.IPV6 = true uts.IPV6 = true
@@ -242,18 +248,29 @@ func UploadText(absPath string) (string, string, error) {
primaryURL := "http://hpaste.spiritlhl.net/api/upload" primaryURL := "http://hpaste.spiritlhl.net/api/upload"
backupURL := "https://paste.spiritlhl.net/api/upload" backupURL := "https://paste.spiritlhl.net/api/upload"
token := network.SecurityUploadToken token := network.SecurityUploadToken
client := req.DefaultClient() client := req.C().SetTimeout(6 * time.Second)
client.SetTimeout(6 * time.Second)
client.R(). client.R().
SetRetryCount(2). SetRetryCount(2).
SetRetryBackoffInterval(1*time.Second, 5*time.Second). SetRetryBackoffInterval(1*time.Second, 5*time.Second).
SetRetryFixedInterval(2 * time.Second) SetRetryFixedInterval(2 * time.Second)
file, err := os.Open(absPath) file, err := os.Open(absPath)
if err != nil { if err != nil {
return "", "", err return "", "", fmt.Errorf("failed to open file: %w", err)
} }
defer file.Close() defer file.Close()
upload := func(url string) (string, string, error) { upload := func(url string) (string, string, error) {
// 重新打开文件,以确保我们总是从文件开头读取
file, err := os.Open(absPath)
if err != nil {
return "", "", fmt.Errorf("failed to re-open file for %s: %w", url, err)
}
defer file.Close()
// 读取文件内容
content, err := io.ReadAll(file)
if err != nil {
return "", "", fmt.Errorf("failed to read file content for %s: %w", url, err)
}
resp, err := client.R(). resp, err := client.R().
SetHeader("Authorization", token). SetHeader("Authorization", token).
SetHeader("Format", "RANDOM"). SetHeader("Format", "RANDOM").
@@ -261,16 +278,17 @@ func UploadText(absPath string) (string, string, error) {
SetHeader("UploadText", "true"). SetHeader("UploadText", "true").
SetHeader("Content-Type", "multipart/form-data"). SetHeader("Content-Type", "multipart/form-data").
SetHeader("No-JSON", "true"). SetHeader("No-JSON", "true").
SetFileReader("file", "goecs.txt", file). SetFileBytes("file", "goecs.txt", content).
Post(url) Post(url)
if err != nil { if err != nil {
return "", "", err return "", "", fmt.Errorf("failed to make request to %s: %w", url, err)
} }
if resp.StatusCode >= 200 && resp.StatusCode <= 299 { if resp.StatusCode >= 200 && resp.StatusCode <= 299 {
return strings.ReplaceAll(resp.String(), "https://paste.spiritlhl.net/", "http://hpaste.spiritlhl.net/"), http_url := strings.ReplaceAll(resp.String(), "https://paste.spiritlhl.net/", "http://hpaste.spiritlhl.net/")
strings.ReplaceAll(resp.String(), "http://hpaste.spiritlhl.net/", "https://paste.spiritlhl.net/"), nil https_url := strings.ReplaceAll(resp.String(), "http://hpaste.spiritlhl.net/", "https://paste.spiritlhl.net/")
return http_url, https_url, nil
} else { } else {
return "", "", fmt.Errorf("upload failed with status code: %d", resp.StatusCode) return "", "", fmt.Errorf("upload failed for %s with status code: %d", url, resp.StatusCode)
} }
} }
http_url, https_url, err := upload(primaryURL) http_url, https_url, err := upload(primaryURL)
@@ -279,7 +297,7 @@ func UploadText(absPath string) (string, string, error) {
} }
http_url, https_url, err = upload(backupURL) http_url, https_url, err = upload(backupURL)
if err != nil { if err != nil {
return "", "", err return "", "", fmt.Errorf("failed to upload to both primary and backup URLs: %w", err)
} }
return http_url, https_url, nil return http_url, https_url, nil
} }
@@ -328,6 +346,6 @@ func ProcessAndUpload(output string, filePath string, enableUplaod bool) {
fmt.Println(err3.Error()) fmt.Println(err3.Error())
return return
} }
fmt.Printf("Upload successful!\nHttp URL:%s\nHttps URL:%s\n", http_url, https_url) fmt.Printf("Upload successful!\nHttp URL: %s\nHttps URL: %s\n", http_url, https_url)
} }
} }