check_ip.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 manually 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" ]&&[ "${gamename}" != "Mumble" ]&&[ "${travistest}" != "1" ]; 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. info_config.sh
  18. if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
  19. if [ "${getipwc}" -ge "2" ]; then
  20. fn_print_dots "Check IP"
  21. sleep 1
  22. fn_print_fail "Check IP: Multiple active network interfaces found."
  23. sleep 1
  24. echo -en "\n"
  25. if [ "${ipsetinconfig}" == "1" ]; then
  26. fn_print_information "Specify the IP you want to use within the server config file ${servercfg}.\n"
  27. echo -en "${servercfgfullpath}\n"
  28. echo -en "Set ${ipinconfigvar} to one of the following:\n"
  29. else
  30. fn_print_information "Specify the IP you want to use within the ${selfname} script.\n"
  31. echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
  32. fi
  33. echo -en "${getip}\n"
  34. echo -en ""
  35. echo -en "https://gameservermanagers.com/network-interfaces\n"
  36. echo -en ""
  37. fn_script_log_fatal "Multiple active network interfaces found."
  38. fn_script_log_fatal "Manually specify the IP you want to use within the ${selfname} script."
  39. fn_script_log_fatal "https://gameservermanagers.com/network-interfaces\n"
  40. core_exit.sh
  41. else
  42. ip=${getip}
  43. fi
  44. fi
  45. fi