update_jediknight2.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 Jedi Knight 2 servers.
  7. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. fn_update_dl() {
  9. # Download and extract files to serverfiles.
  10. fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "nohash"
  11. fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}/GameData" "linux-amd64"
  12. fn_clear_tmp
  13. }
  14. fn_update_localbuild() {
  15. # Gets local build info.
  16. fn_print_dots "Checking local build: ${remotelocation}"
  17. # Uses log file to get local build.
  18. localbuild=$(grep "\"version\"" "${consolelogdir}"/* 2> /dev/null | sed 's/.*://' | awk '{print $1}' | head -n 1 | sed 's/v//')
  19. if [ -z "${localbuild}" ]; then
  20. fn_print_error "Checking local build: ${remotelocation}: missing local build info"
  21. fn_script_log_error "Missing local build info"
  22. fn_script_log_error "Set localbuild to 0"
  23. localbuild="0"
  24. else
  25. fn_print_ok "Checking local build: ${remotelocation}"
  26. fn_script_log_pass "Checking local build"
  27. fi
  28. }
  29. fn_update_remotebuild() {
  30. # Get remote build info.
  31. apiurl="https://api.github.com/repos/mvdevs/jk2mv/releases/latest"
  32. remotebuildresponse=$(curl -s "${apiurl}")
  33. remotebuildfilename=$(echo "${remotebuildresponse}" | jq -r '.assets[]|select(.browser_download_url | contains("dedicated.zip")) | .name')
  34. remotebuildurl=$(echo "${remotebuildresponse}" | jq -r '.assets[]|select(.browser_download_url | contains("dedicated.zip")) | .browser_download_url')
  35. remotebuildversion=$(echo "${remotebuildresponse}" | jq -r '.tag_name')
  36. if [ "${firstcommandname}" != "INSTALL" ]; then
  37. fn_print_dots "Checking remote build: ${remotelocation}"
  38. # Checks if remotebuildversion variable has been set.
  39. if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
  40. fn_print_fail "Checking remote build: ${remotelocation}"
  41. fn_script_log_fatal "Checking remote build"
  42. core_exit.sh
  43. else
  44. fn_print_ok "Checking remote build: ${remotelocation}"
  45. fn_script_log_pass "Checking remote build"
  46. fi
  47. else
  48. # Checks if remotebuild variable has been set.
  49. if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
  50. fn_print_failure "Unable to get remote build"
  51. fn_script_log_fatal "Unable to get remote build"
  52. core_exit.sh
  53. fi
  54. fi
  55. }
  56. fn_update_compare() {
  57. fn_print_dots "Checking for update: ${remotelocation}"
  58. if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then
  59. fn_print_ok_nl "Checking for update: ${remotelocation}"
  60. echo -en "\n"
  61. echo -e "Update available"
  62. echo -e "* Local build: ${red}${localbuild}${default}"
  63. echo -e "* Remote build: ${green}${remotebuildversion}${default}"
  64. if [ -n "${branch}" ]; then
  65. echo -e "* Branch: ${branch}"
  66. fi
  67. if [ -f "${rootdir}/.dev-debug" ]; then
  68. echo -e "Remote build info"
  69. echo -e "* apiurl: ${apiurl}"
  70. echo -e "* remotebuildfilename: ${remotebuildfilename}"
  71. echo -e "* remotebuildurl: ${remotebuildurl}"
  72. echo -e "* remotebuildversion: ${remotebuildversion}"
  73. fi
  74. echo -en "\n"
  75. fn_script_log_info "Update available"
  76. fn_script_log_info "Local build: ${localbuild}"
  77. fn_script_log_info "Remote build: ${remotebuildversion}"
  78. if [ -n "${branch}" ]; then
  79. fn_script_log_info "Branch: ${branch}"
  80. fi
  81. fn_script_log_info "${localbuild} > ${remotebuildversion}"
  82. if [ "${commandname}" == "UPDATE" ]; then
  83. unset updateonstart
  84. check_status.sh
  85. # If server stopped.
  86. if [ "${status}" == "0" ]; then
  87. fn_update_dl
  88. if [ "${localbuild}" == "0" ]; then
  89. exitbypass=1
  90. command_start.sh
  91. fn_firstcommand_reset
  92. exitbypass=1
  93. sleep 5
  94. command_stop.sh
  95. fn_firstcommand_reset
  96. fi
  97. # If server started.
  98. else
  99. fn_print_restart_warning
  100. exitbypass=1
  101. command_stop.sh
  102. fn_firstcommand_reset
  103. exitbypass=1
  104. fn_update_dl
  105. exitbypass=1
  106. command_start.sh
  107. fn_firstcommand_reset
  108. fi
  109. unset exitbypass
  110. date +%s > "${lockdir}/lastupdate.lock"
  111. alert="update"
  112. elif [ "${commandname}" == "CHECK-UPDATE" ]; then
  113. alert="check-update"
  114. fi
  115. alert.sh
  116. else
  117. fn_print_ok_nl "Checking for update: ${remotelocation}"
  118. echo -en "\n"
  119. echo -e "No update available"
  120. echo -e "* Local build: ${green}${localbuild}${default}"
  121. echo -e "* Remote build: ${green}${remotebuildversion}${default}"
  122. if [ -n "${branch}" ]; then
  123. echo -e "* Branch: ${branch}"
  124. fi
  125. echo -en "\n"
  126. fn_script_log_info "No update available"
  127. fn_script_log_info "Local build: ${localbuild}"
  128. fn_script_log_info "Remote build: ${remotebuildversion}"
  129. if [ -n "${branch}" ]; then
  130. fn_script_log_info "Branch: ${branch}"
  131. fi
  132. if [ -f "${rootdir}/.dev-debug" ]; then
  133. echo -e "Remote build info"
  134. echo -e "* apiurl: ${apiurl}"
  135. echo -e "* remotebuildfilename: ${remotebuildfilename}"
  136. echo -e "* remotebuildurl: ${remotebuildurl}"
  137. echo -e "* remotebuildversion: ${remotebuildversion}"
  138. fi
  139. fi
  140. }
  141. # The location where the builds are checked and downloaded.
  142. remotelocation="github.com"
  143. if [ "${firstcommandname}" == "INSTALL" ]; then
  144. fn_update_remotebuild
  145. fn_update_dl
  146. else
  147. update_steamcmd.sh
  148. fn_print_dots "Checking for update"
  149. fn_print_dots "Checking for update: ${remotelocation}"
  150. fn_script_log_info "Checking for update: ${remotelocation}"
  151. fn_update_localbuild
  152. fn_update_remotebuild
  153. fn_update_compare
  154. fi