Compare commits

..

15 Commits

Author SHA1 Message Date
spiritlhl
d80f3451ff v0.0.87 修复部分流媒体检测错误识别Ban为No的问题 2024-12-07 21:25:53 +08:00
spiritlhl
ebce9e493d v0.0.86 增加GooglePlay流媒体检测 2024-11-23 21:01:20 +08:00
spiritlhl
176899d3e9 Update 2024-11-18 13:19:11 +08:00
spiritlhl
e58da9e921 Update 2024-11-18 13:09:43 +08:00
spiritlhl
651bbb94d0 Add noninteractive option 2024-11-18 12:54:09 +08:00
spiritlhl
91ffbfa417 v0.0.85 更新分区模块,更新shell相关脚本修复隐藏BUG 2024-11-18 11:24:36 +08:00
spiritlhl
84b0303468 2024.11.17 2024-11-17 08:58:14 +00:00
spiritlhl
f3e10a999b 2024.11.17 更新shell相关内容,支持epel安装回退和可选是否更新包管理器 2024-11-17 08:38:52 +00:00
spiritlhl
76a6e09d97 2024.11.17 更新shell相关内容,支持epel安装回退和可选是否更新包管理器 2024-11-17 08:37:32 +00:00
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
9 changed files with 260 additions and 103 deletions

View File

@@ -4,9 +4,9 @@ FROM alpine:latest
# 安装必要的工具 # 安装必要的工具
RUN apk add --no-cache wget curl bash RUN apk add --no-cache wget curl bash
RUN apk add --no-cache bind-tools --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main RUN apk add --no-cache bind-tools --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main
RUN apk add --no-cache grep openssl ca-certificates uuidgen RUN apk add --no-cache grep openssl ca-certificates uuidgen
RUN export noninteractive=true
# 下载并执行 goecs.sh 脚本 # 下载并执行 goecs.sh 脚本
RUN curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && \ RUN curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && \
chmod +x goecs.sh && \ chmod +x goecs.sh && \

View File

@@ -47,13 +47,13 @@ Shell版本 https://github.com/spiritLHLS/ecs
### 一键命令 ### 一键命令
``` ```
curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh && bash goecs.sh env && bash goecs.sh install && goecs export noninteractive=true && curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh && bash goecs.sh env && bash goecs.sh install && goecs
``` ```
``` ```
curl -L https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh && bash goecs.sh env && bash goecs.sh install && goecs export noninteractive=true && curl -L https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh && bash goecs.sh env && bash goecs.sh install && goecs
``` ```
### 详细说明 ### 详细说明
@@ -70,12 +70,14 @@ curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o go
curl -L https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh curl -L https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh
``` ```
安装环境 更新包管理器(可选择)和安装环境
``` ```
./goecs.sh env ./goecs.sh env
``` ```
如果不想要互动,可使用```export noninteractive=true```再执行```env```命令
安装goecs 安装goecs
``` ```
@@ -99,18 +101,28 @@ shell脚本的说明
``` ```
可用命令: 可用命令:
./goecs.sh env 检查并安装的包: ./goecs.sh env 检查并安装依赖包
sudo (几乎所有类 Unix 系统都有。) 警告: 此命令会执行系统更新(可选择),可能:
tar (几乎所有类 Unix 系统都有。) 1. 耗时较长
unzip (几乎所有类 Unix 系统都有。) 2. 导致网络短暂中断
dd (几乎所有类 Unix 系统都有。) 3. 影响系统稳定性
fio (几乎所有类 Unix 系统可以通过系统的包管理器安装。) 4. 影响后续系统启动
sysbench (几乎所有类 Unix 系统可以通过系统的包管理器安装。) 对于内存小于1GB的系统还可能导致:
geekbench (geekbench5) (仅支持 IPV4 环境,且内存大于 1GB 并需要持续联网,仅支持 amd64 和 arm64 架构。) 1. 系统卡死
speedtest (使用官方提供的二进制文件以获得更准确的测试结果。) 2. SSH连接中断
ping (使用官方提供的二进制文件以获得更准确的测试结果。) 3. 关键服务失败
systemd-detect-virt 或 dmidecode (几乎所有类 Unix 系统都有,安装以获得更准确的测试结果。) 推荐:
事实上sysbench/geekbench 是上述依赖项中唯一必须安装的,没有它们无法测试 CPU 分数。 环境依赖安装过程中挂起执行
必需组件:
sysbench/geekbench (CPU性能测试必需)
可选组件:
sudo, tar, unzip, dd, fio
speedtest (网络测试)
ping (网络连通性测试)
systemd-detect-virt/dmidecode (系统信息检测)
./goecs.sh install 安装 goecs 命令 ./goecs.sh install 安装 goecs 命令
./goecs.sh upgrade 升级 goecs 命令 ./goecs.sh upgrade 升级 goecs 命令
./goecs.sh uninstall 卸载 goecs 命令 ./goecs.sh uninstall 卸载 goecs 命令

