update_jediknight2.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #!/bin/bash
  2. # LinuxGSM update_jk2.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: http://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Handles updating of jk2 servers.
  7. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. fn_update_jk2_dl(){
  9. fn_fetch_file "https://github.com/mvdevs/jk2mv/releases/download/${remotebuild}/jk2mv-v${remotebuild}-dedicated.zip" "" "" "" "${tmpdir}" "jk2mv-${remotebuild}-dedicated.zip" "" "norun" "noforce" "nohash"
  10. fn_dl_extract "${tmpdir}" "jk2mv-${remotebuild}-dedicated.zip" "${tmpdir}/jk2mv-v${remotebuild}-dedicated"
  11. echo -e "copying to ${serverfiles}...\c"
  12. cp -R "${tmpdir}/jk2mv-v${remotebuild}-dedicated/linux-amd64/jk2mvded"* "${serverfiles}/GameData"
  13. local exitcode=$?
  14. if [ "${exitcode}" == "0" ]; then
  15. fn_print_ok_eol_nl
  16. fn_script_log_pass "Copying to ${serverfiles}"
  17. fn_clear_tmp
  18. else
  19. fn_print_fail_eol_nl
  20. fn_script_log_fatal "Copying to ${serverfiles}"
  21. core_exit.sh
  22. fi
  23. }
  24. fn_update_jk2_localbuild(){
  25. # Gets local build info.
  26. fn_print_dots "Checking local build: ${remotelocation}"
  27. # Uses log file to gather info.
  28. # Log is generated and cleared on startup but filled on shutdown.
  29. requirerestart=1
  30. localbuild=$(grep "\"version\"" "${consolelogdir}"/* 2>/dev/null | sed 's/.*://' | awk '{print $1}' | head -n 1)
  31. if [ -z "${localbuild}" ]; then
  32. fn_print_error "Checking local build: ${remotelocation}"
  33. fn_print_error_nl "Checking local build: ${remotelocation}: no log files containing version info"
  34. fn_print_info_nl "Checking local build: ${remotelocation}: forcing server restart"
  35. fn_script_log_error "No log files containing version info"
  36. fn_script_log_info "Forcing server restart"
  37. check_status.sh
  38. # If server stopped.
  39. if [ "${status}" == "0" ]; then
  40. exitbypass=1
  41. command_start.sh
  42. fn_firstcommand_reset
  43. sleep 3
  44. exitbypass=1
  45. command_stop.sh
  46. fn_firstcommand_reset
  47. # If server started.
  48. else
  49. exitbypass=1
  50. command_stop.sh
  51. fn_firstcommand_reset
  52. fi
  53. fi
  54. if [ -z "${localbuild}" ]; then
  55. localbuild=$(grep Version "$(ls -tr "${consolelogdir}"/* 2>/dev/null)" | tail -1 | sed 's/.*Version //')
  56. fi
  57. if [ -z "${localbuild}" ]; then
  58. localbuild="0"
  59. fn_print_error "Checking local build: ${remotelocation}: waiting for local build: missing local build info"
  60. fn_script_log_error "Missing local build info"
  61. fn_script_log_error "Set localbuild to 0"
  62. else
  63. fn_print_ok "Checking local build: ${remotelocation}"
  64. fn_script_log_pass "Checking local build"
  65. fi
  66. }
  67. fn_update_jk2_remotebuild(){
  68. # Gets remote build info.
  69. remotebuild=$(curl -s "https://api.github.com/repos/mvdevs/jk2mv/releases/latest" | grep dedicated.zip | tail -1 | awk -F"/" '{ print $8 }')
  70. if [ "${firstcommandname}" != "INSTALL" ]; then
  71. fn_print_dots "Checking remote build: ${remotelocation}"
  72. # Checks if remotebuild variable has been set.
  73. if [ -z "${remotebuild}" ]||[ "${remotebuild}" == "null" ]; then
  74. fn_print_fail "Checking remote build: ${remotelocation}"
  75. fn_script_log_fatal "Checking remote build"
  76. core_exit.sh
  77. else
  78. fn_print_ok "Checking remote build: ${remotelocation}"
  79. fn_script_log_pass "Checking remote build"
  80. fi
  81. else
  82. # Checks if remotebuild variable has been set.
  83. if [ -z "${remotebuild}" ]||[ "${remotebuild}" == "null" ]; then
  84. fn_print_failure "Unable to get remote build"
  85. fn_script_log_fatal "Unable to get remote build"
  86. core_exit.sh
  87. fi
  88. fi
  89. }
  90. fn_update_jk2_compare(){
  91. # Removes dots so if statement can compare version numbers.
  92. fn_print_dots "Checking for update: ${remotelocation}"
  93. localbuilddigit=$(echo -e "${localbuild}" | tr -cd '[:digit:]')
  94. remotebuilddigit=$(echo -e "${remotebuild}" | tr -cd '[:digit:]')
  95. if [ "${localbuilddigit}" -ne "${remotebuilddigit}" ]||[ "${forceupdate}" == "1" ]; then
  96. fn_print_ok_nl "Checking for update: ${remotelocation}"
  97. echo -en "\n"
  98. echo -e "Update available"
  99. echo -e "* Local build: ${red}${localbuild} ${jk2arch}${default}"
  100. echo -e "* Remote build: ${green}${remotebuild} ${jk2arch}${default}"
  101. echo -en "\n"
  102. fn_script_log_info "Update available"
  103. fn_script_log_info "Local build: ${localbuild} ${jk2arch}"
  104. fn_script_log_info "Remote build: ${remotebuild} ${jk2arch}"
  105. fn_script_log_info "${localbuild} > ${remotebuild}"
  106. unset updateonstart
  107. check_status.sh
  108. # If server stopped.
  109. if [ "${status}" == "0" ]; then
  110. exitbypass=1
  111. fn_update_jk2_dl
  112. if [ "${requirerestart}" == "1" ]; then
  113. exitbypass=1
  114. command_start.sh
  115. fn_firstcommand_reset
  116. exitbypass=1
  117. command_stop.sh
  118. fn_firstcommand_reset
  119. fi
  120. # If server started.
  121. else
  122. fn_print_restart_warning
  123. exitbypass=1
  124. command_stop.sh
  125. fn_firstcommand_reset
  126. exitbypass=1
  127. fn_update_jk2_dl
  128. exitbypass=1
  129. command_start.sh
  130. fn_firstcommand_reset
  131. fi
  132. date +%s > "${lockdir}/lastupdate.lock"
  133. alert="update"
  134. alert.sh
  135. else
  136. fn_print_ok_nl "Checking for update: ${remotelocation}"
  137. echo -en "\n"
  138. echo -e "No update available"
  139. echo -e "* Local build: ${green}${localbuild} ${jk2arch}${default}"
  140. echo -e "* Remote build: ${green}${remotebuild} ${jk2arch}${default}"
  141. echo -en "\n"
  142. fn_script_log_info "No update available"
  143. fn_script_log_info "Local build: ${localbuild} ${jk2arch}"
  144. fn_script_log_info "Remote build: ${remotebuild} ${jk2arch}"
  145. fi
  146. }
  147. # The location where the builds are checked and downloaded.
  148. remotelocation="jk2mv.org"
  149. # Game server architecture.
  150. jk2arch="x64"
  151. if [ "${firstcommandname}" == "INSTALL" ]; then
  152. fn_update_jk2_remotebuild
  153. fn_update_jk2_dl
  154. else
  155. update_steamcmd.sh
  156. fn_print_dots "Checking for update"
  157. fn_print_dots "Checking for update: ${remotelocation}"
  158. fn_script_log_info "Checking for update: ${remotelocation}"
  159. fn_update_jk2_localbuild
  160. fn_update_jk2_remotebuild
  161. fn_update_jk2_compare
  162. fi