mirror of
https://github.com/oneclickvirt/ecs.git
synced 2025-09-28 04:02:12 +08:00
Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
956f65941e | ||
![]() |
6d1f806e94 | ||
![]() |
d727d6b778 | ||
![]() |
ea891861b3 | ||
![]() |
e0826a80c8 | ||
![]() |
74868a918e | ||
![]() |
889ecee3f3 | ||
![]() |
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
|
||||
```
|
4
go.mod
4
go.mod
@@ -7,7 +7,7 @@ require (
|
||||
github.com/oneclickvirt/CommonMediaTests v0.0.2-20240630023003
|
||||
github.com/oneclickvirt/UnlockTests v0.0.10-20240630044930
|
||||
github.com/oneclickvirt/backtrace v0.0.4-20240624090335
|
||||
github.com/oneclickvirt/basics v0.0.3-20240625075226
|
||||
github.com/oneclickvirt/basics v0.0.3-20240701085439
|
||||
github.com/oneclickvirt/cputest v0.0.7-20240701020012
|
||||
github.com/oneclickvirt/defaultset v0.0.2-20240624082446
|
||||
github.com/oneclickvirt/disktest v0.0.3-20240629152513
|
||||
@@ -15,7 +15,7 @@ require (
|
||||
github.com/oneclickvirt/memorytest v0.0.1-20240624151629
|
||||
github.com/oneclickvirt/nt3 v0.0.2-20240630152642
|
||||
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
|
||||
)
|
||||
|
||||
|
8
go.sum
8
go.sum
@@ -83,6 +83,10 @@ github.com/oneclickvirt/backtrace v0.0.4-20240624090335 h1:0LP5KyA6GLlqQAtOF0uyB
|
||||
github.com/oneclickvirt/backtrace v0.0.4-20240624090335/go.mod h1:zvsC7xY/WZqs5KL2JB967OVnuqjNbxu9bW6wXRLo5h8=
|
||||
github.com/oneclickvirt/basics v0.0.3-20240625075226 h1:K9VriCHIYnXPZXBSn9PRQX+jBS6AIFH8tBVb/i8VGAw=
|
||||
github.com/oneclickvirt/basics v0.0.3-20240625075226/go.mod h1:dTB+/oyFQYfTYX55rFJVWatum5F9g62zjfmHCM6Vj1s=
|
||||
github.com/oneclickvirt/basics v0.0.3-20240701085006 h1:wYimtnZuVmWxncwDevEzo4JZ/Xc2hj07vvbX3jgQLME=
|
||||
github.com/oneclickvirt/basics v0.0.3-20240701085006/go.mod h1:dTB+/oyFQYfTYX55rFJVWatum5F9g62zjfmHCM6Vj1s=
|
||||
github.com/oneclickvirt/basics v0.0.3-20240701085439 h1:1PE7Womqy4AW2c9PlyFdHsBocZXSo02V5uJDSzQLzgs=
|
||||
github.com/oneclickvirt/basics v0.0.3-20240701085439/go.mod h1:dTB+/oyFQYfTYX55rFJVWatum5F9g62zjfmHCM6Vj1s=
|
||||
github.com/oneclickvirt/cputest v0.0.7-20240701020012 h1:U5cCI+6ZU3pudoAlmb1b3yB9IQNm5AnDXi1TQAZJCIA=
|
||||
github.com/oneclickvirt/cputest v0.0.7-20240701020012/go.mod h1:MmaHN9+XMntI3rLycwj8Ne31fG18IfNoa8N2utDK1CY=
|
||||
github.com/oneclickvirt/defaultset v0.0.2-20240624082446 h1:5Pg3mK/u/vQvSz7anu0nxzrNdELi/AcDAU1mMsmPzyc=
|
||||
@@ -97,8 +101,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/portchecker v0.0.1-20240624155429 h1:+wapaOcFrg1iWJDhBKThDzppyIMY7hWxK7F5RBkZg4o=
|
||||
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.2-20240630142358/go.mod h1:cUNNOldoVQuovyc0EtAVAZlAT4y2xA1e0uA80aj1ly8=
|
||||
github.com/oneclickvirt/security v0.0.3-20240701065755 h1:eHZDuyvzufOu2yDUIMggK2iRtMWJaFlCzG4+leQn5+0=
|
||||
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/go.mod h1:zd5ZgIGslmtQLQehEfRjyumlvgDHTpCSMchKfKXoASI=
|
||||
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"
|
||||
"github.com/oneclickvirt/portchecker/email"
|
||||
speedtestmodel "github.com/oneclickvirt/speedtest/model"
|
||||
"os"
|
||||
"os/signal"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
ecsVersion = "2024.07.01.1"
|
||||
ecsVersion = "v0.0.21"
|
||||
menuMode bool
|
||||
input, choice string
|
||||
showVersion bool
|
||||
@@ -42,6 +45,8 @@ var (
|
||||
basicStatus, cpuTestStatus, memoryTestStatus, diskTestStatus bool
|
||||
commTestStatus, utTestStatus, securityTestStatus, emailTestStatus bool
|
||||
backtraceStatus, nt3Status, speedTestStatus bool
|
||||
filePath = "goecs.txt"
|
||||
enabelUpload = true
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -70,6 +75,8 @@ func main() {
|
||||
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.Parse()
|
||||
sig := make(chan os.Signal, 1)
|
||||
signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
||||
if showVersion {
|
||||
fmt.Println(ecsVersion)
|
||||
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("9. IP Quality Test (IP Test with 15 Databases + Email Port Test)")
|
||||
}
|
||||
Loop:
|
||||
for {
|
||||
fmt.Print("请输入选项 / Please enter your choice: ")
|
||||
fmt.Scanln(&input)
|
||||
@@ -129,14 +137,14 @@ func main() {
|
||||
backtraceStatus = true
|
||||
nt3Status = true
|
||||
speedTestStatus = true
|
||||
break
|
||||
break Loop
|
||||
case "2":
|
||||
basicStatus = true
|
||||
cpuTestStatus = true
|
||||
memoryTestStatus = true
|
||||
diskTestStatus = true
|
||||
speedTestStatus = true
|
||||
break
|
||||
break Loop
|
||||
case "3":
|
||||
basicStatus = true
|
||||
cpuTestStatus = true
|
||||
@@ -148,7 +156,7 @@ func main() {
|
||||
backtraceStatus = true
|
||||
nt3Status = true
|
||||
speedTestStatus = true
|
||||
break
|
||||
break Loop
|
||||
case "4":
|
||||
basicStatus = true
|
||||
cpuTestStatus = true
|
||||
@@ -157,7 +165,7 @@ func main() {
|
||||
backtraceStatus = true
|
||||
nt3Status = true
|
||||
speedTestStatus = true
|
||||
break
|
||||
break Loop
|
||||
case "5":
|
||||
basicStatus = true
|
||||
cpuTestStatus = true
|
||||
@@ -165,30 +173,30 @@ func main() {
|
||||
diskTestStatus = true
|
||||
securityTestStatus = true
|
||||
speedTestStatus = true
|
||||
break
|
||||
break Loop
|
||||
case "6":
|
||||
speedTestStatus = true
|
||||
backtraceStatus = true
|
||||
nt3Status = true
|
||||
break
|
||||
break Loop
|
||||
case "7":
|
||||
securityTestStatus = true
|
||||
commTestStatus = true
|
||||
break
|
||||
break Loop
|
||||
case "8":
|
||||
basicStatus = true
|
||||
cpuTestStatus = true
|
||||
memoryTestStatus = true
|
||||
diskTestStatus = true
|
||||
break
|
||||
break Loop
|
||||
case "9":
|
||||
emailTestStatus = true
|
||||
break
|
||||
break Loop
|
||||
case "10":
|
||||
backtraceStatus = true
|
||||
nt3Status = true
|
||||
speedTestStatus = true
|
||||
break
|
||||
break Loop
|
||||
default:
|
||||
if language == "zh" {
|
||||
fmt.Println("无效的选项")
|
||||
@@ -211,10 +219,17 @@ func main() {
|
||||
}
|
||||
startTime := time.Now()
|
||||
var (
|
||||
wg1, wg2, wg3 sync.WaitGroup
|
||||
basicInfo, securityInfo, emailInfo, mediaInfo, backtraceInfo string
|
||||
output, tempOutput string
|
||||
wg1, wg2 sync.WaitGroup
|
||||
basicInfo, securityInfo, emailInfo, mediaInfo string
|
||||
output, tempOutput string
|
||||
)
|
||||
// 启动一个goroutine来等待信号
|
||||
go func() {
|
||||
// 等待信号
|
||||
<-sig
|
||||
utils.ProcessAndUpload(output, filePath, enabelUpload)
|
||||
os.Exit(1) // 使用非零状态码退出,表示意外退出
|
||||
}()
|
||||
output = utils.PrintAndCapture(func() {
|
||||
switch language {
|
||||
case "zh":
|
||||
@@ -243,7 +258,7 @@ func main() {
|
||||
if emailTestStatus {
|
||||
wg2.Add(1)
|
||||
go func() {
|
||||
defer wg1.Done()
|
||||
defer wg2.Done()
|
||||
emailInfo = email.EmailCheck()
|
||||
}()
|
||||
}
|
||||
@@ -254,17 +269,6 @@ func main() {
|
||||
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 {
|
||||
utils.PrintCenteredTitle("御三家流媒体解锁", width)
|
||||
commediatest.ComMediaTest(language)
|
||||
@@ -286,8 +290,7 @@ func main() {
|
||||
if runtime.GOOS != "windows" {
|
||||
if backtraceStatus {
|
||||
utils.PrintCenteredTitle("三网回程", width)
|
||||
wg3.Wait()
|
||||
fmt.Printf(backtraceInfo)
|
||||
backtrace.BackTrace()
|
||||
}
|
||||
// nexttrace 在win上不支持检测,报错 bind: An invalid argument was supplied.
|
||||
if nt3Status {
|
||||
@@ -383,6 +386,5 @@ func main() {
|
||||
fmt.Println("Unsupported language")
|
||||
}
|
||||
}, tempOutput, output)
|
||||
filePath := "goecs.txt"
|
||||
utils.ProcessAndUpload(output, filePath, true)
|
||||
utils.ProcessAndUpload(output, filePath, enabelUpload)
|
||||
}
|
||||
|
51
goecs.sh
51
goecs.sh
@@ -59,17 +59,16 @@ goecs_check() {
|
||||
ECS_VERSION=$(curl -m 6 -sSL "https://githubapi.spiritlhl.top/repos/oneclickvirt/ecs/releases/latest" | awk -F \" '/tag_name/{gsub(/^v/,"",$4); print $4}')
|
||||
fi
|
||||
# 检测原始goecs命令是否存在,若存在则升级,不存在则安装
|
||||
version_output=$(goecs -v || ./goecs -v)
|
||||
version_output=$(goecs -v command 2>/dev/null || ./goecs -v command 2>/dev/null)
|
||||
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
|
||||
current_version=$(echo "$extracted_version" | cut -c 2-)
|
||||
ecs_version=$ECS_VERSION
|
||||
if [[ "$(echo -e "$current_version\n$ecs_version" | sort -V | tail -n 1)" == "$current_version" ]]; then
|
||||
echo "goecs version ($current_version) is latest, no need to upgrade."
|
||||
if [[ "$(echo -e "$extracted_version\n$ecs_version" | sort -V | tail -n 1)" == "$extracted_version" ]]; then
|
||||
echo "goecs version ($extracted_version) is latest, no need to upgrade."
|
||||
return
|
||||
else
|
||||
echo "goecs version ($current_version) < $ecs_version, need to upgrade, 5 seconds later will start to upgrade"
|
||||
echo "goecs version ($extracted_version) < $ecs_version, need to upgrade, 5 seconds later will start to upgrade"
|
||||
rm -rf /usr/bin/goecs
|
||||
rm -rf goecs
|
||||
fi
|
||||
@@ -163,7 +162,7 @@ InstallSysbench() {
|
||||
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" ;;
|
||||
*) echo "Error: Unknown OS release: $os_release" && exit 1 ;;
|
||||
*) echo "Error: Unknown OS release: $os_release" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -230,7 +229,7 @@ prepare_compile_env() {
|
||||
env_check() {
|
||||
REGEX=("debian|astra" "ubuntu" "centos|red hat|kernel|oracle linux|alma|rocky" "'amazon linux'" "fedora" "arch" "freebsd" "alpine" "openbsd")
|
||||
RELEASE=("Debian" "Ubuntu" "CentOS" "CentOS" "Fedora" "Arch" "FreeBSD" "Alpine" "OpenBSD")
|
||||
PACKAGE_UPDATE=("! apt-get update && apt-get --fix-broken install -y && 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 -u")
|
||||
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_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_UNINSTALL=("apt-get -y autoremove" "apt-get -y autoremove" "yum -y autoremove" "yum -y autoremove" "yum -y autoremove" "" "pkg autoremove" "apk autoremove")
|
||||
@@ -245,6 +244,16 @@ env_check() {
|
||||
done
|
||||
cdn_urls=("https://cdn0.spiritlhl.top/" "http://cdn3.spiritlhl.net/" "http://cdn1.spiritlhl.net/" "http://cdn2.spiritlhl.net/")
|
||||
check_cdn_file
|
||||
_green "Update system manager."
|
||||
$PACKAGE_UPDATE command 2>/dev/null
|
||||
if ! command -v tar >/dev/null 2>&1; then
|
||||
_green "Installing tar"
|
||||
$PACKAGE_INSTALL tar
|
||||
fi
|
||||
if ! command -v unzip >/dev/null 2>&1; then
|
||||
_green "Installing unzip"
|
||||
$PACKAGE_INSTALL unzip
|
||||
fi
|
||||
if ! command -v dd >/dev/null 2>&1; then
|
||||
_green "Installing dd"
|
||||
$PACKAGE_INSTALL dd
|
||||
@@ -291,16 +300,31 @@ env_check() {
|
||||
echo "rm -rf /usr/bin/speedtest-go"
|
||||
_blue "to uninstall speedtest and speedtest-go"
|
||||
fi
|
||||
_green "The environment is ready."
|
||||
}
|
||||
|
||||
delete_goecs() {
|
||||
rm -rf /root/goecs
|
||||
rm -rf /usr/bin/goecs
|
||||
}
|
||||
|
||||
show_help() {
|
||||
cat <<"EOF"
|
||||
Available commands:
|
||||
|
||||
env Check and Install package: dd fio sysbench geekbench5 speedtest
|
||||
install Install goecs command
|
||||
upgrade Upgrade goecs command
|
||||
help Show this message
|
||||
./goecs.sh env Check and Install package:
|
||||
tar (Almost all unix-like systems have it.)
|
||||
unzip (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.)
|
||||
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.)
|
||||
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
|
||||
}
|
||||
@@ -315,6 +339,9 @@ case "$1" in
|
||||
"install" | "upgrade")
|
||||
goecs_check
|
||||
;;
|
||||
"delete")
|
||||
delete_goecs
|
||||
;;
|
||||
*)
|
||||
echo "No command found."
|
||||
echo
|
||||
|
@@ -91,56 +91,6 @@ func SecurityCheck(language, nt3CheckType string, securtyCheckStatus bool) (stri
|
||||
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 捕获函数输出和错误输出,实时输出,并返回字符串
|
||||
func CaptureOutput(f func()) string {
|
||||
// 保存旧的 stdout 和 stderr
|
||||
@@ -265,16 +215,16 @@ func ProcessAndUpload(output string, filePath string, enableUplaod bool) {
|
||||
}
|
||||
if enableUplaod {
|
||||
// 获取文件的绝对路径
|
||||
absPath, err := filepath.Abs(filePath)
|
||||
if err != nil {
|
||||
fmt.Println("Failed to get absolute file path:", err)
|
||||
absPath, err2 := filepath.Abs(filePath)
|
||||
if err2 != nil {
|
||||
fmt.Println("Failed to get absolute file path:", err2)
|
||||
return
|
||||
}
|
||||
// 上传文件并生成短链接
|
||||
shorturl, err := UploadText(absPath)
|
||||
if err != nil {
|
||||
shorturl, err3 := UploadText(absPath)
|
||||
if err3 != nil {
|
||||
fmt.Println("Upload failed, cannot generate short URL.")
|
||||
fmt.Println(err.Error())
|
||||
fmt.Println(err3.Error())
|
||||
return
|
||||
}
|
||||
fmt.Println("Upload successful, short URL:", shorturl)
|
||||
|
Reference in New Issue
Block a user