diff --git a/bin/update_domain.sh b/bin/update_domain.sh new file mode 100644 index 0000000..758f94a --- /dev/null +++ b/bin/update_domain.sh @@ -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 diff --git a/bin/utils/base.sh b/bin/utils/base.sh index 4f850f0..0974679 100644 --- a/bin/utils/base.sh +++ b/bin/utils/base.sh @@ -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 +} \ No newline at end of file diff --git a/install.sh b/install.sh index 12210f4..fb8fdbe 100644 --- a/install.sh +++ b/install.sh @@ -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 ;; *)