From 589db04e8e28cdfc930dd40d3c4e86f912e3b7f8 Mon Sep 17 00:00:00 2001 From: Olia Lisa Date: Thu, 9 Oct 2025 15:23:28 +0800 Subject: [PATCH] update set_domain.sh --- bin/set_domain.sh | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/bin/set_domain.sh b/bin/set_domain.sh index 5ad21de..90bc8a5 100644 --- a/bin/set_domain.sh +++ b/bin/set_domain.sh @@ -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" \ No newline at end of file