- Extracted common config file validation into a new `check_config` function - Renumbered menu options for logical order, with exit as the last option - Added config checks before viewing share links, updating port, and changing Reality destination - Removed trailing backslash and added final newline for proper formatting This update improves code reusability, prevents errors from missing configs, and enhances menu usability.
103 lines
2.4 KiB
Bash
103 lines
2.4 KiB
Bash
#!/bin/bash
|
||
|
||
restart_docker(){
|
||
echo "正在重启容器..."
|
||
docker-compose -f ./docker-compose.yml down
|
||
docker-compose -f ./docker-compose.yml up -d
|
||
}
|
||
|
||
|
||
check_config(){
|
||
if [ ! -e "$config_dir/config.json" ] || [ ! -s "$config_dir/config.json" ];then
|
||
echo "请先'创建配置'"
|
||
exit 0
|
||
fi
|
||
}
|
||
|
||
|
||
change_reality_dest(){
|
||
local config_dir="./conf"
|
||
|
||
check_config
|
||
|
||
source ./bin/utils/jq_util.sh
|
||
|
||
# 输入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 "1. 创建配置 / 重置配置"
|
||
echo "2. 启动容器"
|
||
echo "3. 查看分享链接"
|
||
echo "4. 停止容器"
|
||
echo "5. 更新镜像"
|
||
echo "6. 修改端口"
|
||
echo "7. 修改Reality目标域名"
|
||
echo "8. 退出"
|
||
|
||
# 读取用户选择
|
||
read -p "输入您的选择: " choice
|
||
|
||
# 根据用户选择执行相应的操作
|
||
case $choice in
|
||
1)
|
||
# 创建配置 / 重置配置
|
||
bash ./bin/create_config.sh
|
||
;;
|
||
2)
|
||
# 启动容器
|
||
echo "启动容器.."
|
||
bash ./bin/run.sh
|
||
;;
|
||
3)
|
||
# 查看分享链接
|
||
echo "查看分享链接.."
|
||
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_config
|
||
bash ./bin/update_port.sh
|
||
restart_docker
|
||
;;
|
||
7)
|
||
# 修改Reality目标域名
|
||
check_config
|
||
change_reality_dest
|
||
restart_docker
|
||
;;
|
||
8)
|
||
# 退出
|
||
echo "退出程序."
|
||
;;
|
||
*)
|
||
echo "无效的选择, 请重新选择."
|
||
;;
|
||
esac
|
||
}
|
||
|
||
main
|