diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml index 4cdbd16..2954356 100644 --- a/server/src/main/resources/application.yml +++ b/server/src/main/resources/application.yml @@ -10,7 +10,7 @@ spring: port: 20672 username: boge password: boge8tingH - virtual-host: /wdd + virtual-host: / listener: simple: retry: diff --git a/source/src/main/java/io/wdd/source/shell/agent-bootup.sh b/source/src/main/java/io/wdd/source/shell/agent-bootup.sh index 38e819b..e302c6c 100644 --- a/source/src/main/java/io/wdd/source/shell/agent-bootup.sh +++ b/source/src/main/java/io/wdd/source/shell/agent-bootup.sh @@ -12,7 +12,7 @@ DependLibFiles=( ) OctopusAgentUrl=https://happybirthday.107421.xyz/octopus-agent/ - +AgentConfigUrl=https://happybirthday.107421.xyz/agent-config/ RepoSourcePath=https://happybirthday.107421.xyz/shell OctopusAgentPath=/octopus-agent/shell ##### environment variables ###### @@ -261,38 +261,61 @@ DownloadAllFile() { } +####################################### +# description +# Globals: +# AgentConfigUrl +# BLUE +# GREEN +# LinuxRelease +# OctopusAgentUrl +# agentConfig +# agentConfigFileList +# Arguments: +# None +####################################### CheckAndDownloadLatestVersion() { FunctionStart colorEcho $BLUE "checking for the latest version" local latestVersion=$(curl $OctopusAgentUrl | grep -v h1 | grep "a href=" | head -1 | awk '{print$2}' | cut -d">" -f2 | cut -d"<" -f1 | cut -d"_" -f4-) - rm -rf /octopus-agent/octopus-agent* cd /octopus-agent colorEcho $BLUE "start to download the latest version !" - # Agent二进制文件的命名规则为 octopus-agent_linux_amd64_ local latestAgentVersion="octopus-agent_linux_${LinuxRelease}_${latestVersion}" colorEcho $BLUE "" colorEcho $BLUE "octopus agent latest version is => [ $latestAgentVersion ]" colorEcho $BLUE "" - wget -q "$OctopusAgentUrl$latestAgentVersion" cp "$latestAgentVersion" octopus-agent chmod +x octopus-agent echo "" - echo "" colorEcho $GREEN "---------------- ls the /octopus-agent ----------------------" ls /octopus-agent/ | grep octopus-agent + echo "" + + colorEcho $BLUE "start to download the agent config!" + agentConfigFileList=$(curl $AgentConfigUrl | grep -v h1 | grep "a href=" | awk '{print$2}' | cut -d">" -f2 | cut -d"<" -f1 | cut -d"_" -f4-) + + for agentConfig in "${agentConfigFileList[@]}"; do + colorEcho $BLUE "agent config file is => $agentConfig" + wget -q "$AgentConfigUrl$agentConfig" + echo "" + done + + echo "" + colorEcho $GREEN "---------------- ls the /octopus-agent ----------------------" + ls /octopus-agent/ | grep ".yaml" + echo "" FunctionSuccess FunctionEnd } - ####################################### # description # Globals: @@ -391,7 +414,6 @@ ExecStop=/bin/kill -15 \$MAINPID WantedBy=multi-user.target EOF - colorEcho ${BLUE} "开始配置Agent日志输出文件!" # https://www.benzhu.xyz/linux12/ cat >/etc/rsyslog.d/octopus-agent.conf < $managePort" + } ####################################### @@ -233,6 +251,7 @@ GetIpv4Info() { log "start to get system public ip info !" + # public ip info org="$(wget -q -T10 -O- ipinfo.io/org)" city="$(wget -q -T10 -O- ipinfo.io/city)" country="$(wget -q -T10 -O- ipinfo.io/country)" @@ -240,6 +259,46 @@ GetIpv4Info() { public_ipv4="$(wget -q -T10 -O- ipinfo.io/ip)" public_ipv6="$(curl --max-time 5 -6 https://ifconfig.co/ip)" + if [ -z "$public_ipv4" ] ; then + public_ipv4="" + fi + + if [ -z "$public_ipv6" ] ; then + public_ipv6="" + fi + + if [ -z "$public_ipv4" ] ; then + public_ipv4="" + fi + + + # inner ipinfo + interface_prefix=(" eth[0-9]{1,2}" " ens[0-9]{1,3}" " eno[0-9]{1,3}" " enp[0-9]{1,2}") + real_interface="eth90" + + for interface in "${interface_prefix[@]}"; do + echo $(ip link show) | grep -oE ${interface} + if [[ $? -eq 0 ]]; then + real_interface=$(echo $(ip link show) | grep -oE ${interface} | cut -d" " -f2) + echo "当前主机的真实内网网卡为 => $real_interface" + return + fi + done + + # 提取IPv4地址(CIDR格式) + ipv4_regex="inet (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/[0-9]{1,2}" + + # 提取IPv6地址(CIDR格式) + ipv6_regex="inet6 ([0-9a-fA-F]{0,4}(:[0-9a-fA-F]{0,4}){1,7})\/[0-9]{1,3}" + + # 查找IPv4地址 + inner_ipv4=$(echo $(ip addr show $real_interface) | grep -oE $ipv4_regex | cut -d" " -f2) + echo "Interface: $interface, IPv4 Address: $inner_ipv4" + + # 查找IPv6地址 + inner_ipv6=$(echo $(ip addr show $real_interface) | grep -oE $ipv6_regex | cut -d" " -f2) + echo "Interface: $interface, IPv4 Address: $inner_ipv6" + } log "start to collect system info !" @@ -307,6 +366,8 @@ tcpctrl=$(sysctl net.ipv4.tcp_congestion_control | awk -F ' ' '{print $3}') # todo # StartIOTest +GetManagePort + GetIpv4Info Check_Virtualization @@ -318,16 +379,18 @@ if [[ $(cat /etc/hostname | cut -d"-" -f 3 | grep -c '^[0-9][0-9]') -gt 0 ]]; th else machineNumber=99 fi +agentServerInfoFile="/octopus-agent/octopus-agent.conf " + #cat >/etc/environment.d/octopus-agent.conf </octopus-agent/octopus-agent.conf <"$agentServerInfoFile"< /octopus-agent/octopus-agent.conf" +log "file is => $agentServerInfoFile"