mirror of
https://github.com/oneclickvirt/ecs.git
synced 2025-10-03 22:46:28 +08:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f6dd0bbb56 | ||
![]() |
01686f3e9d | ||
![]() |
5a6cd7d671 | ||
![]() |
35e183b640 | ||
![]() |
a684052966 | ||
![]() |
2beb74c319 | ||
![]() |
5218c95162 |
@@ -27,4 +27,8 @@ Shell版本: https://github.com/spiritLHLS/ecs
|
|||||||
|
|
||||||
## 说明
|
## 说明
|
||||||
|
|
||||||
开发中,勿要使用
|
开发中,勿要使用
|
||||||
|
|
||||||
|
```
|
||||||
|
curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh
|
||||||
|
```
|
2
go.mod
2
go.mod
@@ -15,7 +15,7 @@ require (
|
|||||||
github.com/oneclickvirt/memorytest v0.0.1-20240624151629
|
github.com/oneclickvirt/memorytest v0.0.1-20240624151629
|
||||||
github.com/oneclickvirt/nt3 v0.0.2-20240630152642
|
github.com/oneclickvirt/nt3 v0.0.2-20240630152642
|
||||||
github.com/oneclickvirt/portchecker v0.0.1-20240624155429
|
github.com/oneclickvirt/portchecker v0.0.1-20240624155429
|
||||||
github.com/oneclickvirt/security v0.0.2-20240630142358
|
github.com/oneclickvirt/security v0.0.3-20240701065755
|
||||||
github.com/oneclickvirt/speedtest v0.0.6-20240630114816
|
github.com/oneclickvirt/speedtest v0.0.6-20240630114816
|
||||||
)
|
)
|
||||||
|
|
||||||
|
4
go.sum
4
go.sum
@@ -97,8 +97,8 @@ github.com/oneclickvirt/nt3 v0.0.2-20240630152642 h1:BkpR1j9JaDxMzx7iIwtsnFDxSld
|
|||||||
github.com/oneclickvirt/nt3 v0.0.2-20240630152642/go.mod h1:UojPmtangn17TiQaDccVrZbn6sZwJOtzBgg3idp68cA=
|
github.com/oneclickvirt/nt3 v0.0.2-20240630152642/go.mod h1:UojPmtangn17TiQaDccVrZbn6sZwJOtzBgg3idp68cA=
|
||||||
github.com/oneclickvirt/portchecker v0.0.1-20240624155429 h1:+wapaOcFrg1iWJDhBKThDzppyIMY7hWxK7F5RBkZg4o=
|
github.com/oneclickvirt/portchecker v0.0.1-20240624155429 h1:+wapaOcFrg1iWJDhBKThDzppyIMY7hWxK7F5RBkZg4o=
|
||||||
github.com/oneclickvirt/portchecker v0.0.1-20240624155429/go.mod h1:HQxSTrqM8/QFqHMTBZ7S8H9eEO5FkUXU1eb7ZX5Mk+k=
|
github.com/oneclickvirt/portchecker v0.0.1-20240624155429/go.mod h1:HQxSTrqM8/QFqHMTBZ7S8H9eEO5FkUXU1eb7ZX5Mk+k=
|
||||||
github.com/oneclickvirt/security v0.0.2-20240630142358 h1:yioMtHuW9wbJ7payL8GCPnj1ScEqNoqbNHt3+4Z4VAg=
|
github.com/oneclickvirt/security v0.0.3-20240701065755 h1:eHZDuyvzufOu2yDUIMggK2iRtMWJaFlCzG4+leQn5+0=
|
||||||
github.com/oneclickvirt/security v0.0.2-20240630142358/go.mod h1:cUNNOldoVQuovyc0EtAVAZlAT4y2xA1e0uA80aj1ly8=
|
github.com/oneclickvirt/security v0.0.3-20240701065755/go.mod h1:cUNNOldoVQuovyc0EtAVAZlAT4y2xA1e0uA80aj1ly8=
|
||||||
github.com/oneclickvirt/speedtest v0.0.6-20240630114816 h1:gI2hqV0IwcvGqYzLhlt4w2oZvYhCL+73jftUuJYBsuI=
|
github.com/oneclickvirt/speedtest v0.0.6-20240630114816 h1:gI2hqV0IwcvGqYzLhlt4w2oZvYhCL+73jftUuJYBsuI=
|
||||||
github.com/oneclickvirt/speedtest v0.0.6-20240630114816/go.mod h1:zd5ZgIGslmtQLQehEfRjyumlvgDHTpCSMchKfKXoASI=
|
github.com/oneclickvirt/speedtest v0.0.6-20240630114816/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=
|
||||||
|
62
goecs.go
62
goecs.go
@@ -18,15 +18,18 @@ import (
|
|||||||
gostunmodel "github.com/oneclickvirt/gostun/model"
|
gostunmodel "github.com/oneclickvirt/gostun/model"
|
||||||
"github.com/oneclickvirt/portchecker/email"
|
"github.com/oneclickvirt/portchecker/email"
|
||||||
speedtestmodel "github.com/oneclickvirt/speedtest/model"
|
speedtestmodel "github.com/oneclickvirt/speedtest/model"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ecsVersion = "2024.07.01.1"
|
ecsVersion = "v0.0.19"
|
||||||
menuMode bool
|
menuMode bool
|
||||||
input, choice string
|
input, choice string
|
||||||
showVersion bool
|
showVersion bool
|
||||||
@@ -42,6 +45,8 @@ var (
|
|||||||
basicStatus, cpuTestStatus, memoryTestStatus, diskTestStatus bool
|
basicStatus, cpuTestStatus, memoryTestStatus, diskTestStatus bool
|
||||||
commTestStatus, utTestStatus, securityTestStatus, emailTestStatus bool
|
commTestStatus, utTestStatus, securityTestStatus, emailTestStatus bool
|
||||||
backtraceStatus, nt3Status, speedTestStatus bool
|
backtraceStatus, nt3Status, speedTestStatus bool
|
||||||
|
filePath = "goecs.txt"
|
||||||
|
enabelUpload = true
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -70,6 +75,8 @@ func main() {
|
|||||||
flag.IntVar(&spNum, "spnum", 2, "Set the number of servers per operator for speed test")
|
flag.IntVar(&spNum, "spnum", 2, "Set the number of servers per operator for speed test")
|
||||||
flag.BoolVar(&enableLogger, "log", false, "Enable/Disable logging in the current path")
|
flag.BoolVar(&enableLogger, "log", false, "Enable/Disable logging in the current path")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
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
|
||||||
@@ -108,6 +115,7 @@ func main() {
|
|||||||
fmt.Println("8. Hardware-Only Test (Basic System Info + CPU + Memory + dd Disk Test + fio Disk Test)")
|
fmt.Println("8. Hardware-Only Test (Basic System Info + CPU + Memory + dd Disk Test + fio Disk Test)")
|
||||||
fmt.Println("9. IP Quality Test (IP Test with 15 Databases + Email Port Test)")
|
fmt.Println("9. IP Quality Test (IP Test with 15 Databases + Email Port Test)")
|
||||||
}
|
}
|
||||||
|
Loop:
|
||||||
for {
|
for {
|
||||||
fmt.Print("请输入选项 / Please enter your choice: ")
|
fmt.Print("请输入选项 / Please enter your choice: ")
|
||||||
fmt.Scanln(&input)
|
fmt.Scanln(&input)
|
||||||
@@ -129,14 +137,14 @@ func main() {
|
|||||||
backtraceStatus = true
|
backtraceStatus = true
|
||||||
nt3Status = true
|
nt3Status = true
|
||||||
speedTestStatus = true
|
speedTestStatus = true
|
||||||
break
|
break Loop
|
||||||
case "2":
|
case "2":
|
||||||
basicStatus = true
|
basicStatus = true
|
||||||
cpuTestStatus = true
|
cpuTestStatus = true
|
||||||
memoryTestStatus = true
|
memoryTestStatus = true
|
||||||
diskTestStatus = true
|
diskTestStatus = true
|
||||||
speedTestStatus = true
|
speedTestStatus = true
|
||||||
break
|
break Loop
|
||||||
case "3":
|
case "3":
|
||||||
basicStatus = true
|
basicStatus = true
|
||||||
cpuTestStatus = true
|
cpuTestStatus = true
|
||||||
@@ -148,7 +156,7 @@ func main() {
|
|||||||
backtraceStatus = true
|
backtraceStatus = true
|
||||||
nt3Status = true
|
nt3Status = true
|
||||||
speedTestStatus = true
|
speedTestStatus = true
|
||||||
break
|
break Loop
|
||||||
case "4":
|
case "4":
|
||||||
basicStatus = true
|
basicStatus = true
|
||||||
cpuTestStatus = true
|
cpuTestStatus = true
|
||||||
@@ -157,7 +165,7 @@ func main() {
|
|||||||
backtraceStatus = true
|
backtraceStatus = true
|
||||||
nt3Status = true
|
nt3Status = true
|
||||||
speedTestStatus = true
|
speedTestStatus = true
|
||||||
break
|
break Loop
|
||||||
case "5":
|
case "5":
|
||||||
basicStatus = true
|
basicStatus = true
|
||||||
cpuTestStatus = true
|
cpuTestStatus = true
|
||||||
@@ -165,30 +173,30 @@ func main() {
|
|||||||
diskTestStatus = true
|
diskTestStatus = true
|
||||||
securityTestStatus = true
|
securityTestStatus = true
|
||||||
speedTestStatus = true
|
speedTestStatus = true
|
||||||
break
|
break Loop
|
||||||
case "6":
|
case "6":
|
||||||
speedTestStatus = true
|
speedTestStatus = true
|
||||||
backtraceStatus = true
|
backtraceStatus = true
|
||||||
nt3Status = true
|
nt3Status = true
|
||||||
break
|
break Loop
|
||||||
case "7":
|
case "7":
|
||||||
securityTestStatus = true
|
securityTestStatus = true
|
||||||
commTestStatus = true
|
commTestStatus = true
|
||||||
break
|
break Loop
|
||||||
case "8":
|
case "8":
|
||||||
basicStatus = true
|
basicStatus = true
|
||||||
cpuTestStatus = true
|
cpuTestStatus = true
|
||||||
memoryTestStatus = true
|
memoryTestStatus = true
|
||||||
diskTestStatus = true
|
diskTestStatus = true
|
||||||
break
|
break Loop
|
||||||
case "9":
|
case "9":
|
||||||
emailTestStatus = true
|
emailTestStatus = true
|
||||||
break
|
break Loop
|
||||||
case "10":
|
case "10":
|
||||||
backtraceStatus = true
|
backtraceStatus = true
|
||||||
nt3Status = true
|
nt3Status = true
|
||||||
speedTestStatus = true
|
speedTestStatus = true
|
||||||
break
|
break Loop
|
||||||
default:
|
default:
|
||||||
if language == "zh" {
|
if language == "zh" {
|
||||||
fmt.Println("无效的选项")
|
fmt.Println("无效的选项")
|
||||||
@@ -211,10 +219,17 @@ func main() {
|
|||||||
}
|
}
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
var (
|
var (
|
||||||
wg1, wg2, wg3 sync.WaitGroup
|
wg1, wg2 sync.WaitGroup
|
||||||
basicInfo, securityInfo, emailInfo, mediaInfo, backtraceInfo string
|
basicInfo, securityInfo, emailInfo, mediaInfo string
|
||||||
output, tempOutput string
|
output, tempOutput string
|
||||||
)
|
)
|
||||||
|
// 启动一个goroutine来等待信号
|
||||||
|
go func() {
|
||||||
|
// 等待信号
|
||||||
|
<-sig
|
||||||
|
utils.ProcessAndUpload(output, filePath, enabelUpload)
|
||||||
|
os.Exit(1) // 使用非零状态码退出,表示意外退出
|
||||||
|
}()
|
||||||
output = utils.PrintAndCapture(func() {
|
output = utils.PrintAndCapture(func() {
|
||||||
switch language {
|
switch language {
|
||||||
case "zh":
|
case "zh":
|
||||||
@@ -243,7 +258,7 @@ func main() {
|
|||||||
if emailTestStatus {
|
if emailTestStatus {
|
||||||
wg2.Add(1)
|
wg2.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg1.Done()
|
defer wg2.Done()
|
||||||
emailInfo = email.EmailCheck()
|
emailInfo = email.EmailCheck()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
@@ -254,17 +269,6 @@ func main() {
|
|||||||
mediaInfo = unlocktest.MediaTest(language)
|
mediaInfo = unlocktest.MediaTest(language)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
if backtraceStatus {
|
|
||||||
wg3.Add(1)
|
|
||||||
go func() {
|
|
||||||
defer wg3.Done()
|
|
||||||
backtraceInfo = utils.GetCaptureOutput(func() {
|
|
||||||
backtrace.BackTrace()
|
|
||||||
})
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if commTestStatus {
|
if commTestStatus {
|
||||||
utils.PrintCenteredTitle("御三家流媒体解锁", width)
|
utils.PrintCenteredTitle("御三家流媒体解锁", width)
|
||||||
commediatest.ComMediaTest(language)
|
commediatest.ComMediaTest(language)
|
||||||
@@ -286,8 +290,7 @@ func main() {
|
|||||||
if runtime.GOOS != "windows" {
|
if runtime.GOOS != "windows" {
|
||||||
if backtraceStatus {
|
if backtraceStatus {
|
||||||
utils.PrintCenteredTitle("三网回程", width)
|
utils.PrintCenteredTitle("三网回程", width)
|
||||||
wg3.Wait()
|
backtrace.BackTrace()
|
||||||
fmt.Printf(backtraceInfo)
|
|
||||||
}
|
}
|
||||||
// nexttrace 在win上不支持检测,报错 bind: An invalid argument was supplied.
|
// nexttrace 在win上不支持检测,报错 bind: An invalid argument was supplied.
|
||||||
if nt3Status {
|
if nt3Status {
|
||||||
@@ -383,6 +386,5 @@ func main() {
|
|||||||
fmt.Println("Unsupported language")
|
fmt.Println("Unsupported language")
|
||||||
}
|
}
|
||||||
}, tempOutput, output)
|
}, tempOutput, output)
|
||||||
filePath := "goecs.txt"
|
utils.ProcessAndUpload(output, filePath, enabelUpload)
|
||||||
utils.ProcessAndUpload(output, filePath, true)
|
|
||||||
}
|
}
|
||||||
|
25
goecs.sh
25
goecs.sh
@@ -61,7 +61,7 @@ goecs_check() {
|
|||||||
# 检测原始goecs命令是否存在,若存在则升级,不存在则安装
|
# 检测原始goecs命令是否存在,若存在则升级,不存在则安装
|
||||||
version_output=$(goecs -v || ./goecs -v)
|
version_output=$(goecs -v || ./goecs -v)
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
extracted_version=$(echo "$version_output" | grep -oP '^v\d+(\.\d+)+')
|
extracted_version=$(echo "${version_output//v/}")
|
||||||
if [ -n "$extracted_version" ]; then
|
if [ -n "$extracted_version" ]; then
|
||||||
current_version=$(echo "$extracted_version" | cut -c 2-)
|
current_version=$(echo "$extracted_version" | cut -c 2-)
|
||||||
ecs_version=$ECS_VERSION
|
ecs_version=$ECS_VERSION
|
||||||
@@ -293,14 +293,26 @@ env_check() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete_goecs() {
|
||||||
|
rm -rf /root/goecs
|
||||||
|
rm -rf /usr/bin/goecs
|
||||||
|
}
|
||||||
|
|
||||||
show_help() {
|
show_help() {
|
||||||
cat <<"EOF"
|
cat <<"EOF"
|
||||||
Available commands:
|
Available commands:
|
||||||
|
|
||||||
env Check and Install package: dd fio sysbench geekbench5 speedtest
|
./goecs.sh env Check and Install package:
|
||||||
install Install goecs command
|
dd (Almost all unix-like systems have it, it's only for testing on most systems.)
|
||||||
upgrade Upgrade goecs command
|
fio (Almost all unix-like systems can be installed through the system's package manager.)
|
||||||
help Show this message
|
sysbench (Almost all unix-like systems can be installed through the system's package manager.)
|
||||||
|
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.)
|
||||||
|
In fact, sysbench/geekbench is the only one of the above dependencies that must be installed, without which the CPU score cannot be tested.
|
||||||
|
./goecs.sh install Install goecs command
|
||||||
|
./goecs.sh upgrade Upgrade goecs command
|
||||||
|
./goecs.sh delete Uninstall goecs command
|
||||||
|
./goecs.sh help Show this message
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
@@ -315,6 +327,9 @@ case "$1" in
|
|||||||
"install" | "upgrade")
|
"install" | "upgrade")
|
||||||
goecs_check
|
goecs_check
|
||||||
;;
|
;;
|
||||||
|
"delete")
|
||||||
|
delete_goecs
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "No command found."
|
echo "No command found."
|
||||||
echo
|
echo
|
||||||
|
@@ -91,56 +91,6 @@ func SecurityCheck(language, nt3CheckType string, securtyCheckStatus bool) (stri
|
|||||||
return basicInfo, securityInfo, nt3CheckType
|
return basicInfo, securityInfo, nt3CheckType
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCaptureOutput 仅捕获输出不实时输出
|
|
||||||
func GetCaptureOutput(f func()) string {
|
|
||||||
// 保存旧的 stdout 和 stderr
|
|
||||||
oldStdout := os.Stdout
|
|
||||||
oldStderr := os.Stderr
|
|
||||||
// 创建管道
|
|
||||||
stdoutPipeR, stdoutPipeW, err := os.Pipe()
|
|
||||||
if err != nil {
|
|
||||||
return "Error creating stdout pipe"
|
|
||||||
}
|
|
||||||
stderrPipeR, stderrPipeW, err := os.Pipe()
|
|
||||||
if err != nil {
|
|
||||||
stdoutPipeW.Close()
|
|
||||||
stdoutPipeR.Close()
|
|
||||||
return "Error creating stderr pipe"
|
|
||||||
}
|
|
||||||
// 替换标准输出和标准错误输出为管道写入端
|
|
||||||
os.Stdout = stdoutPipeW
|
|
||||||
os.Stderr = stderrPipeW
|
|
||||||
// 恢复标准输出和标准错误输出
|
|
||||||
defer func() {
|
|
||||||
os.Stdout = oldStdout
|
|
||||||
os.Stderr = oldStderr
|
|
||||||
stdoutPipeW.Close()
|
|
||||||
stderrPipeW.Close()
|
|
||||||
}()
|
|
||||||
// 缓冲区
|
|
||||||
var stdoutBuf, stderrBuf bytes.Buffer
|
|
||||||
// 并发读取 stdout 和 stderr
|
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
io.Copy(&stdoutBuf, stdoutPipeR)
|
|
||||||
done <- struct{}{}
|
|
||||||
}()
|
|
||||||
go func() {
|
|
||||||
io.Copy(&stderrBuf, stderrPipeR)
|
|
||||||
done <- struct{}{}
|
|
||||||
}()
|
|
||||||
// 执行函数
|
|
||||||
f()
|
|
||||||
// 关闭管道写入端,让管道读取端可以读取所有数据
|
|
||||||
stdoutPipeW.Close()
|
|
||||||
stderrPipeW.Close()
|
|
||||||
// 等待两个 goroutine 完成
|
|
||||||
<-done
|
|
||||||
<-done
|
|
||||||
// 返回捕获的输出字符串
|
|
||||||
return stdoutBuf.String() + stderrBuf.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// CaptureOutput 捕获函数输出和错误输出,实时输出,并返回字符串
|
// CaptureOutput 捕获函数输出和错误输出,实时输出,并返回字符串
|
||||||
func CaptureOutput(f func()) string {
|
func CaptureOutput(f func()) string {
|
||||||
// 保存旧的 stdout 和 stderr
|
// 保存旧的 stdout 和 stderr
|
||||||
|
1
发布版本.bat
1
发布版本.bat
@@ -24,6 +24,7 @@ REM 提示用户输入版本号
|
|||||||
set /p version="Enter the version number (e.g., v1.0.0): "
|
set /p version="Enter the version number (e.g., v1.0.0): "
|
||||||
|
|
||||||
REM 创建并推送标签
|
REM 创建并推送标签
|
||||||
|
:push_tag
|
||||||
git tag %version%
|
git tag %version%
|
||||||
git push origin %version%
|
git push origin %version%
|
||||||
if errorlevel 1 (
|
if errorlevel 1 (
|
||||||
|
Reference in New Issue
Block a user