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

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
bin/update_domain.sh Normal file
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

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
}

View File

@ -40,7 +40,8 @@ echo "3. 查看分享链接"
echo "4. 启动容器"
echo "5. 停止容器"
echo "6. 更新镜像"
echo "7. 更新端口"
echo "7. 修改域名"
echo "8. 修改端口"
# 读取用户选择
read -p "输入您的选择: " choice
@ -59,6 +60,7 @@ case $choice in
;;
3)
# 查看分享链接
check_config_file
bash ./bin/print_share_link.sh
;;
4)
@ -76,7 +78,13 @@ case $choice in
bash ./bin/update_docker_images.sh
;;
7)
# 更新端口
# 修改域名
check_config_file
bash ./bin/update_domain.sh
;;
8)
# 修改端口
check_config_file
bash ./bin/update_port.sh
;;
*)