Compare commits

...

26 Commits

Author SHA1 Message Date
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
spiritsoul
a85a06b440 v0.0.76
调整输出文本
2024-10-04 23:53:57 +08:00
spiritsoul
681da08f01 v0.0.75
修复终止命令在选项选择时不可用的问题
展示分享链接时同时展示http和https协议的链接
2024-10-04 23:30:06 +08:00
spiritsoul
bdd00d46f8 v0.0.74 2024-08-25 18:01:24 +08:00
spiritsoul
1f213bb788 update 2024-08-22 20:33:39 +08:00
spiritsoul
1dec7c323b update 2024-08-20 17:22:12 +08:00
spiritsoul
391cc351c4 update 2024-08-20 17:05:54 +08:00
spiritsoul
282a947156 update 2024-08-15 21:47:56 +08:00
spiritsoul
73916d324a v0.0.72 2024-08-14 20:34:24 +08:00
spiritsoul
6cce2a7e8e Add https://hub.docker.com/r/spiritlhl/goecs 2024-08-14 18:01:29 +08:00
spiritsoul
2a653930a8 update 2024-08-14 17:54:20 +08:00
spiritsoul
2295035706 v0.0.71 2024-08-14 17:32:21 +08:00
spiritsoul
3e8c7112a0 Merge branch 'master' of https://github.com/oneclickvirt/ecs 2024-08-14 17:09:25 +08:00
spiritlhl
a827583b76 Update build_docker.yaml 2024-08-14 15:37:48 +08:00
9 changed files with 297 additions and 225 deletions

View File

@@ -29,7 +29,7 @@ jobs:
with: with:
context: . context: .
file: ./Dockerfile file: ./Dockerfile
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/s390x,linux/riscv64 platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/riscv64
# linux/mips,linux/mipsle 暂不支持 alpine # linux/mips,linux/mipsle 暂不支持 alpine, linux/s390x 编译卡死
push: true push: true
tags: ${{ secrets.DOCKER_USERNAME }}/goecs:latest tags: ${{ secrets.DOCKER_USERNAME }}/goecs:latest

View File

@@ -104,6 +104,7 @@ shell脚本的说明
tar (几乎所有类 Unix 系统都有。) tar (几乎所有类 Unix 系统都有。)
unzip (几乎所有类 Unix 系统都有。) unzip (几乎所有类 Unix 系统都有。)
dd (几乎所有类 Unix 系统都有。) dd (几乎所有类 Unix 系统都有。)
iproute2 (几乎所有类 Unix 系统可以通过系统的包管理器安装。)
fio (几乎所有类 Unix 系统可以通过系统的包管理器安装。) fio (几乎所有类 Unix 系统可以通过系统的包管理器安装。)
sysbench (几乎所有类 Unix 系统可以通过系统的包管理器安装。) sysbench (几乎所有类 Unix 系统可以通过系统的包管理器安装。)
geekbench (geekbench5) (仅支持 IPV4 环境,且内存大于 1GB 并需要持续联网,仅支持 amd64 和 arm64 架构。) geekbench (geekbench5) (仅支持 IPV4 环境,且内存大于 1GB 并需要持续联网,仅支持 amd64 和 arm64 架构。)
@@ -163,7 +164,7 @@ Usage: goecs [options]
-memory -memory
Enable/Disable memory test (default true) Enable/Disable memory test (default true)
-memorym string -memorym string
Set memory test method (supported: sysbench, dd, winsat) (default "dd") Set memory test method (supported: sysbench, dd, winsat) (default "sysbench")
-menu -menu
Enable/Disable menu mode, disable example: -menu=false (default true) Enable/Disable menu mode, disable example: -menu=false (default true)
-nt3 -nt3
@@ -199,6 +200,8 @@ windows测试无需进行环境安装
## 在Docker中使用的说明 ## 在Docker中使用的说明
地址https://hub.docker.com/r/spiritlhl/goecs
请确保执行下述命令前本机已安装Docker 请确保执行下述命令前本机已安装Docker
特权模式+host网络 特权模式+host网络