View File

@@ -47,7 +47,7 @@ Systems to be supported (hardware testing bugs not yet fixed): MacOS、FreeBSD
### one-click command ### one-click command
``` ```
curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh && bash goecs.sh env && bash goecs.sh install && goecs -l en export noninteractive=true && curl -L https://raw.githubusercontent.com/oneclickvirt/ecs/master/goecs.sh -o goecs.sh && chmod +x goecs.sh && bash goecs.sh env && bash goecs.sh install && goecs -l en
``` ```
### explain in detail ### explain in detail
@@ -64,6 +64,8 @@ Install environment
./goecs.sh env ./goecs.sh env
``` ```
If you don't want interaction, use ```export noninteractive=true``` and then execute the ```env``` command
Install goecs Install goecs
``` ```
@@ -87,18 +89,28 @@ Explanation of the shell script
``` ```
Available commands: Available commands:
./goecs.sh env Check and Install package: ./goecs.sh env Check and Install dependencies
sudo (Almost all unix-like systems have it.) Warning: This command performs system update(optional), which may:
tar (Almost all unix-like systems have it.) 1. Take considerable time
unzip (Almost all unix-like systems have it.) 2. Cause temporary network interruptions
dd (Almost all unix-like systems have it.) 3. Impact system stability
fio (Almost all unix-like systems can be installed through the system's package manager.) 4. Affect subsequent system startups
sysbench (Almost all unix-like systems can be installed through the system's package manager.) For systems with less than 1GB RAM, additional risks:
geekbench (geekbench5)(Only support IPV4 environment, and memory greater than 1GB network detection, only support amd64 and arm64 architecture.) 1. System freeze
speedtest (Use the officially provided binaries for more accurate test results.) 2. SSH connection loss
ping (Use the officially provided binaries for more accurate test results.) 3. Critical service failures
systemd-detect-virt OR dmidecode (Almost all unix-like systems have it, for more accurate test results.) Recommended:
In fact, sysbench/geekbench is the only one of the above dependencies that must be installed, without which the CPU score cannot be tested. Hanging execution during environment dependency installation
Required components:
sysbench/geekbench (Required for CPU testing)
Optional components:
sudo, tar, unzip, dd, fio
speedtest (Network testing)
ping (Network connectivity)
systemd-detect-virt/dmidecode (System info detection)
./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

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)

4
go.mod
View File

@@ -5,9 +5,9 @@ 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.16-20240823051211 github.com/oneclickvirt/UnlockTests v0.0.20-20241207132231
github.com/oneclickvirt/backtrace v0.0.4-20240702140722 github.com/oneclickvirt/backtrace v0.0.4-20240702140722
github.com/oneclickvirt/basics v0.0.7-20240821160408 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

8
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.16-20240823051211 h1:oDYlAXbUSt6JYTC+wcFDVWTacGuyBtWNfJhpKkrqNkU= github.com/oneclickvirt/UnlockTests v0.0.20-20241207132231 h1:GS84R/LZL5oOaVIYHkivSrYcAHxRGY/CNJpyAdEwwJk=
github.com/oneclickvirt/UnlockTests v0.0.16-20240823051211/go.mod h1:UELwZDDiddSxe38boYOPl1FlrL0ptEZYSQwdE3MYvUM= github.com/oneclickvirt/UnlockTests v0.0.20-20241207132231/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-20240821160408 h1:IOqa7bBAkjhfru6arDsOTKB7qZ36ojfOP73kE+cDaqc= github.com/oneclickvirt/basics v0.0.8-20241108124433 h1:eKZcoNoa9uLWmfisk+qN/QOvSGT4ajCmZdZfIAcHG+o=
github.com/oneclickvirt/basics v0.0.7-20240821160408/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=

View File

@@ -39,7 +39,7 @@ import (
) )
var ( var (
ecsVersion = "v0.0.80" ecsVersion = "v0.0.87"
menuMode bool menuMode bool
onlyChinaTest bool onlyChinaTest bool
input, choice string input, choice string
@@ -340,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 {
@@ -481,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 {

217
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.10.06 # 2024.11.18
# 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
@@ -24,6 +24,7 @@ _red() { echo -e "\033[31m\033[01m$@\033[0m"; }
_green() { echo -e "\033[32m\033[01m$@\033[0m"; } _green() { echo -e "\033[32m\033[01m$@\033[0m"; }
_yellow() { echo -e "\033[33m\033[01m$@\033[0m"; } _yellow() { echo -e "\033[33m\033[01m$@\033[0m"; }
_blue() { echo -e "\033[36m\033[01m$@\033[0m"; } _blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
reading() { read -rp "$(_green "$1")" "$2"; }
check_cdn() { check_cdn() {
local o_url=$1 local o_url=$1
@@ -59,6 +60,32 @@ download_file() {
return 0 return 0
} }
get_memory_size() {
if [ -f /proc/meminfo ]; then
local mem_kb=$(grep MemTotal /proc/meminfo | awk '{print $2}')
echo $((mem_kb / 1024)) # Convert to MB
return
fi
if command -v free >/dev/null 2>&1; then
local mem_kb=$(free -m | awk '/^Mem:/ {print $2}')
echo "$mem_kb" # Already in MB
return
fi
if command -v sysctl >/dev/null 2>&1; then
local mem_bytes=$(sysctl -n hw.memsize 2>/dev/null || sysctl -n hw.physmem 2>/dev/null)
if [ -n "$mem_bytes" ]; then
echo $((mem_bytes / 1024 / 1024)) # Convert to MB
return
fi
fi
}
cleanup_epel() {
_yellow "Cleaning up EPEL repositories..."
rm -f /etc/yum.repos.d/*epel*
yum clean all
}
goecs_check() { goecs_check() {
os=$(uname -s) os=$(uname -s)
arch=$(uname -m) arch=$(uname -m)
@@ -213,23 +240,70 @@ InstallSysbench() {
else else
Var_OSRelease="unknown" # 未知系统分支 Var_OSRelease="unknown" # 未知系统分支
fi fi
local mem_size=$(get_memory_size)
case "$Var_OSRelease" in if [ -z "$mem_size" ] || [ "$mem_size" -eq 0 ]; then
ubuntu | debian | astra) echo "Error: Unable to determine memory size or memory size is zero."
! apt-get install -y sysbench && apt-get --fix-broken install -y && apt-get install --no-install-recommends -y sysbench ;; elif [ $mem_size -lt 1024 ]; then
centos | rhel | almalinux | redhat | opencloudos) _red "Warning: Your system has less than 1GB RAM (${mem_size}MB)"
(yum -y install epel-release && yum -y install sysbench) || (dnf install epel-release -y && dnf install sysbench -y) ;; if [ "$noninteractive" != "true" ]; then
fedora) reading "Do you want to continue with EPEL installation? (y/N): " confirm
dnf -y install sysbench ;; if [[ ! $confirm =~ ^[Yy]$ ]]; then
arch) _yellow "Skipping EPEL installation"
pacman -S --needed --noconfirm sysbench && pacman -S --needed --noconfirm libaio && ldconfig ;; return 1
freebsd) fi
pkg install -y sysbench ;; fi
alpinelinux) case "$Var_OSRelease" in
echo -e "${Msg_Warning}Sysbench Module not found, installing ..." && echo -e "${Msg_Warning}SysBench Current not support Alpine Linux, Skipping..." && Var_Skip_SysBench="1" ;; ubuntu | debian | astra)
*) ! apt-get install -y sysbench && apt-get --fix-broken install -y && apt-get install --no-install-recommends -y sysbench ;;
_red "Sysbench Install Error: Unknown OS release: $Var_OSRelease" ;; centos | rhel | almalinux | redhat | opencloudos)
esac (yum -y install epel-release && yum -y install sysbench) || (dnf install epel-release -y && dnf install sysbench -y) ;;
fedora)
dnf -y install sysbench ;;
arch)
pacman -S --needed --noconfirm sysbench && pacman -S --needed --noconfirm libaio && ldconfig ;;
freebsd)
pkg install -y sysbench ;;
alpinelinux)
if [ "$noninteractive" != "true" ]; then
reading "Do you want to continue with sysbench installation? (y/N): " confirm
if [[ ! $confirm =~ ^[Yy]$ ]]; then
_yellow "Skipping sysbench installation"
return 1
fi
fi
ALPINE_VERSION=$(grep -o '^[0-9]\+\.[0-9]\+' /etc/alpine-release)
COMMUNITY_REPO="http://dl-cdn.alpinelinux.org/alpine/v${ALPINE_VERSION}/community"
if grep -q "^${COMMUNITY_REPO}" /etc/apk/repositories; then
echo "Community repository is already enabled."
else
echo "Enabling community repository..."
echo "${COMMUNITY_REPO}" >> /etc/apk/repositories
echo "Community repository has been added."
echo "Updating apk package index..."
apk update && echo "Package index updated successfully."
fi
if apk info sysbench >/dev/null 2>&1; then
echo -e "${Msg_Info}Sysbench already installed."
else
apk add --no-cache sysbench
if [ $? -ne 0 ]; then
echo -e "${Msg_Warning}Sysbench Module not found, installing ..." && echo -e "${Msg_Warning}SysBench Current not support Alpine Linux, Skipping..." && Var_Skip_SysBench="1"
else
echo -e "${Msg_Success}Sysbench installed successfully."
fi
fi ;;
*)
_red "Sysbench Install Error: Unknown OS release: $Var_OSRelease" ;;
esac
if [[ $SYSTEM =~ ^(CentOS|RHEL|AlmaLinux)$ ]]; then
_yellow "Installing EPEL repository..."
if ! yum -y install epel-release; then
_red "EPEL installation failed!"
cleanup_epel
_yellow "Attempting to continue without EPEL..."
fi
fi
fi
} }
Check_SysBench() { Check_SysBench() {
@@ -258,6 +332,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}"
@@ -294,10 +371,10 @@ 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" "opencloudos") 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" "OpenCloudOS") 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" "yum -y update" "pacman -Sy" "pkg update" "apk update" "yum -y update") 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 -qu" "yum -y update")
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_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" "yum -y remove" "pacman -Rsc --noconfirm" "pkg delete" "apk del" "yum -y remove") 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" "yum -y autoremove" "pacman -Rns --noconfirm" "pkg autoremove" "apk autoremove" "yum -y autoremove") 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")
# 检查系统信息 # 检查系统信息
if [ -f /etc/opencloudos-release ]; then if [ -f /etc/opencloudos-release ]; then
SYS="opencloudos" SYS="opencloudos"
@@ -343,11 +420,27 @@ env_check() {
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." _yellow "Warning: System update will be performed"
${PACKAGE_UPDATE[int]} 2>/dev/null _yellow "This operation may:"
_yellow "1. Take significant time to complete"
_yellow "2. Cause temporary network interruptions"
_yellow "3. Impact system stability"
_yellow "4. Affect future system startup"
if [ "$noninteractive" != "true" ]; then
reading "Do you want to proceed with system update? (y/N): " update_confirm
if [[ ! $update_confirm =~ ^[Yy]$ ]]; then
_yellow "Skipping system update"
_yellow "Note: Some package installations may fail"
else
_green "Updating system package manager..."
if ! ${PACKAGE_UPDATE[int]} 2>/dev/null; then
_red "System update failed!"
fi
fi
fi
# 安装必要的命令 # 安装必要的命令
for cmd in sudo wget tar unzip systemd-detect-virt dd fio; do for cmd in sudo wget tar unzip iproute2 systemd-detect-virt dd fio; do
if ! command -v "$cmd" >/dev/null 2>&1; then if ! command -v "$cmd" >/dev/null 2>&1; then
_green "Installing $cmd" _green "Installing $cmd"
${PACKAGE_INSTALL[int]} "$cmd" ${PACKAGE_INSTALL[int]} "$cmd"
@@ -401,8 +494,8 @@ env_check() {
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 brew install --force sysbench iproute2mac fio
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
@@ -423,37 +516,59 @@ show_help() {
cat <<"EOF" cat <<"EOF"
可用命令: 可用命令:
./goecs.sh env 检查并安装的包: ./goecs.sh env 检查并安装依赖包
sudo (几乎所有类 Unix 系统都有。) 警告: 此命令会执行系统更新(可选择),可能:
tar (几乎所有类 Unix 系统都有。) 1. 耗时较长
unzip (几乎所有类 Unix 系统都有。) 2. 导致网络短暂中断
dd (几乎所有类 Unix 系统都有。) 3. 影响系统稳定性
fio (几乎所有类 Unix 系统可以通过系统的包管理器安装。) 4. 影响后续系统启动
sysbench (几乎所有类 Unix 系统可以通过系统的包管理器安装。) 对于内存小于1GB的系统还可能导致:
geekbench (geekbench5) (仅支持 IPV4 环境,且内存大于 1GB 并需要持续联网,仅支持 amd64 和 arm64 架构。) 1. 系统卡死
speedtest (使用官方提供的二进制文件以获得更准确的测试结果。) 2. SSH连接中断
ping (使用官方提供的二进制文件以获得更准确的测试结果。) 3. 关键服务失败
systemd-detect-virt 或 dmidecode (几乎所有类 Unix 系统都有,安装以获得更准确的测试结果。) 推荐:
事实上sysbench/geekbench 是上述依赖项中唯一必须安装的,没有它们无法测试 CPU 分数。 环境依赖安装过程中挂起执行
必需组件:
sysbench/geekbench (CPU性能测试必需)
可选组件:
sudo, tar, unzip, dd, fio
speedtest (网络测试)
ping (网络连通性测试)
systemd-detect-virt/dmidecode (系统信息检测)
./goecs.sh install 安装 goecs 命令 ./goecs.sh install 安装 goecs 命令
./goecs.sh upgrade 升级 goecs 命令 ./goecs.sh upgrade 升级 goecs 命令
./goecs.sh uninstall 卸载 goecs 命令 ./goecs.sh uninstall 卸载 goecs 命令
./goecs.sh help 显示此消息 ./goecs.sh help 显示此消息
[English version follows...]
Available commands: Available commands:
./goecs.sh env Check and Install package: ./goecs.sh env Check and Install dependencies
sudo (Almost all unix-like systems have it.) Warning: This command performs system update(optional), which may:
tar (Almost all unix-like systems have it.) 1. Take considerable time
unzip (Almost all unix-like systems have it.) 2. Cause temporary network interruptions
dd (Almost all unix-like systems have it.) 3. Impact system stability
fio (Almost all unix-like systems can be installed through the system's package manager.) 4. Affect subsequent system startups
sysbench (Almost all unix-like systems can be installed through the system's package manager.) For systems with less than 1GB RAM, additional risks:
geekbench (geekbench5)(Only support IPV4 environment, and memory greater than 1GB network detection, only support amd64 and arm64 architecture.) 1. System freeze
speedtest (Use the officially provided binaries for more accurate test results.) 2. SSH connection loss
ping (Use the officially provided binaries for more accurate test results.) 3. Critical service failures
systemd-detect-virt OR dmidecode (Almost all unix-like systems have it, for more accurate test results.) Recommended:
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. Hanging execution during environment dependency installation
Required components:
sysbench/geekbench (Required for CPU testing)
Optional components:
sudo, tar, unzip, dd, fio
speedtest (Network testing)
ping (Network connectivity)
systemd-detect-virt/dmidecode (System info detection)
./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

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
@@ -242,18 +248,29 @@ 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, 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,16 +278,17 @@ func UploadText(absPath string) (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/"), http_url := strings.ReplaceAll(resp.String(), "https://paste.spiritlhl.net/", "http://hpaste.spiritlhl.net/")
strings.ReplaceAll(resp.String(), "http://hpaste.spiritlhl.net/", "https://paste.spiritlhl.net/"), nil 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)
} }
} }
http_url, https_url, err := upload(primaryURL) http_url, https_url, err := upload(primaryURL)
@@ -279,7 +297,7 @@ func UploadText(absPath string) (string, string, error) {
} }
http_url, https_url, 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 http_url, https_url, nil return http_url, https_url, nil
} }