tuic_docker/bin/print_share_link.sh
2026-01-15 12:31:44 +08:00

53 lines
1.9 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
print_share_link() {
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
local config_dir=$(readlink -f "$script_dir/../config")
# 检查jq是否安装
check_jq
# 检查配置是否正确
local uuid=$(jq -r '.inbounds[0].users[0].uuid' "$config_dir/config.json")
if [ "$uuid" = "你的UUID" ] || [ -z "$uuid" ] || [[ "$uuid" == null ]]; then
red "error: 配置有误, 请重新生成配置"
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"
}