Compare commits

...

10 Commits

Author SHA1 Message Date
spiritlhl
c81ebb3c7a fix: 异步函数传值需要指针传递,值传递可能会出现同步问题 2025-06-29 08:45:15 +00:00
github-actions[bot]
7896b3ead5 chore: update ECS_VERSION to 0.1.42 in goecs.sh 2025-06-29 08:33:10 +00:00
spiritlhl
eb98a7b857 fix: 更加严格的启动条件,同时避免死锁等待 2025-06-29 08:29:24 +00:00
github-actions[bot]
d4d86229de chore: update ECS_VERSION to 0.1.41 in goecs.sh 2025-06-29 07:59:30 +00:00
spiritlhl
651a183382 fix: 修复版本号 2025-06-29 15:55:56 +08:00
spiritlhl
afc313a2a8 fix: 同步流媒体检测的判断逻辑 2025-06-29 15:44:16 +08:00
github-actions[bot]
39ac8d198d chore: update ECS_VERSION to 0.1.40 in goecs.sh 2025-06-29 07:36:33 +00:00
spiritlhl
a70dc2bab1 fix: 更新版本号至 v0.1.40 2025-06-29 07:26:48 +00:00
spiritlhl
5041a16a9a fix: 修复同步机制问题,保护最终输出不出现数据竞争 2025-06-29 07:22:27 +00:00
github-actions[bot]
21deb3587e chore: update ECS_VERSION to 0.1.39 in goecs.sh 2025-06-29 07:07:10 +00:00
2 changed files with 62 additions and 57 deletions

111
goecs.go
View File

