check_ip.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 commandname="CHECK"
  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_dots ""
  20. sleep 0.5
  21. fn_print_fail "Multiple active network interfaces found.\n\n"
  22. fn_print_infomation "Specify the IP you want to use within the ${selfname} script.\n"
  23. echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
  24. echo -en "${getip}\n"
  25. echo -en ""
  26. echo -en "https://gameservermanagers.com/network-interfaces\n"
  27. echo -en ""
  28. fn_script_log_fatal "Multiple active network interfaces found."
  29. fn_script_log_fatal "Manually specify the IP you want to use within the ${selfname} script."
  30. fn_script_log_fatal "https://gameservermanagers.com/network-interfaces\n"
  31. core_exit.sh
  32. else
  33. ip=${getip}
  34. fi
  35. fi
  36. fi