﻿#!/bin/bash
#中文-UTF8

cd /root
mkdir vos3000
cd vos3000
# 应该是查两个CPU
cat /proc/bus/pci/devices | grep 8086 | awk '{print $2}' > pci
PCI1=$(sort pci | uniq | sort -r | head -1 | tail -1)
echo $PCI1
PCI2=$(sort pci | uniq | sort -r | head -2 | tail -1)
echo $PCI2
# 查找网卡
ipa=$(ip a | egrep "link/ether" | awk '{print $2}' | head -1)
echo $ipa
# 网卡小写转大写
MAC=$(echo $ipa | tr a-z A-Z)
echo $MAC
# 查找注册的IP 如:10.10.91.19 192.168.1.11
HOSTIP=$(ip a | grep -o -e 'inet [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}' | grep -v "127" | awk '{print $2}')
echo $HOSTIP
# 查找出注册需要的最后的字符 1704530527
license=$(/bin/rpm --qf %{INSTALLTIME} -q vos3000)
echo $license
# 将值追加到hostip
echo -e "$HOSTIP\n" >> hostip
# 查看外网IP（默认网卡的）
Nat=$(curl -s https://ip.3322.net/)
echo $Nat
# 把hostip文件赋值到HIP
HIP=$(cat hostip)
echo $HIP
# 把变量HIP追加到文件HIP
echo -e $HIP >> HIP
# 用:把多个IP拼接在一起
HIP=$(sed s/[[:space:]]/,/g HIP)
echo $HIP
# 不知是什么，答案是4，循环查找外网IP，如存在将1写到文件HIP1
HANG=$(awk '{print NR}' hostip | tail -n1)
echo $HANG
i=1
for i in `seq 1 $HANG`
do    
IP=$(head -$i hostip | tail -1)
if [[ "$IP" == "$Nat" ]]; then
    echo -e "1" >> HIP1
fi 
let "i=$i+1" 
done
# 如存在外网IP，将1赋值到HIP1
HIP1=$(cat HIP1)
echo $HIP1
if [[ "$HIP1" != "1" ]]; then
    echo -e "\033[31m$HIP","$Nat $MAC $PCI1$PCI2 $license\033[0m" 
fi
if [[ "$HIP1" == "1" ]]; then
    echo -e "\033[31m$HIP $MAC $PCI1$PCI2 $license\033[0m" 	
fi
ip add
uuid=$(head -2 /home/kunshi/vos3000/etc/server.conf | tail -1)
vos=$(head -23 /home/kunshi/vos3000/etc/server.conf | tail -1)
web=$(head -61 /home/kunshiweb/base/apache-tomcat/conf/server.xml | tail -1)
phone=$(head -64 /home/kunshiweb/base/apache-tomcat/conf/server.xml | tail -1)
echo "系统标识" ${uuid#*ACCESS_UUID=}
echo "登录端口" ${vos#*GUI_SERVER_PORT=}
echo "查费端口" ${web#*port=}
echo "手机端口" ${phone#*redirectPort=}
cd /root
rm -rf vos*
echo "done"
cd /root
echo > ./.bash_history
echo > .bash_history
echo > /root/.bash_history
history -c
