#!/bin/sh

# 检查 jq 是否安装
if ! command -v jq &> /dev/null; then
  echo "jq 未安装"
  exit 1
fi

# 检查 qrencode 是否安装
if ! command -v qrencode &> /dev/null; then
  echo "qrencode 未安装"
  exit 1
fi


# 获取本机IP
IPV4=$(curl -4 -sSL --connect-timeout 3 --retry 2  ip.sb || echo "null")

UUID=$(jq -r '.inbounds[0].settings.clients[0].id' ./conf/config.json)
PORT=$(jq -r '.inbounds[0].port' ./conf/config.json)
DEST=$(jq -r '.inbounds[0].streamSettings.realitySettings.dest' ./conf/config.json)
SNI=$(echo $DEST | awk -F ':' '{print $1}')
NETWORK="tcp"
PUBLIC_KEY=$(cat ./conf/key.txt | grep "Public" | awk -F ': ' '{print $2}')

# config info with green color
echo -e "\033[32m" 
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"




