diff --git a/bin/print_share_link.sh b/bin/print_share_link.sh index 3f4a9cd..66af0f7 100644 --- a/bin/print_share_link.sh +++ b/bin/print_share_link.sh @@ -20,22 +20,26 @@ ipv4=$(curl -4 -sSL --connect-timeout 3 --retry 2 ip.sb || echo "null") uuid=$(jq -r '.inbounds[0].settings.clients[0].id' $config_dir/config.json) port=$(jq -r '.inbounds[0].port' $config_dir/config.json) -target=$(jq -r '.inbounds[0].streamSettings.realitySettings.target' $config_dir/config.json) -sni=$(echo $target | awk -F ':' '{print $1}') +dest=$(jq -r '.inbounds[0].streamSettings.realitySettings.dest' $config_dir/config.json) +sni=$(echo $dest | awk -F ':' '{print $1}') network="tcp" public_key=$(cat $config_dir/key.txt | grep "Public" | awk -F ': ' '{print $2}') # 打印配置信息 echo -e "\033[32m" # config info with green color -echo "IPV4: $ipv4" -echo "PORT: $port" -echo "UUID: $uuid" -echo "SNI: $sni" -echo "PUBLIC_KEY: $public_key" -echo "NETWORK: $network" +echo "ipv4: $ipv4" +echo "port: $port" +echo "uuid: $uuid" +echo "dest: $dest" +echo "sni: $sni" +echo "public_key: $public_key" +echo "network: $network" if [ "$ipv4" != "null" ]; then sub_ipv4="vless://$uuid@$ipv4:$port?encryption=none&security=reality&type=$network&sni=$sni&fp=chrome&pbk=$public_key&flow=xtls-rprx-vision#my_docker_vless_reality_vision" + echo "" echo "IPV4 订阅连接: $sub_ipv4" + echo "" + # 如果qrencode安装了,则打印二维码 if command -v qrencode &> /dev/null; then echo -e "IPV4 订阅二维码:\n$(echo "$sub_ipv4" | qrencode -o - -t UTF8)" diff --git a/bin/update_port.sh b/bin/update_port.sh index 8c35107..51950d2 100644 --- a/bin/update_port.sh +++ b/bin/update_port.sh @@ -2,13 +2,29 @@ script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径 config_dir="$script_dir/../conf" - source $script_dir/utils/jq_util.sh old_port=$(jq -r '.inbounds[0].port' "$config_dir/config.json") read -p "请输入新的端口[当前端口: $old_port]: " port +# 如果输入为空,退出脚本 +if [[ -z "$port" ]]; then + echo "输入端口为空, 退出脚本" + exit 0 +fi + # 修改端口 modify_json_file "$config_dir/config.json" ".inbounds[0].port" "$port" echo "端口修改成功!新端口为: $port" + + +read -p "是否要重启容器? (y/N): " restart_choice +if [[ "$restart_choice" =~ ^[Yy]$ ]]; then + echo "正在重启容器..." + docker-compose -f $script_dir/../docker-compose.yml down + docker-compose -f $script_dir/../docker-compose.yml up -d +else + echo "已跳过重启,请手动重启容器使配置生效" +fi + diff --git a/bin/update_reality_dest.sh b/bin/update_reality_dest.sh new file mode 100644 index 0000000..a461a99 --- /dev/null +++ b/bin/update_reality_dest.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +script_dir=$(cd "$(dirname "$0")"; pwd) +config_dir="$script_dir/../conf" +source $script_dir/utils/jq_util.sh + +# 输入dest值 +old_dest=$(jq -r '.inbounds[0].streamSettings.realitySettings.dest' "$config_dir/config.json") +read -p "请输入新的dest地址[当前地址: $old_dest]: " dest + +# 如果输入dest为空 +if [[ -z "$dest" ]]; then + echo "输入dest为空,退出脚本" + exit 1 +fi + +domain=$(echo "$dest" | awk -F ':' '{print $1}') + + +echo "正在修改配置文件..." + +# 修改配置文件的dest +modify_json_file "$config_dir/config.json" ".inbounds[0].streamSettings.realitySettings.dest" "$dest" + +# 修改配置文件的serverNames +modify_json_file "$config_dir/config.json" ".inbounds[0].streamSettings.realitySettings.serverNames" "[\"$domain\"]" + +echo "配置文件修改成功!" +echo "新的dest地址为: $dest" +echo "新的serverNames数组为: [\"$domain\"]" + + +read -p "是否要重启容器? (y/N): " restart_choice +if [[ "$restart_choice" =~ ^[Yy]$ ]]; then + echo "正在重启容器..." + docker-compose -f "$script_dir/../docker-compose.yml" down + docker-compose -f "$script_dir/../docker-compose.yml" up -d +else + echo "已跳过重启,请手动重启容器使配置生效" +fi \ No newline at end of file diff --git a/bin/utils/jq_util.sh b/bin/utils/jq_util.sh index 64dfc01..c2b8370 100644 --- a/bin/utils/jq_util.sh +++ b/bin/utils/jq_util.sh @@ -1,7 +1,9 @@ #!/bin/bash # 修改json文件的属性值 -# 调用方式:modify_json_file "/foo/bar.json" "person.name" "张三" +# 案例1:modify_json_file "/foo/bar.json" "person.name" "张三" +# 案例2:modify_json_file "/foo/bar.json" "servers" '["a.com", "b.com"]' +# 该函数能自动处理不同数据类型,包括数组、对象和数字等。 function modify_json_file() { local json_file=$1 # json文件路径 local key=$2 # 要修改的key @@ -12,6 +14,14 @@ function modify_json_file() { key=${key:1} fi - jq ".${key} = \"${value}\"" ${json_file} > ${json_file}.tmp + # 检查值是否为有效的 JSON 格式(如数组、对象或数字)。 + # 如果是,则直接将值传递给 jq,无需引号。 + if echo "${value}" | jq . >/dev/null 2>&1; then + jq ".${key} = ${value}" "${json_file}" > "${json_file}.tmp" + else + # 否则,将值视为字符串,并添加引号。 + jq ".${key} = \"${value}\"" "${json_file}" > "${json_file}.tmp" + fi + mv ${json_file}.tmp ${json_file} } diff --git a/conf/config.json b/conf/config.json index 8312a7a..01c9110 100644 --- a/conf/config.json +++ b/conf/config.json @@ -56,7 +56,7 @@ "security": "reality", "realitySettings": { "show": true, - "target": "www.expedia.com:443", + "dest": "www.expedia.com:443", "xver": 0, "maxTimeDiff": 0, "minClientVer": "", diff --git a/install.sh b/install.sh index 8b6749c..9678a65 100644 --- a/install.sh +++ b/install.sh @@ -6,7 +6,8 @@ echo "1. 启动容器" echo "2. 查看分享链接" echo "3. 停止容器" echo "4. 更新镜像" -echo "5. 更新端口" +echo "5. 修改端口" +echo "6. 修改Reality目标域名" echo "0. 退出" # 读取用户选择 @@ -34,9 +35,13 @@ case $choice in bash ./bin/update_docker_images.sh ;; 5) - # 更新端口 + # 修改端口 bash ./bin/update_port.sh ;; + 6) + # 修改Reality目标域名 + bash ./bin/update_reality_dest.sh + ;; 0) # 退出 echo "退出程序."