重构代码,统一项目入口为install.sh

This commit is contained in:
Olia Lisa 2026-01-15 13:38:07 +08:00
parent 737378d7ee
commit 2c4a44f924
11 changed files with 55 additions and 73 deletions

View File

@ -7,16 +7,16 @@ create_reality_config(){
cp "$config_dir/template/reality_config.json" "$config_dir/config.json" cp "$config_dir/template/reality_config.json" "$config_dir/config.json"
# 生成uui, 写入到config.json文件 # 生成uui, 写入到config.json文件
bash $script_dir/update_uuid.sh update_uuid
# 生成密钥对, 修改config.json中的密钥属性 # 生成密钥对, 修改config.json中的密钥属性
bash $script_dir/update_key.sh update_key
# 设置端口 # 设置端口
bash $script_dir/update_port.sh update_port
# 设置realty_dest目标域名 # 设置realty_dest目标域名
bash $script_dir/update_reality_dest.sh update_reality_dest
green "成功创建配置" green "成功创建配置"
} }
@ -28,27 +28,27 @@ create_xhttp_reality_config(){
cp "$config_dir/template/xhttp_reality_config.json" "$config_dir/config.json" cp "$config_dir/template/xhttp_reality_config.json" "$config_dir/config.json"
# 生成uui, 写入到config.json文件 # 生成uui, 写入到config.json文件
bash $script_dir/update_uuid.sh update_uuid
# 生成密钥对, 修改config.json中的密钥属性 # 生成密钥对, 修改config.json中的密钥属性
bash $script_dir/update_key.sh update_key
# 生成xhttp_path, 写入到config.json文件 # 生成xhttp_path, 写入到config.json文件
bash $script_dir/update_xhttp_path.sh update_xhttp_path
# 设置realty_dest目标域名 # 设置realty_dest目标域名
bash $script_dir/update_reality_dest.sh update_reality_dest
# 设置端口 # 设置端口
bash $script_dir/update_port.sh update_port
green "成功创建配置" green "成功创建配置"
} }
create_config(){ create_config(){
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件绝对路径 local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件绝对路径
source "$script_dir/utils/base.sh"
# 检查jq是否安装 # 检查jq是否安装
check_jq check_jq
@ -73,7 +73,3 @@ create_config(){
*) echo "无效选择,退出" ;; *) echo "无效选择,退出" ;;
esac esac
} }
create_config

View File

@ -71,7 +71,6 @@ print_share_link(){
local config_dir=$(readlink -f "$script_dir/../conf") # xray配置文件绝对路径 local config_dir=$(readlink -f "$script_dir/../conf") # xray配置文件绝对路径
# 检查 jq 是否安装 # 检查 jq 是否安装
source $script_dir/utils/base.sh
check_jq check_jq
local xhttp_path=$(jq -r ".inbounds[0].streamSettings.xhttpSettings.path" $config_dir/config.json) 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 print_xhttp_reality_share_link
fi fi
} }
print_share_link

View File

@ -12,6 +12,3 @@ run(){
docker-compose -f "$docker_compose_file" up -d # 启动容器 docker-compose -f "$docker_compose_file" up -d # 启动容器
} }
run

View File

@ -23,5 +23,3 @@ update_docker_images(){
echo "正在启动容器.." echo "正在启动容器.."
docker-compose -f $docker_compose_file up -d docker-compose -f $docker_compose_file up -d
} }
update_docker_images

View File