@@ -39,7 +39,7 @@ import (
) )
var ( var (
ecsVersion = "v0.1.38" ecsVersion = "v0.1.43"
menuMode bool menuMode bool
onlyChinaTest bool onlyChinaTest bool
input, choice string input, choice string
@@ -387,8 +387,7 @@ func handleLanguageSpecificSettings() {
} }
} }
func handleSignalInterrupt(sig chan os.Signal, startTime *time.Time, output *string, tempOutput string, uploadDone chan bool) { func handleSignalInterrupt(sig chan os.Signal, startTime *time.Time, output *string, tempOutput string, uploadDone chan bool, outputMutex *sync.Mutex) {
*startTime = time.Now()
select { select {
case <-sig: case <-sig:
if !finish { if !finish {
@@ -397,21 +396,23 @@ func handleSignalInterrupt(sig chan os.Signal, startTime *time.Time, output *str
minutes := int(duration.Minutes()) minutes := int(duration.Minutes())
seconds := int(duration.Seconds()) % 60 seconds := int(duration.Seconds()) % 60
currentTime := time.Now().Format("Mon Jan 2 15:04:05 MST 2006") currentTime := time.Now().Format("Mon Jan 2 15:04:05 MST 2006")
var mu sync.Mutex outputMutex.Lock()
mu.Lock()
*output = utils.PrintAndCapture(func() { *output = utils.PrintAndCapture(func() {
utils.PrintCenteredTitle("", width) utils.PrintCenteredTitle("", width)
fmt.Printf("Cost Time : %d min %d sec\n", minutes, seconds) fmt.Printf("Cost Time : %d min %d sec\n", minutes, seconds)
fmt.Printf("Current Time : %s\n", currentTime) fmt.Printf("Current Time : %s\n", currentTime)
utils.PrintCenteredTitle("", width) utils.PrintCenteredTitle("", width)
}, tempOutput, *output) }, tempOutput, *output)
mu.Unlock() outputMutex.Unlock()
resultChan := make(chan struct { resultChan := make(chan struct {
httpURL string httpURL string
httpsURL string httpsURL string
}, 1) }, 1)
go func() { go func() {
httpURL, httpsURL := utils.ProcessAndUpload(*output, filePath, enabelUpload) outputMutex.Lock()
finalOutput := *output
outputMutex.Unlock()
httpURL, httpsURL := utils.ProcessAndUpload(finalOutput, filePath, enabelUpload)
resultChan <- struct { resultChan <- struct {
httpURL string httpURL string
httpsURL string httpsURL string
@@ -434,7 +435,11 @@ func handleSignalInterrupt(sig chan os.Signal, startTime *time.Time, output *str
} }
os.Exit(0) os.Exit(0)
case <-time.After(30 * time.Second): case <-time.After(30 * time.Second):
fmt.Println("上传超时,程序退出") if language == "en" {
fmt.Println("Upload timeout, program exit")
} else {
fmt.Println("上传超时,程序退出")
}
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()
@@ -446,11 +451,11 @@ func handleSignalInterrupt(sig chan os.Signal, startTime *time.Time, output *str
} }
} }
func runChineseTests(preCheck utils.NetCheckResult, wg1, wg2, wg3 *sync.WaitGroup, basicInfo, securityInfo, emailInfo, mediaInfo, ptInfo *string, output, tempOutput string, startTime time.Time) string { func runChineseTests(preCheck utils.NetCheckResult, wg1, wg2, wg3 *sync.WaitGroup, basicInfo, securityInfo, emailInfo, mediaInfo, ptInfo *string, output, tempOutput string, startTime time.Time, outputMutex *sync.Mutex) string {
output = runBasicTests(preCheck, basicInfo, securityInfo, output, tempOutput) output = runBasicTests(preCheck, basicInfo, securityInfo, output, tempOutput, outputMutex)
output = runCPUTest(output, tempOutput) output = runCPUTest(output, tempOutput, outputMutex)
output = runMemoryTest(output, tempOutput) output = runMemoryTest(output, tempOutput, outputMutex)
output = runDiskTest(output, tempOutput) output = runDiskTest(output, tempOutput, outputMutex)
if (onlyChinaTest || pingTestStatus) && preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" { if (onlyChinaTest || pingTestStatus) && preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" {
wg3.Add(1) wg3.Add(1)
go func() { go func() {
@@ -458,14 +463,14 @@ func runChineseTests(preCheck utils.NetCheckResult, wg1, wg2, wg3 *sync.WaitGrou
*ptInfo = pt.PingTest() *ptInfo = pt.PingTest()
}() }()
} }
if emailTestStatus { if emailTestStatus && preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" {
wg2.Add(1) wg2.Add(1)
go func() { go func() {
defer wg2.Done() defer wg2.Done()
*emailInfo = email.EmailCheck() *emailInfo = email.EmailCheck()
}() }()
} }
if utTestStatus && !onlyChinaTest { if utTestStatus && preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" && !onlyChinaTest {
wg1.Add(1) wg1.Add(1)
go func() { go func() {
defer wg1.Done() defer wg1.Done()
@@ -473,24 +478,24 @@ func runChineseTests(preCheck utils.NetCheckResult, wg1, wg2, wg3 *sync.WaitGrou
}() }()
} }
if preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" { if preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" {
output = runStreamingTests(wg1, *mediaInfo, output, tempOutput) output = runStreamingTests(wg1, mediaInfo, output, tempOutput, outputMutex)
output = runSecurityTests(*securityInfo, output, tempOutput) output = runSecurityTests(*securityInfo, output, tempOutput, outputMutex)
output = runEmailTests(wg2, *emailInfo, output, tempOutput) output = runEmailTests(wg2, emailInfo, output, tempOutput, outputMutex)
} }
if runtime.GOOS != "windows" && preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" { if runtime.GOOS != "windows" && preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" {
output = runNetworkTests(wg3, *ptInfo, output, tempOutput) output = runNetworkTests(wg3, ptInfo, output, tempOutput, outputMutex)
} }
if preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" { if preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" {
output = runSpeedTests(output, tempOutput) output = runSpeedTests(output, tempOutput, outputMutex)
} }
return appendTimeInfo(output, tempOutput, startTime) return appendTimeInfo(output, tempOutput, startTime, outputMutex)
} }
func runEnglishTests(preCheck utils.NetCheckResult, wg1, wg2 *sync.WaitGroup, basicInfo, securityInfo, emailInfo, mediaInfo *string, output, tempOutput string, startTime time.Time) string { func runEnglishTests(preCheck utils.NetCheckResult, wg1, wg2 *sync.WaitGroup, basicInfo, securityInfo, emailInfo, mediaInfo *string, output, tempOutput string, startTime time.Time, outputMutex *sync.Mutex) string {
output = runBasicTests(preCheck, basicInfo, securityInfo, output, tempOutput) output = runBasicTests(preCheck, basicInfo, securityInfo, output, tempOutput, outputMutex)
output = runCPUTest(output, tempOutput) output = runCPUTest(output, tempOutput, outputMutex)
output = runMemoryTest(output, tempOutput) output = runMemoryTest(output, tempOutput, outputMutex)
output = runDiskTest(output, tempOutput) output = runDiskTest(output, tempOutput, outputMutex)
if preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" { if preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" {
if utTestStatus { if utTestStatus {
wg1.Add(1) wg1.Add(1)
@@ -506,15 +511,15 @@ func runEnglishTests(preCheck utils.NetCheckResult, wg1, wg2 *sync.WaitGroup, ba
*emailInfo = email.EmailCheck() *emailInfo = email.EmailCheck()
}() }()
} }
output = runStreamingTests(wg1, *mediaInfo, output, tempOutput) output = runStreamingTests(wg1, mediaInfo, output, tempOutput, outputMutex) // 传递指针
output = runSecurityTests(*securityInfo, output, tempOutput) output = runSecurityTests(*securityInfo, output, tempOutput, outputMutex)
output = runEmailTests(wg2, *emailInfo, output, tempOutput) output = runEmailTests(wg2, emailInfo, output, tempOutput, outputMutex)
output = runEnglishSpeedTests(output, tempOutput) output = runEnglishSpeedTests(output, tempOutput, outputMutex)
} }
return appendTimeInfo(output, tempOutput, startTime) return appendTimeInfo(output, tempOutput, startTime, outputMutex)
} }
func runBasicTests(preCheck utils.NetCheckResult, basicInfo, securityInfo *string, output, tempOutput string) string { func runBasicTests(preCheck utils.NetCheckResult, basicInfo, securityInfo *string, output, tempOutput string, outputMutex *sync.Mutex) string {
return utils.PrintAndCapture(func() { return utils.PrintAndCapture(func() {
utils.PrintHead(language, width, ecsVersion) utils.PrintHead(language, width, ecsVersion)
if basicStatus || securityTestStatus { if basicStatus || securityTestStatus {
@@ -550,7 +555,7 @@ func runBasicTests(preCheck utils.NetCheckResult, basicInfo, securityInfo *strin
}, tempOutput, output) }, tempOutput, output)
} }
func runCPUTest(output, tempOutput string) string { func runCPUTest(output, tempOutput string, outputMutex *sync.Mutex) string {
return utils.PrintAndCapture(func() { return utils.PrintAndCapture(func() {
if cpuTestStatus { if cpuTestStatus {
if language == "zh" { if language == "zh" {
@@ -563,7 +568,7 @@ func runCPUTest(output, tempOutput string) string {
}, tempOutput, output) }, tempOutput, output)
} }
func runMemoryTest(output, tempOutput string) string { func runMemoryTest(output, tempOutput string, outputMutex *sync.Mutex) string {
return utils.PrintAndCapture(func() { return utils.PrintAndCapture(func() {
if memoryTestStatus { if memoryTestStatus {
if language == "zh" { if language == "zh" {
@@ -576,7 +581,7 @@ func runMemoryTest(output, tempOutput string) string {
}, tempOutput, output) }, tempOutput, output)
} }
func runDiskTest(output, tempOutput string) string { func runDiskTest(output, tempOutput string, outputMutex *sync.Mutex) string {
return utils.PrintAndCapture(func() { return utils.PrintAndCapture(func() {
if diskTestStatus && autoChangeDiskTestMethod { if diskTestStatus && autoChangeDiskTestMethod {
if language == "zh" { if language == "zh" {
@@ -601,7 +606,7 @@ func runDiskTest(output, tempOutput string) string {
}, tempOutput, output) }, tempOutput, output)
} }
func runStreamingTests(wg1 *sync.WaitGroup, mediaInfo string, output, tempOutput string) string { func runStreamingTests(wg1 *sync.WaitGroup, mediaInfo *string, output, tempOutput string, outputMutex *sync.Mutex) string {
return utils.PrintAndCapture(func() { return utils.PrintAndCapture(func() {
if language == "zh" { if language == "zh" {
if commTestStatus && !onlyChinaTest { if commTestStatus && !onlyChinaTest {
@@ -610,18 +615,18 @@ func runStreamingTests(wg1 *sync.WaitGroup, mediaInfo string, output, tempOutput
} }
} }
if utTestStatus && (language == "zh" && !onlyChinaTest || language == "en") { if utTestStatus && (language == "zh" && !onlyChinaTest || language == "en") {
wg1.Wait()
if language == "zh" { if language == "zh" {
utils.PrintCenteredTitle("跨国流媒体解锁", width) utils.PrintCenteredTitle("跨国流媒体解锁", width)
} else { } else {
utils.PrintCenteredTitle("Cross-Border-Streaming-Media-Unlock", width) utils.PrintCenteredTitle("Cross-Border-Streaming-Media-Unlock", width)
} }
fmt.Printf("%s", mediaInfo) fmt.Printf("%s", *mediaInfo)
} }
wg1.Wait()
}, tempOutput, output) }, tempOutput, output)
} }
func runSecurityTests(securityInfo string, output, tempOutput string) string { func runSecurityTests(securityInfo, output, tempOutput string, outputMutex *sync.Mutex) string {
return utils.PrintAndCapture(func() { return utils.PrintAndCapture(func() {
if securityTestStatus { if securityTestStatus {
if language == "zh" { if language == "zh" {
@@ -634,21 +639,21 @@ func runSecurityTests(securityInfo string, output, tempOutput string) string {
}, tempOutput, output) }, tempOutput, output)
} }
func runEmailTests(wg2 *sync.WaitGroup, emailInfo string, output, tempOutput string) string { func runEmailTests(wg2 *sync.WaitGroup, emailInfo *string, output, tempOutput string, outputMutex *sync.Mutex) string {
return utils.PrintAndCapture(func() { return utils.PrintAndCapture(func() {
if emailTestStatus { if emailTestStatus {
wg2.Wait()
if language == "zh" { if language == "zh" {
utils.PrintCenteredTitle("邮件端口检测", width) utils.PrintCenteredTitle("邮件端口检测", width)
} else { } else {
utils.PrintCenteredTitle("Email-Port-Check", width) utils.PrintCenteredTitle("Email-Port-Check", width)
} }
fmt.Println(emailInfo) fmt.Println(*emailInfo)
} }
wg2.Wait()
}, tempOutput, output) }, tempOutput, output)
} }
func runNetworkTests(wg3 *sync.WaitGroup, ptInfo string, output, tempOutput string) string { func runNetworkTests(wg3 *sync.WaitGroup, ptInfo *string, output, tempOutput string, outputMutex *sync.Mutex) string {
output = utils.PrintAndCapture(func() { output = utils.PrintAndCapture(func() {
if backtraceStatus && !onlyChinaTest { if backtraceStatus && !onlyChinaTest {
utils.PrintCenteredTitle("三网回程线路检测", width) utils.PrintCenteredTitle("三网回程线路检测", width)
@@ -667,14 +672,14 @@ func runNetworkTests(wg3 *sync.WaitGroup, ptInfo string, output, tempOutput stri
}, tempOutput, output) }, tempOutput, output)
return utils.PrintAndCapture(func() { return utils.PrintAndCapture(func() {
if onlyChinaTest || pingTestStatus { if onlyChinaTest || pingTestStatus {
wg3.Wait()
utils.PrintCenteredTitle("三网ICMP的PING值检测", width) utils.PrintCenteredTitle("三网ICMP的PING值检测", width)
fmt.Println(ptInfo) fmt.Println(*ptInfo)
} }
wg3.Wait()
}, tempOutput, output) }, tempOutput, output)
} }
func runSpeedTests(output, tempOutput string) string { func runSpeedTests(output, tempOutput string, outputMutex *sync.Mutex) string {
return utils.PrintAndCapture(func() { return utils.PrintAndCapture(func() {
if speedTestStatus { if speedTestStatus {
utils.PrintCenteredTitle("就近节点测速", width) utils.PrintCenteredTitle("就近节点测速", width)
@@ -694,7 +699,7 @@ func runSpeedTests(output, tempOutput string) string {
}, tempOutput, output) }, tempOutput, output)
} }
func runEnglishSpeedTests(output, tempOutput string) string { func runEnglishSpeedTests(output, tempOutput string, outputMutex *sync.Mutex) string {
return utils.PrintAndCapture(func() { return utils.PrintAndCapture(func() {
if speedTestStatus { if speedTestStatus {
utils.PrintCenteredTitle("Speed-Test", width) utils.PrintCenteredTitle("Speed-Test", width)
@@ -705,7 +710,7 @@ func runEnglishSpeedTests(output, tempOutput string) string {
}, tempOutput, output) }, tempOutput, output)
} }
func appendTimeInfo(output, tempOutput string, startTime time.Time) string { func appendTimeInfo(output, tempOutput string, startTime time.Time, outputMutex *sync.Mutex) string {
endTime := time.Now() endTime := time.Now()
duration := endTime.Sub(startTime) duration := endTime.Sub(startTime)
minutes := int(duration.Minutes()) minutes := int(duration.Minutes())
@@ -750,21 +755,21 @@ func main() {
} }
handleLanguageSpecificSettings() handleLanguageSpecificSettings()
var ( var (
startTime time.Time
wg1, wg2, wg3 sync.WaitGroup wg1, wg2, wg3 sync.WaitGroup
basicInfo, securityInfo, emailInfo, mediaInfo, ptInfo string basicInfo, securityInfo, emailInfo, mediaInfo, ptInfo string
output, tempOutput string output, tempOutput string
outputMutex sync.Mutex
) )
startTime := time.Now()
uploadDone := make(chan bool, 1) uploadDone := make(chan bool, 1)
sig := make(chan os.Signal, 1) sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
go handleSignalInterrupt(sig, &startTime, &output, tempOutput, uploadDone) go handleSignalInterrupt(sig, &startTime, &output, tempOutput, uploadDone, &outputMutex)
startTime = time.Now()
switch language { switch language {
case "zh": case "zh":
output = runChineseTests(preCheck, &wg1, &wg2, &wg3, &basicInfo, &securityInfo, &emailInfo, &mediaInfo, &ptInfo, output, tempOutput, startTime) output = runChineseTests(preCheck, &wg1, &wg2, &wg3, &basicInfo, &securityInfo, &emailInfo, &mediaInfo, &ptInfo, output, tempOutput, startTime, &outputMutex)
case "en": case "en":
output = runEnglishTests(preCheck, &wg1, &wg2, &basicInfo, &securityInfo, &emailInfo, &mediaInfo, output, tempOutput, startTime) output = runEnglishTests(preCheck, &wg1, &wg2, &basicInfo, &securityInfo, &emailInfo, &mediaInfo, output, tempOutput, startTime, &outputMutex)
default: default:
fmt.Println("Unsupported language") fmt.Println("Unsupported language")
} }

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# From https://github.com/oneclickvirt/ecs # From https://github.com/oneclickvirt/ecs
# 2025.06.05 # 2025.06.29
# 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
# 或 # 或
@@ -143,7 +143,7 @@ goecs_check() {
os=$(uname -s 2>/dev/null || echo "Unknown") os=$(uname -s 2>/dev/null || echo "Unknown")
arch=$(uname -m 2>/dev/null || echo "Unknown") arch=$(uname -m 2>/dev/null || echo "Unknown")
check_china check_china
ECS_VERSION="0.1.38" ECS_VERSION="0.1.42"
for api in \ for api in \
"https://api.github.com/repos/oneclickvirt/ecs/releases/latest" \ "https://api.github.com/repos/oneclickvirt/ecs/releases/latest" \
"https://githubapi.spiritlhl.workers.dev/repos/oneclickvirt/ecs/releases/latest" \ "https://githubapi.spiritlhl.workers.dev/repos/oneclickvirt/ecs/releases/latest" \
@@ -155,8 +155,8 @@ goecs_check() {
sleep 1 sleep 1
done done
if [ -z "$ECS_VERSION" ]; then if [ -z "$ECS_VERSION" ]; then
_yellow "Unable to get version info, using default version 0.1.38" _yellow "Unable to get version info, using default version 0.1.42"
ECS_VERSION="0.1.38" ECS_VERSION="0.1.42"
fi fi
version_output="" version_output=""
for cmd_path in "goecs" "./goecs" "/usr/bin/goecs" "/usr/local/bin/goecs"; do for cmd_path in "goecs" "./goecs" "/usr/bin/goecs" "/usr/local/bin/goecs"; do