hysteria_docker/bin/set_domain.sh
2024-05-16 20:49:01 +08:00

28 lines
978 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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
}
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文件