View File

@@ -93,6 +93,7 @@ Available commands:
unzip (Almost all unix-like systems have it.) unzip (Almost all unix-like systems have it.)
dd (Almost all unix-like systems have it.) dd (Almost all unix-like systems have it.)
fio (Almost all unix-like systems can be installed through the system's package manager.) fio (Almost all unix-like systems can be installed through the system's package manager.)
iproute2 (Almost all unix-like systems can be installed through the system's package manager.)
sysbench (Almost all unix-like systems can be installed through the system's package manager.) sysbench (Almost all unix-like systems can be installed through the system's package manager.)
geekbench (geekbench5)(Only support IPV4 environment, and memory greater than 1GB network detection, only support amd64 and arm64 architecture.) geekbench (geekbench5)(Only support IPV4 environment, and memory greater than 1GB network detection, only support amd64 and arm64 architecture.)
speedtest (Use the officially provided binaries for more accurate test results.) speedtest (Use the officially provided binaries for more accurate test results.)
@@ -151,7 +152,7 @@ Usage: goecs [options]
-memory -memory
Enable/Disable memory test (default true) Enable/Disable memory test (default true)
-memorym string -memorym string
Set memory test method (supported: sysbench, dd, winsat) (default "dd") Set memory test method (supported: sysbench, dd, winsat) (default "sysbench")
-menu -menu
Enable/Disable menu mode, disable example: -menu=false (default true) Enable/Disable menu mode, disable example: -menu=false (default true)
-nt3 -nt3
@@ -187,6 +188,8 @@ No environment installation is required for Windows testing.
## Instructions for Use in Docker ## Instructions for Use in Docker
Link: https://hub.docker.com/r/spiritlhl/goecs
Please make sure that Docker is installed on your machine before executing the following commands Please make sure that Docker is installed on your machine before executing the following commands
Privileged Mode + host network Privileged Mode + host network
@@ -195,7 +198,7 @@ Privileged Mode + host network
docker run --rm --privileged --network host spiritlhl/goecs:latest -menu=false -l en docker run --rm --privileged --network host spiritlhl/goecs:latest -menu=false -l en
``` ```
Unprivileged mode + non-host network -menu=false -l en Unprivileged mode + non-host network
```shell ```shell
docker run --rm spiritlhl/goecs:latest docker run --rm spiritlhl/goecs:latest

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)

