check_ip.sh 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. # LinuxGSM check_ip.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://linuxgsm.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. info_parms.sh
  19. # IP is not set to specific IP
  20. if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
  21. fn_print_dots "Check IP"
  22. sleep 0.5
  23. # Multiple interfaces
  24. if [ "${getipwc}" -ge "2" ]; then
  25. fn_print_fail "Check IP: Multiple IP addresses found."
  26. sleep 0.5
  27. echo -en "\n"
  28. # IP is set within game config
  29. if [ "${ipsetinconfig}" == "1" ]; then
  30. fn_print_information "Specify the IP you want to bind within ${servercfg}.\n"
  31. echo -en " * location: ${servercfgfullpath}\n"
  32. echo -en "\n"
  33. echo -en "Set ${ipinconfigvar} to one of the following:\n"
  34. fn_script_log_fatal "Multiple IP addresses found."
  35. fn_script_log_fatal "Specify the IP you want to bind within: ${servercfgfullpath}."
  36. # IP is set within LinuxGSM config
  37. else
  38. fn_print_information_nl "Specify the IP you want to bind within a LinuxGSM config file.\n"
  39. echo -en " * location: ${configdirserver}\n"
  40. echo -en "\n"
  41. echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
  42. fn_script_log_fatal "Multiple IP addresses found."
  43. if [ "${legacymode}" == "1" ]; then
  44. fn_script_log_fatal "Specify the IP you want to bind within the ${selfname} script."
  45. else
  46. fn_script_log_fatal "Specify the IP you want to bind within: ${configdirserver}."
  47. fi
  48. fi
  49. echo -en "${getip}\n"
  50. echo -en "\n"
  51. echo -en "https://linuxgsm.com/network-interfaces\n"
  52. echo -en ""
  53. fn_script_log_fatal "https://linuxgsm.com/network-interfaces\n"
  54. core_exit.sh
  55. # Single interface
  56. elif [ "${ipsetinconfig}" == "1" ]; then
  57. fn_print_fail "Check IP: IP address not set in game config."
  58. sleep 0.5
  59. echo -en "\n"
  60. fn_print_information "Specify the IP you want to bind within ${servercfg}.\n"
  61. echo -en " * location: ${servercfgfullpath}\n"
  62. echo -en "\n"
  63. echo -en "Set ${ipinconfigvar} to the following:\n"
  64. echo -en "${getip}\n"
  65. echo -en "\n"
  66. echo -en "https://linuxgsm.com/network-interfaces\n"
  67. echo -en ""
  68. fn_script_log_fatal "IP address not set in game config."
  69. fn_script_log_fatal "Specify the IP you want to bind within: ${servercfgfullpath}."
  70. fn_script_log_fatal "https://linuxgsm.com/network-interfaces\n"
  71. core_exit.sh
  72. else
  73. fn_print_info_nl "Check IP: ${getip}"
  74. fn_script_log_info "IP automatically set as: ${getip}"
  75. sleep 0.5
  76. ip="${getip}"
  77. fi
  78. fi
  79. fi