tuic_docker/bin/create_config.sh
2026-01-14 23:30:02 +08:00

113 lines
3.1 KiB
Bash

#!/bin/bash
# 导入依赖脚本文件
for f in $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utils/*.sh; do
source "$f"
done
create_config_with_tls_cert() {
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
local config_dir="$script_dir/../config"
local config_file="$config_dir/config.json"
cp "$config_dir/template/tls_cert_config.json" "$config_file"
# 设置端口
bash "$script_dir/update_port.sh"
# 设置密码
bash "$script_dir/update_password.sh"
# 设置UUID
bash "$script_dir/update_uuid.sh"
# 获取邮箱
local user_email
read -p "请输入你的邮箱(可留空): " user_email
if [[ -z "$user_email" ]]; then
user_email="example@example.com"
fi
# 获取域名
local user_domain
read -p "请输入你的域名 (例如: example.com): " user_domain
while [[ -z "$user_domain" ]]; do
echo "[错误] 域名不能为空"
read -p "请输入你的域名: " user_domain
done
# 获取 Cloudflare API Token
local cloudflare_token
read -p "请输入你的 Cloudflare API Token: " cloudflare_token
while [[ -z "$cloudflare_token" ]]; do
echo "[错误] Cloudflare API Token 不能为空"
read -p "请输入你的 Cloudflare API Token: " cloudflare_token
done
sed -i "s/你的邮箱/$user_email/g" "$config_file"
sed -i "s/你的域名/$user_domain/g" "$config_file"
sed -i "s/你的Cloudflare_API_Token/$cloudflare_token/g" "$config_file"
green "成功创建配置"
}
create_self_tls_config() {
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
cp "$script_dir/../config/template/self_cert_config.json" "$script_dir/../config/config.json"
# 设置端口
bash "$script_dir/update_port.sh"
# 设置密码
bash "$script_dir/update_password.sh"
# 设置UUID
bash "$script_dir/update_uuid.sh"
# 生成自签名证书和设置域名
bash "$script_dir/gen_self_tls.sh" "bing.com"
green "成功创建配置"
}
create_config(){
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
local config_file="$script_dir/../config/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. 自签名证书配置"
echo "2. tls证书配置"
local choice
read -p "输入您的选择: " choice
case $choice in
1)
echo "重置为自签名证书配置..."
create_self_tls_config
;;
2)
echo "重置为tls证书配置..."
create_config_with_tls_cert
;;
*)
echo "无效的选择, 请重新选择."
;;
esac
}
create_config