update_mta.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/bin/bash
  2. # LGSM update_mta.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: Handles updating of Multi Theft Auto servers.
  6. local commandname="UPDATE"
  7. local commandaction="Update"
  8. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  9. fn_update_mta_dl(){
  10. fn_fetch_file "http://linux.mtasa.com/dl/${NUM_VERSION}/multitheftauto_linux_x64-${FUL_VERSION}.tar.gz" "${tmpdir}" "multitheftauto_linux_x64-${FUL_VERSION}.tar.gz"
  11. mkdir "${tmpdir}/multitheftauto_linux_x64-${FUL_VERSION}"
  12. fn_dl_extract "${tmpdir}" "multitheftauto_linux_x64-${FUL_VERSION}.tar.gz" "${tmpdir}/multitheftauto_linux_x64-${FUL_VERSION}"
  13. echo -e "copying to ${filesdir}...\c"
  14. fn_script_log "Copying to ${filesdir}"
  15. cp -R "${tmpdir}/multitheftauto_linux_x64-${FUL_VERSION}/multitheftauto_linux_x64-${FUL_VERSION}"* "${filesdir}"
  16. local exitcode=$?
  17. if [ "${exitcode}" == "0" ]; then
  18. fn_print_ok_eol_nl
  19. else
  20. fn_print_fail_eol_nl
  21. fi
  22. }
  23. fn_update_mta_currentbuild(){
  24. # Gets current build info
  25. # Checks if current build info is available. If it fails, then a server restart will be forced to generate logs.
  26. if [ ! -f "${consolelogdir}/${servicename}-console.log" ]; then
  27. fn_print_error "Checking for update: linux.mtasa.com"
  28. sleep 1
  29. fn_print_error_nl "Checking for update: linux.mtasa.com: No logs with server version found"
  30. fn_script_log_error "Checking for update: linux.mtasa.com: No logs with server version found"
  31. sleep 1
  32. fn_print_info_nl "Checking for update: linux.mtasa.com: Forcing server restart"
  33. fn_script_log_info "Checking for update: linux.mtasa.com: Forcing server restart"
  34. sleep 1
  35. exitbypass=1
  36. command_stop.sh
  37. exitbypass=1
  38. command_start.sh
  39. sleep 1
  40. # Check again and exit on failure.
  41. if [ ! -f "${consolelogdir}/${servicename}-console.log" ]; then
  42. fn_print_fail_nl "Checking for update: linux.mtasa.com: Still No logs with server version found"
  43. fn_script_log_fatal "Checking for update: linux.mtasa.com: Still No logs with server version found"
  44. core_exit.sh
  45. fi
  46. fi
  47. # Get current build from logs
  48. currentbuild=$(awk -F"= Multi Theft Auto: San Andreas v" '{print $2}' "${consolelogdir}"/"${servicename}"-console.log | awk '{print $1}')
  49. if [ -z "${currentbuild}" ]; then
  50. fn_print_error_nl "Checking for update: linux.mtasa.com: Current build version not found"
  51. fn_script_log_error "Checking for update: linux.mtasa.com: Current build version not found"
  52. sleep 1
  53. fn_print_info_nl "Checking for update: linux.mtasa.com: Forcing server restart"
  54. fn_script_log_info "Checking for update: linux.mtasa.com: Forcing server restart"
  55. exitbypass=1
  56. command_stop.sh
  57. exitbypass=1
  58. command_start.sh
  59. currentbuild=$(awk -F"= Multi Theft Auto: San Andreas v" '{print $2}' "${consolelogdir}"/"${servicename}"-console.log | awk '{print $1}')
  60. if [ -z "${currentbuild}" ]; then
  61. fn_print_fail_nl "Checking for update: linux.mtasa.com: Current build version still not found"
  62. fn_script_log_fatal "Checking for update: linux.mtasa.com: Current build version still not found"
  63. core_exit.sh
  64. fi
  65. fi
  66. }
  67. fn_mta_getServerVersion()
  68. {
  69. fn_fetch_file "https://raw.githubusercontent.com/multitheftauto/mtasa-blue/master/Server/version.h" "${tmpdir}" "version.h" # we need to find latest stable version here
  70. local MAJOR_VERSION="$(cat ${tmpdir}/version.h | grep "#define MTASA_VERSION_MAJOR" | awk '{ print $3 }' | sed 's/\r//g')"
  71. local MINOR_VERSION="$(cat ${tmpdir}/version.h | grep "#define MTASA_VERSION_MINOR" | awk '{ print $3 }' | sed 's/\r//g')"
  72. local MAINTENANCE_VERSION="$(cat ${tmpdir}/version.h | grep "#define MTASA_VERSION_MAINTENANCE" | awk '{ print $3 }' | sed 's/\r//g')"
  73. NUM_VERSION="${MAJOR_VERSION}${MINOR_VERSION}${MAINTENANCE_VERSION}"
  74. FUL_VERSION="${MAJOR_VERSION}.${MINOR_VERSION}.${MAINTENANCE_VERSION}"
  75. rm -f "${tmpdir}/version.h"
  76. }
  77. fn_update_mta_compare(){
  78. # Removes dots so if can compare version numbers
  79. currentbuilddigit=$(echo "${currentbuild}"|tr -cd '[:digit:]')
  80. if [ "${currentbuilddigit}" -ne "${NUM_VERSION}" ]; then
  81. echo -e "\n"
  82. echo -e "Update available:"
  83. sleep 1
  84. echo -e " Current build: ${red}${currentbuild} ${default}"
  85. echo -e " Available build: ${green}${FULL_VERSION} ${default}"
  86. echo -e ""
  87. sleep 1
  88. echo ""
  89. echo -en "Applying update.\r"
  90. sleep 1
  91. echo -en "Applying update..\r"
  92. sleep 1
  93. echo -en "Applying update...\r"
  94. sleep 1
  95. echo -en "\n"
  96. fn_script_log "Update available"
  97. fn_script_log "Current build: ${currentbuild}"
  98. fn_script_log "Available build: ${FULL_VERSION}"
  99. fn_script_log "${currentbuild} > ${FULL_VERSION}"
  100. unset updateonstart
  101. check_status.sh
  102. if [ "${status}" == "0" ]; then
  103. fn_update_mta_dl
  104. exitbypass=1
  105. command_start.sh
  106. exitbypass=1
  107. command_stop.sh
  108. else
  109. exitbypass=1
  110. command_stop.sh
  111. fn_update_mta_dl
  112. exitbypass=1
  113. command_start.sh
  114. fi
  115. alert="update"
  116. alert.sh
  117. else
  118. echo -e "\n"
  119. echo -e "No update available:"
  120. echo -e " Current version: ${green}${currentbuild}${default}"
  121. echo -e " Available version: ${green}${FULL_VERSION}${default}"
  122. echo -e ""
  123. fn_print_ok_nl "No update available"
  124. fn_script_log_info "Current build: ${currentbuild}"
  125. fn_script_log_info "Available build: ${FULL_VERSION}"
  126. fi
  127. }
  128. if [ "${installer}" == "1" ]; then
  129. fn_mta_getServerVersion
  130. fn_update_mta_dl
  131. else
  132. # Checks for server update from linux.mtasa.com using the github repo.
  133. fn_print_dots "Checking for update: linux.mtasa.com"
  134. fn_script_log_info "Checking for update: linux.mtasa.com"
  135. sleep 1
  136. fn_update_mta_currentbuild
  137. fn_mta_getServerVersion
  138. fn_update_mta_compare
  139. fi