Skip to content

Commit

Permalink
feat(monitor): docker integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jusito committed Mar 31, 2023
1 parent a9bd66a commit 242d0a4
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 161 deletions.
31 changes: 18 additions & 13 deletions lgsm/functions/check_ip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,37 @@ for ethtool_command in "${ethtool_commands_array[@]}"; do
fi
done

getip=$(${ipcommand} -o -4 addr | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
getipwc=$(${ipcommand} -o -4 addr | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -vc 127.0.0)
mapfile -t current_ips < <(${ipcommand} -o -4 addr | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)

function fn_is_valid_ip() {
local ip="${1}"
# excluding 0.* ips also
grep -qEe '^[1-9]+[0-9]*\.[0-9]+\.[0-9]+\.[0-9]+$' <<< "${ip}"
}

# Check if server has multiple IP addresses

# If the IP variable has been set by user.
if [ -n "${ip}" ] && [ "${ip}" != "0.0.0.0" ]; then
queryips=("${ip}")
webadminip=("${ip}")
telnetip=("${ip}")
if fn_is_valid_ip "${ip}"; then
queryips=( "${ip}" )
webadminip=( "${ip}" )
telnetip=( "${ip}" )
# If game config does have an IP set.
elif [ -n "${configip}" ] && [ "${configip}" != "0.0.0.0" ]; then
queryips=("${configip}")
elif fn_is_valid_ip "${configip}";then
queryips=( "${configip}" )
ip="${configip}"
webadminip=("${configip}")
telnetip=("${configip}")
# If there is only 1 server IP address.
# Some IP details can automaticly use the one IP
elif [ "${getipwc}" == "1" ]; then
queryips=($(echo "${getip}"))
elif [ "${#current_ips[@]}" == "1" ]; then
queryips=( "127.0.0.1" "${current_ips[@]}" )
ip="0.0.0.0"
webadminip=("${getip}")
telnetip=("${getip}")
webadminip=("${current_ips[@]}")
telnetip=("${current_ips[@]}")
# If no ip is set by the user and server has more than one IP.
else
queryips=($(echo "${getip}"))
queryips=( "127.0.0.1" "${current_ips[@]}" )
ip="0.0.0.0"
webadminip=("${ip}")
telnetip=("${ip}")
Expand Down
Loading

0 comments on commit 242d0a4

Please sign in to comment.