25 lines
1.0 KiB
Bash
25 lines
1.0 KiB
Bash
#!/bin/bash
|
||
|
||
gen_cert() {
|
||
local domain="$1"
|
||
local script_dir="$(dirname "$(realpath "$0")")" # 当前脚本所在目录的绝对路径
|
||
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
|
||
}
|
||
|
||
update_config() {
|
||
local domain="$1"
|
||
local script_dir="$(dirname "$(realpath "$0")")" # 当前脚本所在目录的绝对路径
|
||
local config_file="$script_dir/../config.json" # config.json文件路径
|
||
# 使用jq命令修改文件conifg.json中的masquerade.proxy.url
|
||
new_config=$(jq --arg new_url "https://$domain" '.masquerade.proxy.url = $new_url' "$config_file")
|
||
echo "$new_config" > "$config_file"
|
||
}
|
||
|
||
domain="${1:-bing.com}" # 域名, 默认为"bing.com"
|
||
gen_cert "$domain" # 生成证书
|
||
update_config "$domain" # 更新config.json文件
|
||
|
||
|