diff --git a/bin/create_config.sh b/bin/create_config.sh index af2378f..ab89e74 100644 --- a/bin/create_config.sh +++ b/bin/create_config.sh @@ -7,16 +7,16 @@ create_reality_config(){ cp "$config_dir/template/reality_config.json" "$config_dir/config.json" # 生成uui, 写入到config.json文件 - bash $script_dir/update_uuid.sh + update_uuid # 生成密钥对, 修改config.json中的密钥属性 - bash $script_dir/update_key.sh + update_key # 设置端口 - bash $script_dir/update_port.sh + update_port # 设置realty_dest目标域名 - bash $script_dir/update_reality_dest.sh + update_reality_dest green "成功创建配置" } @@ -28,27 +28,27 @@ create_xhttp_reality_config(){ cp "$config_dir/template/xhttp_reality_config.json" "$config_dir/config.json" # 生成uui, 写入到config.json文件 - bash $script_dir/update_uuid.sh + update_uuid # 生成密钥对, 修改config.json中的密钥属性 - bash $script_dir/update_key.sh + update_key # 生成xhttp_path, 写入到config.json文件 - bash $script_dir/update_xhttp_path.sh + update_xhttp_path # 设置realty_dest目标域名 - bash $script_dir/update_reality_dest.sh + update_reality_dest # 设置端口 - bash $script_dir/update_port.sh + update_port green "成功创建配置" } + create_config(){ local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件绝对路径 - source "$script_dir/utils/base.sh" # 检查jq是否安装 check_jq @@ -73,7 +73,3 @@ create_config(){ *) echo "无效选择,退出" ;; esac } - -create_config - - diff --git a/bin/print_share_link.sh b/bin/print_share_link.sh index e180463..f72c5f3 100644 --- a/bin/print_share_link.sh +++ b/bin/print_share_link.sh @@ -71,7 +71,6 @@ print_share_link(){ local config_dir=$(readlink -f "$script_dir/../conf") # xray配置文件绝对路径 # 检查 jq 是否安装 - source $script_dir/utils/base.sh check_jq local xhttp_path=$(jq -r ".inbounds[0].streamSettings.xhttpSettings.path" $config_dir/config.json) @@ -81,5 +80,3 @@ print_share_link(){ print_xhttp_reality_share_link fi } - -print_share_link diff --git a/bin/run.sh b/bin/run.sh index eb2717b..2f3a8de 100644 --- a/bin/run.sh +++ b/bin/run.sh @@ -12,6 +12,3 @@ run(){ docker-compose -f "$docker_compose_file" up -d # 启动容器 } - - -run diff --git a/bin/update_docker_images.sh b/bin/update_docker_images.sh index 0deb00c..af396be 100644 --- a/bin/update_docker_images.sh +++ b/bin/update_docker_images.sh @@ -23,5 +23,3 @@ update_docker_images(){ echo "正在启动容器.." docker-compose -f $docker_compose_file up -d } - -update_docker_images diff --git a/bin/update_key.sh b/bin/update_key.sh index b82ba90..390b875 100644 --- a/bin/update_key.sh +++ b/bin/update_key.sh @@ -3,7 +3,6 @@ update_key(){ local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件绝对路径 local config_dir="$script_dir/../conf" - source $script_dir/utils/jq_util.sh # 使用docker运行xray镜像生成密钥文件 docker run --rm teddysun/xray:latest /usr/bin/xray x25519 > $config_dir/key.txt @@ -17,6 +16,3 @@ update_key(){ echo "生成和设置密钥成功." } - - -update_key \ No newline at end of file diff --git a/bin/update_port.sh b/bin/update_port.sh index 4fcae37..b05bed9 100644 --- a/bin/update_port.sh +++ b/bin/update_port.sh @@ -77,11 +77,8 @@ find_free_port() { update_port(){ local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹路径 local config_file="$script_dir/../conf/config.json" - source "$script_dir/utils/jq_util.sh" - + local port=$(find_free_port) modify_json_file "$config_file" ".inbounds[0].port" "$port" echo "设置端口成功" } - -update_port diff --git a/bin/update_reality_dest.sh b/bin/update_reality_dest.sh index b5910ac..d969b4f 100644 --- a/bin/update_reality_dest.sh +++ b/bin/update_reality_dest.sh @@ -3,7 +3,6 @@ update_reality_dest(){ local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" local config_dir="$script_dir/../conf" - source $script_dir/utils/jq_util.sh # 获取当前dest值 local old_dest=$(jq -r '.inbounds[0].streamSettings.realitySettings.dest' "$config_dir/config.json") @@ -33,5 +32,3 @@ update_reality_dest(){ echo "修改realty_dest成功" } - -update_reality_dest diff --git a/bin/update_uuid.sh b/bin/update_uuid.sh index cd2003c..ef83688 100644 --- a/bin/update_uuid.sh +++ b/bin/update_uuid.sh @@ -5,8 +5,6 @@ update_uuid(){ local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件绝对路径 local config_dir="$script_dir/../conf" - source $script_dir/utils/jq_util.sh - # 生成 UUID local uuid=$(cat /proc/sys/kernel/random/uuid) @@ -15,5 +13,3 @@ update_uuid(){ echo "设置UUID成功." } - -update_uuid diff --git a/bin/update_xhttp_path.sh b/bin/update_xhttp_path.sh index c363186..be99e32 100644 --- a/bin/update_xhttp_path.sh +++ b/bin/update_xhttp_path.sh @@ -4,7 +4,6 @@ update_xhttp_path(){ local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件绝对路径 local config_dir="$script_dir/../conf" - source $script_dir/utils/jq_util.sh local path_length="$(( RANDOM % 4 + 8 ))" local xhttp_path="/"$(docker run --rm teddysun/xray:latest xray uuid | tr -d '-' | cut -c 1-$path_length) @@ -14,5 +13,3 @@ update_xhttp_path(){ echo "设置xhttp_path成功" } - -update_xhttp_path diff --git a/bin/utils/base.sh b/bin/utils/base.sh index 24b2b05..94827f4 100644 --- a/bin/utils/base.sh +++ b/bin/utils/base.sh @@ -109,4 +109,28 @@ check_config(){ echo "配置文件不是有效的JSON格式, 请重新生成配置文件." exit 1 fi -} \ No newline at end of file +} + +restart_docker() { + local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../" # 脚本文件夹绝对路径 + + # 如果容器未运行,提示启动 + local running_count=$(docker-compose -f $script_dir/../docker-compose.yml ps -q | wc -l) + if [ "$running_count" -eq 0 ]; then + read -p "容器未启动,是否启动容器?(y/n): " choice + case "$choice" in + Y|y) + docker-compose -f $script_dir/../docker-compose.yml up -d + return + ;; + *) + echo "已取消启动" + return + ;; + esac + fi + + echo "正在重启容器..." + docker-compose -f $script_dir/../docker-compose.yml down + docker-compose -f $script_dir/../docker-compose.yml up -d +} \ No newline at end of file diff --git a/install.sh b/install.sh index e402068..226b2fa 100644 --- a/install.sh +++ b/install.sh @@ -1,26 +1,13 @@ #!/bin/bash -restart_docker() { - # 如果容器未运行,提示启动 - local running_count=$(docker-compose -f ./docker-compose.yml ps -q | wc -l) - if [ "$running_count" -eq 0 ]; then - read -p "容器未启动,是否启动容器?(y/n): " choice - case "$choice" in - Y|y) - docker-compose -f ./docker-compose.yml up -d - return - ;; - *) - echo "已取消启动" - return - ;; - esac - fi - - echo "正在重启容器..." - docker-compose -f ./docker-compose.yml down - docker-compose -f ./docker-compose.yml up -d -} +# 导入依赖脚本文件 +BASE_DIR="$(cd "$(dirname "$0")" && pwd)" +for f in "$BASE_DIR"/bin/utils/*.sh; do + [ -f "$f" ] && source "$f" +done +for f in "$BASE_DIR"/bin/*.sh; do + [ -f "$f" ] && source "$f" +done # 安装依赖 @@ -74,27 +61,27 @@ main(){ # 根据用户选择执行相应的操作 case $choice in - 1) + 1) # 一键部署 install_dependencies - bash $script_dir/create_config.sh - bash $script_dir/run.sh - bash $script_dir/print_share_link.sh + create_config + run + print_share_link ;; 2) # 创建配置 / 重置配置 - bash $script_dir/create_config.sh + create_config ;; 3) # 查看分享链接 check_config - bash $script_dir/print_share_link.sh + print_share_link ;; 4) # 启动容器 check_config - bash $script_dir/run.sh - bash $script_dir/print_share_link.sh + run + print_share_link ;; 5) # 停止容器 @@ -102,18 +89,18 @@ main(){ ;; 6) # 更新镜像 - bash $script_dir/update_docker_images.sh + update_docker_images ;; 7) # 修改端口 check_config - bash $script_dir/update_port.sh + update_port restart_docker ;; 8) # 修改Reality目标域名 check_config - bash $script_dir/update_reality_dest.sh + update_reality_dest restart_docker ;; *)