update_jediknight2.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #!/bin/bash
  2. # LinuxGSM update_jk2.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://linuxgsm.com
  5. # Description: Handles updating of jk2 servers.
  6. local commandname="UPDATE"
  7. local commandaction="Update"
  8. local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  9. fn_update_jk2_dl(){
  10. fn_fetch_file "https://github.com/mvdevs/jk2mv/releases/download/${remotebuild}/jk2mv-v${remotebuild}-dedicated.zip" "" "" "" "${tmpdir}" "jk2mv-${remotebuild}-dedicated.zip" "" "norun" "noforce" "nomd5"
  11. fn_dl_extract "${tmpdir}" "jk2mv-${remotebuild}-dedicated.zip" "${tmpdir}/jk2mv-v${remotebuild}-dedicated"
  12. echo -e "copying to ${serverfiles}...\c"
  13. cp -R "${tmpdir}/jk2mv-v${remotebuild}-dedicated/linux-amd64/jk2mvded"* "${serverfiles}/GameData"
  14. local exitcode=$?
  15. if [ "${exitcode}" == "0" ]; then
  16. fn_print_ok_eol_nl
  17. fn_script_log_pass "Copying to ${serverfiles}"
  18. fn_clear_tmp
  19. else
  20. fn_print_fail_eol_nl
  21. fn_script_log_fatal "Copying to ${serverfiles}"
  22. core_exit.sh
  23. fi
  24. }
  25. fn_update_jk2_localbuild(){
  26. # Gets local build info.
  27. fn_print_dots "Checking local build: ${remotelocation}"
  28. # Uses log file to gather info.
  29. # Log is generated and cleared on startup but filled on shutdown.
  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. exitbypass=1
  113. command_start.sh
  114. exitbypass=1
  115. command_stop.sh
  116. fn_firstcommand_reset
  117. # If server started.
  118. else
  119. fn_print_restart_warning
  120. exitbypass=1
  121. command_stop.sh
  122. fn_firstcommand_reset
  123. exitbypass=1
  124. fn_update_jk2_dl
  125. exitbypass=1
  126. command_start.sh
  127. fn_firstcommand_reset
  128. fi
  129. date +%s > "${lockdir}/lastupdate.lock"
  130. alert="update"
  131. alert.sh
  132. else
  133. fn_print_ok_nl "Checking for update: ${remotelocation}"
  134. echo -en "\n"
  135. echo -e "No update available"
  136. echo -e "* Local build: ${green}${localbuild} ${jk2arch}${default}"
  137. echo -e "* Remote build: ${green}${remotebuild} ${jk2arch}${default}"
  138. echo -en "\n"
  139. fn_script_log_info "No update available"
  140. fn_script_log_info "Local build: ${localbuild} ${jk2arch}"
  141. fn_script_log_info "Remote build: ${remotebuild} ${jk2arch}"
  142. fi
  143. }
  144. # The location where the builds are checked and downloaded.
  145. remotelocation="jk2mv.org"
  146. # Game server architecture.
  147. jk2arch="x64"
  148. if [ "${firstcommandname}" == "INSTALL" ]; then
  149. fn_update_jk2_remotebuild
  150. fn_update_jk2_dl
  151. else
  152. update_steamcmd.sh
  153. fn_print_dots "Checking for update"
  154. fn_print_dots "Checking for update: ${remotelocation}"
  155. fn_script_log_info "Checking for update: ${remotelocation}"
  156. fn_update_jk2_localbuild
  157. fn_update_jk2_remotebuild
  158. fn_update_jk2_compare
  159. fi