This commit is contained in:
sindricn
2025-09-24 16:17:07 +08:00
parent 43818ba7fe
commit faf3fcf70a
5 changed files with 65 additions and 29 deletions
+10 -18
View File
@@ -3,8 +3,8 @@
# Hysteria2 安装脚本 (改进版本)
# 作为 s-hy2 管理脚本的一部分
# 严格错误处理
set -euo pipefail
# 适度的错误处理
set -uo pipefail
# 加载公共库
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -79,31 +79,23 @@ check_system_compatibility() {
# 检查网络连接
check_network_connection() {
log_info "检查网络连接..."
local test_urls=(
"github.com"
"get.hy2.sh"
"google.com"
"https://github.com"
"https://get.hy2.sh"
"https://www.google.com"
"https://raw.githubusercontent.com"
)
local connected=false
# 直接使用 HTTP 连接测试,更可靠
for url in "${test_urls[@]}"; do
if ping -c 1 -W 5 "$url" &>/dev/null; then
if curl -s --connect-timeout 3 --max-time 8 --head "$url" >/dev/null 2>&1; then
connected=true
break
fi
done
if ! $connected; then
# 尝试 HTTP 连接测试
for url in "${test_urls[@]}"; do
if curl -s --connect-timeout 5 --max-time 10 "https://$url" &>/dev/null; then
connected=true
break
fi
done
fi
if $connected; then
log_success "网络连接正常"
return 0
+46 -2
View File
@@ -3,8 +3,8 @@
# 公共函数库 - 统一错误处理和日志记录
# 为所有脚本提供标准化的错误处理、日志记录和工具函数
# 严格错误处理
set -euo pipefail
# 适度的错误处理 (不使用 -e 避免意外退出)
set -uo pipefail
# 全局变量 (防止重复定义)
if [[ -z "${SCRIPT_NAME:-}" ]]; then
@@ -276,6 +276,50 @@ wait_for_user() {
read -p "按回车键继续..." -r
}
# 检查Hysteria2是否已安装和配置
check_hysteria2_ready() {
local check_type="${1:-install}" # install, config, service
case $check_type in
"install")
if ! command -v hysteria >/dev/null 2>&1; then
log_warn "Hysteria2 未安装"
echo ""
echo -e "${YELLOW}提示:${NC}请先安装 Hysteria2"
echo " 返回主菜单选择 '1. 安装 Hysteria2'"
echo ""
wait_for_user
return 1
fi
;;
"config")
if [[ ! -f "/etc/hysteria/config.yaml" ]]; then
log_warn "Hysteria2 配置文件不存在"
echo ""
echo -e "${YELLOW}提示:${NC}请先配置 Hysteria2"
echo " 1. 返回主菜单选择 '2. 快速配置' 或 '3. 手动配置'"
echo " 2. 如未安装,请先选择 '1. 安装 Hysteria2'"
echo ""
wait_for_user
return 1
fi
;;
"service")
if ! systemctl is-enabled hysteria-server >/dev/null 2>&1; then
log_warn "Hysteria2 服务未启用"
echo ""
echo -e "${YELLOW}提示:${NC}请先启用服务"
echo " 返回主菜单选择 '7. 服务管理'"
echo ""
wait_for_user
return 1
fi
;;
esac
return 0
}
# 显示进度条
show_progress() {
local current="$1"
+2 -2
View File
@@ -3,8 +3,8 @@
# Hysteria2 防火墙管理模块
# 自动检测并管理 Linux 系统防火墙
# 严格错误处理
set -euo pipefail
# 适度的错误处理
set -uo pipefail
# 加载公共库
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+5 -5
View File
@@ -3,8 +3,8 @@
# Hysteria2 出站规则管理模块
# 用于配置和管理 Hysteria2 的出站规则
# 严格错误处理
set -euo pipefail
# 适度的错误处理
set -uo pipefail
# 加载公共库
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -130,9 +130,9 @@ show_outbound_menu() {
view_current_outbound() {
log_info "查看当前出站配置"
if [[ ! -f "$HYSTERIA_CONFIG" ]]; then
log_warn "Hysteria2 配置文件不存在"
return 1
# 使用统一的检查函数
if ! check_hysteria2_ready "config"; then
return 0 # 友好返回,不退出脚本
fi
echo -e "${BLUE}=== 当前出站配置 ===${NC}"
+2 -2
View File
@@ -3,8 +3,8 @@
# Hysteria2 部署后检查模块
# 确保节点部署完成后各项功能正常
# 严格错误处理
set -euo pipefail
# 适度的错误处理
set -uo pipefail
# 加载公共库
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"