command_debug.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/bin/bash
  2. # LinuxGSM command_debug.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Runs the server without tmux and directly from the terminal.
  7. commandname="DEBUG"
  8. commandaction="Debuging"
  9. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  10. fn_firstcommand_set
  11. # Trap to remove lockfile on quit.
  12. fn_lockfile_trap() {
  13. # Remove lockfile.
  14. rm -f "${lockdir:?}/${selfname}-started.lock"
  15. # resets terminal. Servers can sometimes mess up the terminal on exit.
  16. reset
  17. fn_print_dots "Stopping debug"
  18. fn_print_ok_nl "Stopping debug"
  19. fn_script_log_pass "Stopping debug"
  20. # remove trap.
  21. trap - INT
  22. core_exit.sh
  23. }
  24. check.sh
  25. fix.sh
  26. info_distro.sh
  27. info_game.sh
  28. fn_print_header
  29. {
  30. echo -e "${lightblue}Distro:\t\t${default}${distroname}"
  31. echo -e "${lightblue}Architecture:\t\t${default}${arch}"
  32. echo -e "${lightblue}Kernel:\t\t${default}${kernel}"
  33. echo -e "${lightblue}Hostname:\t\t${default}${HOSTNAME}"
  34. echo -e "${lightblue}tmux:\t\t${default}${tmuxversion}"
  35. echo -e "${lightblue}Avg Load:\t\t${default}${load}"
  36. echo -e "${lightblue}Free Memory:\t\t${default}${physmemfree}"
  37. echo -e "${lightblue}Free Disk:\t\t${default}${availspace}"
  38. } | column -s $'\t' -t
  39. # glibc required.
  40. if [ -n "${glibc}" ]; then
  41. if [ "${glibc}" == "null" ]; then
  42. # Glibc is not required.
  43. :
  44. elif [ -z "${glibc}" ]; then
  45. echo -e "${lightblue}glibc required:\t${red}UNKNOWN${default}"
  46. elif [ "$(printf '%s\n'${glibc}'\n' ${glibcversion} | sort -V | head -n 1)" != "${glibc}" ]; then
  47. echo -e "${lightblue}glibc required:\t${red}${glibc} ${default}(${red}distro glibc ${glibcversion} too old${default})"
  48. else
  49. echo -e "${lightblue}glibc required:\t${green}${glibc}${default}"
  50. fi
  51. fi
  52. # Server IP.
  53. echo -e "${lightblue}Game Server IP:\t${default}${ip}:${port}"
  54. # External server IP.
  55. if [ "${publicip}" ]; then
  56. if [ "${ip}" != "${publicip}" ]; then
  57. echo -e "${lightblue}Internet IP:\t${default}${publicip}:${port}"
  58. fi
  59. fi
  60. # Server password.
  61. if [ "${serverpassword}" ]; then
  62. echo -e "${lightblue}Server password:\t${default}${serverpassword}"
  63. fi
  64. fn_reload_startparameters
  65. echo -e "${lightblue}Start parameters:${default}"
  66. if [ "${engine}" == "source" ] || [ "${engine}" == "goldsrc" ]; then
  67. echo -e "${executable} ${startparameters} -debug"
  68. elif [ "${engine}" == "quake" ]; then
  69. echo -e "${executable} ${startparameters} -condebug"
  70. else
  71. echo -e "${preexecutable} ${executable} ${startparameters}"
  72. fi
  73. echo -e ""
  74. echo -e "Use debug for identifying server issues only!"
  75. echo -e "Press CTRL+c to drop out of debug mode."
  76. fn_print_warning_nl "If ${selfname} is already running it will be stopped."
  77. if ! fn_prompt_yn "Continue?" Y; then
  78. exitcode=0
  79. core_exit.sh
  80. fi
  81. fn_print_info_nl "Stopping any running servers"
  82. fn_script_log_info "Stopping any running servers"
  83. exitbypass=1
  84. command_stop.sh
  85. fn_firstcommand_reset
  86. unset exitbypass
  87. fn_print_dots "Starting debug"
  88. fn_script_log_info "Starting debug"
  89. fn_print_ok_nl "Starting debug"
  90. # Create started lockfile.
  91. date '+%s' > "${lockdir:?}/${selfname}-started.lock"
  92. echo "${version}" >> "${lockdir}/${selfname}-started.lock"
  93. echo "${port}" >> "${lockdir}/${selfname}-started.lock"
  94. fn_script_log_info "Lockfile generated"
  95. fn_script_log_info "${lockdir}/${selfname}-started.lock"
  96. if [ "${shortname}" == "av" ]; then
  97. cd "${systemdir}" || exit
  98. else
  99. cd "${executabledir}" || exit
  100. fi
  101. # Note: do not add double quotes to ${executable} ${startparameters}.
  102. if [ "${engine}" == "source" ] || [ "${engine}" == "goldsrc" ]; then
  103. eval "${executable} ${startparameters} -debug"
  104. elif [ "${engine}" == "quake" ]; then
  105. eval "${executable} ${startparameters} -condebug"
  106. else
  107. # shellcheck disable=SC2086
  108. eval "${preexecutable} ${executable} ${startparameters}"
  109. fi
  110. if [ $? -ne 0 ]; then
  111. fn_print_error_nl "Server has stopped: exit code: $?"
  112. fn_script_log_error "Server has stopped: exit code: $?"
  113. fn_print_error_nl "Press ENTER to exit debug mode"
  114. read -r
  115. else
  116. fn_print_ok_nl "Server has stopped"
  117. fn_script_log_pass "Server has stopped"
  118. fn_print_ok_nl "Press ENTER to exit debug mode"
  119. read -r
  120. fi
  121. fn_lockfile_trap
  122. fn_print_dots "Stopping debug"
  123. fn_print_ok_nl "Stopping debug"
  124. fn_script_log_info "Stopping debug"
  125. core_exit.sh