新增域名修改脚本,更新安装脚本以支持域名修改功能,并添加配置文件检查

This commit is contained in:
Olia Lisa
2026-01-11 16:31:31 +08:00
parent a97a5bc02a
commit 4ccef4cb1a
3 changed files with 64 additions and 2 deletions
+36
View File
@@ -0,0 +1,36 @@
#!/bin/bash
# 修改域名
update_domain(){
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
source "$script_dir/utils/jq_util.sh"
source "$script_dir/utils/base.sh"
local config_file="$script_dir/../config/config.json"
# 检查jq是否安装
check_jq
# 输入新的domain
local domain
read -p "请输入新的域名: " domain
# 如果输入为空,退出脚本
if [[ -z "$domain" ]]; then
echo "输入域名为空,退出脚本"
exit 1
fi
modify_json_file "$config_file" ".masquerade.proxy.url" "https://$domain"
# 是否存在acme域名, 存在则修改
local acme_exists=$(jq -r 'has("acem")' "$config_file")
if [[ "$acme_exists" == "true" ]]; then
modify_json_file "$config_file" ".acme.domains[0]" "$domain"
fi
echo "修改域名成功"
}
update_domain
+18
View File
@@ -70,3 +70,21 @@ gen_password() {
echo "$rand"
}
# 检查配置文件
check_config_file(){
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../" # 脚本文件夹绝对路径
local config_file="$script_dir/../config/config.json"
# 检查配置文件是否存在
if [ ! -e "$config_file" ]; then
echo "配置文件不存在, 请先生成配置文件."
exit 1
fi
# 检查配置文件是否为有效的JSON格式
if ! jq '.' "$config_file" >/dev/null 2>&1; then
echo "配置文件不是有效的JSON格式, 请重新生成配置文件."
exit 1
fi
}