hysteria_docker/bin/set_domain.sh
2024-05-16 14:22:14 +08:00

25 lines
1.0 KiB
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
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文件