Compare commits

..

77 Commits
v1.0 ... master

Author SHA1 Message Date
Olia Lisa
08ebda7617 减少提示语 2025-12-09 12:14:57 +08:00
Olia Lisa
9dc4858d2f fix bug 2025-12-09 12:13:11 +08:00
Olia Lisa
62ec78ac54 fix bug 2025-12-09 12:11:38 +08:00
Olia Lisa
990f42843e update 2025-11-26 16:47:37 +08:00
Olia Lisa
a03b0f397a update, 增加检查依赖和安装依赖操作 2025-11-26 16:39:53 +08:00
Olia Lisa
b7d979e8a0 update 2025-11-26 16:26:56 +08:00
Olia Lisa
9e5865219b 重构代码 2025-11-26 16:10:31 +08:00
Olia Lisa
683a9a68f0 重构代码 2025-11-26 16:08:48 +08:00
Olia Lisa
f86de491ed refactor(install.sh): remove unused 2025-11-26 10:52:02 +08:00
Olia Lisa
f1078a2ecd 动态容器名称 2025-11-26 09:47:16 +08:00
Olia Lisa
70f71d4b5e fix bug 2025-11-24 22:08:06 +08:00
Olia Lisa
97686c7908 update 2025-11-23 22:57:21 +08:00
Olia Lisa
c925536970 修正文字描述 2025-11-23 17:58:06 +08:00
Olia Lisa
7a847caa5c update 2025-11-23 17:55:26 +08:00
Olia Lisa
00e91414e6 update 2025-11-23 17:45:45 +08:00
Olia Lisa
0c58672c3b 修正部分文字描述 2025-11-23 17:30:16 +08:00
Olia Lisa
f45ed259cb 删除重复的判断 2025-11-23 17:25:12 +08:00
Olia Lisa
d962dcd36e fix bug 2025-11-23 17:21:46 +08:00
Olia Lisa
bf72ff2521 feat(install): add config validation checks for uuid and file integrity
- Added comments for clarity on config file existence and blank checks
- Included UUID validation to prevent uninitialized config usage
- Improves robustness by prompting users to create proper configs upfront
2025-11-23 14:18:44 +08:00
Olia Lisa
9a3e20082c refactor: reorganize menu options and add config validation checks
- Extracted common config file validation into a new `check_config` function
- Renumbered menu options for logical order, with exit as the last option
- Added config checks before viewing share links, updating port, and changing Reality destination
- Removed trailing backslash and added final newline for proper formatting

