tuic_docker/bin/print_share_link.sh
2025-12-29 23:42:30 +08:00

52 lines
2.0 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 "$0")"; pwd)
local config_dir=$(readlink -f "$script_dir/../config")
source "${script_dir}/utils/base.sh"
# 检查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表示不跳过
# 检查sni
if [ "$sni" = "你的域名或伪装域名" ] || [ -z "$sni" ] || [[ "$sni" == null ]]; then
sni="bing.com" # 可根据需要修改默认值
fi
# 构建分享链接
local share_link="tuic://$uuid:$password@$ipv4:$port?sni=$sni&alpn=h3&insecure=1&allowInsecure=$allowInsecure&congestion_control=bbr#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 # 输出分享链接