From e55a18b3debf5a1c9856b7e7ae8a07deb6df1614 Mon Sep 17 00:00:00 2001 From: spiritlhl Date: Fri, 3 Jan 2025 13:53:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E4=BA=9B=E4=BF=AE=E5=A4=8D=E5=92=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新nt3依赖,增加自动重试机制 - 修改ctrl+c的终止命令时也支持自动上传测试结果并保存 - 优化安装命令,在无法识别系统/架构等情况下也尽量可使用默认的命令 --- go.mod | 26 +-- go.sum | 47 +++--- goecs.go | 56 ++++--- goecs.sh | 418 +++++++++++++++++++++++-------------------------- utils/utils.go | 43 +++-- 5 files changed, 296 insertions(+), 294 deletions(-) diff --git a/go.mod b/go.mod index f81aa89..1812c53 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module github.com/oneclickvirt/ecs -go 1.22.4 +go 1.22.10 + +toolchain go1.23.1 require ( github.com/imroc/req/v3 v3.49.0 @@ -13,7 +15,7 @@ require ( github.com/oneclickvirt/disktest v0.0.4-20240809053456 github.com/oneclickvirt/gostun v0.0.3-20240702054621 github.com/oneclickvirt/memorytest v0.0.4-20240820095126 - github.com/oneclickvirt/nt3 v0.0.3-20240809100110 + github.com/oneclickvirt/nt3 v0.0.4-20250103052821 github.com/oneclickvirt/pingtest v0.0.5-20241006123443 github.com/oneclickvirt/portchecker v0.0.2-20240803151204 github.com/oneclickvirt/security v0.0.4-20240729065854 @@ -26,8 +28,8 @@ require ( github.com/andybalholm/brotli v1.1.1 // indirect github.com/andybalholm/cascadia v1.3.2 // indirect github.com/cloudflare/circl v1.5.0 // indirect - github.com/fatih/color v1.17.0 // indirect - github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/fatih/color v1.18.0 // indirect + github.com/fsnotify/fsnotify v1.8.0 // indirect github.com/ghodss/yaml v1.0.0 // indirect github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect @@ -35,7 +37,7 @@ require ( github.com/google/gopacket v1.1.19 // indirect github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect github.com/google/uuid v1.6.0 // indirect - github.com/gorilla/websocket v1.5.2 // indirect + github.com/gorilla/websocket v1.5.3 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/hcl v1.0.0 // indirect @@ -50,20 +52,20 @@ require ( github.com/libp2p/go-netroute v0.2.1 // indirect github.com/lionsoul2014/ip2region v2.11.2+incompatible // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect - github.com/magiconair/properties v1.8.7 // indirect + github.com/magiconair/properties v1.8.9 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mattn/go-runewidth v0.0.15 // indirect + github.com/mattn/go-runewidth v0.0.16 // indirect github.com/miekg/dns v1.1.61 // indirect github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/nxtrace/NTrace-core v1.3.2 // indirect + github.com/nxtrace/NTrace-core v1.3.6 // indirect github.com/onsi/ginkgo/v2 v2.22.1 // indirect github.com/oschwald/maxminddb-golang v1.13.1 // indirect - github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/pion/dtls/v2 v2.2.7 // indirect github.com/pion/logging v0.2.2 // indirect github.com/pion/stun/v2 v2.0.0 // indirect @@ -76,7 +78,7 @@ require ( github.com/quic-go/quic-go v0.48.2 // indirect github.com/refraction-networking/utls v1.6.7 // indirect github.com/rivo/uniseg v0.4.7 // indirect - github.com/rodaine/table v1.2.0 // indirect + github.com/rodaine/table v1.3.0 // indirect github.com/sagikazarmark/locafero v0.6.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/schollz/progressbar/v3 v3.14.4 // indirect @@ -86,11 +88,11 @@ require ( github.com/showwin/speedtest-go v1.7.7 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect - github.com/spf13/cast v1.6.0 // indirect + github.com/spf13/cast v1.7.1 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.19.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect - github.com/tidwall/gjson v1.17.1 // indirect + github.com/tidwall/gjson v1.18.0 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect github.com/tklauser/go-sysconf v0.3.14 // indirect diff --git a/go.sum b/go.sum index 1ea95fa..18b93ef 100644 --- a/go.sum +++ b/go.sum @@ -12,12 +12,12 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= -github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= +github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= +github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= -github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= -github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M= +github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= @@ -39,8 +39,8 @@ github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/Z github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/websocket v1.5.2 h1:qoW6V1GT3aZxybsbC6oLnailWnB+qTMVwMreOso9XUw= -github.com/gorilla/websocket v1.5.2/go.mod h1:0n9H61RBAcf5/38py2MCYbxzPIY9rOkpvvMT24Rqs30= +github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= +github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -78,15 +78,15 @@ github.com/lionsoul2014/ip2region v2.11.2+incompatible h1:+VRsGcrHz8ewXI/2UzTptJ github.com/lionsoul2014/ip2region v2.11.2+incompatible/go.mod h1:+ZBN7PBoh5gG6/y0ZQ85vJDBe21WnfbRrQQwTfliJJI= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= -github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= -github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/magiconair/properties v1.8.9 h1:nWcCbLq1N2v/cpNsy5WvQ37Fb+YElfq20WJ/a8RkpQM= +github.com/magiconair/properties v1.8.9/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= -github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= +github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/miekg/dns v1.1.61 h1:nLxbwF3XxhwVSm8g9Dghm9MHPaUZuqhPiGL+675ZmEs= github.com/miekg/dns v1.1.61/go.mod h1:mnAarhS3nWaW+NVP2wTkYVIZyHNJ098SJZUki3eykwQ= github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= @@ -100,8 +100,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/nxtrace/NTrace-core v1.3.2 h1:8aU/IQFmPnwbaWGVBIJHwwVIWk+roo+9+lG+U0OFZ+o= -github.com/nxtrace/NTrace-core v1.3.2/go.mod h1:qCVsgSs982jw02BVjTtN8mjSg5OIXW9TaUdISQrMnTw= +github.com/nxtrace/NTrace-core v1.3.6 h1:2VbytjCUUBKNb0MwPg/KwF3NfZdg/mup0KPUVbwL4eg= +github.com/nxtrace/NTrace-core v1.3.6/go.mod h1:gnArhBqgO1j29LH9KIy/tddQY8PpYdwsZJCuaelrJXw= 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/UnlockTests v0.0.22-20241221103638 h1:31Ek7CLX94vWzbU4fysqCxn7scC53Zk4OhlaB3OQDYQ= @@ -120,8 +120,8 @@ github.com/oneclickvirt/gostun v0.0.3-20240702054621 h1:IE89eEYV9TJbF94SakQDAxTL github.com/oneclickvirt/gostun v0.0.3-20240702054621/go.mod h1:f7DPEXAxbmwXSW33dbxtb0/KzqvOBWhTs2Or5xBerQA= github.com/oneclickvirt/memorytest v0.0.4-20240820095126 h1:Il3rvWkrZy/6B2iO3HRe9039/qRllA4CzcZ/dI8aG2A= 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/go.mod h1:4SDl5o83wbixk9YJqvG0eNo2w8aWt/QgntfPBi9wEpY= +github.com/oneclickvirt/nt3 v0.0.4-20250103052821 h1:0c7pcAriroa12VOSro+/CfzN0mbiKJG+cvqbsPtH+BM= +github.com/oneclickvirt/nt3 v0.0.4-20250103052821/go.mod h1:4OURspZirunYgme1bvImFCPgZW2XzNtkvnBNKvIlFUU= github.com/oneclickvirt/pingtest v0.0.5-20241006123443 h1:Ywrh0Yd/PYXOKGE8VaNiKGWlIqdgLLgsthAzxy0t7s8= 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= @@ -136,8 +136,8 @@ github.com/onsi/gomega v1.36.1 h1:bJDPBO7ibjxcbHMgSCoo4Yj18UWbKDlLwX1x9sybDcw= github.com/onsi/gomega v1.36.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog= github.com/oschwald/maxminddb-golang v1.13.1 h1:G3wwjdN9JmIK2o/ermkHM+98oX5fS+k5MbwsmL4MRQE= github.com/oschwald/maxminddb-golang v1.13.1/go.mod h1:K4pgV9N/GcK694KSTmVSDTODk4IsCNThNdTmnaBZ/F8= -github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= -github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= +github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= github.com/pion/dtls/v2 v2.2.7 h1:cSUBsETxepsCSFSxC3mc/aDo14qQLMSL+O6IjG28yV8= github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s= github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY= @@ -166,8 +166,8 @@ github.com/refraction-networking/utls v1.6.7/go.mod h1:BC3O4vQzye5hqpmDTWUqi4P5D github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= -github.com/rodaine/table v1.2.0 h1:38HEnwK4mKSHQJIkavVj+bst1TEY7j9zhLMWu4QJrMA= -github.com/rodaine/table v1.2.0/go.mod h1:wejb/q/Yd4T/SVmBSRMr7GCq3KlcZp3gyNYdLSBhkaE= +github.com/rodaine/table v1.3.0 h1:4/3S3SVkHnVZX91EHFvAMV7K42AnJ0XuymRR2C5HlGE= +github.com/rodaine/table v1.3.0/go.mod h1:47zRsHar4zw0jgxGxL9YtFfs7EGN6B/TaS+/Dmk4WxU= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/sagikazarmark/locafero v0.6.0 h1:ON7AQg37yzcRPU69mt7gwhFEBwxI6P9T4Qu3N51bwOk= @@ -190,8 +190,8 @@ github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9yS github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= -github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= -github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y= +github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= @@ -205,12 +205,13 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= -github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U= -github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY= +github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= diff --git a/goecs.go b/goecs.go index 5b55b77..e7b73dc 100644 --- a/goecs.go +++ b/goecs.go @@ -39,7 +39,7 @@ import ( ) var ( - ecsVersion = "v0.1.01" + ecsVersion = "v0.1.2" menuMode bool onlyChinaTest bool input, choice string @@ -308,29 +308,47 @@ func main() { basicInfo, securityInfo, emailInfo, mediaInfo, ptInfo string output, tempOutput string ) - // 设置主程序的信号处理 + // 信号处理部分 + uploadDone := make(chan bool, 1) sig := make(chan os.Signal, 1) signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) - // 启动一个goroutine来等待信号,内置计时器 + // 启动一个goroutine来等待信号 go func() { startTime = time.Now() - // 等待信号 - <-sig - if !finish { - endTime := time.Now() - duration := endTime.Sub(startTime) - minutes := int(duration.Minutes()) - seconds := int(duration.Seconds()) % 60 - currentTime := time.Now().Format("Mon Jan 2 15:04:05 MST 2006") - output = utils.PrintAndCapture(func() { - utils.PrintCenteredTitle("", width) - fmt.Printf("Cost Time : %d min %d sec\n", minutes, seconds) - fmt.Printf("Current Time : %s\n", currentTime) - utils.PrintCenteredTitle("", width) - }, tempOutput, output) - utils.ProcessAndUpload(output, filePath, enabelUpload) + select { + case <-sig: + if !finish { + endTime := time.Now() + duration := endTime.Sub(startTime) + minutes := int(duration.Minutes()) + seconds := int(duration.Seconds()) % 60 + currentTime := time.Now().Format("Mon Jan 2 15:04:05 MST 2006") + // 使用互斥锁保护output的写入 + var mu sync.Mutex + mu.Lock() + output = utils.PrintAndCapture(func() { + utils.PrintCenteredTitle("", width) + fmt.Printf("Cost Time : %d min %d sec\n", minutes, seconds) + fmt.Printf("Current Time : %s\n", currentTime) + utils.PrintCenteredTitle("", width) + }, tempOutput, output) + mu.Unlock() + // 启动新的goroutine处理上传 + go func() { + utils.ProcessAndUpload(output, filePath, enabelUpload) + uploadDone <- true + }() + // 等待上传完成或超时 + select { + case <-uploadDone: + os.Exit(0) + case <-time.After(30 * time.Second): + fmt.Println("上传超时,程序退出") + os.Exit(1) + } + } + os.Exit(0) } - os.Exit(0) }() switch language { case "zh": diff --git a/goecs.sh b/goecs.sh index 35f5860..fcc4b42 100644 --- a/goecs.sh +++ b/goecs.sh @@ -150,201 +150,149 @@ cleanup_epel() { } goecs_check() { - os=$(uname -s) - arch=$(uname -m) - # 先进行中国IP检测 + # Get system and architecture info with error handling + os=$(uname -s 2>/dev/null || echo "Unknown") + arch=$(uname -m 2>/dev/null || echo "Unknown") + # First check for China IP check_china - ECS_VERSION=$(curl -m 6 -sSL "https://api.github.com/repos/oneclickvirt/ecs/releases/latest" | awk -F \" '/tag_name/{gsub(/^v/,"",$4); print $4}') - # 如果 https://api.github.com/ 请求失败,则使用 https://githubapi.spiritlhl.workers.dev/ ,此时可能宿主机无IPV4网络 + # Get latest version number with multiple backup sources + ECS_VERSION="" + for api in \ + "https://api.github.com/repos/oneclickvirt/ecs/releases/latest" \ + "https://githubapi.spiritlhl.workers.dev/repos/oneclickvirt/ecs/releases/latest" \ + "https://githubapi.spiritlhl.top/repos/oneclickvirt/ecs/releases/latest"; do + ECS_VERSION=$(curl -m 6 -sSL "$api" | awk -F \" '/tag_name/{gsub(/^v/,"",$4); print $4}') + if [ -n "$ECS_VERSION" ]; then + break + fi + sleep 1 + done if [ -z "$ECS_VERSION" ]; then - ECS_VERSION=$(curl -m 6 -sSL "https://githubapi.spiritlhl.workers.dev/repos/oneclickvirt/ecs/releases/latest" | awk -F \" '/tag_name/{gsub(/^v/,"",$4); print $4}') + _yellow "Unable to get version info, using default version 0.1.2" + ECS_VERSION="0.1.2" fi - # 如果 https://githubapi.spiritlhl.workers.dev/ 请求失败,则使用 https://githubapi.spiritlhl.top/ ,此时可能宿主机在国内 - if [ -z "$ECS_VERSION" ]; then - 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 command 2>/dev/null || ./goecs -v command 2>/dev/null) - if [ $? -eq 0 ]; then + # Check if original goecs command exists + version_output="" + for cmd_path in "goecs" "./goecs" "/usr/bin/goecs" "/usr/local/bin/goecs"; do + if [ -x "$(command -v $cmd_path 2>/dev/null)" ]; then + version_output=$($cmd_path -v command 2>/dev/null) + break + fi + done + if [ -n "$version_output" ]; then extracted_version=${version_output//v/} if [ -n "$extracted_version" ]; then ecs_version=$ECS_VERSION if [[ "$(echo -e "$extracted_version\n$ecs_version" | sort -V | tail -n 1)" == "$extracted_version" ]]; then - _green "goecs version ($extracted_version) is latest, no need to upgrade." + _green "goecs version ($extracted_version) is up to date, no upgrade needed" return else - _yellow "goecs version ($extracted_version) < $ecs_version, need to upgrade, 5 seconds later will start to upgrade" - rm -rf /usr/bin/goecs - rm -rf goecs + _yellow "goecs version ($extracted_version) < $ecs_version, upgrade needed, starting in 5 seconds" + rm -rf /usr/bin/goecs /usr/local/bin/goecs ./goecs fi fi else - _green "Can not find goecs, need to download and install, 5 seconds later will start to install" + _green "goecs not found, installation needed, starting in 5 seconds" fi sleep 5 + # Download corresponding version with error handling if [[ "$CN" == true ]]; then - _yellow "使用中国镜像下载..." - case $os in - Linux) - case $arch in - "x86_64" | "x86" | "amd64" | "x64") - download_file "https://cnb.cool/oneclickvirt/ecs/-/git/raw/main/goecs_linux_amd64.zip" "goecs.zip" - ;; - "i386" | "i686") - download_file "https://cnb.cool/oneclickvirt/ecs/-/git/raw/main/goecs_linux_386.zip" "goecs.zip" - ;; - "armv7l" | "armv8" | "armv8l" | "aarch64" | "arm64") - download_file "https://cnb.cool/oneclickvirt/ecs/-/git/raw/main/goecs_linux_arm64.zip" "goecs.zip" - ;; - "mips") - download_file "https://cnb.cool/oneclickvirt/ecs/-/git/raw/main/goecs_linux_mips.zip" "goecs.zip" - ;; - "mipsle") - download_file "https://cnb.cool/oneclickvirt/ecs/-/git/raw/main/goecs_linux_mipsle.zip" "goecs.zip" - ;; - "s390x") - download_file "https://cnb.cool/oneclickvirt/ecs/-/git/raw/main/goecs_linux_s390x.zip" "goecs.zip" - ;; - "riscv64") - download_file "https://cnb.cool/oneclickvirt/ecs/-/git/raw/main/goecs_linux_riscv64.zip" "goecs.zip" - ;; - *) - _red "不支持的架构: $arch" - exit 1 - ;; - esac - ;; - FreeBSD) - case $arch in - "x86_64" | "x86" | "amd64" | "x64") - download_file "https://cnb.cool/oneclickvirt/ecs/-/git/raw/main/goecs_freebsd_amd64.zip" "goecs.zip" - ;; - "i386" | "i686") - download_file "https://cnb.cool/oneclickvirt/ecs/-/git/raw/main/goecs_freebsd_386.zip" "goecs.zip" - ;; - "armv7l" | "armv8" | "armv8l" | "aarch64" | "arm64") - download_file "https://cnb.cool/oneclickvirt/ecs/-/git/raw/main/goecs_freebsd_arm64.zip" "goecs.zip" - ;; - *) - _red "不支持的架构: $arch" - exit 1 - ;; - esac - ;; - Darwin) - case $arch in - "x86_64" | "x86" | "amd64" | "x64") - download_file "https://cnb.cool/oneclickvirt/ecs/-/git/raw/main/goecs_darwin_amd64.zip" "goecs.zip" - ;; - "armv7l" | "armv8" | "armv8l" | "aarch64" | "arm64") - download_file "https://cnb.cool/oneclickvirt/ecs/-/git/raw/main/goecs_darwin_arm64.zip" "goecs.zip" - ;; - *) - _red "不支持的架构: $arch" - exit 1 - ;; - esac - ;; - *) - _red "不支持的操作系统: $os" - exit 1 - ;; - esac + _yellow "Using China mirror for download..." + base_url="https://cnb.cool/oneclickvirt/ecs/-/git/raw/main" else cdn_urls=("https://cdn0.spiritlhl.top/" "http://cdn3.spiritlhl.net/" "http://cdn1.spiritlhl.net/" "http://cdn2.spiritlhl.net/") check_cdn_file - case $os in - Linux) - case $arch in - "x86_64" | "x86" | "amd64" | "x64") - download_file "${cdn_success_url}https://github.com/oneclickvirt/ecs/releases/download/v${ECS_VERSION}/goecs_linux_amd64.zip" "goecs.zip" - ;; - "i386" | "i686") - download_file "${cdn_success_url}https://github.com/oneclickvirt/ecs/releases/download/v${ECS_VERSION}/goecs_linux_386.zip" "goecs.zip" - ;; - "armv7l" | "armv8" | "armv8l" | "aarch64" | "arm64") - download_file "${cdn_success_url}https://github.com/oneclickvirt/ecs/releases/download/v${ECS_VERSION}/goecs_linux_arm64.zip" "goecs.zip" - ;; - "mips") - download_file "${cdn_success_url}https://github.com/oneclickvirt/ecs/releases/download/v${ECS_VERSION}/goecs_linux_mips.zip" "goecs.zip" - ;; - "mipsle") - download_file "${cdn_success_url}https://github.com/oneclickvirt/ecs/releases/download/v${ECS_VERSION}/goecs_linux_mipsle.zip" "goecs.zip" - ;; - "s390x") - download_file "${cdn_success_url}https://github.com/oneclickvirt/ecs/releases/download/v${ECS_VERSION}/goecs_linux_s390x.zip" "goecs.zip" - ;; - "riscv64") - download_file "${cdn_success_url}https://github.com/oneclickvirt/ecs/releases/download/v${ECS_VERSION}/goecs_linux_riscv64.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." - exit 1 - ;; - esac - ;; - FreeBSD) - case $arch in - "x86_64" | "x86" | "amd64" | "x64") - download_file "${cdn_success_url}https://github.com/oneclickvirt/ecs/releases/download/v${ECS_VERSION}/goecs_freebsd_amd64.zip" "goecs.zip" - ;; - "i386" | "i686") - download_file "${cdn_success_url}https://github.com/oneclickvirt/ecs/releases/download/v${ECS_VERSION}/goecs_freebsd_386.zip" "goecs.zip" - ;; - "armv7l" | "armv8" | "armv8l" | "aarch64" | "arm64") - download_file "${cdn_success_url}https://github.com/oneclickvirt/ecs/releases/download/v${ECS_VERSION}/goecs_freebsd_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." - exit 1 - ;; - esac - ;; - Darwin) - case $arch in - "x86_64" | "x86" | "amd64" | "x64") - 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") - 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." - exit 1 - ;; - esac - ;; - *) - _red "Unsupported operating system: $os , please check https://github.com/oneclickvirt/ecs/releases to download the zip for yourself and unzip it to use the binary for testing." - exit 1 - ;; - esac - fi - unzip goecs.zip - rm -rf goecs.zip - rm -rf README.md - rm -rf LICENSE - sleep 1 - chmod 777 goecs - rm -rf /usr/bin/goecs - sleep 1 - cp goecs /usr/bin/goecs - rm -rf README_EN.md - rm -rf README.md - PARAM="net.ipv4.ping_group_range" - NEW_VALUE="0 2147483647" - CURRENT_VALUE=$(sysctl -n "$PARAM" 2>/dev/null) - if [ -f /etc/sysctl.conf ] && [ "$CURRENT_VALUE" != "$NEW_VALUE" ]; then - if grep -q "^$PARAM" /etc/sysctl.conf; then - sudo sed -i "s/^$PARAM.*/$PARAM = $NEW_VALUE/" /etc/sysctl.conf + if [ -n "$cdn_success_url" ]; then + base_url="${cdn_success_url}https://github.com/oneclickvirt/ecs/releases/download/v${ECS_VERSION}" else - echo "$PARAM = $NEW_VALUE" | sudo tee -a /etc/sysctl.conf + base_url="https://github.com/oneclickvirt/ecs/releases/download/v${ECS_VERSION}" fi - sudo sysctl -p fi - setcap cap_net_raw=+ep goecs - setcap cap_net_raw=+ep /usr/bin/goecs - echo "goecs version:" + # Build download URL with architecture support + local zip_file="" + case $os in + Linux|linux|LINUX) + case $arch in + x86_64|amd64|x64) zip_file="goecs_linux_amd64.zip" ;; + i386|i686) zip_file="goecs_linux_386.zip" ;; + aarch64|arm64|armv8|armv8l) zip_file="goecs_linux_arm64.zip" ;; + arm|armv7l) zip_file="goecs_linux_arm.zip" ;; + mips) zip_file="goecs_linux_mips.zip" ;; + mipsle) zip_file="goecs_linux_mipsle.zip" ;; + s390x) zip_file="goecs_linux_s390x.zip" ;; + riscv64) zip_file="goecs_linux_riscv64.zip" ;; + *) zip_file="goecs_linux_amd64.zip" ;; + esac + ;; + FreeBSD|freebsd) + case $arch in + x86_64|amd64) zip_file="goecs_freebsd_amd64.zip" ;; + i386|i686) zip_file="goecs_freebsd_386.zip" ;; + arm64|aarch64) zip_file="goecs_freebsd_arm64.zip" ;; + *) zip_file="goecs_freebsd_amd64.zip" ;; + esac + ;; + Darwin|darwin) + case $arch in + x86_64|amd64) zip_file="goecs_darwin_amd64.zip" ;; + arm64|aarch64) zip_file="goecs_darwin_arm64.zip" ;; + *) zip_file="goecs_darwin_amd64.zip" ;; + esac + ;; + *) + _yellow "Unknown system $os, trying amd64 version" + zip_file="goecs_linux_amd64.zip" + ;; + esac + download_url="${base_url}/${zip_file}" + _green "Downloading $download_url" + # Download file with retry mechanism + local max_retries=3 + local retry_count=0 + while [ $retry_count -lt $max_retries ]; do + if download_file "$download_url" "goecs.zip"; then + break + fi + _yellow "Download failed, retrying (${retry_count}/${max_retries})..." + retry_count=$((retry_count + 1)) + sleep 2 + done + if [ $retry_count -eq $max_retries ]; then + _red "Download failed, please check your network connection or download manually" + return 1 + fi + # Extract and install with error handling + if ! unzip -o goecs.zip >/dev/null 2>&1; then + _red "Extraction failed" + return 1 + fi + rm -f goecs.zip README.md LICENSE README_EN.md + # Set execution permissions and install + chmod 777 goecs + for install_path in "/usr/bin" "/usr/local/bin"; do + if [ -d "$install_path" ]; then + cp -f goecs "$install_path/" + break + fi + done + # Set system parameters + if [ "$os" != "Darwin" ]; then + PARAM="net.ipv4.ping_group_range" + NEW_VALUE="0 2147483647" + if [ -f /etc/sysctl.conf ]; then + if grep -q "^$PARAM" /etc/sysctl.conf; then + sed -i "s/^$PARAM.*/$PARAM = $NEW_VALUE/" /etc/sysctl.conf + else + echo "$PARAM = $NEW_VALUE" >> /etc/sysctl.conf + fi + sysctl -p >/dev/null 2>&1 + fi + fi + # Set special permissions + setcap cap_net_raw=+ep goecs 2>/dev/null + setcap cap_net_raw=+ep /usr/bin/goecs 2>/dev/null + setcap cap_net_raw=+ep /usr/local/bin/goecs 2>/dev/null + _green "goecs installation complete, current version:" goecs -v || ./goecs -v } @@ -509,7 +457,7 @@ env_check() { PACKAGE_INSTALL=("apt-get -y install" "apt-get -y install" "yum -y install" "yum -y install" "yum -y install" "pacman -Sy --noconfirm --needed" "pkg install -y" "apk add --no-cache" "pkg_add -I" "yum -y install") PACKAGE_REMOVE=("apt-get -y remove" "apt-get -y remove" "yum -y remove" "yum -y remove" "yum -y remove" "pacman -Rsc --noconfirm" "pkg delete" "apk del" "pkg_delete -I" "yum -y remove") PACKAGE_UNINSTALL=("apt-get -y autoremove" "apt-get -y autoremove" "yum -y autoremove" "yum -y autoremove" "yum -y autoremove" "pacman -Rns --noconfirm" "pkg autoremove" "apk autoremove" "pkg_delete -a" "yum -y autoremove") - # 检查系统信息 + # Check system information if [ -f /etc/opencloudos-release ]; then SYS="opencloudos" elif [ -s /etc/os-release ]; then @@ -527,65 +475,97 @@ env_check() { else SYS="$(uname -s)" fi - [[ -n $SYS ]] || exit 1 - - # 匹配操作系统 + # Match operating system + SYSTEM="" for ((int = 0; int < ${#REGEX[@]}; int++)); do if [[ $(echo "$SYS" | tr '[:upper:]' '[:lower:]') =~ ${REGEX[int]} ]]; then SYSTEM="${RELEASE[int]}" - [[ -n $SYSTEM ]] && break + UPDATE_CMD=${PACKAGE_UPDATE[int]} + INSTALL_CMD=${PACKAGE_INSTALL[int]} + REMOVE_CMD=${PACKAGE_REMOVE[int]} + UNINSTALL_CMD=${PACKAGE_UNINSTALL[int]} + break fi done - - # 检查是否成功匹配 - [[ -n $SYSTEM ]] || exit 1 - - # 根据 SYSTEM 设置相应的包管理命令 - UPDATE_CMD=${PACKAGE_UPDATE[int]} - INSTALL_CMD=${PACKAGE_INSTALL[int]} - REMOVE_CMD=${PACKAGE_REMOVE[int]} - UNINSTALL_CMD=${PACKAGE_UNINSTALL[int]} - - echo "System: $SYSTEM" - echo "Update command: $UPDATE_CMD" - echo "Install command: $INSTALL_CMD" - echo "Remove command: $REMOVE_CMD" - echo "Uninstall command: $UNINSTALL_CMD" - + # If system is unrecognized, try common package managers + if [ -z "$SYSTEM" ]; then + _yellow "Unable to recognize system, trying common package managers..." + # Try apt + if command -v apt-get >/dev/null 2>&1; then + SYSTEM="Unknown-Debian" + UPDATE_CMD="apt-get update" + INSTALL_CMD="apt-get -y install" + REMOVE_CMD="apt-get -y remove" + UNINSTALL_CMD="apt-get -y autoremove" + # Try yum + elif command -v yum >/dev/null 2>&1; then + SYSTEM="Unknown-RHEL" + UPDATE_CMD="yum -y update" + INSTALL_CMD="yum -y install" + REMOVE_CMD="yum -y remove" + UNINSTALL_CMD="yum -y autoremove" + # Try dnf + elif command -v dnf >/dev/null 2>&1; then + SYSTEM="Unknown-Fedora" + UPDATE_CMD="dnf -y update" + INSTALL_CMD="dnf -y install" + REMOVE_CMD="dnf -y remove" + UNINSTALL_CMD="dnf -y autoremove" + # Try pacman + elif command -v pacman >/dev/null 2>&1; then + SYSTEM="Unknown-Arch" + UPDATE_CMD="pacman -Sy" + INSTALL_CMD="pacman -S --noconfirm" + REMOVE_CMD="pacman -R --noconfirm" + UNINSTALL_CMD="pacman -Rns --noconfirm" + # Try apk + elif command -v apk >/dev/null 2>&1; then + SYSTEM="Unknown-Alpine" + UPDATE_CMD="apk update" + INSTALL_CMD="apk add" + REMOVE_CMD="apk del" + UNINSTALL_CMD="apk del" + else + _red "Unable to recognize package manager, exiting installation" + exit 1 + fi + fi + _green "System information: $SYSTEM" + _green "Update command: $UPDATE_CMD" + _green "Install command: $INSTALL_CMD" cdn_urls=("https://cdn0.spiritlhl.top/" "http://cdn3.spiritlhl.net/" "http://cdn1.spiritlhl.net/" "http://cdn2.spiritlhl.net/") check_cdn_file _yellow "Warning: System update will be performed" _yellow "This operation may:" - _yellow "1. Take significant time to complete" + _yellow "1. Take considerable time" _yellow "2. Cause temporary network interruptions" _yellow "3. Impact system stability" - _yellow "4. Affect future system startup" + _yellow "4. Affect subsequent system startups" if [ "$noninteractive" != "true" ]; then - reading "Do you want to proceed with system update? (y/N): " update_confirm + reading "Continue with system update? (y/N): " update_confirm if [[ ! $update_confirm =~ ^[Yy]$ ]]; then _yellow "Skipping system update" - _yellow "Note: Some package installations may fail" + _yellow "Note: Some packages may fail to install" else _green "Updating system package manager..." - if ! ${PACKAGE_UPDATE[int]} 2>/dev/null; then + if ! ${UPDATE_CMD} 2>/dev/null; then _red "System update failed!" fi fi fi - - # 安装必要的命令 + # Install necessary commands for cmd in sudo wget tar unzip iproute2 systemd-detect-virt dd fio; do if ! command -v "$cmd" >/dev/null 2>&1; then _green "Installing $cmd" - ${PACKAGE_INSTALL[int]} "$cmd" + ${INSTALL_CMD} "$cmd" fi done - + # sysbench installation if ! command -v sysbench >/dev/null 2>&1; then _green "Installing sysbench" - ${PACKAGE_INSTALL[int]} sysbench + ${INSTALL_CMD} sysbench if [ $? -ne 0 ]; then - echo "Unable to download sysbench through the system's package manager, trying to compile and install it..." + echo "Unable to download sysbench through package manager, attempting compilation..." 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" if [ ! -f /tmp/sysbench.zip ]; then wget -q -O /tmp/sysbench.zip "https://hub.fgit.cf/akopytov/sysbench/archive/1.0.20.zip" @@ -595,40 +575,28 @@ env_check() { Check_SysBench fi fi - + # geekbench and speedtest installation if ! command -v geekbench >/dev/null 2>&1; then _green "Installing geekbench" 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 - _blue "If you do not want to use geekbench5, you can use" - echo "bash dgb.sh -v gb6" - echo "bash dgb.sh -v gb4" - _blue "to change version, or use" - echo "rm -rf /usr/bin/geekbench*" - _blue "to uninstall geekbench" rm -rf dgb.sh fi - if ! command -v speedtest >/dev/null 2>&1; then _green "Installing speedtest" curl -L "${cdn_success_url}https://raw.githubusercontent.com/oneclickvirt/speedtest/main/dspt.sh" -o dspt.sh && chmod +x dspt.sh bash dspt.sh rm -rf dspt.sh rm -rf speedtest.tar.gz - _blue "if you want to use golang original speedtest, you can use" - echo "rm -rf /usr/bin/speedtest" - echo "rm -rf /usr/bin/speedtest-go" - _blue "to uninstall speedtest and speedtest-go" fi - if ! command -v ping >/dev/null 2>&1; then _green "Installing ping" - ${PACKAGE_INSTALL[int]} iputils-ping >/dev/null 2>&1 - ${PACKAGE_INSTALL[int]} ping >/dev/null 2>&1 + ${INSTALL_CMD} iputils-ping >/dev/null 2>&1 + ${INSTALL_CMD} ping >/dev/null 2>&1 fi - + # MacOS support if [ "$(uname -s)" = "Darwin" ]; then - echo "Detected MacOS. Installing sysbench iproute2mac fio..." + echo "Detected MacOS, installing sysbench iproute2mac fio..." brew install --force sysbench iproute2mac fio else if ! grep -q "^net.ipv4.ping_group_range = 0 2147483647$" /etc/sysctl.conf; then @@ -636,8 +604,8 @@ env_check() { sysctl -p fi fi - _green "The environment is ready." - _green "The next command is: ./goecs.sh install" + _green "Environment preparation complete." + _green "Next command is: ./goecs.sh install" } uninstall_goecs() { diff --git a/utils/utils.go b/utils/utils.go index edb3e1b..5470f83 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -1,6 +1,7 @@ package utils import ( + "bufio" "bytes" "fmt" "github.com/imroc/req/v3" @@ -299,19 +300,25 @@ func UploadText(absPath string) (string, string, error) { // ProcessAndUpload 创建结果文件并上传文件 func ProcessAndUpload(output string, filePath string, enableUplaod bool) { + // 使用 defer 来处理 panic + defer func() { + if r := recover(); r != nil { + fmt.Printf("处理上传时发生错误: %v\n", r) + } + }() // 检查文件是否存在 if _, err := os.Stat(filePath); err == nil { // 文件存在,删除文件 err = os.Remove(filePath) if err != nil { - fmt.Println("Cannot delete file:", err) + fmt.Println("无法删除文件:", err) return } } // 创建文件 file, err := os.Create(filePath) if err != nil { - fmt.Println("Cannot create file:", err) + fmt.Println("无法创建文件:", err) return } defer file.Close() @@ -319,28 +326,34 @@ func ProcessAndUpload(output string, filePath string, enableUplaod bool) { ansiRegex := regexp.MustCompile("\x1B\\[[0-9;]+[a-zA-Z]") // 移除 ANSI 转义序列 cleanedOutput := ansiRegex.ReplaceAllString(output, "") - // 写入文件 - _, err = file.WriteString(cleanedOutput) + // 使用 bufio.Writer 提高写入效率 + writer := bufio.NewWriter(file) + _, err = writer.WriteString(cleanedOutput) if err != nil { - fmt.Println("Cannot write to file:", err) + fmt.Println("无法写入文件:", err) return - } else { - fmt.Println("Write test result in ", filePath) } + // 确保写入缓冲区的数据都刷新到文件中 + err = writer.Flush() + if err != nil { + fmt.Println("无法刷新文件缓冲:", err) + return + } + fmt.Printf("测试结果已写入 %s\n", filePath) if enableUplaod { // 获取文件的绝对路径 - absPath, err2 := filepath.Abs(filePath) - if err2 != nil { - fmt.Println("Failed to get absolute file path:", err2) + absPath, err := filepath.Abs(filePath) + if err != nil { + fmt.Println("无法获取文件绝对路径:", err) return } // 上传文件并生成短链接 - http_url, https_url, err3 := UploadText(absPath) - if err3 != nil { - fmt.Println("Upload failed, cannot generate short URL.") - fmt.Println(err3.Error()) + http_url, https_url, err := UploadText(absPath) + if err != nil { + fmt.Println("上传失败,无法生成链接") + fmt.Println(err.Error()) return } - fmt.Printf("Upload successful!\nHttp URL: %s\nHttps URL: %s\n", http_url, https_url) + fmt.Printf("上传成功!\nHttp URL: %s\nHttps URL: %s\n", http_url, https_url) } }