This update improves code reusability, prevents errors from missing configs, and enhances menu usability.
2025-11-23 14:15:50 +08:00
Olia Lisa
f1f54ce1b5 update 2025-11-23 14:07:28 +08:00
Olia Lisa
796ac78f05 删除config文件 2025-11-23 13:57:24 +08:00
Olia Lisa
d0341d1324 update 2025-11-23 13:56:34 +08:00
Olia Lisa
3f5c3eb348 fix bug 2025-11-23 13:49:20 +08:00
Olia Lisa
8adfd590fa update 2025-11-22 17:46:19 +08:00
Olia Lisa
5ed3434bf3 fix bug 2025-11-22 17:10:56 +08:00
Olia Lisa
0e9714c3f0 update 2025-11-22 17:09:30 +08:00
Olia Lisa
774b5955ad 函数改名 2025-11-22 16:54:46 +08:00
Olia Lisa
f79590b229 减少提示语 2025-11-22 16:53:18 +08:00
Olia Lisa
0c884a87fc 重构代码, 改为函数形式 2025-11-22 16:51:09 +08:00
Olia Lisa
dd80d3601b update 2025-11-22 16:45:35 +08:00
Olia Lisa
f3bc373407 重构代码 2025-11-22 16:41:58 +08:00
Olia Lisa
adca43cbba 增加新的配置文件模板 2025-11-22 16:39:46 +08:00
Olia Lisa
bb01321871 重构代码 2025-11-22 16:34:18 +08:00
Olia Lisa
745e09c77f update 2025-11-22 16:24:55 +08:00
Olia Lisa
3e9a22b044 更新模板 2025-11-22 16:10:27 +08:00
Olia Lisa
77a86350a8 增加配置文件模板 2025-11-22 16:07:22 +08:00
Olia Lisa
6101e89a57 update 2025-10-31 13:28:10 +08:00
Olia Lisa
e9f4747a12 修改提示语 2025-10-09 22:47:20 +08:00
Olia Lisa
fdfc3b5e11 增加提示语 2025-10-09 22:42:47 +08:00
Olia Lisa
b2a81f7964 初始化操作中, 增加设置端口 2025-10-09 22:41:11 +08:00
Olia Lisa
48604a2692 修改Reality目标域名, 重启docker容器 2025-10-09 22:40:45 +08:00
Olia Lisa
05bc3fb9b4 update 2025-10-09 22:37:12 +08:00
Olia Lisa
6163d72e2a 修改设置端口 2025-10-09 22:32:05 +08:00
Olia Lisa
18adcb65ce [fix] 修复新版本xray-core publickey 字段变更问题 2025-09-11 10:08:34 +08:00
Olia Lisa
0319d932e3 update 2025-08-16 11:43:24 +08:00
Olia Lisa
e3801150c0 update 2025-08-15 21:43:15 +08:00
Olia Lisa
5cab57adf4 docs: 更新快速开始指南格式和内容 2025-02-08 22:28:53 +08:00
Olia Lisa
35a9f84893 feat: 添加更新端口选项并修改退出选项 2025-02-08 22:02:52 +08:00
Olia Lisa
9286478963 feat: 添加端口更新脚本 2025-02-08 22:01:24 +08:00
Olia Lisa
0cab56158a refactor: 修改脚本引用文件并添加错误提示 2025-02-08 21:36:55 +08:00
Olia Lisa
27e9871c8b style: 删除不必要的输出信息 2025-02-08 21:26:40 +08:00
Olia Lisa
016d4103a8 fix: 更新容器选项说明和脚本内容 2025-02-08 21:18:40 +08:00
Olia Lisa
44bf650f26 fix: 添加初始化脚本执行前后的提示信息 2025-02-08 21:16:30 +08:00
Olia Lisa
2bbde50393 feat: 添加安装脚本菜单功能 2025-02-08 21:14:02 +08:00
Olia Lisa
496eb641e6 refactor: 移除重复的jq安装检查并使用外部脚本 2025-02-08 18:12:01 +08:00
Olia Lisa
14e6d30cd3 refactor: 简化jq安装检查逻辑 2025-02-08 18:10:21 +08:00
Olia Lisa
9d0fed291e feat: 添加检查和安装 jq 的功能 2025-02-08 18:10:14 +08:00
Olia Lisa
1409916165 refactor: 使用函数简化配置文件修改 2025-02-08 17:56:11 +08:00
Olia Lisa
319ae7be6c refactor: 使用函数修改 JSON 文件 2025-02-08 17:52:54 +08:00
Olia Lisa
6951d0d46f feat: 新增获取系统包管理器的函数 2025-02-08 17:49:52 +08:00
Kiolow
c68d16b360 fix bug, 修改删除"正在删除未使用的镜像"命令 2025-01-11 13:04:30 +08:00
Kiolow
d9d342437f 修正项目下载地址 2024-12-15 21:17:48 +08:00
Kiolow
4858bfa772 更新文档, 修改快速开始 2024-12-15 21:16:29 +08:00
Kiolow
63839669ce 修改注释 2024-12-15 21:12:14 +08:00
Kiolow
a76a47ffab 修改docker-compose启动命令 2024-12-15 21:06:56 +08:00
Kiolow
544eb665b8 增加启动脚本, 初始化脚本不再打印分享链接, 2024-12-15 21:02:02 +08:00
Kiolow
b80d7dc367 update 2024-12-14 20:30:23 +08:00
Kiolow
26d0d36b31 update 2024-12-14 20:27:01 +08:00
Kiolow
305c40ab16 增加映射log文件夹 2024-12-14 20:24:48 +08:00
Kiolow
fa6f416c13 update 2024-12-14 20:23:59 +08:00
Kiolow
16184ffd47 update 2024-11-03 00:25:34 +08:00
Kiolow
7307383451 修改生成uuid方式 2024-10-27 14:30:08 +08:00
Kiolow
4ac024f8a7 优化生成密钥对逻辑 2024-07-19 18:19:30 +08:00
Kiolow
c6349dba03 修复bug 2024-07-19 17:57:56 +08:00
Kiolow
b2c8f5178e update, 增加功能: 删除无用镜像.. 2024-07-05 14:43:51 +08:00
Kiolow
1fcad6d680 新增bash工具函数 2024-06-07 13:10:23 +08:00
19 changed files with 785 additions and 106 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
conf/key.txt conf/key.txt
conf/config.json
log/*

View File

@ -1,59 +1,64 @@
# 说明 # 说明
## 前提 ## 前提
提前安装好以下软件 提前安装好以下软件
- git
- curl - curl
- docker - docker
- docker-compose - docker-compose
- jq - 用于查看json文件, 提取json文件信息. 编辑json文件 - jq - 用于查看 json 文件, 提取 json 文件信息. 编辑 json 文件
- qrencode - (可选, 非必要)用于生成二维码 - qrencode - (可选, 非必要)用于生成二维码
## 快速开始 ## 快速开始
1. 下载项目 1. 下载项目
```bash ```bash
git clone https://gittea.wingogo.top/William/xray_docker.git git clone https://gitea.9001001.xyz/William/xray_docker.git
``` ```
2. 进入项目目录 2. 进入项目目录
```bash ```bash
cd xray_docker cd xray_docker
``` ```
3. 初始化xray配置, 设置密钥和uuid, **第一次运行必须执行** 3. 执行命令生成配置并启动容器
```bash
bash ./bin/init.sh
```
4. 启动
```
docker-compose up -d
```
5. 查看分享链接
```bash ```bash
bash ./bin/print_share_link.sh bash ./bin/run.sh
``` ```
## 停止 ## 停止
如果需要停止服务, 进入项目目录, 执行以下命令 如果需要停止服务, 进入项目目录, 执行以下命令
```bash ```bash
docker-compose down docker-compose down
``` ```
## 更新镜像 ## 更新镜像
进入项目目录, 执行以下命令 进入项目目录, 执行以下命令
```bash ```bash
bash ./bin/update_docker_images.sh bash ./bin/update_docker_images.sh
``` ```
## 查看分享链接 ## 查看分享链接
进入项目目录, 执行以下命令 进入项目目录, 执行以下命令
```bash ```bash
bash ./bin/print_share_link.sh bash ./bin/print_share_link.sh
``` ```
## 修改端口 ## 修改端口
修改conf/config.json
修改 conf/config.json
```json ```json
// ... // ...
@ -70,7 +75,8 @@ bash ./bin/print_share_link.sh
``` ```
## 参考信息 ## 参考信息
- [xray官方文档](https://xtls.github.io/)
- [xray代码仓库](https://github.com/xtls/xray-core) - [xray 官方文档](https://xtls.github.io/)
- [xray docker镜像](https://hub.docker.com/r/teddysun/xray) - [xray 代码仓库](https://github.com/xtls/xray-core)
- [xray安装命令](https://github.com/XTLS/Xray-install) - [xray docker 镜像](https://hub.docker.com/r/teddysun/xray)
- [xray 安装命令](https://github.com/XTLS/Xray-install)

66
bin/create_config.sh Normal file
View File

@ -0,0 +1,66 @@
#!/bin/bash
create_reality_config(){
local script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径
local config_dir=$(readlink -f "$script_dir/../conf") # 配置文件绝对路径
cp "$config_dir/template/reality_config.json" "$config_dir/config.json"
# 生成uui, 写入到config.json文件
bash $script_dir/update_uuid.sh
# 生成密钥对, 修改config.json中的密钥属性
bash $script_dir/update_key.sh
# 设置端口
bash $script_dir/update_port.sh
# 设置realty_dest
bash $script_dir/update_reality_dest.sh www.pranichealingsrilanka.com
echo "初始化完成"
}
create_xhttp_reality_config(){
local script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径
local config_dir=$(readlink -f "$script_dir/../conf") # 配置文件绝对路径
cp "$config_dir/template/xhttp_reality_config.json" "$config_dir/config.json"
# 生成uui, 写入到config.json文件
bash $script_dir/update_uuid.sh
# 生成密钥对, 修改config.json中的密钥属性
bash $script_dir/update_key.sh
# 生成xhttp_path, 写入到config.json文件
bash $script_dir/update_xhttp_path.sh
# 设置realty_dest
bash $script_dir/update_reality_dest.sh www.pranichealingsrilanka.com
# 设置端口
bash $script_dir/update_port.sh
}
create_config(){
local script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径
source "$script_dir/utils/base.sh"
# 检查jq是否安装
check_jq
echo "请选择配置文件类型:"
echo "1. 创建reality配置"
echo "2. 创建xhttp_reality配置"
read -p "请输入选择 (1 或 2): " choice
case $choice in
1) create_reality_config ;;
2) create_xhttp_reality_config ;;
*) echo "无效选择,退出" ;;
esac
}
create_config

View File

@ -1,15 +0,0 @@
#!/bin/bash
# 安装xray
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install
script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径
# 生成uui, 写入到config.json文件
bash $script_dir/update_uuid.sh
# 生成密钥对, 修改config.json中的密钥属性
bash $script_dir/update_key.sh
# 打印分享链接
bash $script_dir/print_share_link.sh

View File

@ -1,40 +1,96 @@
#!/bin/bash #!/bin/bash
# 检查 jq 是否安装 print_reality_share_link(){
if ! command -v jq &> /dev/null; then local script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径
echo "jq 未安装" local config_dir=$(readlink -f "$script_dir/../conf") # 配置文件绝对路径
exit 1
fi # 获取本机IP
local ipv4=$(curl -4 -sSL --connect-timeout 3 --retry 2 ip.sb || echo "null")
local uuid=$(jq -r '.inbounds[0].settings.clients[0].id' $config_dir/config.json)
local port=$(jq -r '.inbounds[0].port' $config_dir/config.json)
local dest=$(jq -r '.inbounds[0].streamSettings.realitySettings.dest' $config_dir/config.json)
local sni=$(echo $dest | awk -F ':' '{print $1}')
local network="tcp"
local public_key=$(cat $config_dir/key.txt | grep "Password" | awk -F ': ' '{print $2}')
# 打印配置信息
echo -e "\033[32m" # config info with green color
echo "ipv4: $ipv4"
echo "port: $port"
echo "uuid: $uuid"
echo "dest: $dest"
echo "sni: $sni"
echo "publicKey/password: $public_key"
echo "network: $network"
if [ "$ipv4" != "null" ]; then
sub_ipv4="vless://$uuid@$ipv4:$port?encryption=none&security=reality&type=$network&sni=$sni&fp=chrome&pbk=$public_key&flow=xtls-rprx-vision#我的最新vless机场"
echo ""
echo "IPV4 分享连接: $sub_ipv4"
echo ""
# 如果qrencode安装了则打印二维码
if command -v qrencode &> /dev/null; then
echo -e "IPV4 分享二维码:\n$(echo "$sub_ipv4" | qrencode -o - -t UTF8)"
fi
fi
echo -e "\033[0m"
}
script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径 print_xhttp_reality_share_link(){
config_dir=$(readlink -f "$script_dir/../conf") # 配置文件绝对路径 local script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径
local config_dir=$(readlink -f "$script_dir/../conf") # xray配置文件绝对路径
# 获取本机IP local ipv4=$(curl -4 -sSL --connect-timeout 3 --retry 2 ip.sb || echo "null") # 本机IP
ipv4=$(curl -4 -sSL --connect-timeout 3 --retry 2 ip.sb || echo "null") local uuid=$(jq -r '.inbounds[0].settings.clients[0].id' $config_dir/config.json)
local port=$(jq -r '.inbounds[0].port' $config_dir/config.json)
local dest=$(jq -r '.inbounds[0].streamSettings.realitySettings.dest' $config_dir/config.json)
local sni=$(echo $dest | awk -F ':' '{print $1}')
local network=$(jq -r '.inbounds[0].streamSettings.network' $config_dir/config.json)
local xhttp_path=$(jq -r ".inbounds[0].streamSettings.xhttpSettings.path" $config_dir/config.json)
local public_key=$(cat $config_dir/key.txt | grep "Password" | awk -F ': ' '{print $2}')
uuid=$(jq -r '.inbounds[0].settings.clients[0].id' $config_dir/config.json)
port=$(jq -r '.inbounds[0].port' $config_dir/config.json)
dest=$(jq -r '.inbounds[0].streamSettings.realitySettings.dest' $config_dir/config.json)
sni=$(echo $dest | awk -F ':' '{print $1}')
network="tcp"
public_key=$(cat $config_dir/key.txt | grep "Public" | awk -F ': ' '{print $2}')
# 打印配置信息 # 打印配置信息
echo -e "\033[32m" # config info with green color echo -e "\033[32m" # config info with green color
echo "IPV4: $ipv4" echo "ipv4: $ipv4"
echo "PORT: $port" echo "port: $port"
echo "UUID: $uuid" echo "uuid: $uuid"
echo "DEST: $dest" echo "dest: $dest"
echo "PUBLIC_KEY: $public_key" echo "sni: $sni"
echo "NETWORK: $network" echo "publicKey/password: $public_key"
if [ "$ipv4" != "null" ]; then echo "network: $network"
sub_ipv4="vless://$uuid@$ipv4:$port?encryption=none&security=reality&type=$network&sni=$sni&fp=chrome&pbk=$public_key&flow=xtls-rprx-vision#my_docker_vless_reality_vision" echo "xhttp_path: $xhttp_path"
echo "IPV4 订阅连接: $sub_ipv4" if [ "$ipv4" != "null" ]; then
# 如果qrencode安装了则打印二维码 sub_ipv4="vless://$uuid@$ipv4:$port?encryption=none&security=reality&type=$network&sni=$sni&fp=chrome&pbk=$public_key&path=$xhttp_path&mode=auto#${ipv4}-my_xray_xhttp_reality"
if command -v qrencode &> /dev/null; then echo ""
echo -e "IPV4 订阅二维码:\n$(echo "$sub_ipv4" | qrencode -o - -t UTF8)" echo "ipv4 分享连接: $sub_ipv4"
echo ""
# 如果qrencode安装了则打印二维码
if command -v qrencode &> /dev/null; then
echo -e "ipv4 分享二维码:\n$(echo "$sub_ipv4" | qrencode -o - -t UTF8)"
fi
fi fi
fi
echo -e "\033[0m" echo -e "\033[0m"
}
print_share_link(){
local script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径
local config_dir=$(readlink -f "$script_dir/../conf") # xray配置文件绝对路径
# 检查 jq 是否安装
source $script_dir/utils/base.sh
check_jq
local xhttp_path=$(jq -r ".inbounds[0].streamSettings.xhttpSettings.path" $config_dir/config.json)
if [ -z $xhttp_path ] || [ "$xhttp_path" = "null" ];then
print_reality_share_link
else
print_xhttp_reality_share_link
fi
}
print_share_link

View File

@ -1,4 +0,0 @@
#!/bin/bash
# Remove Xray
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ remove

21
bin/run.sh Normal file
View File

@ -0,0 +1,21 @@
#!/bin/bash
script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径
config_dir=$(readlink -f "$script_dir/../conf") # 配置文件绝对路径
# 如果配置文件不存在或者空白
if [ ! -e "$config_dir/config.json" ] || [ ! -s "$config_dir/config.json" ] ; then
bash "$script_dir/create_config.sh"
fi
# 如果配置未初始化
uuid=$(jq -r '.inbounds[0].settings.clients[0].id' "$config_dir/config.json")
if [ "$uuid" = "你的UUID" ] || [ -z "$uuid" ]; then
# 执行初始化脚本
bash "$script_dir/create_config.sh"
fi
## 启动docker容器
docker-compose -f $script_dir/../docker-compose.yml up -d
# 打印分享链接
bash $script_dir/print_share_link.sh

View File

@ -1,19 +1,27 @@
#!/bin/bash #!/bin/bash
script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径
docker_compose_file="$script_dir/../docker-compose.yml" # docker-compose.yml文件路径
# 检查是否存在 docker-compose.yml 文件 update_docker_images(){
if [ ! -f $docker_compose_file ]; then script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径
echo "Error: docker-compose.yml 文件不存在." docker_compose_file="$script_dir/../docker-compose.yml" # docker-compose.yml文件路径
exit 1
fi
echo "正在关闭容器.." # 检查是否存在 docker-compose.yml 文件
docker-compose -f $docker_compose_file down if [ ! -f $docker_compose_file ]; then
echo "Error: docker-compose.yml 文件不存在."
exit 1
fi
echo "正在更新镜像.." echo "正在关闭容器.."
docker-compose -f $docker_compose_file pull docker-compose -f $docker_compose_file down
echo "正在启动容器.." echo "正在更新镜像.."
docker-compose -f $docker_compose_file up -d docker-compose -f $docker_compose_file pull
echo "正在删除未使用的镜像..."
docker image prune -f
echo "正在启动容器.."
docker-compose -f $docker_compose_file up -d
}
update_docker_images

View File

@ -1,15 +1,23 @@
#!/bin/bash #!/bin/bash
script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径 update_key(){
config_dir="$script_dir/../conf"
# Save keys to key.txt script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径
xray x25519 > $config_dir/key.txt config_dir="$script_dir/../conf"
source $script_dir/utils/jq_util.sh
private_key=$(grep "Private key" $config_dir/key.txt | awk -F ': ' '{print $2}') # 使用docker运行xray镜像生成密钥文件
docker run --rm teddysun/xray:latest /usr/bin/xray x25519 > $config_dir/key.txt
# 修改config.json密钥属性 # 获取私钥
jq ".inbounds[0].streamSettings.realitySettings.privateKey=\"$private_key\"" $config_dir/config.json > $config_dir/config_temp.json private_key=$(grep "Private" $config_dir/key.txt | awk -F ': ' '{print $2}')
mv $config_dir/config_temp.json $config_dir/config.json
echo "生成和设置密钥成功." # 修改config.json密钥属性
modify_json_file "$config_dir/config.json" ".inbounds[0].streamSettings.realitySettings.privateKey" "$private_key"
echo "生成和设置密钥成功."
}
update_key

57
bin/update_port.sh Normal file
View File

@ -0,0 +1,57 @@
#!/bin/bash
# 查找空闲端口
find_free_port() {
local start="${1:-10001}"
local max="${2:-65535}"
# 收集当前监听端口TCP + UDP
local used_ports raw
if command -v ss >/dev/null 2>&1; then
raw=$(ss -lntu 2>/dev/null || true)
used_ports=$(printf "%s\n" "$raw" | awk '{print $5}' | sed -n '2,$p' | sed -E 's/.*[:]//g' | sed '/^$/d')
elif command -v netstat >/dev/null 2>&1; then
raw=$(netstat -lntu 2>/dev/null || true)
used_ports=$(printf "%s\n" "$raw" | awk '{print $4}' | sed -n '2,$p' | sed -E 's/.*[:]//g' | sed '/^$/d')
elif command -v lsof >/dev/null 2>&1; then
raw=$(lsof -i -P -n 2>/dev/null || true)
used_ports=$(printf "%s\n" "$raw" | awk '/LISTEN/ {print $9}' | sed -E 's/.*[:]//g' | sed '/^$/d')
else
echo "Error: neither ss, netstat nor lsof is available to check listening ports." >&2
return 2
fi
# 用关联数组记录已占用端口(需要 bash 4+
declare -A used_map
local p
for p in $used_ports; do
# 过滤掉非数字
if [[ $p =~ ^[0-9]+$ ]]; then
used_map["$p"]=1
fi
done
# 从 start 到 max 逐个检查
for ((port = start; port <= max; port++)); do
if [[ -z "${used_map[$port]}" ]]; then
echo "$port"
return 0
fi
done
# 没找到可用端口
echo "Error: No available port found in range $start-$max" >&2
return 1
}
update_port(){
local script_dir=$(cd "$(dirname "$0")"; pwd)
local config_dir="$script_dir/../conf"
source "$script_dir/utils/jq_util.sh"
local port=$(find_free_port)
modify_json_file "$config_dir/config.json" ".inbounds[0].port" "$port"
echo "设置端口成功"
}
update_port

View File

@ -0,0 +1,12 @@
#!/bin/bash
update_reality_dest(){
local script_dir=$(cd "$(dirname "$0")"; pwd)
local config_dir="$script_dir/../conf"
local domain=$1
sed -i "s/你的reality_dest/$domain/g" "$config_dir/config.json"
echo "修改realty_dest成功"
}
update_reality_dest $1

View File

@ -1,16 +1,19 @@
#!/bin/bash #!/bin/bash
script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径 update_uuid(){
config_dir="$script_dir/../conf"
# 生成 UUID script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径
uuid=$(xray uuid) config_dir="$script_dir/../conf"
# 使用 jq 修改 JSON 文件 source $script_dir/utils/jq_util.sh
jq ".inbounds[0].settings.clients[0].id=\"$uuid\"" $config_dir/config.json > $config_dir/config.json_tmp
# 替换原始文件 # 生成 UUID
mv $config_dir/config.json_tmp $config_dir/config.json uuid=$(docker run --rm teddysun/xray:latest xray uuid)
# 验证结果 #修改 UUID
echo "设置UUID成功." modify_json_file "$config_dir/config.json" ".inbounds[0].settings.clients[0].id" "$uuid"
echo "设置UUID成功."
}
update_uuid

18
bin/update_xhttp_path.sh Normal file
View File

@ -0,0 +1,18 @@
#!/bin/bash
update_xhttp_path(){
script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径
config_dir="$script_dir/../conf"
source $script_dir/utils/jq_util.sh
path_length="$(( RANDOM % 4 + 8 ))"
xhttp_path="/"$(docker run --rm teddysun/xray:latest xray uuid | tr -d '-' | cut -c 1-$path_length)
# 修改config.json的xhttp_path
modify_json_file "$config_dir/config.json" ".inbounds[0].streamSettings.xhttpSettings.path" "$xhttp_path"
echo "设置xhttp_path成功"
}
update_xhttp_path

82
bin/utils/base.sh Normal file
View File

@ -0,0 +1,82 @@
#!/bin/bash
red(){
echo -e "\033[31m$1\033[0m"
}
# 获取系统包管理器
get_package_manager(){
if command -v apt-get &> /dev/null; then
echo "apt-get"
elif command -v yum &> /dev/null; then
echo "yum"
else
echo "未知的系统包管理器"
return 1 # 返回错误状态码
fi
}
# 检查 jq 是否已安装
check_jq() {
if command -v jq >/dev/null 2>&1; then
return 0
else
echo "jq 未安装"
return 1
fi
}
# 检查 Docker 是否已安装
check_docker() {
if command -v docker >/dev/null 2>&1; then
return 0
else
echo "Docker 未安装"
return 1
fi
}
# 检查 docker-compose 是否已安装
check_docker_compose() {
if command -v docker-compose >/dev/null 2>&1; then
return 0
elif docker compose version >/dev/null 2>&1; then ## Docker 内置 compose 已安装
return 0
else
echo "docker-compose 未安装"
return 1
fi
}
# 安装jq
install_jq(){
local package_manager=$(get_package_manager) # 获取包管理器
if [[ -z "$package_manager" ]]; then
echo "无法识别系统包管理器"
return 1 # 无法识别包管理器
fi
if [[ "$package_manager" == "apt-get" ]]; then
sudo apt-get install -y jq
elif [[ "$package_manager" == "yum" ]]; then
sudo yum install -y jq
else
echo "未知的系统包管理器"
return 1 # 未知的包管理器
fi
}
# 安装docker
install_docker(){
echo 安装docker...
curl -fsSL https://get.docker.com | bash -s docker
}
# 安装docker-compose
install_docker_compose(){
echo 安装docker-compose...
wget -O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/v2.29.0/docker-compose-linux-x86_64
chmod +x /usr/local/bin/docker-compose
}

27
bin/utils/jq_util.sh Normal file
View File

@ -0,0 +1,27 @@
#!/bin/bash
# 修改json文件的属性值
# 案例1modify_json_file "/foo/bar.json" "person.name" "张三"
# 案例2modify_json_file "/foo/bar.json" "servers" '["a.com", "b.com"]'
# 该函数能自动处理不同数据类型,包括数组、对象和数字等。
function modify_json_file() {
local json_file=$1 # json文件路径
local key=$2 # 要修改的key
local value=$3 # 要修改的value
#如果key的值是.开头, 则去掉.号
if [[ ${key} == "."* ]]; then
key=${key:1}
fi
# 检查值是否为有效的 JSON 格式(如数组、对象或数字)。
# 如果是,则直接将值传递给 jq无需引号。
if echo "${value}" | jq . >/dev/null 2>&1; then
jq ".${key} = ${value}" "${json_file}" > "${json_file}.tmp"
else
# 否则,将值视为字符串,并添加引号。
jq ".${key} = \"${value}\"" "${json_file}" > "${json_file}.tmp"
fi
mv ${json_file}.tmp ${json_file}
}

View File

@ -56,12 +56,12 @@
"security": "reality", "security": "reality",
"realitySettings": { "realitySettings": {
"show": true, "show": true,
"dest": "www.expedia.com:443", "dest": "你的reality_dest:443",
"xver": 0, "xver": 0,
"maxTimeDiff": 0, "maxTimeDiff": 0,
"minClientVer": "", "minClientVer": "",
"serverNames": [ "serverNames": [
"www.expedia.com" "你的reality_dest"
], ],
"privateKey": "你的密钥", "privateKey": "你的密钥",
"shortIds": [ "shortIds": [

View File

@ -0,0 +1,182 @@
{
"log": {
"dnsLog": false,
"access": "/var/log/xray/access.log",
"error": "/var/log/xray/error.log",
"loglevel": "error",
"maskAddress": ""
},
"routing": {
"domainStrategy": "IPIfNonMatch",
"rules": [
{
"inboundTag": [
"api"
],
"outboundTag": "api",
"type": "field"
},
{
"domain": [
"domain:byr.pt"
],
"type": "field",
"outboundTag": "direct"
},
{
"domain": [
"domain:iqiyi.com",
"domain:video.qq.com",
"domain:youku.com"
],
"type": "field",
"outboundTag": "blocked"
},
{
"type": "field",
"ip": [
"geoip:cn",
"geoip:private"
],
"outboundTag": "blocked"
},
{
"protocol": [
"bittorrent"
],
"type": "field",
"outboundTag": "blocked"
}
]
},
"dns": {
"servers": [
"https+local://cloudflare-dns.com/dns-query",
"1.1.1.1",
"1.0.0.1",
"8.8.8.8",
"8.8.4.4",
"localhost"
]
},
"inbounds": [
{
"listen": "0.0.0.0",
"port": 8005,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "你的UUID",
"flow": ""
}
],
"decryption": "none",
"fallbacks": []
},
"streamSettings": {
"network": "xhttp",
"realitySettings": {
"dest": "你的reality_dest:443",
"maxClient": "",
"maxTimediff": 0,
"minClient": "",
"privateKey": "",
"serverNames": [
"你的reality_dest"
],
"shortIds": [
""
],
"show": false,
"xver": 0
},
"security": "reality",
"xhttpSettings": {
"headers": {},
"host": "",
"mode": "auto",
"noSSEHeader": false,
"path": "/14e077b4",
"scMaxBufferedPosts": 30,
"scMaxEachPostBytes": "1000000",
"scStreamUpServerSecs": "20-80",
"xPaddingBytes": "100-1000"
}
},
"tag": "inbound-xx",
"sniffing": {
"enabled": false,
"destOverride": [
"http",
"tls",
"quic",
"fakedns"
],
"metadataOnly": false,
"routeOnly": false
},
"allocate": {
"strategy": "always",
"refresh": 5,
"concurrency": 3
}
},
{
"listen": "127.0.0.1",
"port": 65432,
"protocol": "dokodemo-door",
"settings": {
"address": "127.0.0.1"
},
"streamSettings": null,
"tag": "api",
"sniffing": null,
"allocate": null
}
],
"outbounds": [
{
"tag": "direct",
"protocol": "freedom",
"settings": {
"domainStrategy": "AsIs",
"redirect": "",
"noises": []
}
},
{
"tag": "blocked",
"protocol": "blackhole",
"settings": {}
}
],
"transport": null,
"policy": {
"levels": {
"0": {
"statsUserDownlink": true,
"statsUserUplink": true
}
},
"system": {
"statsInboundDownlink": true,
"statsInboundUplink": true,
"statsOutboundDownlink": false,
"statsOutboundUplink": false
}
},
"api": {
"tag": "api",
"services": [
"HandlerService",
"LoggerService",
"StatsService"
]
},
"stats": {},
"reverse": null,
"fakedns": null,
"observatory": null,
"burstObservatory": null
}

View File

@ -1,10 +1,9 @@
version: "3.9"
services: services:
xray: xray:
image: teddysun/xray:latest image: teddysun/xray:latest
restart: always restart: always
container_name: xray container_name: "${COMPOSE_PROJECT_NAME}" # 容器名为文件夹名称
network_mode: "host" network_mode: "host"
volumes: volumes:
- "./conf:/etc/xray" - "./conf:/etc/xray"
- "./log:/var/log/xray"

151
install.sh Normal file
View File

@ -0,0 +1,151 @@
#!/bin/bash
restart_docker(){
echo "正在重启容器..."
docker-compose -f ./docker-compose.yml down
docker-compose -f ./docker-compose.yml up -d
}
check_config(){
local config_dir="./conf"
# 如果配置文件不存在或者空白
if [ ! -e "$config_dir/config.json" ] || [ ! -s "$config_dir/config.json" ];then
echo "请先'创建配置'"
exit 0
fi
# 如果配置未初始化
uuid=$(jq -r '.inbounds[0].settings.clients[0].id' "$config_dir/config.json")
if [ "$uuid" = "你的UUID" ] || [ -z "$uuid" ]; then
echo "请先'创建配置'"
exit 0
fi
}
# 检查依赖
check_dependencies() {
# 内部退出函数:只在本函数作用域内有效
exit_with_dep_error() {
echo "请执行 安装依赖 操作"
exit 1
}
source ./bin/utils/base.sh
check_jq || exit_with_dep_error
check_docker || exit_with_dep_error
check_docker_compose || exit_with_dep_error
}
# 安装依赖
install_dependencies() {
source ./bin/utils/base.sh
if ! command -v jq >/dev/null 2>&1; then
echo "jq 未安装,开始安装..."
install_jq
fi
if ! command -v docker >/dev/null 2>&1; then
echo "Docker 未安装,开始安装..."
install_docker
fi
if ! command -v docker-compose >/dev/null 2>&1; then
echo "docker-compose 未安装,开始安装..."
install_docker_compose
fi
}
change_reality_dest(){
local config_dir="./conf"
# 输入dest值
local old_dest=$(jq -r '.inbounds[0].streamSettings.realitySettings.dest' "$config_dir/config.json")
local dest
read -p "请输入新的dest地址[当前地址: $old_dest]: " dest
local domain=$(echo "$dest" | awk -F ':' '{print $1}')
sed -i "s/你的reality_dest/$domain/g" "$config_dir/config.json"
echo "配置文件修改realty_dest成功"
echo "新的dest地址为: $dest"
echo "新的serverNames数组为: [\"$domain\"]"
}
main(){
# 显示菜单
echo "请选择一个操作:"
echo "0. 安装依赖"
echo "1. 创建配置 / 重置配置"
echo "2. 启动容器"
echo "3. 查看分享链接"
echo "4. 停止容器"
echo "5. 更新镜像"
echo "6. 修改端口"
echo "7. 修改Reality目标域名"
echo "8. 退出"
# 读取用户选择
read -p "输入您的选择: " choice
# 根据用户选择执行相应的操作
case $choice in
0)
# 安装依赖
install_dependencies
;;
1)
# 创建配置 / 重置配置
check_dependencies
bash ./bin/create_config.sh
;;
2)
# 启动容器
echo "启动容器.."
check_dependencies
bash ./bin/run.sh
;;
3)
# 查看分享链接
echo "查看分享链接.."
check_dependencies
check_config
bash ./bin/print_share_link.sh
;;
4)
# 停止容器
echo "正在停止容器.."
docker-compose -f ./docker-compose.yml down
;;
5)
# 更新镜像
bash ./bin/update_docker_images.sh
;;
6)
# 修改端口
check_dependencies
check_config
bash ./bin/update_port.sh
restart_docker
;;
7)
# 修改Reality目标域名
check_dependencies
check_config
change_reality_dest
restart_docker
;;
8)
# 退出
echo "退出程序."
;;
*)
echo "无效的选择, 请重新选择."
;;
esac
}
main