check_ip.sh 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. if [ "${shortname}" != "ts3" ]&&[ "${shortname}" != "mumble" ]&&[ "${travistest}" != "1" ]; then
  9. if [ ! -f "/bin/ip" ]; then
  10. ipcommand="/sbin/ip"
  11. else
  12. ipcommand="ip"
  13. fi
  14. getip=$(${ipcommand} -o -4 addr | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|sort -u|grep -v 127.0.0)
  15. getipwc=$(${ipcommand} -o -4 addr | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|sort -u|grep -vc 127.0.0)
  16. info_config.sh
  17. info_parms.sh
  18. # IP is not set to specific IP
  19. if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
  20. fn_print_dots "Check IP"
  21. sleep 0.2
  22. # Multiple interfaces
  23. if [ "${getipwc}" -ge "2" ]; then
  24. if [ "${function_selfname}" == "command_details.sh" ]; then
  25. fn_print_warn "Check IP: Multiple IP addresses found."
  26. else
  27. fn_print_fail "Check IP: Multiple IP addresses found."
  28. fi
  29. sleep 0.2
  30. echo -en "\n"
  31. # IP is set within game config
  32. if [ "${ipsetinconfig}" == "1" ]; then
  33. fn_print_information "Specify the IP you want to bind within ${servercfg}.\n"
  34. echo -en " * location: ${servercfgfullpath}\n"
  35. echo -en "\n"
  36. echo -en "Set ${ipinconfigvar} to one of the following:\n"
  37. fn_script_log_fatal "Multiple IP addresses found."
  38. fn_script_log_fatal "Specify the IP you want to bind within: ${servercfgfullpath}."
  39. # IP is set within LinuxGSM config
  40. else
  41. fn_print_information_nl "Specify the IP you want to bind within a LinuxGSM config file.\n"
  42. echo -en " * location: ${configdirserver}\n"
  43. echo -en "\n"
  44. echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
  45. fn_script_log_fatal "Multiple IP addresses found."
  46. if [ "${legacymode}" == "1" ]; then
  47. fn_script_log_fatal "Specify the IP you want to bind within the ${selfname} script."
  48. else
  49. fn_script_log_fatal "Specify the IP you want to bind within: ${configdirserver}."
  50. fi
  51. fi
  52. echo -en "${getip}\n"
  53. echo -en "\n"
  54. echo -en "https://linuxgsm.com/network-interfaces\n"
  55. echo -en ""
  56. # Do not exit for details and postdetails commands
  57. if [ "${function_selfname}" != "command_details.sh" ]||[ "${function_selfname}" != "command_postdetails.sh" ]; then
  58. fn_script_log_fatal "https://linuxgsm.com/network-interfaces\n"
  59. core_exit.sh
  60. else
  61. ip="NOT SET"
  62. fi
  63. # Single interface
  64. elif [ "${ipsetinconfig}" == "1" ]; then
  65. fn_print_fail "Check IP: IP address not set in game config."
  66. sleep 0.5
  67. echo -en "\n"
  68. fn_print_information "Specify the IP you want to bind within ${servercfg}.\n"
  69. echo -en " * location: ${servercfgfullpath}\n"
  70. echo -en "\n"
  71. echo -en "Set ${ipinconfigvar} to the following:\n"
  72. echo -en "${getip}\n"
  73. echo -en "\n"
  74. echo -en "https://linuxgsm.com/network-interfaces\n"
  75. echo -en ""
  76. fn_script_log_fatal "IP address not set in game config."
  77. fn_script_log_fatal "Specify the IP you want to bind within: ${servercfgfullpath}."
  78. fn_script_log_fatal "https://linuxgsm.com/network-interfaces\n"
  79. if [ "${function_selfname}" != "command_details.sh" ];then
  80. core_exit.sh
  81. fi
  82. else
  83. fn_print_info_nl "Check IP: ${getip}"
  84. fn_script_log_info "IP automatically set as: ${getip}"
  85. sleep 0.2
  86. ip="${getip}"
  87. fi
  88. fi
  89. fi