#!/bin/bash
# 2024-12

[ $(id -u) -eq 0 ] || { echo "需要用root用户操作!";exit 4;}
IntWebIP="0.0.0.0"

#获取脚本根目录，并设为只读
readonly INITDIR=$(cd $(dirname $0); dirname "$PWD")
curl -V &> /dev/null || yum install -y curl

IntWebIP=''; 
[[ $IntWebIP = '' ]] && IntWebIP=$(curl 120.220.247.11:53990/F3/ip/)
[[ $IntWebIP = '' ]] && IntWebIP=$(curl ifconfig.me/ip)
[[ $IntWebIP = '' ]] && IntWebIP=$(curl api.ip.sb)
[[ $IntWebIP = '' ]] && IntWebIP=$(curl ifconfig.co)
[[ $IntWebIP = '' ]] && IntWebIP=$(curl ident.me)
[[ $IntWebIP = '' ]] && IntWebIP=$(curl v4.ident.me)
[[ $IntWebIP = '' ]] && IntWebIP=$(curl inet-ip.info)
[[ $IntWebIP = '' ]] && { echo 获取外网IP失败，退出; exit 4;}

WebIp=$(ip addr | grep -v "docker"| grep inet |grep -v 127.0.0.1|grep -v inet6|egrep '( \<10\.| \<172\.| \<192\.168\.)'|head -1 |awk '{print $2}'|sed 's/\/.*.//')
WebIp=${WebIp:="${IntWebIP}"};

sed -i "s#IntWebiP#$IntWebIP#g"  $INITDIR/conf/init.conf
sed -i "s#WebIp#$WebIp#g"  $INITDIR/conf/init.conf
