xray_docker/bin/create_config.sh
2026-01-14 17:21:42 +08:00

80 lines
2.2 KiB
Bash

#!/bin/bash
create_reality_config(){
local script_dir="$(cd "$(dirname "${BASH_SOURCE[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
green "成功创建配置"
}
create_xhttp_reality_config(){
local script_dir="$(cd "$(dirname "${BASH_SOURCE[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
# 设置端口
bash $script_dir/update_port.sh
green "成功创建配置"
}
create_config(){
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件绝对路径
source "$script_dir/utils/base.sh"
# 检查jq是否安装
check_jq
local config_file="$script_dir/../conf/config.json" # 配置文件绝对路径
# 如果配置文件已存在, 询问是否重新生成
if [ -e "$config_file" ]; then
local regenerate
read -p "检测到配置已存在,是否重新生成配置?(y/n): " regenerate
if [ "$regenerate" != "y" ] && [ "$regenerate" != "Y" ]; then
echo "取消重新生成配置."
return
fi
fi
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