This commit is contained in:
sindricn
2025-10-01 21:07:56 +08:00
parent 5e57b7f357
commit f85acb54fd
+5 -54
View File
@@ -177,70 +177,21 @@ backup_existing_config() {
install_hysteria2_binary() {
log_info "开始安装 Hysteria2..."
# 加载安全下载模块
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [[ -f "$script_dir/scripts/secure-download.sh" ]]; then
source "$script_dir/scripts/secure-download.sh"
else
log_warn "安全下载模块未找到,使用基础安全检查"
fi
# 设置安装脚本的环境变量
export HYSTERIA_INSTALL_METHOD="script"
# 安全下载并执行官方安装脚本
# 使用官方推荐的安装方式
local install_script_url="https://get.hy2.sh/"
local temp_script
temp_script=$(mktemp)
chmod 600 "$temp_script" # 设置安全权限
# 设置清理陷阱
trap 'rm -f "$temp_script"' EXIT
log_info "执行官方安装脚本..."
log_info "安全下载官方安装脚本..."
# 使用安全下载(如果可用)
if command -v download_script_secure >/dev/null 2>&1; then
if ! download_script_secure "$install_script_url" "$temp_script"; then
log_error "安全下载安装脚本失败"
return 1
fi
else
# 基础安全下载
if ! curl --silent --show-error --fail --location \
--max-time 30 --max-filesize 10485760 \
--proto "=https" --tlsv1.2 \
"$install_script_url" -o "$temp_script"; then
log_error "下载安装脚本失败"
return 1
fi
# 验证脚本内容
if [[ ! -s "$temp_script" ]]; then
log_error "安装脚本为空"
return 1
fi
# 基本语法检查
if ! bash -n "$temp_script"; then
log_error "安装脚本语法错误"
return 1
fi
# 检查危险命令
if grep -qE "rm -rf /|dd if=|mkfs|fdisk" "$temp_script"; then
log_error "安装脚本包含危险命令"
return 1
fi
fi
# 执行安装脚本
log_info "执行安装脚本..."
if timeout 300 bash "$temp_script" --version latest; then
# 使用官方推荐的管道方式安装
if timeout 300 bash <(curl -fsSL "$install_script_url"); then
log_success "Hysteria2 安装成功"
return 0
else
log_error "Hysteria2 安装失败"
log_info "如果安装失败,请检查网络连接或手动执行: bash <(curl -fsSL https://get.hy2.sh/)"
return 1
fi
}