check_ip.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. # LinuxGSM 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 LinuxGSM config file."
  31. echo -en "Location: ${configdir}\n"
  32. echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
  33. fi
  34. echo -en "${getip}\n"
  35. echo -en ""
  36. echo -en "https://gameservermanagers.com/network-interfaces\n"
  37. echo -en ""
  38. fn_script_log_fatal "Multiple active network interfaces found."
  39. fn_script_log_fatal "Manually specify the IP you want to use within the ${selfname} script."
  40. fn_script_log_fatal "https://gameservermanagers.com/network-interfaces\n"
  41. core_exit.sh
  42. else
  43. ip=${getip}
  44. fi
  45. fi
  46. fi