10
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.15-20240814090726 github.com/oneclickvirt/UnlockTests v0.0.17-20241020033546
github.com/oneclickvirt/backtrace v0.0.4-20240702140722 github.com/oneclickvirt/backtrace v0.0.4-20240702140722
github.com/oneclickvirt/basics v0.0.7-20240801050316 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-20240814081347 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 (

20
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.15-20240814090726 h1:dwxFOF8AvnIIpMd7dmAOX0yqY6TZDAsRwpDM0SGGCGA= github.com/oneclickvirt/UnlockTests v0.0.17-20241020033546 h1:KXRNdYPnZ10vi0+6WwrNK5E8GHvGRjaVAv5z7XEfb9Q=
github.com/oneclickvirt/UnlockTests v0.0.15-20240814090726/go.mod h1:UELwZDDiddSxe38boYOPl1FlrL0ptEZYSQwdE3MYvUM= github.com/oneclickvirt/UnlockTests v0.0.17-20241020033546/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-20240801050316 h1:LX0qJK5ZVL2WPQ2g6Yn15jOOyCeZeCXjyjJZe0gzJ48= github.com/oneclickvirt/basics v0.0.8-20241108124433 h1:eKZcoNoa9uLWmfisk+qN/QOvSGT4ajCmZdZfIAcHG+o=
github.com/oneclickvirt/basics v0.0.7-20240801050316/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=
@@ -118,18 +118,18 @@ github.com/oneclickvirt/disktest v0.0.4-20240809053456 h1:g6fKzvImIV8YQZKKEJ2Fdv
github.com/oneclickvirt/disktest v0.0.4-20240809053456/go.mod h1:wIZy8G6Mbcy8Op8tc0HmJNpbJQQ5A15fvnUqMJXIdO0= github.com/oneclickvirt/disktest v0.0.4-20240809053456/go.mod h1:wIZy8G6Mbcy8Op8tc0HmJNpbJQQ5A15fvnUqMJXIdO0=
github.com/oneclickvirt/gostun v0.0.3-20240702054621 h1:IE89eEYV9TJbF94SakQDAxTLIaqX+Tb6ZhJ/CCIP+90= github.com/oneclickvirt/gostun v0.0.3-20240702054621 h1:IE89eEYV9TJbF94SakQDAxTLIaqX+Tb6ZhJ/CCIP+90=
github.com/oneclickvirt/gostun v0.0.3-20240702054621/go.mod h1:f7DPEXAxbmwXSW33dbxtb0/KzqvOBWhTs2Or5xBerQA= github.com/oneclickvirt/gostun v0.0.3-20240702054621/go.mod h1:f7DPEXAxbmwXSW33dbxtb0/KzqvOBWhTs2Or5xBerQA=
github.com/oneclickvirt/memorytest v0.0.4-20240814081347 h1:xOlCh8IpcI0YtP0IU/+IID8ri/Jz6mQ3gGg6zIQ0D6g= github.com/oneclickvirt/memorytest v0.0.4-20240820095126 h1:Il3rvWkrZy/6B2iO3HRe9039/qRllA4CzcZ/dI8aG2A=
github.com/oneclickvirt/memorytest v0.0.4-20240814081347/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=

285
goecs.go
View File

@@ -2,6 +2,7 @@ package main
import ( import (
"bufio" "bufio"
"context"
"flag" "flag"
"fmt" "fmt"
"github.com/oneclickvirt/CommonMediaTests/commediatests" "github.com/oneclickvirt/CommonMediaTests/commediatests"
@@ -38,7 +39,7 @@ import (
) )
var ( var (
ecsVersion = "v0.0.70" ecsVersion = "v0.0.84"
menuMode bool menuMode bool
onlyChinaTest bool onlyChinaTest bool
input, choice string input, choice string
@@ -60,8 +61,67 @@ 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 {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(sigChan)
inputChan := make(chan string, 1)
go func() {
select {
case <-sigChan:
fmt.Println("\n程序在选择过程中被用户中断")
os.Exit(0)
case <-ctx.Done():
return
}
}()
for {
go func() {
var input string
fmt.Print("请输入选项 / Please enter your choice: ")
fmt.Scanln(&input)
input = strings.TrimSpace(input)
input = strings.TrimRight(input, "\n")
select {
case inputChan <- input:
case <-ctx.Done():
return
}
}()
select {
case input := <-inputChan:
re := regexp.MustCompile(`^\d+$`) // 正则表达式匹配纯数字
if re.MatchString(input) {
inChoice := input
switch inChoice {
case "1", "2", "3", "4", "5", "6", "7", "8", "9", "10":
return inChoice
default:
if language == "zh" {
fmt.Println("无效的选项")
} else {
fmt.Println("Invalid choice")
}
}
} else {
if language == "zh" {
fmt.Println("输入错误,请输入一个纯数字")
} else {
fmt.Println("Invalid input, please enter a number")
}
}
case <-ctx.Done():
return ""
}
}
}
func main() { func main() {
goecsFlag.BoolVar(&help, "h", false, "Show help information") goecsFlag.BoolVar(&help, "h", false, "Show help information")
goecsFlag.BoolVar(&showVersion, "v", false, "Display version information") goecsFlag.BoolVar(&showVersion, "v", false, "Display version information")
@@ -80,7 +140,7 @@ func main() {
goecsFlag.BoolVar(&speedTestStatus, "speed", true, "Enable/Disable speed test") goecsFlag.BoolVar(&speedTestStatus, "speed", true, "Enable/Disable speed test")
goecsFlag.StringVar(&cpuTestMethod, "cpum", "sysbench", "Set CPU test method (supported: sysbench, geekbench, winsat)") goecsFlag.StringVar(&cpuTestMethod, "cpum", "sysbench", "Set CPU test method (supported: sysbench, geekbench, winsat)")
goecsFlag.StringVar(&cpuTestThreadMode, "cput", "multi", "Set CPU test thread mode (supported: single, multi)") goecsFlag.StringVar(&cpuTestThreadMode, "cput", "multi", "Set CPU test thread mode (supported: single, multi)")
goecsFlag.StringVar(&memoryTestMethod, "memorym", "dd", "Set memory test method (supported: sysbench, dd, winsat)") goecsFlag.StringVar(&memoryTestMethod, "memorym", "sysbench", "Set memory test method (supported: sysbench, dd, winsat)")
goecsFlag.StringVar(&diskTestMethod, "diskm", "fio", "Set disk test method (supported: fio, dd, winsat)") goecsFlag.StringVar(&diskTestMethod, "diskm", "fio", "Set disk test method (supported: fio, dd, winsat)")
goecsFlag.StringVar(&diskTestPath, "diskp", "", "Set disk test path, e.g., -diskp /root") goecsFlag.StringVar(&diskTestPath, "diskp", "", "Set disk test path, e.g., -diskp /root")
goecsFlag.BoolVar(&diskMultiCheck, "diskmc", false, "Enable/Disable multiple disk checks, e.g., -diskmc=false") goecsFlag.BoolVar(&diskMultiCheck, "diskmc", false, "Enable/Disable multiple disk checks, e.g., -diskmc=false")
@@ -95,8 +155,6 @@ func main() {
goecsFlag.PrintDefaults() goecsFlag.PrintDefaults()
return return
} }
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
if showVersion { if showVersion {
fmt.Println(ecsVersion) fmt.Println(ecsVersion)
return return
@@ -149,103 +207,90 @@ func main() {
} }
Loop: Loop:
for { for {
fmt.Print("请输入选项 / Please enter your choice: ") choice = getMenuChoice(language)
fmt.Scanln(&input) switch choice {
input = strings.TrimSpace(input) case "1":
input = strings.TrimRight(input, "\n") basicStatus = true
re := regexp.MustCompile(`^\d+$`) // 正则表达式匹配纯数字 cpuTestStatus = true
if re.MatchString(input) { memoryTestStatus = true
choice = input diskTestStatus = true
switch choice { commTestStatus = true
case "1": utTestStatus = true
basicStatus = true securityTestStatus = true
cpuTestStatus = true emailTestStatus = true
memoryTestStatus = true backtraceStatus = true
diskTestStatus = true nt3Status = true
commTestStatus = true speedTestStatus = true
utTestStatus = true onlyChinaTest = utils.CheckChina(enableLogger)
securityTestStatus = true break Loop
emailTestStatus = true case "2":
backtraceStatus = true basicStatus = true
nt3Status = true cpuTestStatus = true
speedTestStatus = true memoryTestStatus = true
onlyChinaTest = utils.CheckChina(enableLogger) diskTestStatus = true
break Loop speedTestStatus = true
case "2": break Loop
basicStatus = true case "3":
cpuTestStatus = true basicStatus = true
memoryTestStatus = true cpuTestStatus = true
diskTestStatus = true memoryTestStatus = true
speedTestStatus = true diskTestStatus = true
break Loop utTestStatus = true
case "3": nt3Status = true
basicStatus = true speedTestStatus = true
cpuTestStatus = true break Loop
memoryTestStatus = true case "4":
diskTestStatus = true basicStatus = true
utTestStatus = true cpuTestStatus = true
nt3Status = true memoryTestStatus = true
speedTestStatus = true diskTestStatus = true
break Loop backtraceStatus = true
case "4": nt3Status = true
basicStatus = true speedTestStatus = true
cpuTestStatus = true break Loop
memoryTestStatus = true case "5":
diskTestStatus = true basicStatus = true
backtraceStatus = true cpuTestStatus = true
nt3Status = true memoryTestStatus = true
speedTestStatus = true diskTestStatus = true
break Loop commTestStatus = true
case "5": utTestStatus = true
basicStatus = true speedTestStatus = true
cpuTestStatus = true break Loop
memoryTestStatus = true case "6":
diskTestStatus = true securityTestStatus = true
commTestStatus = true speedTestStatus = true
utTestStatus = true backtraceStatus = true
speedTestStatus = true nt3Status = true
break Loop break Loop
case "6": case "7":
securityTestStatus = true commTestStatus = true
speedTestStatus = true utTestStatus = true
backtraceStatus = true enabelUpload = false
nt3Status = true break Loop
break Loop case "8":
case "7": basicStatus = true
commTestStatus = true cpuTestStatus = true
utTestStatus = true memoryTestStatus = true
enabelUpload = false diskTestStatus = true
break Loop securityTestStatus = false
case "8": autoChangeDiskTestMethod = false
basicStatus = true break Loop
cpuTestStatus = true case "9":
memoryTestStatus = true securityTestStatus = true
diskTestStatus = true emailTestStatus = true
securityTestStatus = false break Loop
autoChangeDiskTestMethod = false case "10":
break Loop backtraceStatus = true
case "9": nt3Status = true
securityTestStatus = true pingTestStatus = true
emailTestStatus = true enabelUpload = false
break Loop break Loop
case "10": default:
backtraceStatus = true
nt3Status = true
pingTestStatus = true
enabelUpload = false
break Loop
default:
if language == "zh" {
fmt.Println("无效的选项")
} else {
fmt.Println("Invalid choice")
}
}
} else {
if language == "zh" { if language == "zh" {
fmt.Println("输入错误,请输入一个纯数字") fmt.Println("无效的选项")
} else { } else {
fmt.Println("Invalid input, please enter a number") fmt.Println("Invalid choice")
} }
} }
} }
@@ -263,24 +308,29 @@ func main() {
basicInfo, securityInfo, emailInfo, mediaInfo, ptInfo string basicInfo, securityInfo, emailInfo, mediaInfo, ptInfo string
output, tempOutput string output, tempOutput string
) )
// 设置主程序的信号处理
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
// 启动一个goroutine来等待信号内置计时器 // 启动一个goroutine来等待信号内置计时器
go func() { go func() {
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":
@@ -290,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 {
@@ -400,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)
@@ -429,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 {
@@ -523,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()

132
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.10.06
# 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
@@ -145,7 +145,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 +158,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 +188,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 +206,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,14 +213,22 @@ InstallSysbench() {
else else
Var_OSRelease="unknown" # 未知系统分支 Var_OSRelease="unknown" # 未知系统分支
fi fi
case "$Var_OSRelease" in 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 ;; ubuntu | debian | astra)
centos | rhel | almalinux | redhat) (yum -y install epel-release && yum -y install sysbench) || (dnf install epel-release -y && dnf install sysbench -y) ;; ! apt-get install -y sysbench && apt-get --fix-broken install -y && apt-get install --no-install-recommends -y sysbench ;;
fedora) dnf -y install sysbench ;; centos | rhel | almalinux | redhat | opencloudos)
arch) pacman -S --needed --noconfirm sysbench && pacman -S --needed --noconfirm libaio && ldconfig ;; (yum -y install epel-release && yum -y install sysbench) || (dnf install epel-release -y && dnf install sysbench -y) ;;
freebsd) pkg install -y sysbench ;; fedora)
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" ;; dnf -y install sysbench ;;
*) _red "Sysbench Install Error: Unknown OS release: $os_release" ;; arch)
pacman -S --needed --noconfirm sysbench && pacman -S --needed --noconfirm libaio && ldconfig ;;
freebsd)
pkg install -y sysbench ;;
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" ;;
*)
_red "Sysbench Install Error: Unknown OS release: $Var_OSRelease" ;;
esac esac
} }
@@ -248,6 +258,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 +295,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" "yum -y update" "pacman -Sy" "pkg update" "apk update" "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" "yum -y install" "pacman -Sy --noconfirm --needed" "pkg install -y" "apk add" "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" "yum -y remove" "pacman -Rsc --noconfirm" "pkg delete" "apk del" "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" "yum -y autoremove" "pacman -Rns --noconfirm" "pkg autoremove" "apk autoremove" "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 +320,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,65 +328,41 @@ 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." _green "Update system manager."
${PACKAGE_UPDATE[int]} 2>/dev/null ${PACKAGE_UPDATE[int]} 2>/dev/null
if ! command -v sudo >/dev/null 2>&1; then
_green "Installing sudo" # 安装必要的命令
${PACKAGE_INSTALL[int]} sudo for cmd in sudo wget tar unzip iproute2 systemd-detect-virt dd fio; do
fi if ! command -v "$cmd" >/dev/null 2>&1; then
if ! command -v wget >/dev/null 2>&1; then _green "Installing $cmd"
_green "Installing wget" ${PACKAGE_INSTALL[int]} "$cmd"
${PACKAGE_INSTALL[int]} wget
fi
if ! command -v tar >/dev/null 2>&1; then
_green "Installing tar"
${PACKAGE_INSTALL[int]} tar
fi
if ! command -v unzip >/dev/null 2>&1; then
_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 done
if ! command -v dd >/dev/null 2>&1; then
_green "Installing dd" if ! command -v sysbench >/dev/null 2>&1; then
${PACKAGE_INSTALL[int]} dd
fi
if ! command -v fio >/dev/null 2>&1; then
_green "Installing fio"
${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
@@ -381,11 +371,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"
@@ -393,26 +384,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
@@ -424,9 +417,9 @@ 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() {
@@ -463,7 +456,7 @@ Available commands:
speedtest (Use the officially provided binaries for more accurate test results.) speedtest (Use the officially provided binaries for more accurate test results.)
ping (Use the officially provided binaries for more accurate test results.) ping (Use the officially provided binaries for more accurate test results.)
systemd-detect-virt OR dmidecode (Almost all unix-like systems have it, for more accurate test results.) systemd-detect-virt OR dmidecode (Almost all unix-like systems have it, for more accurate test results.)
In fact, sysbench/geekbench is the only one of the above dependencies that must be installed, without which the CPU score cannot be tested. In fact, sysbench/geekbench is the only one of the above dependencies that must be installed, without which the CPU score cannot be tested without which the CPU score cannot be tested.
./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
@@ -490,3 +483,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
@@ -238,22 +244,33 @@ func PrintAndCapture(f func(), tempOutput, output string) string {
} }
// UploadText 上传文本内容到指定URL // UploadText 上传文本内容到指定URL
func UploadText(absPath string) (string, error) { 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, 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,26 +278,28 @@ func UploadText(absPath 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/"), nil http_url := strings.ReplaceAll(resp.String(), "https://paste.spiritlhl.net/", "http://hpaste.spiritlhl.net/")
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)
} }
} }
result, err := upload(primaryURL) http_url, https_url, err := upload(primaryURL)
if err == nil { if err == nil {
return result, nil return http_url, https_url, nil
} }
result, 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 result, nil return http_url, https_url, nil
} }
// ProcessAndUpload 创建结果文件并上传文件 // ProcessAndUpload 创建结果文件并上传文件
@@ -321,12 +340,12 @@ func ProcessAndUpload(output string, filePath string, enableUplaod bool) {
return return
} }
// 上传文件并生成短链接 // 上传文件并生成短链接
shorturl, err3 := UploadText(absPath) http_url, https_url, err3 := UploadText(absPath)
if err3 != nil { if err3 != nil {
fmt.Println("Upload failed, cannot generate short URL.") fmt.Println("Upload failed, cannot generate short URL.")
fmt.Println(err3.Error()) fmt.Println(err3.Error())
return return
} }
fmt.Println("Upload successful, short URL:", shorturl) fmt.Printf("Upload successful!\nHttp URL: %s\nHttps URL: %s\n", http_url, https_url)
} }
} }