From 9140165d0596f524c221be08523cf93d29e41f9b Mon Sep 17 00:00:00 2001 From: vincent Date: Thu, 16 May 2024 14:56:04 +0800 Subject: [PATCH] update --- bin/init.sh | 8 ++++---- bin/print_share_link.sh | 40 ++++++++++++++++++------------------- bin/update_docker_images.sh | 12 +++++------ bin/update_key.sh | 15 +++++++------- bin/update_uuid.sh | 14 ++++++------- 5 files changed, 43 insertions(+), 46 deletions(-) diff --git a/bin/init.sh b/bin/init.sh index 34caab9..60b2aaa 100644 --- a/bin/init.sh +++ b/bin/init.sh @@ -3,13 +3,13 @@ # 安装xray bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径 +script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径 # 生成uui, 写入到config.json文件 -bash $SCRIPT_DIR/update_uuid.sh +bash $script_dir/update_uuid.sh # 生成密钥对, 修改config.json中的密钥属性 -bash $SCRIPT_DIR/update_key.sh +bash $script_dir/update_key.sh # 打印分享链接 -bash $SCRIPT_DIR/print_share_link.sh +bash $script_dir/print_share_link.sh \ No newline at end of file diff --git a/bin/print_share_link.sh b/bin/print_share_link.sh index ff71bc6..438b28e 100644 --- a/bin/print_share_link.sh +++ b/bin/print_share_link.sh @@ -12,31 +12,31 @@ if ! command -v qrencode &> /dev/null; then exit 1 fi -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径 -CONFIG_DIR=$(readlink -f "$SCRIPT_DIR/../conf") # 配置文件绝对路径 +script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径 +config_dir=$(readlink -f "$script_dir/../conf") # 配置文件绝对路径 # 获取本机IP -IPV4=$(curl -4 -sSL --connect-timeout 3 --retry 2 ip.sb || echo "null") +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) -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}') +uuid=$(jq -r '.inbounds[0].settings.clients[0].id' $config_dir/config.json) +port=$(jq -r '.inbounds[0].port' $config_dir/config.json) +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 "DEST: $DEST" -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 "IPV4 订阅连接: $SUB_IPV4" - echo -e "IPV4 订阅二维码:\n$(echo "$SUB_IPV4" | qrencode -o - -t UTF8)" +echo "IPV4: $ipv4" +echo "PORT: $port" +echo "UUID: $uuid" +echo "DEST: $dest" +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 "IPV4 订阅连接: $sub_ipv4" + echo -e "IPV4 订阅二维码:\n$(echo "$sub_ipv4" | qrencode -o - -t UTF8)" fi -echo -e "\033[0m" +echo -e "\033[0m" \ No newline at end of file diff --git a/bin/update_docker_images.sh b/bin/update_docker_images.sh index d629a71..8ca2ad8 100644 --- a/bin/update_docker_images.sh +++ b/bin/update_docker_images.sh @@ -1,19 +1,19 @@ #!/bin/bash -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径 -DOCKER_COMPOSE_FILE="$SCRIPT_DIR/../docker-compose.yml" # docker-compose.yml文件路径 +script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径 +docker_compose_file="$script_dir/../docker-compose.yml" # docker-compose.yml文件路径 # 检查是否存在 docker-compose.yml 文件 -if [ ! -f $DOCKER_COMPOSE_FILE ]; then +if [ ! -f $docker_compose_file ]; then echo "Error: docker-compose.yml 文件不存在." exit 1 fi echo "正在关闭容器.." -docker-compose -f $DOCKER_COMPOSE_FILE down +docker-compose -f $docker_compose_file down echo "正在更新镜像.." -docker-compose -f $DOCKER_COMPOSE_FILE pull +docker-compose -f $docker_compose_file pull echo "正在启动容器.." -docker-compose -f $DOCKER_COMPOSE_FILE up -d \ No newline at end of file +docker-compose -f $docker_compose_file up -d \ No newline at end of file diff --git a/bin/update_key.sh b/bin/update_key.sh index 6fea243..512fc09 100644 --- a/bin/update_key.sh +++ b/bin/update_key.sh @@ -1,16 +1,15 @@ #!/bin/bash -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径 -CONFIG_DIR="$SCRIPT_DIR/../conf" +script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径 +config_dir="$script_dir/../conf" # Save keys to key.txt -xray x25519 > $CONFIG_DIR/key.txt +xray x25519 > $config_dir/key.txt -PRIVATE_KEY=$(grep "Private key" $CONFIG_DIR/key.txt | awk -F ': ' '{print $2}') +private_key=$(grep "Private key" $config_dir/key.txt | awk -F ': ' '{print $2}') # 修改config.json密钥属性 -jq ".inbounds[0].streamSettings.realitySettings.privateKey=\"$PRIVATE_KEY\"" $CONFIG_DIR/config.json > $CONFIG_DIR/config_temp.json -mv $CONFIG_DIR/config_temp.json $CONFIG_DIR/config.json - -echo "生成和设置密钥成功." +jq ".inbounds[0].streamSettings.realitySettings.privateKey=\"$private_key\"" $config_dir/config.json > $config_dir/config_temp.json +mv $config_dir/config_temp.json $config_dir/config.json +echo "生成和设置密钥成功." \ No newline at end of file diff --git a/bin/update_uuid.sh b/bin/update_uuid.sh index d7adf5f..2cea527 100644 --- a/bin/update_uuid.sh +++ b/bin/update_uuid.sh @@ -1,18 +1,16 @@ #!/bin/bash -SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径 -CONFIG_DIR="$SCRIPT_DIR/../conf" +script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本文件绝对路径 +config_dir="$script_dir/../conf" # 生成 UUID -UUID=$(xray uuid) +uuid=$(xray uuid) # 使用 jq 修改 JSON 文件 -jq ".inbounds[0].settings.clients[0].id=\"$UUID\"" $CONFIG_DIR/config.json > $CONFIG_DIR/config.json_tmp +jq ".inbounds[0].settings.clients[0].id=\"$uuid\"" $config_dir/config.json > $config_dir/config.json_tmp # 替换原始文件 -mv $CONFIG_DIR/config.json_tmp $CONFIG_DIR/config.json +mv $config_dir/config.json_tmp $config_dir/config.json # 验证结果 -echo "设置UUID成功." - - +echo "设置UUID成功." \ No newline at end of file