重构代码, 将变量改为大写
This commit is contained in:
+10
-10
@@ -2,32 +2,32 @@
|
||||
|
||||
# 修改域名
|
||||
update_domain(){
|
||||
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
|
||||
local config_file="$script_dir/../config/config.json"
|
||||
local SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
|
||||
local CONFIG_FILE="$SCRIPT_DIR/../config/config.json"
|
||||
|
||||
# 检查jq是否安装
|
||||
check_jq
|
||||
|
||||
# 获取旧的domain
|
||||
local old_domain=$(jq -r ".inbounds[0].tls.server_name" "$config_file")
|
||||
local OLD_DOMAIN=$(jq -r ".inbounds[0].tls.server_name" "$CONFIG_FILE")
|
||||
|
||||
# 输入新的domain
|
||||
local domain
|
||||
read -p "请输入域名[当前域名: $old_domain]: " domain
|
||||
local DOMAIN
|
||||
read -p "请输入域名[当前域名: $OLD_DOMAIN]: " DOMAIN
|
||||
|
||||
# 如果输入为空,退出脚本
|
||||
if [[ -z "$domain" ]]; then
|
||||
if [[ -z "$DOMAIN" ]]; then
|
||||
echo "输入域名为空,退出脚本"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 修改server_name
|
||||
modify_json_file "$config_file" ".inbounds[0].tls.server_name" "$domain"
|
||||
modify_json_file "$CONFIG_FILE" ".inbounds[0].tls.server_name" "$DOMAIN"
|
||||
|
||||
# 是否存在acme域名, 存在则修改
|
||||
local acme_exists=$(jq -r 'has("inbounds") and (.inbounds[0] | has("tls")) and (.inbounds[0].tls | has("acme"))' "$config_file")
|
||||
if [[ "$acme_exists" == "true" ]]; then
|
||||
modify_json_file "$config_file" ".inbounds[0].tls.acme.domain[0]" "$domain"
|
||||
local ACME_EXISTS=$(jq -r 'has("inbounds") and (.inbounds[0] | has("tls")) and (.inbounds[0].tls | has("acme"))' "$CONFIG_FILE")
|
||||
if [[ "$ACME_EXISTS" == "true" ]]; then
|
||||
modify_json_file "$CONFIG_FILE" ".inbounds[0].tls.acme.domain[0]" "$DOMAIN"
|
||||
fi
|
||||
|
||||
echo "修改域名成功"
|
||||
|
||||
Reference in New Issue
Block a user