#!/bin/bash
# 2024-12

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

#获取脚本根目录，并设为只读
readonly INITDIR=$(cd $(dirname $0); dirname "$PWD")

source $INITDIR/conf/init.conf

hostN=$(cat /etc/hosts | wc -l)
if [ "$hostN" -gt "2" ]; then
 sed -i '/^$/d' /etc/hosts 
 cat /etc/hosts
fi

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

#检查CPU、内存、系统
SysV=0;  CpuN=0; MemN=0;

grep -E "Anolis.*7\.[7]*|CentOS.*7\.[2-9].*" /etc/redhat-release || SysV=1
[ `grep 'processor' /proc/cpuinfo | wc -l` -lt 7 ] && CpuN=1
[ `free -g | grep Mem | awk -F : '{print $2}' | awk '{print $1}'` -lt 29 ] && MemN=1
  
if [ $SysV -eq 1 ]; then
  echo -e "\033[5;31mF3平台运行系统需在Centos7.2 - 7.9,请确认您的操作系统版本\033[0m"
  exit 4
fi

if [ $CpuN -eq 1 ]; then
  echo -e "\033[5;31mF3平台当前版本运行环境需要CPU至少8核心,请确认您的服务器配置\033[0m"
  exit 4
fi

if [ $MemN -eq 1 ]; then
  echo -e "\033[5;31mF3平台当前版本运行环境需要内存至少32G,请确认您的服务器配置\033[0m"
  exit 4
fi

