This commit is contained in:
sindricn
2025-08-05 20:00:33 +08:00
parent 915e00cfc7
commit 016c53b8c9
15 changed files with 455 additions and 2361 deletions
-198
View File
@@ -1,198 +0,0 @@
# S-Hy2 安装问题解决方案
## 问题描述
用户反馈运行安装命令后,安装界面出现但脚本直接退出,无法继续安装。
## 问题分析
经过分析,可能的原因包括:
1. **脚本错误处理过于严格**: 原始脚本使用 `set -e`,任何命令失败都会导致脚本退出
2. **网络连接问题**: GitHub 访问受限或网络不稳定
3. **依赖缺失**: 系统缺少必要的命令或工具
4. **权限问题**: 文件创建或目录访问权限不足
5. **脚本逻辑错误**: 主脚本中存在未定义的函数调用
## 解决方案
### 方案1: 使用测试脚本诊断
首先运行测试脚本检查环境:
```bash
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/test-install.sh | sudo bash
```
测试脚本会检查:
- 网络连接状态
- GitHub 访问能力
- Root 权限
- 系统兼容性
- 必要命令可用性
- 文件下载能力
- 目录创建权限
- 符号链接权限
### 方案2: 使用简化版安装脚本
创建了一个简化版的安装脚本,移除了复杂的错误处理:
```bash
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install-simple.sh | sudo bash
```
简化版特点:
- 移除了 `set -e` 严格错误处理
- 简化了依赖安装过程
- 增加了详细的状态反馈
- 容错性更强
### 方案3: 使用调试模式
修复了原始安装脚本,增加了调试模式:
```bash
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install.sh | sudo bash -s -- --debug
```
调试模式特点:
- 启用 `set -x` 显示详细执行过程
- 增加了错误日志输出
- 改进了错误处理逻辑
### 方案4: 手动安装
如果自动安装都失败,可以手动安装:
```bash
# 1. 创建目录
sudo mkdir -p /opt/s-hy2/scripts /opt/s-hy2/templates
# 2. 下载主脚本
sudo curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/hy2-manager.sh -o /opt/s-hy2/hy2-manager.sh
# 3. 设置权限
sudo chmod +x /opt/s-hy2/hy2-manager.sh
# 4. 创建快捷方式
sudo ln -sf /opt/s-hy2/hy2-manager.sh /usr/local/bin/s-hy2
# 5. 测试运行
sudo s-hy2
```
## 修复的问题
### 1. 主脚本逻辑错误
**问题**: 主脚本中调用了未定义的 `troubleshoot` 函数
**修复**: 移除了故障排除菜单选项,调整了菜单编号
### 2. 安装脚本错误处理
**问题**: `set -e` 导致任何命令失败都会退出脚本
**修复**:
- 移除了 `set -e`
- 增加了手动错误处理
- 改进了函数返回值检查
### 3. 网络连接检查
**问题**: 网络检查过于严格,单点失败就退出
**修复**:
- 测试多个网站
- 网络检查失败不强制退出
- 增加了警告提示
### 4. 依赖安装处理
**问题**: 依赖安装失败会导致脚本退出
**修复**:
- 依赖安装失败只显示警告
- 继续执行后续步骤
- 增加了错误提示
### 5. 文件下载处理
**问题**: 单个文件下载失败就退出
**修复**:
- 分别处理每个文件下载
- 统计下载成功/失败数量
- 部分失败不影响整体安装
## 使用建议
### 推荐安装顺序
1. **首选**: 简化版安装
```bash
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install-simple.sh | sudo bash
```
2. **备选**: 调试模式安装
```bash
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install.sh | sudo bash -s -- --debug
```
3. **最后**: 手动安装
```bash
# 按照手动安装步骤执行
```
### 环境要求
- **操作系统**: Ubuntu 18.04+, Debian 9+, CentOS 7+, RHEL 7+, Fedora 30+
- **权限**: Root 权限 (使用 sudo)
- **网络**: 能够访问 GitHub 和相关资源
- **工具**: curl, wget, mkdir, chmod, ln 等基本命令
### 故障排除
如果仍然遇到问题:
1. **查看详细文档**: [TROUBLESHOOTING.md](TROUBLESHOOTING.md)
2. **运行测试脚本**: 诊断具体问题
3. **收集错误信息**: 记录完整的错误消息
4. **提交 Issue**: 在 GitHub 仓库报告问题
## 文件清单
为解决安装问题,创建了以下文件:
1. **test-install.sh** - 环境测试脚本
2. **quick-install-simple.sh** - 简化版安装脚本
3. **TROUBLESHOOTING.md** - 详细故障排除指南
4. **INSTALL_SOLUTIONS.md** - 安装问题解决方案
同时修复了:
1. **hy2-manager.sh** - 修复了菜单逻辑错误
2. **quick-install.sh** - 改进了错误处理
## 验证安装
安装完成后,验证是否正常工作:
```bash
# 检查命令是否可用
which s-hy2
# 检查文件是否存在
ls -la /opt/s-hy2/
# 测试运行
sudo s-hy2
```
如果看到 S-Hy2 的主菜单,说明安装成功。
## 联系支持
如果问题仍然存在,请:
1. 运行测试脚本收集诊断信息
2. 在 GitHub 仓库提交详细的 Issue
3. 包含系统信息、错误消息和执行步骤
**GitHub 仓库**: https://github.com/sindricn/s-hy2
-251
View File
@@ -1,251 +0,0 @@
# S-Hy2 安装问题修复报告
## 问题总结
用户反馈了三个主要问题:
1. **提示(y/n)没有实际功能** - 运行命令后自动安装了
2. **一键安装后会弹出服务器界面** - 无法选择和退出
3. **安装完成后选择1安装hy2提示没有安装脚本**
## 问题分析与修复
### 问题1: 提示(y/n)没有实际功能
**原因分析:**
- 脚本通过管道运行时,标准输入不是终端
- `read` 命令无法正常接收用户输入
- 脚本继续执行,看起来像是自动安装
**修复方案:**
```bash
# 检查是否为交互模式
if [[ -t 0 ]]; then
# 交互模式 - 等待用户输入
echo -n -e "${YELLOW}是否继续安装? [Y/n]: ${NC}"
read -r confirm
if [[ $confirm =~ ^[Nn]$ ]]; then
echo -e "${BLUE}取消安装${NC}"
exit 0
fi
else
# 管道模式 - 自动确认
echo -e "${YELLOW}检测到管道模式,自动开始安装...${NC}"
sleep 2
fi
```
**修复文件:**
- `quick-install-simple.sh`
- `install-fixed.sh`
### 问题2: 一键安装后自动弹出服务器界面
**原因分析:**
- 安装脚本在完成后自动执行了主脚本
- 没有给用户选择是否立即运行的机会
- 用户可能只想安装,不想立即使用
**修复方案:**
```bash
# 询问是否立即运行
if [[ -t 0 ]]; then
echo -n -e "${YELLOW}是否立即运行 s-hy2? [y/N]: ${NC}"
read -r run_now
if [[ $run_now =~ ^[Yy]$ ]]; then
echo ""
echo -e "${BLUE}正在启动 s-hy2...${NC}"
exec "$INSTALL_DIR/hy2-manager.sh"
else
echo -e "${BLUE}安装完成,稍后可运行 'sudo s-hy2' 开始使用${NC}"
fi
else
echo -e "${BLUE}安装完成,请运行 'sudo s-hy2' 开始使用${NC}"
fi
```
**修复文件:**
- `quick-install-simple.sh`
- `install-fixed.sh`
### 问题3: 安装脚本不存在
**原因分析:**
1. **函数名不匹配**: 主脚本调用 `install_hysteria_main`,但安装脚本中函数名是 `install_hysteria2`
2. **文件下载失败**: 网络问题导致脚本文件没有正确下载
3. **路径问题**: 脚本文件路径不正确
**修复方案:**
#### 修复1: 函数名统一
```bash
# 主脚本中修改函数调用
install_hysteria() {
echo -e "${BLUE}正在安装 Hysteria2...${NC}"
if [[ -f "$SCRIPTS_DIR/install.sh" ]]; then
source "$SCRIPTS_DIR/install.sh"
install_hysteria2 # 修改为正确的函数名
else
echo -e "${RED}错误: 安装脚本不存在${NC}"
echo "脚本路径: $SCRIPTS_DIR/install.sh"
echo "请检查脚本是否正确下载"
read -p "按回车键继续..."
fi
}
```
#### 修复2: 改进下载验证
```bash
# 验证关键文件下载
verify_installation() {
echo -e "${BLUE}验证安装...${NC}"
local required_files=(
"$INSTALL_DIR/hy2-manager.sh"
"$INSTALL_DIR/scripts/install.sh"
"$INSTALL_DIR/scripts/config.sh"
"$INSTALL_DIR/scripts/service.sh"
)
local missing=0
for file in "${required_files[@]}"; do
if [[ ! -f "$file" ]]; then
echo -e "${RED}✗ 缺少文件: $file${NC}"
((missing++))
fi
done
if [[ $missing -eq 0 ]]; then
echo -e "${GREEN}✓ 安装验证通过${NC}"
return 0
else
echo -e "${RED}✗ 安装验证失败,缺少 $missing 个关键文件${NC}"
return 1
fi
}
```
#### 修复3: 详细下载日志
```bash
# 改进下载函数,提供详细反馈
download_file() {
local url="$1"
local output="$2"
local description="$3"
if curl -fsSL "$url" -o "$output" 2>/dev/null; then
echo -e "${GREEN}$description${NC}"
return 0
else
echo -e "${RED}$description${NC}"
return 1
fi
}
```
**修复文件:**
- `hy2-manager.sh` - 修复函数调用
- `quick-install-simple.sh` - 改进下载验证
- `install-fixed.sh` - 新的修复版安装脚本
## 新增文件
### install-fixed.sh
创建了一个全新的修复版安装脚本,特点:
1. **智能交互检测**: 自动识别交互模式和管道模式
2. **详细进度反馈**: 每个步骤都有清晰的状态显示
3. **完整验证机制**: 安装后验证关键文件是否存在
4. **错误处理改进**: 更好的错误提示和处理
5. **用户选择权**: 安装完成后询问是否立即运行
### 使用方法
```bash
# 推荐使用修复版安装
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/install-fixed.sh | sudo bash
```
## 测试验证
### 测试场景1: 交互模式
```bash
# 下载后本地运行
wget https://raw.githubusercontent.com/sindricn/s-hy2/main/install-fixed.sh
sudo bash install-fixed.sh
```
**预期结果**: 显示确认提示,等待用户输入
### 测试场景2: 管道模式
```bash
# 通过管道运行
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/install-fixed.sh | sudo bash
```
**预期结果**: 自动开始安装,不等待用户输入
### 测试场景3: 安装验证
```bash
# 安装完成后检查
ls -la /opt/s-hy2/scripts/
sudo s-hy2
```
**预期结果**: 所有脚本文件存在,主程序正常运行
## 兼容性说明
### 支持的运行方式
1. **直接管道运行**: `curl ... | sudo bash`
2. **下载后运行**: `wget ... && sudo bash ...`
3. **交互式运行**: 支持用户确认和选择
### 支持的系统
- Ubuntu 18.04+
- Debian 9+
- CentOS 7+
- RHEL 7+
- Fedora 30+
## 使用建议
### 推荐安装顺序
1. **首选**: 修复版安装
```bash
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/install-fixed.sh | sudo bash
```
2. **备选**: 简化版安装
```bash
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install-simple.sh | sudo bash
```
3. **调试**: 原版调试模式
```bash
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install.sh | sudo bash -s -- --debug
```
### 故障排除
如果仍然遇到问题:
1. **运行测试脚本**:
```bash
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/test-install.sh | sudo bash
```
2. **查看详细日志**: 使用调试模式安装
3. **手动安装**: 按照 TROUBLESHOOTING.md 中的步骤
4. **提交问题**: 在 GitHub 仓库报告具体错误
## 更新说明
### README.md 更新
- 将修复版安装设为推荐方式
- 调整其他安装方式为备选方案
- 更新使用说明
### 文档完善
- 新增 ISSUES_FIXED.md (本文档)
- 更新 TROUBLESHOOTING.md
- 完善安装指南
这些修复应该能够解决用户遇到的所有安装问题,提供更好的用户体验。
+8 -39
View File
@@ -5,56 +5,25 @@
## 功能特性
- 🚀 **一键安装/卸载** Hysteria2 服务器
- ⚙️ **交互式配置生成** 支持 ACME 自动证书和自签名证书
- 🌐 **智能伪装域名选择** 自动测试延迟选择最优域名
- 🔧 **进阶配置支持** 端口修改、混淆密码、端口跳跃
- 📊 **服务管理** 状态查看、日志查询、服务重启
- ⚙️ **智能配置生成** 支持 ACME 自动证书和自签名证书,智能域名配置
- 🌐 **服务器域名管理** 配置和验证服务器域名解析
- 🔧 **智能端口跳跃** 配置后自动检测和管理端口跳跃状态
- 📊 **智能服务管理** 配置后询问是否立即重启服务
- 📱 **多客户端支持** 生成适配不同客户端的订阅链接
- 📝 **配置模板** 预设多种常用配置模板
## 快速开始
### 一键安装 (推荐)
### 一键安装
```bash
# 修复版安装 (推荐)
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/install-fixed.sh | sudo bash
# 一键安装到服务器
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install.sh | sudo bash
# 运行脚本
sudo s-hy2
```
### 安装问题修复
如果安装后遇到问题,可以运行对应的修复脚本:
```bash
# 修复安装问题(如"安装脚本不存在")
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/fix-installation.sh | sudo bash
# 修复域名测试问题(如显示调试信息而非域名)
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/fix-domain-test.sh | sudo bash
```
### 其他安装方式
如果上述安装遇到问题,可以尝试:
```bash
# 1. 运行测试脚本检查环境
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/test-install.sh | sudo bash
# 2. 使用简化版安装
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install-simple.sh | sudo bash
# 3. 使用原版安装 (调试模式)
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install.sh | sudo bash -s -- --debug
```
### 交互模式说明
- **管道运行** (`curl ... | sudo bash`): 自动安装,不等待用户输入
- **本地运行** (`sudo bash script.sh`): 交互模式,等待用户确认
### 手动安装
```bash
-321
View File
@@ -1,321 +0,0 @@
# S-Hy2 故障排除指南
## 安装问题
### 问题1: 安装脚本直接退出
**症状**: 运行安装命令后,显示安装界面但立即退出
**可能原因**:
1. 网络连接问题
2. GitHub 访问受限
3. 权限不足
4. 系统不兼容
**解决方案**:
#### 步骤1: 运行测试脚本
```bash
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/test-install.sh | sudo bash
```
#### 步骤2: 使用简化版安装
```bash
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install-simple.sh | sudo bash
```
#### 步骤3: 使用调试模式
```bash
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install.sh | sudo bash -s -- --debug
```
#### 步骤4: 手动安装
```bash
# 1. 创建目录
sudo mkdir -p /opt/s-hy2/scripts /opt/s-hy2/templates
# 2. 下载主脚本
sudo curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/hy2-manager.sh -o /opt/s-hy2/hy2-manager.sh
# 3. 设置权限
sudo chmod +x /opt/s-hy2/hy2-manager.sh
# 4. 创建快捷方式
sudo ln -sf /opt/s-hy2/hy2-manager.sh /usr/local/bin/s-hy2
# 5. 测试运行
sudo s-hy2
```
### 问题2: 网络连接失败
**症状**: 提示网络连接失败或下载失败
**解决方案**:
#### 方案1: 检查网络连接
```bash
# 测试基本网络连接
ping -c 3 8.8.8.8
# 测试 HTTPS 连接
curl -I https://www.google.com
# 测试 GitHub 连接
curl -I https://github.com
```
#### 方案2: 使用代理
```bash
# 如果有 HTTP 代理
export http_proxy=http://proxy.example.com:8080
export https_proxy=http://proxy.example.com:8080
# 然后重新运行安装命令
```
#### 方案3: 使用镜像源
```bash
# 使用 Gitee 镜像 (如果有的话)
# 或者下载到本地后手动安装
```
### 问题3: 权限不足
**症状**: 提示权限不足或无法创建文件/目录
**解决方案**:
#### 检查 root 权限
```bash
# 确保使用 sudo
sudo whoami # 应该显示 root
# 检查 sudo 配置
sudo -l
```
#### 检查目录权限
```bash
# 检查 /opt 目录权限
ls -la /opt
# 检查 /usr/local/bin 目录权限
ls -la /usr/local/bin
```
### 问题4: 系统不兼容
**症状**: 提示系统类型检测失败
**支持的系统**:
- Ubuntu 18.04+
- Debian 9+
- CentOS 7+
- RHEL 7+
- Fedora 30+
**解决方案**:
```bash
# 检查系统信息
cat /etc/os-release
# 检查内核版本
uname -a
# 如果系统不在支持列表中,可以尝试手动安装
```
## 运行问题
### 问题1: 命令找不到
**症状**: 运行 `s-hy2` 提示命令找不到
**解决方案**:
```bash
# 检查符号链接
ls -la /usr/local/bin/s-hy2
# 检查 PATH 环境变量
echo $PATH
# 手动创建符号链接
sudo ln -sf /opt/s-hy2/hy2-manager.sh /usr/local/bin/s-hy2
# 或者直接运行完整路径
sudo /opt/s-hy2/hy2-manager.sh
```
### 问题2: 脚本运行错误
**症状**: 脚本运行时出现错误或异常退出
**解决方案**:
#### 检查脚本完整性
```bash
# 检查主脚本是否存在且可执行
ls -la /opt/s-hy2/hy2-manager.sh
# 检查脚本内容
head -10 /opt/s-hy2/hy2-manager.sh
```
#### 检查依赖脚本
```bash
# 检查功能脚本
ls -la /opt/s-hy2/scripts/
# 重新下载缺失的脚本
sudo curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/scripts/install.sh -o /opt/s-hy2/scripts/install.sh
sudo chmod +x /opt/s-hy2/scripts/install.sh
```
### 问题3: 菜单选项错误
**症状**: 选择菜单选项后提示错误或无响应
**解决方案**:
```bash
# 重新下载最新版本
sudo curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/hy2-manager.sh -o /opt/s-hy2/hy2-manager.sh
sudo chmod +x /opt/s-hy2/hy2-manager.sh
```
## Hysteria2 相关问题
### 问题1: Hysteria2 安装失败
**解决方案**:
```bash
# 手动安装 Hysteria2
bash <(curl -fsSL https://get.hy2.sh/)
# 检查安装结果
which hysteria
hysteria version
```
### 问题2: 服务启动失败
**解决方案**:
```bash
# 检查服务状态
sudo systemctl status hysteria-server
# 查看详细日志
sudo journalctl -u hysteria-server -f
# 检查配置文件
sudo cat /etc/hysteria/config.yaml
# 验证配置文件语法
sudo hysteria server --config /etc/hysteria/config.yaml --check
```
### 问题3: 端口被占用
**解决方案**:
```bash
# 检查端口占用
sudo netstat -tulnp | grep :443
# 查找占用进程
sudo lsof -i :443
# 停止占用进程或更换端口
```
## 网络问题
### 问题1: 防火墙阻止
**解决方案**:
```bash
# Ubuntu/Debian
sudo ufw allow 443/udp
sudo ufw status
# CentOS/RHEL
sudo firewall-cmd --permanent --add-port=443/udp
sudo firewall-cmd --reload
sudo firewall-cmd --list-ports
```
### 问题2: 端口跳跃失败
**解决方案**:
```bash
# 检查 iptables 规则
sudo iptables -t nat -L PREROUTING
# 检查网络接口
ip link show
# 手动添加规则
sudo iptables -t nat -A PREROUTING -i eth0 -p udp --dport 20000:50000 -j REDIRECT --to-ports 443
```
## 日志和调试
### 启用详细日志
```bash
# 查看系统日志
sudo journalctl -f
# 查看 Hysteria2 日志
sudo journalctl -u hysteria-server -f
# 启用调试模式
sudo HYSTERIA_DEBUG=1 /opt/s-hy2/hy2-manager.sh
```
### 收集诊断信息
```bash
# 系统信息
uname -a
cat /etc/os-release
# 网络信息
ip addr show
ip route show
# 服务信息
sudo systemctl status hysteria-server
sudo netstat -tulnp | grep hysteria
# 配置信息
sudo ls -la /etc/hysteria/
sudo cat /etc/hysteria/config.yaml
```
## 获取帮助
如果以上方法都无法解决问题,请:
1. **收集错误信息**: 记录完整的错误消息和日志
2. **提供系统信息**: 包括操作系统版本、内核版本等
3. **描述操作步骤**: 详细说明执行了哪些操作
4. **提交 Issue**: 在 GitHub 仓库提交详细的问题报告
**GitHub 仓库**: https://github.com/sindricn/s-hy2
**常用命令汇总**:
```bash
# 测试安装环境
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/test-install.sh | sudo bash
# 简化安装
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install-simple.sh | sudo bash
# 调试安装
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install.sh | sudo bash -s -- --debug
# 手动运行
sudo /opt/s-hy2/hy2-manager.sh
# 重新安装
sudo rm -rf /opt/s-hy2 /usr/local/bin/s-hy2 /usr/local/bin/hy2-manager
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install-simple.sh | sudo bash
```
-213
View File
@@ -1,213 +0,0 @@
# S-Hy2 卸载方式对比
## 三种卸载方式详细对比
### 📊 对比表格
| 卸载方式 | 程序文件 | 配置文件 | 证书文件 | 用户账户 | 管理脚本 | 快捷命令 | 适用场景 |
|---------|---------|---------|---------|---------|---------|---------|---------|
| **方式1: 仅卸载服务器** | ✅ 删除 | ❌ 保留 | ❌ 保留 | ❌ 保留 | ❌ 保留 | ❌ 保留 | 临时卸载、升级、重装 |
| **方式2: 卸载服务器及配置** | ✅ 删除 | ✅ 删除 | ✅ 删除 | ✅ 删除 | ❌ 保留 | ❌ 保留 | 清理配置,保留脚本 |
| **方式3: 卸载所有内容** | ✅ 删除 | ✅ 删除 | ✅ 删除 | ✅ 删除 | ✅ 删除 | ✅ 删除 | 彻底清理、不再使用 |
## 🎯 选择建议
### 方式1: 仅卸载 Hysteria2 服务器
**推荐指数: ⭐⭐⭐⭐⭐**
**何时使用:**
- 🔄 临时卸载,计划重新安装
- 🆙 系统升级或重装前的准备
- 💾 保留配置以备后用
- 🧪 测试不同版本的 Hysteria2
**优点:**
- 保留所有配置,重新安装后可直接使用
- 保留证书文件,无需重新生成
- 保留管理脚本,操作便捷
- 卸载过程快速,风险最低
**操作:**
```bash
sudo s-hy2
# 选择 "9. 卸载服务" -> "1. 仅卸载 Hysteria2 服务器"
```
### 方式2: 卸载 Hysteria2 服务器及配置文件
**推荐指数: ⭐⭐⭐⭐**
**何时使用:**
- 🧹 清理所有配置,但保留管理脚本
- 🆕 重新开始全新配置
- 🧪 清理测试环境
- 🔒 出于安全考虑清理敏感配置
**优点:**
- 清理所有 Hysteria2 相关配置
- 保留管理脚本,便于重新部署
- 清理用户账户和证书
- 重新配置时从零开始
**操作:**
```bash
sudo s-hy2
# 选择 "9. 卸载服务" -> "2. 卸载 Hysteria2 服务器及配置文件"
```
### 方式3: 卸载脚本及 Hysteria2 服务器和所有文件
**推荐指数: ⭐⭐⭐**
**何时使用:**
- 🚫 不再使用 Hysteria2 和管理脚本
- 🧹 彻底清理系统
- 🔄 服务器用途完全改变
- 💾 释放所有相关存储空间
**优点:**
- 完全清理,不留任何痕迹
- 释放所有相关存储空间
- 适合服务器用途完全改变的情况
**缺点:**
- 重新使用需要重新安装脚本
- 操作不可逆,需要谨慎确认
**操作:**
```bash
sudo s-hy2
# 选择 "9. 卸载服务" -> "3. 卸载脚本及 Hysteria2 服务器和所有文件"
# 输入 "YES" 确认
```
## 🔄 重新安装指南
### 从方式1卸载后重新安装
```bash
# 直接重新安装 Hysteria2
sudo s-hy2
# 选择 "1. 安装 Hysteria2"
# 选择 "4. 管理服务" -> "1. 启动服务"
```
### 从方式2卸载后重新安装
```bash
# 重新安装和配置
sudo s-hy2
# 选择 "1. 安装 Hysteria2"
# 选择 "2. 一键快速配置"
```
### 从方式3卸载后重新安装
```bash
# 重新安装脚本
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install.sh | sudo bash
# 运行脚本并配置
sudo s-hy2
# 选择 "1. 安装 Hysteria2"
# 选择 "2. 一键快速配置"
```
## 🛡️ 安全注意事项
### 配置文件安全
- 配置文件包含认证密码和混淆密码
- 方式1保留配置文件,注意保护敏感信息
- 方式2和3会删除配置文件,确保数据安全
### 证书文件处理
- 自签名证书文件包含私钥信息
- ACME 证书会自动续期,卸载前考虑备份
- 方式1保留证书,方式2和3删除证书
### 端口跳跃规则
- 所有方式都会清理 iptables 规则
- 确保清理不会影响其他服务
- 如有自定义规则,请提前备份
## 📋 卸载验证清单
### 通用验证命令
```bash
# 检查 Hysteria2 程序
which hysteria
# 检查服务状态
sudo systemctl status hysteria-server
# 检查端口监听
sudo netstat -tulnp | grep :443
```
### 方式1验证 (应该存在)
```bash
# 检查配置文件
ls -la /etc/hysteria/
# 检查用户账户
id hysteria
# 检查管理脚本
which s-hy2
```
### 方式2验证 (应该存在)
```bash
# 检查管理脚本
which s-hy2
# 检查配置文件 (应该不存在)
ls -la /etc/hysteria/
```
### 方式3验证 (全部应该不存在)
```bash
# 检查管理脚本
which s-hy2
# 检查安装目录
ls -la /opt/s-hy2/
# 检查配置文件
ls -la /etc/hysteria/
```
## 🆘 故障恢复
### 误操作恢复
如果误选了错误的卸载方式:
1. **立即停止操作** - 如果还在确认阶段,选择取消
2. **检查剩余文件** - 使用验证命令检查还有哪些文件
3. **重新安装** - 根据剩余文件情况选择合适的重新安装方式
### 部分卸载失败
如果卸载过程中出现错误:
1. **查看错误信息** - 记录具体的错误提示
2. **手动清理** - 根据错误信息手动清理相关文件
3. **重新尝试** - 修复问题后重新尝试卸载
### 网络问题处理
如果因网络问题导致官方卸载脚本失败:
1. **检查网络连接** - 确保可以访问 get.hy2.sh
2. **手动删除文件** - 手动删除程序文件和服务文件
3. **清理残留** - 使用脚本的其他步骤清理残留文件
## 📞 技术支持
如果在卸载过程中遇到问题:
1. **查看日志** - 检查系统日志获取详细错误信息
2. **参考文档** - 查看 UNINSTALL_GUIDE.md 获取详细说明
3. **社区支持** - 在 GitHub 仓库提交 Issue
---
**仓库地址:** https://github.com/sindricn/s-hy2
**一键安装命令:**
```bash
curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install.sh | sudo bash
```
-107
View File
@@ -1,107 +0,0 @@
#!/bin/bash
# 修复域名测试功能脚本
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
INSTALL_DIR="/opt/s-hy2"
RAW_URL="https://raw.githubusercontent.com/sindricn/s-hy2/main"
echo -e "${CYAN}修复域名测试功能${NC}"
echo ""
# 检查权限
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}错误: 需要 root 权限${NC}"
echo "请使用: sudo bash"
exit 1
fi
# 检查安装目录
if [[ ! -d "$INSTALL_DIR" ]]; then
echo -e "${RED}错误: S-Hy2 未安装${NC}"
echo "请先运行安装脚本"
exit 1
fi
echo -e "${BLUE}正在修复域名测试功能...${NC}"
# 备份原文件
if [[ -f "$INSTALL_DIR/scripts/domain-test.sh" ]]; then
cp "$INSTALL_DIR/scripts/domain-test.sh" "$INSTALL_DIR/scripts/domain-test.sh.backup.$(date +%Y%m%d_%H%M%S)"
echo -e "${GREEN}✓ 已备份原文件${NC}"
fi
# 下载修复后的域名测试脚本
echo -e "${BLUE}下载修复后的域名测试脚本...${NC}"
if curl -fsSL "$RAW_URL/scripts/domain-test.sh" -o "$INSTALL_DIR/scripts/domain-test.sh"; then
chmod +x "$INSTALL_DIR/scripts/domain-test.sh"
echo -e "${GREEN}✓ 域名测试脚本更新成功${NC}"
else
echo -e "${RED}✗ 域名测试脚本下载失败${NC}"
exit 1
fi
# 同时更新主脚本,确保路径问题也被修复
echo -e "${BLUE}更新主脚本...${NC}"
if curl -fsSL "$RAW_URL/hy2-manager.sh" -o "$INSTALL_DIR/hy2-manager.sh"; then
chmod +x "$INSTALL_DIR/hy2-manager.sh"
echo -e "${GREEN}✓ 主脚本更新成功${NC}"
else
echo -e "${YELLOW}⚠ 主脚本更新失败,但域名测试功能已修复${NC}"
fi
# 验证修复效果
echo -e "${BLUE}验证修复效果...${NC}"
# 加载修复后的脚本
source "$INSTALL_DIR/scripts/domain-test.sh"
# 测试静默版本
echo "测试静默版本域名测试..."
if results=$(test_all_domains_silent 2>/dev/null | head -3); then
if [[ -n "$results" ]]; then
echo -e "${GREEN}✓ 静默版本测试成功${NC}"
# 验证输出格式
valid=true
while IFS= read -r line; do
if [[ -n "$line" ]]; then
latency=$(echo "$line" | awk '{print $1}')
domain=$(echo "$line" | awk '{print $2}')
if [[ ! "$latency" =~ ^[0-9]+$ ]] || [[ -z "$domain" ]] || [[ "$domain" =~ [[:space:]] ]]; then
valid=false
break
fi
fi
done <<< "$results"
if [[ "$valid" == "true" ]]; then
echo -e "${GREEN}✓ 输出格式验证通过${NC}"
else
echo -e "${YELLOW}⚠ 输出格式可能仍有问题${NC}"
fi
else
echo -e "${YELLOW}⚠ 静默版本无输出,可能是网络问题${NC}"
fi
else
echo -e "${RED}✗ 静默版本测试失败${NC}"
fi
echo ""
echo -e "${CYAN}修复完成!${NC}"
echo ""
echo -e "${YELLOW}现在可以测试域名功能:${NC}"
echo "1. 运行: sudo s-hy2"
echo "2. 选择 '6. 测试伪装域名'"
echo "3. 选择 '2. 交互式选择域名'"
echo ""
echo -e "${YELLOW}如果仍有问题,可以运行验证脚本:${NC}"
echo "curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/test-domain-fix.sh | bash"
-193
View File
@@ -1,193 +0,0 @@
#!/bin/bash
# S-Hy2 安装修复脚本
# 用于修复已安装但有问题的 s-hy2
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
# 配置
INSTALL_DIR="/opt/s-hy2"
BIN_DIR="/usr/local/bin"
RAW_URL="https://raw.githubusercontent.com/sindricn/s-hy2/main"
echo -e "${CYAN}S-Hy2 安装修复脚本${NC}"
echo ""
# 检查 root 权限
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}错误: 需要 root 权限${NC}"
echo "请使用: sudo bash"
exit 1
fi
# 诊断当前安装状态
echo -e "${BLUE}诊断当前安装状态...${NC}"
echo "1. 检查安装目录:"
if [[ -d "$INSTALL_DIR" ]]; then
echo -e " ${GREEN}✓ 安装目录存在: $INSTALL_DIR${NC}"
ls -la "$INSTALL_DIR"
else
echo -e " ${RED}✗ 安装目录不存在: $INSTALL_DIR${NC}"
fi
echo ""
echo "2. 检查主脚本:"
if [[ -f "$INSTALL_DIR/hy2-manager.sh" ]]; then
echo -e " ${GREEN}✓ 主脚本存在${NC}"
ls -la "$INSTALL_DIR/hy2-manager.sh"
else
echo -e " ${RED}✗ 主脚本不存在${NC}"
fi
echo ""
echo "3. 检查功能脚本目录:"
if [[ -d "$INSTALL_DIR/scripts" ]]; then
echo -e " ${GREEN}✓ 功能脚本目录存在${NC}"
echo " 目录内容:"
ls -la "$INSTALL_DIR/scripts/"
else
echo -e " ${RED}✗ 功能脚本目录不存在${NC}"
fi
echo ""
echo "4. 检查快捷方式:"
if [[ -L "$BIN_DIR/s-hy2" ]]; then
echo -e " ${GREEN}✓ s-hy2 快捷方式存在${NC}"
echo " 链接目标: $(readlink "$BIN_DIR/s-hy2")"
else
echo -e " ${RED}✗ s-hy2 快捷方式不存在${NC}"
fi
echo ""
echo -e "${YELLOW}开始修复...${NC}"
# 创建必要目录
echo -e "${BLUE}1. 创建必要目录...${NC}"
mkdir -p "$INSTALL_DIR/scripts" "$INSTALL_DIR/templates"
echo -e "${GREEN}✓ 目录创建完成${NC}"
# 下载主脚本
echo -e "${BLUE}2. 下载/更新主脚本...${NC}"
if curl -fsSL "$RAW_URL/hy2-manager.sh" -o "$INSTALL_DIR/hy2-manager.sh"; then
chmod +x "$INSTALL_DIR/hy2-manager.sh"
echo -e "${GREEN}✓ 主脚本下载成功${NC}"
else
echo -e "${RED}✗ 主脚本下载失败${NC}"
exit 1
fi
# 下载功能脚本
echo -e "${BLUE}3. 下载/更新功能脚本...${NC}"
scripts=(
"install.sh"
"config.sh"
"service.sh"
"domain-test.sh"
"advanced.sh"
"node-info.sh"
)
success=0
total=${#scripts[@]}
for script in "${scripts[@]}"; do
echo " 下载 $script..."
if curl -fsSL "$RAW_URL/scripts/$script" -o "$INSTALL_DIR/scripts/$script"; then
chmod +x "$INSTALL_DIR/scripts/$script"
echo -e " ${GREEN}$script${NC}"
((success++))
else
echo -e " ${RED}$script${NC}"
fi
done
echo -e "${GREEN}✓ 功能脚本下载完成 ($success/$total)${NC}"
# 下载配置模板
echo -e "${BLUE}4. 下载/更新配置模板...${NC}"
templates=(
"acme-config.yaml"
"self-cert-config.yaml"
"advanced-config.yaml"
"client-config.yaml"
)
template_success=0
template_total=${#templates[@]}
for template in "${templates[@]}"; do
echo " 下载 $template..."
if curl -fsSL "$RAW_URL/templates/$template" -o "$INSTALL_DIR/templates/$template"; then
echo -e " ${GREEN}$template${NC}"
((template_success++))
else
echo -e " ${RED}$template${NC}"
fi
done
echo -e "${GREEN}✓ 配置模板下载完成 ($template_success/$template_total)${NC}"
# 修复快捷方式
echo -e "${BLUE}5. 修复快捷方式...${NC}"
rm -f "$BIN_DIR/s-hy2" "$BIN_DIR/hy2-manager"
if ln -sf "$INSTALL_DIR/hy2-manager.sh" "$BIN_DIR/s-hy2" && \
ln -sf "$INSTALL_DIR/hy2-manager.sh" "$BIN_DIR/hy2-manager"; then
echo -e "${GREEN}✓ 快捷方式修复成功${NC}"
else
echo -e "${YELLOW}⚠ 快捷方式创建失败,可直接运行: $INSTALL_DIR/hy2-manager.sh${NC}"
fi
# 验证修复结果
echo -e "${BLUE}6. 验证修复结果...${NC}"
required_files=(
"$INSTALL_DIR/hy2-manager.sh"
"$INSTALL_DIR/scripts/install.sh"
"$INSTALL_DIR/scripts/config.sh"
"$INSTALL_DIR/scripts/service.sh"
)
missing=0
for file in "${required_files[@]}"; do
if [[ -f "$file" ]]; then
echo -e " ${GREEN}$(basename "$file")${NC}"
else
echo -e " ${RED}$(basename "$file")${NC}"
((missing++))
fi
done
echo ""
if [[ $missing -eq 0 ]]; then
echo -e "${GREEN}🎉 修复完成!所有关键文件都已就位${NC}"
echo ""
echo -e "${YELLOW}现在可以运行:${NC}"
echo " sudo s-hy2"
echo ""
# 询问是否立即测试
echo -n -e "${YELLOW}是否立即测试运行 s-hy2? [y/N]: ${NC}"
read -r test_run
if [[ $test_run =~ ^[Yy]$ ]]; then
echo ""
echo -e "${BLUE}正在启动 s-hy2...${NC}"
exec "$INSTALL_DIR/hy2-manager.sh"
fi
else
echo -e "${RED}❌ 修复未完全成功,仍缺少 $missing 个关键文件${NC}"
echo ""
echo -e "${YELLOW}建议:${NC}"
echo "1. 检查网络连接"
echo "2. 重新运行完整安装:"
echo " curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/install-fixed.sh | sudo bash"
exit 1
fi
echo -e "${BLUE}修复完成!${NC}"
+206 -8
View File
@@ -35,6 +35,7 @@ TEMPLATES_DIR="$SCRIPT_DIR/templates"
# 配置文件路径
CONFIG_PATH="/etc/hysteria/config.yaml"
SERVER_DOMAIN_CONFIG="/etc/hysteria/server-domain.conf"
SERVICE_NAME="hysteria-server.service"
# 检查是否为 root 用户
@@ -65,13 +66,14 @@ print_menu() {
echo -e "${GREEN}4.${NC} 管理服务"
echo -e "${GREEN}5.${NC} 查看日志"
echo -e "${GREEN}6.${NC} 测试伪装域名"
echo -e "${GREEN}7.${NC} 进阶配置"
echo -e "${GREEN}8.${NC} 节点信息"
echo -e "${GREEN}9.${NC} 卸载服务"
echo -e "${GREEN}10.${NC} 关于脚本"
echo -e "${GREEN}7.${NC} 服务器域名配置"
echo -e "${GREEN}8.${NC} 进阶配置"
echo -e "${GREEN}9.${NC} 节点信息"
echo -e "${GREEN}10.${NC} 卸载服务"
echo -e "${GREEN}11.${NC} 关于脚本"
echo -e "${RED}0.${NC} 退出"
echo ""
echo -n -e "${BLUE}请输入选项 [0-10]: ${NC}"
echo -n -e "${BLUE}请输入选项 [0-11]: ${NC}"
}
# 检查 Hysteria2 是否已安装
@@ -199,6 +201,199 @@ test_domains() {
fi
}
# 服务器域名配置
server_domain_config() {
echo -e "${BLUE}服务器域名配置${NC}"
echo ""
# 显示当前配置
if [[ -f "$SERVER_DOMAIN_CONFIG" ]]; then
local current_domain=$(cat "$SERVER_DOMAIN_CONFIG")
echo -e "${YELLOW}当前配置域名: $current_domain${NC}"
else
echo -e "${YELLOW}当前未配置服务器域名${NC}"
fi
echo ""
echo -e "${GREEN}1.${NC} 设置服务器域名"
echo -e "${GREEN}2.${NC} 验证域名解析"
echo -e "${GREEN}3.${NC} 删除域名配置"
echo -e "${RED}0.${NC} 返回主菜单"
echo ""
echo -n -e "${BLUE}请选择操作 [0-3]: ${NC}"
read -r choice
case $choice in
1)
set_server_domain
;;
2)
verify_domain_resolution
;;
3)
remove_server_domain
;;
0)
return
;;
*)
echo -e "${RED}无效选项${NC}"
sleep 1
server_domain_config
;;
esac
}
# 设置服务器域名
set_server_domain() {
echo ""
echo -e "${BLUE}设置服务器域名${NC}"
echo ""
echo "请输入解析到此服务器的域名 (例如: example.com):"
echo -n -e "${YELLOW}域名: ${NC}"
read -r domain
if [[ -z "$domain" ]]; then
echo -e "${RED}域名不能为空${NC}"
read -p "按回车键继续..."
return
fi
# 简单的域名格式验证
if [[ ! "$domain" =~ ^[a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?)*$ ]]; then
echo -e "${RED}域名格式不正确${NC}"
read -p "按回车键继续..."
return
fi
# 保存域名配置
echo "$domain" > "$SERVER_DOMAIN_CONFIG"
echo -e "${GREEN}服务器域名已设置: $domain${NC}"
# 询问是否立即验证
echo ""
echo -n -e "${YELLOW}是否立即验证域名解析? [Y/n]: ${NC}"
read -r verify
if [[ ! $verify =~ ^[Nn]$ ]]; then
verify_domain_resolution
fi
read -p "按回车键继续..."
}
# 验证域名解析
verify_domain_resolution() {
echo ""
echo -e "${BLUE}验证域名解析${NC}"
if [[ ! -f "$SERVER_DOMAIN_CONFIG" ]]; then
echo -e "${RED}未配置服务器域名${NC}"
read -p "按回车键继续..."
return
fi
local domain=$(cat "$SERVER_DOMAIN_CONFIG")
local server_ip=$(get_server_ip)
echo "正在验证域名: $domain"
echo "服务器IP: $server_ip"
echo ""
# 使用多种方法解析域名
local resolved_ip=""
# 方法1: 使用 dig
if command -v dig &> /dev/null; then
resolved_ip=$(dig +short "$domain" A | head -1)
fi
# 方法2: 使用 nslookup (备选)
if [[ -z "$resolved_ip" ]] && command -v nslookup &> /dev/null; then
resolved_ip=$(nslookup "$domain" | grep -A1 "Name:" | tail -1 | awk '{print $2}')
fi
# 方法3: 使用 host (备选)
if [[ -z "$resolved_ip" ]] && command -v host &> /dev/null; then
resolved_ip=$(host "$domain" | grep "has address" | awk '{print $4}' | head -1)
fi
if [[ -n "$resolved_ip" ]]; then
echo "域名解析结果: $resolved_ip"
if [[ "$resolved_ip" == "$server_ip" ]]; then
echo -e "${GREEN}✅ 域名解析正确,指向当前服务器${NC}"
else
echo -e "${RED}❌ 域名解析错误${NC}"
echo "域名指向: $resolved_ip"
echo "服务器IP: $server_ip"
echo ""
echo "请检查域名DNS设置"
fi
else
echo -e "${YELLOW}⚠️ 无法解析域名,可能原因:${NC}"
echo "1. 域名DNS设置未生效"
echo "2. 网络连接问题"
echo "3. DNS服务器问题"
fi
read -p "按回车键继续..."
}
# 删除服务器域名配置
remove_server_domain() {
echo ""
echo -e "${YELLOW}删除服务器域名配置${NC}"
if [[ ! -f "$SERVER_DOMAIN_CONFIG" ]]; then
echo -e "${YELLOW}未配置服务器域名${NC}"
read -p "按回车键继续..."
return
fi
local domain=$(cat "$SERVER_DOMAIN_CONFIG")
echo "当前配置域名: $domain"
echo ""
echo -n -e "${RED}确定要删除域名配置吗? [y/N]: ${NC}"
read -r confirm
if [[ $confirm =~ ^[Yy]$ ]]; then
rm -f "$SERVER_DOMAIN_CONFIG"
echo -e "${GREEN}域名配置已删除${NC}"
else
echo -e "${BLUE}取消删除${NC}"
fi
read -p "按回车键继续..."
}
# 获取服务器IP
get_server_ip() {
local ip=""
# 尝试多种方法获取公网IP
ip=$(curl -s --connect-timeout 5 ipv4.icanhazip.com 2>/dev/null) || \
ip=$(curl -s --connect-timeout 5 ifconfig.me 2>/dev/null) || \
ip=$(curl -s --connect-timeout 5 ip.sb 2>/dev/null) || \
ip=$(curl -s --connect-timeout 5 checkip.amazonaws.com 2>/dev/null)
if [[ -n "$ip" && "$ip" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
echo "$ip"
else
# 如果无法获取公网IP,尝试获取本地IP
ip=$(ip route get 8.8.8.8 2>/dev/null | grep -oP 'src \K\S+')
echo "${ip:-127.0.0.1}"
fi
}
# 获取配置的服务器域名
get_server_domain() {
if [[ -f "$SERVER_DOMAIN_CONFIG" ]]; then
cat "$SERVER_DOMAIN_CONFIG"
else
echo ""
fi
}
# 进阶配置
advanced_config() {
echo -e "${BLUE}进阶配置...${NC}"
@@ -528,15 +723,18 @@ main() {
test_domains
;;
7)
advanced_config
server_domain_config
;;
8)
show_node_info
advanced_config
;;
9)
uninstall_hysteria
show_node_info
;;
10)
uninstall_hysteria
;;
11)
about_script
;;
0)
-302
View File
@@ -1,302 +0,0 @@
#!/bin/bash
# Hysteria2 配置管理脚本修复版安装脚本
# 使用方法: curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/install-fixed.sh | sudo bash
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
# 脚本信息
SCRIPT_NAME="s-hy2"
INSTALL_DIR="/opt/$SCRIPT_NAME"
BIN_DIR="/usr/local/bin"
RAW_URL="https://raw.githubusercontent.com/sindricn/s-hy2/main"
# 检查是否为交互模式
INTERACTIVE=false
if [[ -t 0 ]]; then
INTERACTIVE=true
fi
# 打印标题
print_header() {
clear
echo -e "${CYAN}================================================${NC}"
echo -e "${CYAN} Hysteria2 配置管理脚本安装程序${NC}"
echo -e "${CYAN}================================================${NC}"
echo ""
}
# 检查 root 权限
check_root() {
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}错误: 需要 root 权限运行此脚本${NC}"
echo "请使用: sudo bash"
exit 1
fi
echo -e "${GREEN}✓ Root 权限检查通过${NC}"
}
# 检测系统
detect_system() {
if [[ -f /etc/os-release ]]; then
source /etc/os-release
OS=$ID
echo -e "${GREEN}✓ 系统: $PRETTY_NAME${NC}"
else
echo -e "${RED}✗ 无法检测系统类型${NC}"
exit 1
fi
}
# 安装依赖
install_dependencies() {
echo -e "${BLUE}安装基本依赖...${NC}"
case $OS in
ubuntu|debian)
apt update -qq >/dev/null 2>&1
apt install -y curl wget >/dev/null 2>&1
;;
centos|rhel|fedora)
if command -v dnf &>/dev/null; then
dnf install -y curl wget >/dev/null 2>&1
else
yum install -y curl wget >/dev/null 2>&1
fi
;;
esac
echo -e "${GREEN}✓ 依赖安装完成${NC}"
}
# 创建目录
create_directories() {
echo -e "${BLUE}创建安装目录...${NC}"
if mkdir -p "$INSTALL_DIR" "$INSTALL_DIR/scripts" "$INSTALL_DIR/templates"; then
echo -e "${GREEN}✓ 目录创建成功${NC}"
else
echo -e "${RED}✗ 目录创建失败${NC}"
exit 1
fi
}
# 下载文件
download_file() {
local url="$1"
local output="$2"
local description="$3"
if curl -fsSL "$url" -o "$output" 2>/dev/null; then
echo -e "${GREEN}$description${NC}"
return 0
else
echo -e "${RED}$description${NC}"
return 1
fi
}
# 下载所有文件
download_files() {
echo -e "${BLUE}下载脚本文件...${NC}"
cd "$INSTALL_DIR" || exit 1
local total=0
local success=0
# 下载主脚本
((total++))
if download_file "$RAW_URL/hy2-manager.sh" "hy2-manager.sh" "主脚本"; then
chmod +x hy2-manager.sh
((success++))
fi
# 下载功能脚本
local scripts=(
"install.sh:安装脚本"
"config.sh:配置脚本"
"service.sh:服务管理脚本"
"domain-test.sh:域名测试脚本"
"advanced.sh:进阶配置脚本"
"node-info.sh:节点信息脚本"
)
for script_info in "${scripts[@]}"; do
IFS=':' read -r script_name script_desc <<< "$script_info"
((total++))
if download_file "$RAW_URL/scripts/$script_name" "scripts/$script_name" "$script_desc"; then
chmod +x "scripts/$script_name"
((success++))
fi
done
# 下载配置模板
local templates=(
"acme-config.yaml:ACME配置模板"
"self-cert-config.yaml:自签名配置模板"
"advanced-config.yaml:高级配置模板"
"client-config.yaml:客户端配置模板"
)
for template_info in "${templates[@]}"; do
IFS=':' read -r template_name template_desc <<< "$template_info"
((total++))
if download_file "$RAW_URL/templates/$template_name" "templates/$template_name" "$template_desc"; then
((success++))
fi
done
echo -e "${GREEN}✓ 文件下载完成 ($success/$total)${NC}"
if [[ $success -lt 7 ]]; then # 至少需要主脚本和6个核心脚本
echo -e "${RED}✗ 关键文件下载失败,安装无法继续${NC}"
exit 1
fi
}
# 创建快捷方式
create_shortcuts() {
echo -e "${BLUE}创建快捷方式...${NC}"
if ln -sf "$INSTALL_DIR/hy2-manager.sh" "$BIN_DIR/s-hy2" && \
ln -sf "$INSTALL_DIR/hy2-manager.sh" "$BIN_DIR/hy2-manager"; then
echo -e "${GREEN}✓ 快捷方式创建成功${NC}"
else
echo -e "${YELLOW}⚠ 快捷方式创建失败,可直接运行: $INSTALL_DIR/hy2-manager.sh${NC}"
fi
}
# 验证安装
verify_installation() {
echo -e "${BLUE}验证安装...${NC}"
# 检查关键文件
local required_files=(
"$INSTALL_DIR/hy2-manager.sh"
"$INSTALL_DIR/scripts/install.sh"
"$INSTALL_DIR/scripts/config.sh"
"$INSTALL_DIR/scripts/service.sh"
)
local missing=0
for file in "${required_files[@]}"; do
if [[ ! -f "$file" ]]; then
echo -e "${RED}✗ 缺少文件: $file${NC}"
((missing++))
fi
done
if [[ $missing -eq 0 ]]; then
echo -e "${GREEN}✓ 安装验证通过${NC}"
return 0
else
echo -e "${RED}✗ 安装验证失败,缺少 $missing 个关键文件${NC}"
return 1
fi
}
# 显示完成信息
show_completion() {
echo ""
echo -e "${CYAN}================================================${NC}"
echo -e "${CYAN} 安装完成!${NC}"
echo -e "${CYAN}================================================${NC}"
echo ""
echo -e "${GREEN}安装位置:${NC} $INSTALL_DIR"
echo -e "${GREEN}快捷命令:${NC} s-hy2"
echo ""
echo -e "${YELLOW}使用方法:${NC}"
echo " sudo s-hy2"
echo ""
echo -e "${YELLOW}快速开始:${NC}"
echo "1. 运行: sudo s-hy2"
echo "2. 选择 '1. 安装 Hysteria2'"
echo "3. 选择 '2. 一键快速配置'"
echo ""
# 询问是否立即运行
if [[ "$INTERACTIVE" == "true" ]]; then
echo -n -e "${YELLOW}是否立即运行 s-hy2? [y/N]: ${NC}"
read -r run_now
if [[ $run_now =~ ^[Yy]$ ]]; then
echo ""
echo -e "${BLUE}正在启动 s-hy2...${NC}"
sleep 1
exec "$INSTALL_DIR/hy2-manager.sh"
fi
fi
echo -e "${BLUE}安装完成,请运行 'sudo s-hy2' 开始使用${NC}"
}
# 卸载函数
uninstall() {
echo -e "${YELLOW}卸载 S-Hy2 管理脚本...${NC}"
rm -f "$BIN_DIR/s-hy2" "$BIN_DIR/hy2-manager"
rm -rf "$INSTALL_DIR"
echo -e "${GREEN}卸载完成${NC}"
}
# 主函数
main() {
# 检查卸载参数
if [[ "$1" == "--uninstall" ]]; then
uninstall
exit 0
fi
print_header
echo -e "${YELLOW}即将安装 Hysteria2 配置管理脚本${NC}"
echo ""
echo -e "${BLUE}此脚本将会:${NC}"
echo "• 检测系统环境"
echo "• 安装基本依赖"
echo "• 下载脚本文件"
echo "• 创建快捷命令"
echo "• 验证安装结果"
echo ""
# 交互确认
if [[ "$INTERACTIVE" == "true" ]]; then
echo -n -e "${YELLOW}是否继续安装? [Y/n]: ${NC}"
read -r confirm
if [[ $confirm =~ ^[Nn]$ ]]; then
echo -e "${BLUE}取消安装${NC}"
exit 0
fi
else
echo -e "${YELLOW}检测到非交互模式,自动开始安装...${NC}"
sleep 2
fi
echo ""
echo -e "${BLUE}开始安装...${NC}"
# 执行安装步骤
check_root
detect_system
install_dependencies
create_directories
download_files
create_shortcuts
if verify_installation; then
show_completion
else
echo -e "${RED}安装过程中出现问题,请检查错误信息${NC}"
exit 1
fi
}
# 运行主函数
main "$@"
-348
View File
@@ -1,348 +0,0 @@
#!/bin/bash
# Hysteria2 配置管理脚本简化安装脚本
# 使用方法: curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install-simple.sh | sudo bash
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
# 脚本信息
SCRIPT_NAME="s-hy2"
INSTALL_DIR="/opt/$SCRIPT_NAME"
BIN_DIR="/usr/local/bin"
RAW_URL="https://raw.githubusercontent.com/sindricn/s-hy2/main"
# 打印标题
print_header() {
clear
echo -e "${CYAN}================================================${NC}"
echo -e "${CYAN} Hysteria2 配置管理脚本简化安装${NC}"
echo -e "${CYAN}================================================${NC}"
echo ""
}
# 检查是否为 root 用户
check_root() {
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}错误: 此脚本需要 root 权限运行${NC}"
echo "请使用 sudo 运行此脚本"
return 1
fi
echo -e "${GREEN}✓ Root 权限检查通过${NC}"
return 0
}
# 检测系统类型
detect_system() {
if [[ -f /etc/os-release ]]; then
source /etc/os-release
OS=$ID
VER=$VERSION_ID
echo -e "${GREEN}✓ 检测到系统: $PRETTY_NAME${NC}"
return 0
else
echo -e "${RED}✗ 无法检测系统类型${NC}"
return 1
fi
}
# 安装基本依赖
install_basic_deps() {
echo -e "${BLUE}安装基本依赖...${NC}"
case $OS in
ubuntu|debian)
apt update -qq
apt install -y curl wget
;;
centos|rhel|fedora)
if command -v dnf &> /dev/null; then
dnf install -y curl wget
else
yum install -y curl wget
fi
;;
*)
echo -e "${YELLOW}未知系统,跳过依赖安装${NC}"
;;
esac
echo -e "${GREEN}✓ 基本依赖安装完成${NC}"
}
# 创建目录
create_directories() {
echo -e "${BLUE}创建安装目录...${NC}"
if mkdir -p "$INSTALL_DIR" "$INSTALL_DIR/scripts" "$INSTALL_DIR/templates"; then
echo -e "${GREEN}✓ 目录创建成功${NC}"
return 0
else
echo -e "${RED}✗ 目录创建失败${NC}"
return 1
fi
}
# 下载主脚本
download_main_script() {
echo -e "${BLUE}下载主脚本...${NC}"
cd "$INSTALL_DIR" || return 1
if curl -fsSL "$RAW_URL/hy2-manager.sh" -o hy2-manager.sh; then
chmod +x hy2-manager.sh
echo -e "${GREEN}✓ 主脚本下载成功${NC}"
return 0
else
echo -e "${RED}✗ 主脚本下载失败${NC}"
return 1
fi
}
# 下载核心脚本
download_core_scripts() {
echo -e "${BLUE}下载核心脚本...${NC}"
local scripts=(
"install.sh"
"config.sh"
"service.sh"
"domain-test.sh"
"advanced.sh"
"node-info.sh"
)
local success=0
local total=${#scripts[@]}
local failed_scripts=()
for script in "${scripts[@]}"; do
echo " 下载 $script..."
if curl -fsSL "$RAW_URL/scripts/$script" -o "scripts/$script"; then
chmod +x "scripts/$script"
((success++))
echo -e " ${GREEN}$script 下载成功${NC}"
else
echo -e " ${RED}$script 下载失败${NC}"
failed_scripts+=("$script")
fi
done
echo -e "${GREEN}✓ 核心脚本下载完成 ($success/$total)${NC}"
if [[ ${#failed_scripts[@]} -gt 0 ]]; then
echo -e "${YELLOW}失败的脚本: ${failed_scripts[*]}${NC}"
echo -e "${YELLOW}这可能会影响某些功能的使用${NC}"
fi
return 0
}
# 下载配置模板
download_templates() {
echo -e "${BLUE}下载配置模板...${NC}"
local templates=(
"acme-config.yaml"
"self-cert-config.yaml"
"advanced-config.yaml"
"client-config.yaml"
)
local success=0
local total=${#templates[@]}
for template in "${templates[@]}"; do
if curl -fsSL "$RAW_URL/templates/$template" -o "templates/$template"; then
((success++))
else
echo -e "${YELLOW} 警告: $template 下载失败${NC}"
fi
done
echo -e "${GREEN}✓ 配置模板下载完成 ($success/$total)${NC}"
return 0
}
# 创建快捷方式
create_shortcuts() {
echo -e "${BLUE}创建快捷方式...${NC}"
if ln -sf "$INSTALL_DIR/hy2-manager.sh" "$BIN_DIR/hy2-manager" && \
ln -sf "$INSTALL_DIR/hy2-manager.sh" "$BIN_DIR/s-hy2"; then
echo -e "${GREEN}✓ 快捷方式创建成功${NC}"
return 0
else
echo -e "${RED}✗ 快捷方式创建失败${NC}"
return 1
fi
}
# 验证安装
verify_installation() {
echo -e "${BLUE}验证安装...${NC}"
local issues=0
# 检查主脚本
if [[ -f "$INSTALL_DIR/hy2-manager.sh" && -x "$INSTALL_DIR/hy2-manager.sh" ]]; then
echo -e "${GREEN}✓ 主脚本存在且可执行${NC}"
else
echo -e "${RED}✗ 主脚本不存在或不可执行${NC}"
((issues++))
fi
# 检查核心脚本
local required_scripts=("install.sh" "config.sh" "service.sh")
for script in "${required_scripts[@]}"; do
if [[ -f "$INSTALL_DIR/scripts/$script" ]]; then
echo -e "${GREEN}$script 存在${NC}"
else
echo -e "${RED}$script 不存在${NC}"
((issues++))
fi
done
# 检查快捷方式
if [[ -L "$BIN_DIR/s-hy2" ]]; then
echo -e "${GREEN}✓ s-hy2 快捷方式存在${NC}"
else
echo -e "${YELLOW}⚠ s-hy2 快捷方式不存在${NC}"
fi
if [[ $issues -eq 0 ]]; then
echo -e "${GREEN}✓ 安装验证通过${NC}"
return 0
else
echo -e "${YELLOW}⚠ 发现 $issues 个问题,但安装基本完成${NC}"
return 1
fi
}
# 显示完成信息
show_completion() {
echo ""
echo -e "${CYAN}================================================${NC}"
echo -e "${CYAN} 安装完成!${NC}"
echo -e "${CYAN}================================================${NC}"
echo ""
echo -e "${GREEN}安装位置:${NC} $INSTALL_DIR"
echo -e "${GREEN}快捷命令:${NC} s-hy2, hy2-manager"
echo ""
echo -e "${YELLOW}使用方法:${NC}"
echo " sudo s-hy2"
echo ""
echo -e "${YELLOW}快速开始:${NC}"
echo "1. 运行: sudo s-hy2"
echo "2. 选择 '1. 安装 Hysteria2'"
echo "3. 选择 '2. 一键快速配置'"
echo ""
# 询问是否立即运行
if [[ -t 0 ]]; then
echo -n -e "${YELLOW}是否立即运行 s-hy2? [y/N]: ${NC}"
read -r run_now
if [[ $run_now =~ ^[Yy]$ ]]; then
echo ""
echo -e "${BLUE}正在启动 s-hy2...${NC}"
exec "$INSTALL_DIR/hy2-manager.sh"
else
echo -e "${BLUE}安装完成,稍后可运行 'sudo s-hy2' 开始使用${NC}"
fi
else
echo -e "${BLUE}安装完成,请运行 'sudo s-hy2' 开始使用${NC}"
fi
}
# 卸载函数
uninstall() {
echo -e "${YELLOW}卸载 S-Hy2 管理脚本...${NC}"
rm -f "$BIN_DIR/hy2-manager"
rm -f "$BIN_DIR/s-hy2"
rm -rf "$INSTALL_DIR"
echo -e "${GREEN}卸载完成${NC}"
}
# 主函数
main() {
# 检查卸载参数
if [[ "$1" == "--uninstall" ]]; then
uninstall
exit 0
fi
print_header
echo -e "${YELLOW}即将安装 Hysteria2 配置管理脚本${NC}"
echo ""
echo -e "${BLUE}此脚本将会:${NC}"
echo "• 检测系统环境"
echo "• 安装基本依赖"
echo "• 下载脚本文件"
echo "• 创建快捷命令 's-hy2'"
echo "• 设置执行权限"
echo ""
# 检查是否通过管道运行
if [[ -t 0 ]]; then
# 交互模式
echo -n -e "${YELLOW}是否继续安装? [Y/n]: ${NC}"
read -r confirm
if [[ $confirm =~ ^[Nn]$ ]]; then
echo -e "${BLUE}取消安装${NC}"
exit 0
fi
else
# 管道模式,自动确认
echo -e "${YELLOW}检测到管道模式,自动开始安装...${NC}"
sleep 2
fi
echo ""
echo -e "${BLUE}开始安装...${NC}"
# 执行安装步骤
if ! check_root; then
echo -e "${RED}安装失败: 需要 root 权限${NC}"
exit 1
fi
if ! detect_system; then
echo -e "${RED}安装失败: 无法检测系统${NC}"
exit 1
fi
install_basic_deps
if ! create_directories; then
echo -e "${RED}安装失败: 无法创建目录${NC}"
exit 1
fi
if ! download_main_script; then
echo -e "${RED}安装失败: 主脚本下载失败${NC}"
exit 1
fi
download_core_scripts
download_templates
if ! create_shortcuts; then
echo -e "${YELLOW}警告: 快捷方式创建失败${NC}"
fi
# 验证安装
verify_installation
show_completion
}
# 运行主函数
main "$@"
+134 -16
View File
@@ -28,21 +28,49 @@ validate_email() {
fi
}
# 获取服务器域名配置
get_server_domain() {
if [[ -f "/etc/hysteria/server-domain.conf" ]]; then
cat "/etc/hysteria/server-domain.conf"
else
echo ""
fi
}
# ACME 配置模式
configure_acme_mode() {
echo -e "${BLUE}ACME 自动证书配置${NC}"
echo ""
# 输入域名
while true; do
echo -n -e "${BLUE}请输入域名 (例: your.domain.com): ${NC}"
read -r domain
if validate_domain "$domain"; then
break
else
echo -e "${RED}域名格式无效,请重新输入${NC}"
# 检查是否已配置服务器域名
local configured_domain=$(get_server_domain)
local domain=""
if [[ -n "$configured_domain" ]]; then
echo -e "${GREEN}检测到已配置的服务器域名: $configured_domain${NC}"
echo ""
echo -n -e "${YELLOW}是否使用已配置的域名? [Y/n]: ${NC}"
read -r use_configured
if [[ ! $use_configured =~ ^[Nn]$ ]]; then
domain="$configured_domain"
echo -e "${GREEN}使用已配置域名: $domain${NC}"
fi
done
fi
# 如果没有使用已配置域名,则手动输入
if [[ -z "$domain" ]]; then
echo -e "${BLUE}手动输入域名${NC}"
while true; do
echo -n -e "${BLUE}请输入域名 (例: your.domain.com): ${NC}"
read -r domain
if validate_domain "$domain"; then
break
else
echo -e "${RED}域名格式无效,请重新输入${NC}"
fi
done
fi
# 输入邮箱
while true; do
@@ -256,6 +284,72 @@ get_network_interface() {
echo "$interface"
}
# 检查端口跳跃状态
check_port_hopping_status() {
if iptables -t nat -L PREROUTING 2>/dev/null | grep -q "REDIRECT.*--to-ports 443"; then
return 0 # 已开启
else
return 1 # 未开启
fi
}
# 询问端口跳跃设置
ask_port_hopping_config() {
echo -e "${BLUE}检查端口跳跃状态...${NC}"
if check_port_hopping_status; then
echo -e "${GREEN}端口跳跃已开启${NC}"
echo ""
echo -n -e "${YELLOW}是否保持端口跳跃开启? [Y/n]: ${NC}"
read -r keep_hopping
if [[ $keep_hopping =~ ^[Nn]$ ]]; then
echo -e "${BLUE}关闭端口跳跃...${NC}"
# 清除端口跳跃规则
iptables -t nat -D PREROUTING -i $(get_network_interface) -p udp --dport 20000:50000 -j REDIRECT --to-ports 443 2>/dev/null || true
echo -e "${GREEN}端口跳跃已关闭${NC}"
else
echo -e "${GREEN}保持端口跳跃开启${NC}"
fi
else
echo -e "${YELLOW}端口跳跃未开启${NC}"
echo ""
echo -n -e "${YELLOW}是否开启端口跳跃? [y/N]: ${NC}"
read -r enable_hopping
if [[ $enable_hopping =~ ^[Yy]$ ]]; then
echo -e "${BLUE}开启端口跳跃...${NC}"
# 添加端口跳跃规则
iptables -t nat -A PREROUTING -i $(get_network_interface) -p udp --dport 20000:50000 -j REDIRECT --to-ports 443
echo -e "${GREEN}端口跳跃已开启${NC}"
else
echo -e "${BLUE}保持端口跳跃关闭${NC}"
fi
fi
echo ""
}
# 询问是否重启服务
ask_restart_service() {
echo ""
echo -n -e "${YELLOW}配置已完成,是否立即重启 Hysteria2 服务? [Y/n]: ${NC}"
read -r restart_service
if [[ ! $restart_service =~ ^[Nn]$ ]]; then
echo -e "${BLUE}正在重启 Hysteria2 服务...${NC}"
systemctl restart hysteria-server
if systemctl is-active --quiet hysteria-server; then
echo -e "${GREEN}✅ 服务重启成功${NC}"
else
echo -e "${RED}❌ 服务重启失败${NC}"
echo "请检查配置文件或查看日志"
fi
else
echo -e "${YELLOW}请稍后手动重启服务: systemctl restart hysteria-server${NC}"
fi
}
# 一键快速配置
quick_setup_hysteria() {
echo -e "${CYAN}=== Hysteria2 一键快速配置 ===${NC}"
@@ -427,6 +521,12 @@ EOF
echo -e "${RED}服务启动失败${NC}"
fi
# 检查端口跳跃状态并询问
ask_port_hopping_config
# 询问是否重启服务
ask_restart_service
echo ""
read -p "按回车键继续..."
}
@@ -440,6 +540,18 @@ generate_node_info() {
local start_port="$5"
local end_port="$6"
# 检查是否有配置的服务器域名
local configured_domain=$(get_server_domain)
local server_address=""
if [[ -n "$configured_domain" ]]; then
server_address="$configured_domain:443"
echo -e "${GREEN}使用已配置的服务器域名: $configured_domain${NC}"
else
server_address="$server_ip:443"
echo -e "${YELLOW}使用服务器IP地址: $server_ip${NC}"
fi
# 保存节点信息到文件
local node_file="/etc/hysteria/node-info.txt"
@@ -447,7 +559,7 @@ generate_node_info() {
# Hysteria2 节点信息
# 生成时间: $(date)
服务器地址: $server_ip:443
服务器地址: $server_address
认证密码: $auth_password
混淆密码: $obfs_password
SNI域名: $sni_domain
@@ -455,7 +567,7 @@ SNI域名: $sni_domain
证书验证: 忽略 (自签名证书)
# 客户端配置示例
server: $server_ip:443
server: $server_address
auth: $auth_password
tls:
sni: $sni_domain
@@ -536,11 +648,17 @@ generate_hysteria_config() {
echo ""
echo -e "${GREEN}配置文件已保存到: $CONFIG_PATH${NC}"
# 检查端口跳跃状态并询问
ask_port_hopping_config
# 询问是否重启服务
ask_restart_service
echo ""
echo -e "${YELLOW}下一步建议:${NC}"
echo "1. 启动服务: systemctl enable --now hysteria-server.service"
echo "2. 查看状态: systemctl status hysteria-server.service"
echo "3. 查看日志: journalctl -u hysteria-server.service"
echo -e "${YELLOW}其他管理命令:${NC}"
echo "1. 查看状态: systemctl status hysteria-server.service"
echo "2. 查看日志: journalctl -u hysteria-server.service"
echo ""
read -p "按回车键继续..."
}
+107 -57
View File
@@ -45,16 +45,25 @@ parse_config_info() {
echo "$port|$auth_password|$obfs_password|$sni_domain|$cert_type|$insecure"
}
# 获取服务器域名配置
get_server_domain() {
if [[ -f "/etc/hysteria/server-domain.conf" ]]; then
cat "/etc/hysteria/server-domain.conf"
else
echo ""
fi
}
# 获取服务器IP
get_current_server_ip() {
local ip=""
# 尝试多种方法获取公网IP
ip=$(curl -s --connect-timeout 5 ipv4.icanhazip.com 2>/dev/null) || \
ip=$(curl -s --connect-timeout 5 ifconfig.me 2>/dev/null) || \
ip=$(curl -s --connect-timeout 5 ip.sb 2>/dev/null) || \
ip=$(curl -s --connect-timeout 5 checkip.amazonaws.com 2>/dev/null)
if [[ -n "$ip" && "$ip" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
echo "$ip"
else
@@ -64,6 +73,17 @@ get_current_server_ip() {
fi
}
# 获取服务器地址(优先使用域名)
get_server_address() {
local configured_domain=$(get_server_domain)
if [[ -n "$configured_domain" ]]; then
echo "$configured_domain"
else
get_current_server_ip
fi
}
# 获取端口跳跃信息
get_port_hopping_info() {
if [[ -f "/etc/hysteria/port-hopping.conf" ]]; then
@@ -116,18 +136,47 @@ generate_subscription_link() {
echo "$node_link" | base64 -w 0
}
# 生成不同客户端的订阅链接
generate_client_subscriptions() {
local node_link="$1"
echo -e "${CYAN}=== 客户端订阅链接 ===${NC}"
echo ""
# Hysteria2 通用订阅
local hysteria2_sub=$(echo "$node_link" | base64 -w 0)
echo -e "${YELLOW}Hysteria2 通用订阅:${NC}"
echo "$hysteria2_sub"
echo ""
# V2Ray/Xray 兼容订阅 (如果支持)
echo -e "${YELLOW}V2Ray/Xray 兼容订阅:${NC}"
echo "暂不支持,请使用 Hysteria2 专用客户端"
echo ""
# Clash 兼容订阅
echo -e "${YELLOW}Clash 兼容订阅:${NC}"
echo "暂不支持,请使用 Hysteria2 专用客户端"
echo ""
echo -e "${GREEN}推荐客户端:${NC}"
echo "• Windows/macOS/Linux: Hysteria2 官方客户端"
echo "• Android: NekoBox, v2rayNG (支持 Hysteria2)"
echo "• iOS: Shadowrocket, QuantumultX (支持 Hysteria2)"
}
# 生成客户端配置
generate_client_config() {
local server_ip="$1"
local server_address="$1"
local port="$2"
local auth_password="$3"
local obfs_password="$4"
local sni_domain="$5"
local insecure="$6"
cat << EOF
# Hysteria2 客户端配置
server: $server_ip:$port
server: $server_address:$port
auth: $auth_password
tls:
@@ -181,24 +230,31 @@ display_node_info() {
fi
# 获取服务器信息
local server_address=$(get_server_address)
local server_ip=$(get_current_server_ip)
local configured_domain=$(get_server_domain)
local config_info=$(parse_config_info)
if [[ -z "$config_info" ]]; then
echo -e "${RED}错误: 无法解析配置文件${NC}"
read -p "按回车键继续..."
return
fi
# 解析配置信息
IFS='|' read -r port auth_password obfs_password sni_domain cert_type insecure <<< "$config_info"
# 获取端口跳跃信息
local port_hopping=$(get_port_hopping_info)
# 显示基本信息
echo -e "${CYAN}=== 服务器信息 ===${NC}"
echo -e "${YELLOW}服务器地址:${NC} $server_ip:$port"
if [[ -n "$configured_domain" ]]; then
echo -e "${YELLOW}服务器域名:${NC} $configured_domain:$port"
echo -e "${YELLOW}服务器IP:${NC} $server_ip:$port"
else
echo -e "${YELLOW}服务器地址:${NC} $server_ip:$port"
fi
echo -e "${YELLOW}认证密码:${NC} $auth_password"
if [[ -n "$obfs_password" ]]; then
echo -e "${YELLOW}混淆密码:${NC} $obfs_password"
@@ -209,22 +265,20 @@ display_node_info() {
echo -e "${YELLOW}证书类型:${NC} $cert_type"
echo -e "${YELLOW}端口跳跃:${NC} $port_hopping"
echo ""
# 生成链接
local node_link=$(generate_node_link "$server_ip" "$port" "$auth_password" "$obfs_password" "$sni_domain" "$insecure")
local subscription_link=$(generate_subscription_link "$node_link")
# 生成链接(使用服务器地址)
local node_link=$(generate_node_link "$server_address" "$port" "$auth_password" "$obfs_password" "$sni_domain" "$insecure")
while true; do
echo -e "${CYAN}=== 节点信息选项 ===${NC}"
echo -e "${GREEN}1.${NC} 显示节点链接"
echo -e "${GREEN}2.${NC} 显示订阅链接"
echo -e "${GREEN}2.${NC} 显示客户端订阅链接"
echo -e "${GREEN}3.${NC} 显示客户端配置"
echo -e "${GREEN}4.${NC} 保存到文件"
echo -e "${GREEN}5.${NC} 生成二维码 (需要 qrencode)"
echo -e "${GREEN}6.${NC} 刷新信息"
echo -e "${GREEN}5.${NC} 刷新信息"
echo -e "${RED}0.${NC} 返回主菜单"
echo ""
echo -n -e "${BLUE}请选择操作 [0-6]: ${NC}"
echo -n -e "${BLUE}请选择操作 [0-5]: ${NC}"
read -r choice
case $choice in
@@ -237,8 +291,7 @@ display_node_info() {
;;
2)
echo ""
echo -e "${CYAN}订阅链接 (Base64):${NC}"
echo "$subscription_link"
generate_client_subscriptions "$node_link"
echo ""
read -p "按回车键继续..."
;;
@@ -246,24 +299,22 @@ display_node_info() {
echo ""
echo -e "${CYAN}客户端配置:${NC}"
echo ""
generate_client_config "$server_ip" "$port" "$auth_password" "$obfs_password" "$sni_domain" "$insecure"
generate_client_config "$server_address" "$port" "$auth_password" "$obfs_password" "$sni_domain" "$insecure"
echo ""
read -p "按回车键继续..."
;;
4)
save_node_info_to_file "$server_ip" "$port" "$auth_password" "$obfs_password" "$sni_domain" "$insecure" "$port_hopping" "$node_link" "$subscription_link"
save_node_info_to_file "$server_address" "$port" "$auth_password" "$obfs_password" "$sni_domain" "$insecure" "$port_hopping" "$node_link"
;;
5)
generate_qr_code "$node_link"
;;
6)
# 刷新信息
server_address=$(get_server_address)
server_ip=$(get_current_server_ip)
configured_domain=$(get_server_domain)
config_info=$(parse_config_info)
IFS='|' read -r port auth_password obfs_password sni_domain cert_type insecure <<< "$config_info"
port_hopping=$(get_port_hopping_info)
node_link=$(generate_node_link "$server_ip" "$port" "$auth_password" "$obfs_password" "$sni_domain" "$insecure")
subscription_link=$(generate_subscription_link "$node_link")
node_link=$(generate_node_link "$server_address" "$port" "$auth_password" "$obfs_password" "$sni_domain" "$insecure")
echo -e "${GREEN}信息已刷新${NC}"
sleep 1
;;
@@ -280,7 +331,7 @@ display_node_info() {
# 保存节点信息到文件
save_node_info_to_file() {
local server_ip="$1"
local server_address="$1"
local port="$2"
local auth_password="$3"
local obfs_password="$4"
@@ -288,16 +339,30 @@ save_node_info_to_file() {
local insecure="$6"
local port_hopping="$7"
local node_link="$8"
local subscription_link="$9"
local output_file="/etc/hysteria/node-info.txt"
local configured_domain=$(get_server_domain)
local server_ip=$(get_current_server_ip)
cat > "$output_file" << EOF
# Hysteria2 节点信息
# 生成时间: $(date)
=== 服务器信息 ===
服务器地址: $server_ip:$port
EOF
if [[ -n "$configured_domain" ]]; then
cat >> "$output_file" << EOF
服务器域名: $configured_domain:$port
服务器IP: $server_ip:$port
EOF
else
cat >> "$output_file" << EOF
服务器地址: $server_address:$port
EOF
fi
cat >> "$output_file" << EOF
认证密码: $auth_password
混淆密码: ${obfs_password:-未启用}
SNI域名: ${sni_domain:-未设置}
@@ -307,37 +372,22 @@ SNI域名: ${sni_domain:-未设置}
=== 节点链接 ===
$node_link
=== 订阅链接 (Base64) ===
$subscription_link
=== Hysteria2 订阅链接 ===
$(echo "$node_link" | base64 -w 0)
=== 客户端配置 ===
$(generate_client_config "$server_ip" "$port" "$auth_password" "$obfs_password" "$sni_domain" "$insecure")
$(generate_client_config "$server_address" "$port" "$auth_password" "$obfs_password" "$sni_domain" "$insecure")
=== 推荐客户端 ===
• Windows/macOS/Linux: Hysteria2 官方客户端
• Android: NekoBox, v2rayNG (支持 Hysteria2)
• iOS: Shadowrocket, QuantumultX (支持 Hysteria2)
EOF
echo ""
echo -e "${GREEN}节点信息已保存到: $output_file${NC}"
echo ""
read -p "按回车键继续..."
}
# 生成二维码
generate_qr_code() {
local content="$1"
if command -v qrencode &> /dev/null; then
echo ""
echo -e "${CYAN}节点链接二维码:${NC}"
echo ""
qrencode -t ANSIUTF8 "$content"
echo ""
else
echo ""
echo -e "${YELLOW}qrencode 未安装,无法生成二维码${NC}"
echo "安装命令:"
echo " Ubuntu/Debian: apt install qrencode"
echo " CentOS/RHEL: yum install qrencode"
echo ""
fi
read -p "按回车键继续..."
}
-108
View File
@@ -1,108 +0,0 @@
#!/bin/bash
# 测试域名功能修复效果
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
echo -e "${CYAN}域名测试功能修复验证${NC}"
echo ""
# 检查脚本是否存在
if [[ ! -f "/opt/s-hy2/scripts/domain-test.sh" ]]; then
echo -e "${RED}错误: 域名测试脚本不存在${NC}"
echo "请先运行修复脚本:"
echo "curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/fix-installation.sh | sudo bash"
exit 1
fi
# 加载域名测试脚本
source /opt/s-hy2/scripts/domain-test.sh
echo -e "${BLUE}测试1: 静默版本域名测试${NC}"
echo "这个测试应该只输出 '延迟 域名' 格式的数据,没有进度信息"
echo ""
# 测试静默版本
echo "--- 静默版本输出 ---"
results=$(test_all_domains_silent | head -5)
echo "$results"
echo "--- 输出结束 ---"
echo ""
# 验证输出格式
echo -e "${BLUE}验证输出格式:${NC}"
valid_lines=0
total_lines=0
while IFS= read -r line; do
if [[ -n "$line" ]]; then
total_lines=$((total_lines + 1))
latency=$(echo "$line" | awk '{print $1}')
domain=$(echo "$line" | awk '{print $2}')
if [[ "$latency" =~ ^[0-9]+$ ]] && [[ -n "$domain" ]] && [[ ! "$domain" =~ [[:space:]] ]]; then
echo -e "${GREEN}✓ 有效: $latency ms - $domain${NC}"
valid_lines=$((valid_lines + 1))
else
echo -e "${RED}✗ 无效: $line${NC}"
fi
fi
done <<< "$results"
echo ""
echo "统计: $valid_lines/$total_lines 行有效"
if [[ $valid_lines -eq $total_lines ]] && [[ $total_lines -gt 0 ]]; then
echo -e "${GREEN}✅ 静默版本测试通过${NC}"
else
echo -e "${RED}❌ 静默版本测试失败${NC}"
fi
echo ""
echo -e "${BLUE}测试2: 带进度版本域名测试${NC}"
echo "这个测试应该显示进度信息,但不影响结果输出"
echo ""
# 测试带进度版本
echo "--- 带进度版本输出 ---"
results_with_progress=$(test_all_domains | head -5)
echo "$results_with_progress"
echo "--- 输出结束 ---"
echo ""
# 比较两个版本的输出
echo -e "${BLUE}比较两个版本的输出:${NC}"
if [[ "$results" == "$results_with_progress" ]]; then
echo -e "${GREEN}✅ 两个版本输出一致${NC}"
else
echo -e "${RED}❌ 两个版本输出不一致${NC}"
echo ""
echo "静默版本:"
echo "$results"
echo ""
echo "带进度版本:"
echo "$results_with_progress"
fi
echo ""
echo -e "${BLUE}测试3: 获取最优域名${NC}"
best_domain=$(get_best_domain_name)
echo "最优域名: $best_domain"
if [[ -n "$best_domain" ]] && [[ ! "$best_domain" =~ [[:space:]] ]]; then
echo -e "${GREEN}✅ 最优域名获取成功${NC}"
else
echo -e "${RED}❌ 最优域名获取失败${NC}"
fi
echo ""
echo -e "${CYAN}修复验证完成${NC}"
echo ""
echo -e "${YELLOW}如果所有测试都通过,域名测试功能应该已经修复${NC}"
echo -e "${YELLOW}现在可以运行 'sudo s-hy2' 测试交互式域名选择功能${NC}"
-119
View File
@@ -1,119 +0,0 @@
#!/bin/bash
# S-Hy2 安装测试脚本
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
echo -e "${CYAN}S-Hy2 安装测试脚本${NC}"
echo ""
# 测试1: 检查网络连接
echo -e "${BLUE}测试1: 检查网络连接${NC}"
if curl -s --connect-timeout 5 https://raw.githubusercontent.com/sindricn/s-hy2/main/README.md > /dev/null; then
echo -e "${GREEN}✓ 网络连接正常${NC}"
else
echo -e "${RED}✗ 网络连接失败${NC}"
echo "请检查网络设置或防火墙配置"
exit 1
fi
# 测试2: 检查 GitHub 访问
echo -e "${BLUE}测试2: 检查 GitHub 访问${NC}"
if curl -s --connect-timeout 5 https://github.com/sindricn/s-hy2 > /dev/null; then
echo -e "${GREEN}✓ GitHub 访问正常${NC}"
else
echo -e "${YELLOW}⚠ GitHub 访问可能有问题${NC}"
fi
# 测试3: 检查 root 权限
echo -e "${BLUE}测试3: 检查 root 权限${NC}"
if [[ $EUID -eq 0 ]]; then
echo -e "${GREEN}✓ 具有 root 权限${NC}"
else
echo -e "${RED}✗ 需要 root 权限${NC}"
echo "请使用 sudo 运行此脚本"
exit 1
fi
# 测试4: 检查系统类型
echo -e "${BLUE}测试4: 检查系统类型${NC}"
if [[ -f /etc/os-release ]]; then
source /etc/os-release
echo -e "${GREEN}✓ 系统: $PRETTY_NAME${NC}"
else
echo -e "${RED}✗ 无法检测系统类型${NC}"
exit 1
fi
# 测试5: 检查必要命令
echo -e "${BLUE}测试5: 检查必要命令${NC}"
commands=("curl" "wget" "mkdir" "chmod" "ln")
for cmd in "${commands[@]}"; do
if command -v "$cmd" &> /dev/null; then
echo -e "${GREEN}$cmd 可用${NC}"
else
echo -e "${RED}$cmd 不可用${NC}"
missing_commands+=("$cmd")
fi
done
if [[ ${#missing_commands[@]} -gt 0 ]]; then
echo -e "${YELLOW}需要安装缺失的命令: ${missing_commands[*]}${NC}"
fi
# 测试6: 测试下载主脚本
echo -e "${BLUE}测试6: 测试下载主脚本${NC}"
temp_file="/tmp/hy2-manager-test.sh"
if curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/hy2-manager.sh -o "$temp_file"; then
if [[ -f "$temp_file" ]] && [[ -s "$temp_file" ]]; then
echo -e "${GREEN}✓ 主脚本下载成功${NC}"
rm -f "$temp_file"
else
echo -e "${RED}✗ 主脚本下载失败或文件为空${NC}"
fi
else
echo -e "${RED}✗ 主脚本下载失败${NC}"
fi
# 测试7: 测试目录创建权限
echo -e "${BLUE}测试7: 测试目录创建权限${NC}"
test_dir="/opt/s-hy2-test"
if mkdir -p "$test_dir"; then
echo -e "${GREEN}✓ 目录创建权限正常${NC}"
rmdir "$test_dir"
else
echo -e "${RED}✗ 目录创建权限不足${NC}"
fi
# 测试8: 测试符号链接创建权限
echo -e "${BLUE}测试8: 测试符号链接创建权限${NC}"
test_link="/usr/local/bin/s-hy2-test"
test_target="/tmp/test-target"
echo "test" > "$test_target"
if ln -sf "$test_target" "$test_link"; then
echo -e "${GREEN}✓ 符号链接创建权限正常${NC}"
rm -f "$test_link" "$test_target"
else
echo -e "${RED}✗ 符号链接创建权限不足${NC}"
fi
echo ""
echo -e "${CYAN}测试完成!${NC}"
echo ""
echo -e "${YELLOW}如果所有测试都通过,可以运行以下命令安装:${NC}"
echo ""
echo -e "${GREEN}简化版安装 (推荐):${NC}"
echo "curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install-simple.sh | sudo bash"
echo ""
echo -e "${GREEN}完整版安装:${NC}"
echo "curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install.sh | sudo bash"
echo ""
echo -e "${GREEN}调试模式安装:${NC}"
echo "curl -fsSL https://raw.githubusercontent.com/sindricn/s-hy2/main/quick-install.sh | sudo bash -s -- --debug"
echo ""
-81
View File
@@ -1,81 +0,0 @@
#!/bin/bash
# 交互检测测试脚本
echo "=== 交互检测测试 ==="
echo ""
echo "测试方法:"
echo "1. 直接运行: bash test-interactive.sh"
echo "2. 管道运行: echo '' | bash test-interactive.sh"
echo "3. 重定向运行: bash test-interactive.sh < /dev/null"
echo ""
echo "当前检测结果:"
# 方法1: 检查标准输入是否为终端
if [[ -t 0 ]]; then
echo "✓ 标准输入是终端 (交互模式)"
INTERACTIVE_1=true
else
echo "✗ 标准输入不是终端 (非交互模式)"
INTERACTIVE_1=false
fi
# 方法2: 检查标准输出是否为终端
if [[ -t 1 ]]; then
echo "✓ 标准输出是终端"
INTERACTIVE_2=true
else
echo "✗ 标准输出不是终端"
INTERACTIVE_2=false
fi
# 方法3: 检查是否有 TERM 环境变量
if [[ -n "$TERM" ]]; then
echo "✓ TERM 环境变量存在: $TERM"
INTERACTIVE_3=true
else
echo "✗ TERM 环境变量不存在"
INTERACTIVE_3=false
fi
# 方法4: 检查 PS1 变量
if [[ -n "$PS1" ]]; then
echo "✓ PS1 变量存在 (交互式 shell)"
INTERACTIVE_4=true
else
echo "✗ PS1 变量不存在 (非交互式 shell)"
INTERACTIVE_4=false
fi
echo ""
echo "综合判断:"
# 使用最常用的方法
if [[ -t 0 ]]; then
echo "🟢 交互模式 - 可以等待用户输入"
echo ""
echo -n "请输入 'y' 测试交互功能: "
read -r response
if [[ $response =~ ^[Yy]$ ]]; then
echo "✓ 交互功能正常"
else
echo "✗ 用户输入: '$response'"
fi
else
echo "🔴 非交互模式 - 不应等待用户输入"
echo "这通常发生在:"
echo " - 通过管道运行: curl ... | bash"
echo " - 重定向输入: bash script.sh < file"
echo " - 后台运行: bash script.sh &"
echo " - cron 任务中运行"
fi
echo ""
echo "环境信息:"
echo " SHELL: $SHELL"
echo " TERM: $TERM"
echo " TTY: $(tty 2>/dev/null || echo 'not a tty')"
echo " PPID: $PPID"
echo " Parent process: $(ps -p $PPID -o comm= 2>/dev/null || echo 'unknown')"