tuic_docker/bin/print_share_link.sh

56 lines
2.2 KiB
Bash
Raw 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
source "$(dirname "$0")/bin/utils/base.sh"
print_share_link() {
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
local config_dir=$(readlink -f "$script_dir/../config")
# 检查jq是否安装
check_jq
# 检查是否已启动过容器假设UUID已替换为真实值否则视为未启动
local uuid=$(jq -r '.inbounds[0].users[0].uuid' "$config_dir/config.json")
if [ "$uuid" = "你的UUID" ] || [ -z "$uuid" ] || [[ "$uuid" == null ]]; then
red "error: 容器未启动过或UUID未配置, 查看配置失败"
echo '请选择"启动容器"或确保已手动替换UUID'
exit 1
fi
# 读取配置文件内容
local config=$(cat "$config_dir/config.json")
# 提取所需信息
uuid=$(echo "$config" | jq -r '.inbounds[0].users[0].uuid')
local sni=$(echo "$config" | jq -r '.inbounds[0].tls.server_name')
local ipv4=$(curl -4 -sSL --connect-timeout 3 --retry 2 ip.sb || echo "null")
local port=$(echo "$config" | jq -r '.inbounds[0].listen_port')
local password=$(echo "$config" | jq -r '.inbounds[0].users[0].password')
local congestion_control=$(echo "$config" | jq -r '.inbounds[0].congestion_control')
local allowInsecure=1 # 是否跳过证书验证1表示跳过0表示不跳过
local insecure=1 # 是否允许不安全连接1表示允许0表示不允许
# 检查是否使用ACME证书
if jq -e '.inbounds[0].tls.acme' "$config_dir/config.json" > /dev/null 2>&1; then
allowInsecure=0 # 不跳过证书验证
insecure=0
fi
# 构建分享链接
local share_link="tuic://$uuid:$password@$ipv4:$port?sni=$sni&alpn=h3&insecure=$insecure&allowInsecure=$allowInsecure&congestion_control=$congestion_control#Tuic节点"
# 输出分享链接
echo -e "\033[32m"
echo "IPV4: $ipv4"
echo "port: $port"
echo "uuid: $uuid"
echo "password: $password"
echo "sni: $sni"
echo "congestion_control(拥塞控制算法): $congestion_control"
echo ""
echo "分享链接: $share_link"
echo -e "\033[0m"
}
print_share_link # 输出分享链接