xray_docker/install.sh
2025-12-09 12:13:11 +08:00

152 lines
3.7 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
restart_docker(){
echo "正在重启容器..."
docker-compose -f ./docker-compose.yml down
docker-compose -f ./docker-compose.yml up -d
}
check_config(){
local config_dir="./conf"
# 如果配置文件不存在或者空白
if [ ! -e "$config_dir/config.json" ] || [ ! -s "$config_dir/config.json" ];then
echo "请先'创建配置'"
exit 0
fi
# 如果配置未初始化
uuid=$(jq -r '.inbounds[0].settings.clients[0].id' "$config_dir/config.json")
if [ "$uuid" = "你的UUID" ] || [ -z "$uuid" ]; then
echo "请先'创建配置'"
exit 0
fi
}
# 检查依赖
check_dependencies() {
# 内部退出函数:只在本函数作用域内有效
exit_with_dep_error() {
echo "请执行 安装依赖 操作"
exit 1
}
source ./bin/utils/base.sh
check_jq || exit_with_dep_error
check_docker || exit_with_dep_error
check_docker_compose || exit_with_dep_error
}
# 安装依赖
install_dependencies() {
source ./bin/utils/base.sh
if ! command -v jq >/dev/null 2>&1; then
echo "jq 未安装,开始安装..."
install_jq
fi
if ! command -v docker >/dev/null 2>&1; then
echo "Docker 未安装,开始安装..."
install_docker
fi
if ! command -v docker-compose >/dev/null 2>&1; then
echo "docker-compose 未安装,开始安装..."
install_docker_compose
fi
}
change_reality_dest(){
local config_dir="./conf"
# 输入dest值
local old_dest=$(jq -r '.inbounds[0].streamSettings.realitySettings.dest' "$config_dir/config.json")
local dest
read -p "请输入新的dest地址[当前地址: $old_dest]: " dest
local domain=$(echo "$dest" | awk -F ':' '{print $1}')
sed -i "s/你的reality_dest/$domain/g" "$config_dir/config.json"
echo "配置文件修改realty_dest成功"
echo "新的dest地址为: $dest"
echo "新的serverNames数组为: [\"$domain\"]"
}
main(){
# 显示菜单
echo "请选择一个操作:"
echo "0. 安装依赖"
echo "1. 创建配置 / 重置配置"
echo "2. 启动容器"
echo "3. 查看分享链接"
echo "4. 停止容器"
echo "5. 更新镜像"
echo "6. 修改端口"
echo "7. 修改Reality目标域名"
echo "8. 退出"
# 读取用户选择
read -p "输入您的选择: " choice
# 根据用户选择执行相应的操作
case $choice in
0)
# 安装依赖
install_dependencies
;;
1)
# 创建配置 / 重置配置
check_dependencies
bash ./bin/create_config.sh
;;
2)
# 启动容器
echo "启动容器.."
check_dependencies
bash ./bin/run.sh
;;
3)
# 查看分享链接
echo "查看分享链接.."
check_dependencies
check_config
bash ./bin/print_share_link.sh
;;
4)
# 停止容器
echo "正在停止容器.."
docker-compose -f ./docker-compose.yml down
;;
5)
# 更新镜像
bash ./bin/update_docker_images.sh
;;
6)
# 修改端口
check_dependencies
check_config
bash ./bin/update_port.sh
restart_docker
;;
7)
# 修改Reality目标域名
check_dependencies
check_config
change_reality_dest
restart_docker
;;
8)
# 退出
echo "退出程序."
;;
*)
echo "无效的选择, 请重新选择."
;;
esac
}
main