check_ip.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. # LGSM check_ip.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: Automatically identifies the server interface IP.
  6. # If multiple interfaces are detected the user will need to manualy set using ip="0.0.0.0".
  7. local modulename="Checking"
  8. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  9. if [ "${gamename}" != "Teamspeak 3" ]; then
  10. if [ ! -f "/bin/ip" ]; then
  11. ipcommand="/sbin/ip"
  12. else
  13. ipcommand="ip"
  14. fi
  15. getip=$(${ipcommand} -o -4 addr|awk '{print $4}'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0)
  16. getipwc=$(${ipcommand} -o -4 addr|awk '{print $4}'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -vc 127.0.0)
  17. if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
  18. if [ "${getipwc}" -ge "2" ]; then
  19. fn_print_fail "Multiple active network interfaces found.\n\n"
  20. echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
  21. echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
  22. echo -en "${getip}\n"
  23. echo -en ""
  24. echo -en "https://gameservermanagers.com/network-interfaces\n"
  25. echo -en ""
  26. fn_script_log_fatal "Multiple active network interfaces found."
  27. fn_script_log_fatal "Manually specify the IP you want to use within the ${selfname} script."
  28. fn_script_log_fatal "https://gameservermanagers.com/network-interfaces\n"
  29. core_exit.sh
  30. else
  31. ip=${getip}
  32. fi
  33. fi
  34. fi