update set_domain.sh

This commit is contained in:
Olia Lisa 2025-10-09 15:23:28 +08:00
parent d1a6deaab6
commit 589db04e8e

View File

@ -1,27 +1,25 @@
#!/bin/bash
# 当前脚本所在目录的绝对路径
script_dir="$(dirname "$(realpath "$0")")"
# 导入utils文件夹中的jq_util.sh脚本
source "$script_dir/utils/jq_util.sh"
gen_cert() {
local domain="$1"
local key_dir="$script_dir/../key" # key目录绝对路径
# 使用openssl生成自签名证书设置密钥和有效期并指定域名信息
openssl req -x509 -nodes -newkey ec:<(openssl ecparam -name prime256v1) -keyout "$key_dir/server.key" -out "$key_dir/server.crt" -subj "/CN=$domain" -days 36500
# 设置域名和生成证书的函数
set_domain() {
local domain="${1:-bing.com}"
local script_dir="$(dirname "$(realpath "$0")")"
local key_dir="$script_dir/../key"
local config_file="$script_dir/../config.json"
# 导入utils文件夹中的jq_util.sh脚本
source "$script_dir/utils/jq_util.sh"
# 生成自签名证书
openssl req -x509 -nodes -newkey ec:<(openssl ecparam -name prime256v1) \
-keyout "$key_dir/server.key" \
-out "$key_dir/server.crt" \
-subj "/CN=$domain" \
-days 36500
# 更新config.json文件中的域名信息
modify_json_file "$config_file" "masquerade.proxy.url" "https://$domain"
}
update_config() {
local domain="$1"
local config_file="$script_dir/../config.json" # config.json文件路径
# 使用jq_util.sh脚本中的modify_json_file函数修改config.json文件中的域名信息
modify_json_file $config_file "masquerade.proxy.url" "https://$domain"
}
domain="${1:-bing.com}" # 域名, 默认为"bing.com"
gen_cert "$domain" # 生成证书
update_config "$domain" # 更新config.json文件
# 调用函数,传入第一个参数作为域名
set_domain "$1"