@ -3,7 +3,6 @@
update_key(){ update_key(){
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件绝对路径 local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件绝对路径
local config_dir="$script_dir/../conf" local config_dir="$script_dir/../conf"
source $script_dir/utils/jq_util.sh
# 使用docker运行xray镜像生成密钥文件 # 使用docker运行xray镜像生成密钥文件
docker run --rm teddysun/xray:latest /usr/bin/xray x25519 > $config_dir/key.txt docker run --rm teddysun/xray:latest /usr/bin/xray x25519 > $config_dir/key.txt
@ -17,6 +16,3 @@ update_key(){
echo "生成和设置密钥成功." echo "生成和设置密钥成功."
} }
update_key

View File

@ -77,11 +77,8 @@ find_free_port() {
update_port(){ update_port(){
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹路径 local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹路径
local config_file="$script_dir/../conf/config.json" local config_file="$script_dir/../conf/config.json"
source "$script_dir/utils/jq_util.sh"
local port=$(find_free_port) local port=$(find_free_port)
modify_json_file "$config_file" ".inbounds[0].port" "$port" modify_json_file "$config_file" ".inbounds[0].port" "$port"
echo "设置端口成功" echo "设置端口成功"
} }
update_port

View File

@ -3,7 +3,6 @@
update_reality_dest(){ update_reality_dest(){
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
local config_dir="$script_dir/../conf" local config_dir="$script_dir/../conf"
source $script_dir/utils/jq_util.sh
# 获取当前dest值 # 获取当前dest值
local old_dest=$(jq -r '.inbounds[0].streamSettings.realitySettings.dest' "$config_dir/config.json") local old_dest=$(jq -r '.inbounds[0].streamSettings.realitySettings.dest' "$config_dir/config.json")
@ -33,5 +32,3 @@ update_reality_dest(){
echo "修改realty_dest成功" echo "修改realty_dest成功"
} }
update_reality_dest

View File

@ -5,8 +5,6 @@ update_uuid(){
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件绝对路径 local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件绝对路径
local config_dir="$script_dir/../conf" local config_dir="$script_dir/../conf"
source $script_dir/utils/jq_util.sh
# 生成 UUID # 生成 UUID
local uuid=$(cat /proc/sys/kernel/random/uuid) local uuid=$(cat /proc/sys/kernel/random/uuid)
@ -15,5 +13,3 @@ update_uuid(){
echo "设置UUID成功." echo "设置UUID成功."
} }
update_uuid

View File

@ -4,7 +4,6 @@ update_xhttp_path(){
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件绝对路径 local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件绝对路径
local config_dir="$script_dir/../conf" local config_dir="$script_dir/../conf"
source $script_dir/utils/jq_util.sh
local path_length="$(( RANDOM % 4 + 8 ))" local path_length="$(( RANDOM % 4 + 8 ))"
local xhttp_path="/"$(docker run --rm teddysun/xray:latest xray uuid | tr -d '-' | cut -c 1-$path_length) 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成功" echo "设置xhttp_path成功"
} }
update_xhttp_path

View File

@ -109,4 +109,28 @@ check_config(){
echo "配置文件不是有效的JSON格式, 请重新生成配置文件." echo "配置文件不是有效的JSON格式, 请重新生成配置文件."
exit 1 exit 1
fi fi
} }
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
}

View File

@ -1,26 +1,13 @@
#!/bin/bash #!/bin/bash
restart_docker() { # 导入依赖脚本文件
# 如果容器未运行,提示启动 BASE_DIR="$(cd "$(dirname "$0")" && pwd)"
local running_count=$(docker-compose -f ./docker-compose.yml ps -q | wc -l) for f in "$BASE_DIR"/bin/utils/*.sh; do
if [ "$running_count" -eq 0 ]; then [ -f "$f" ] && source "$f"
read -p "容器未启动,是否启动容器?(y/n): " choice done
case "$choice" in for f in "$BASE_DIR"/bin/*.sh; do
Y|y) [ -f "$f" ] && source "$f"
docker-compose -f ./docker-compose.yml up -d done
return
;;
*)
echo "已取消启动"
return
;;
esac
fi
echo "正在重启容器..."
docker-compose -f ./docker-compose.yml down
docker-compose -f ./docker-compose.yml up -d
}
# 安装依赖 # 安装依赖
@ -74,27 +61,27 @@ main(){
# 根据用户选择执行相应的操作 # 根据用户选择执行相应的操作
case $choice in case $choice in
1) 1)
# 一键部署 # 一键部署
install_dependencies install_dependencies
bash $script_dir/create_config.sh create_config
bash $script_dir/run.sh run
bash $script_dir/print_share_link.sh print_share_link
;; ;;
2) 2)
# 创建配置 / 重置配置 # 创建配置 / 重置配置
bash $script_dir/create_config.sh create_config
;; ;;
3) 3)
# 查看分享链接 # 查看分享链接
check_config check_config
bash $script_dir/print_share_link.sh print_share_link
;; ;;
4) 4)
# 启动容器 # 启动容器
check_config check_config
bash $script_dir/run.sh run
bash $script_dir/print_share_link.sh print_share_link
;; ;;
5) 5)
# 停止容器 # 停止容器
@ -102,18 +89,18 @@ main(){
;; ;;
6) 6)
# 更新镜像 # 更新镜像
bash $script_dir/update_docker_images.sh update_docker_images
;; ;;
7) 7)
# 修改端口 # 修改端口
check_config check_config
bash $script_dir/update_port.sh update_port
restart_docker restart_docker
;; ;;
8) 8)
# 修改Reality目标域名 # 修改Reality目标域名
check_config check_config
bash $script_dir/update_reality_dest.sh update_reality_dest
restart_docker restart_docker
;; ;;
*) *)