update_steamcmd.sh 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #!/bin/bash
  2. # LinuxGSM update_steamcmd.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://linuxgsm.com
  5. # Description: Handles updating using SteamCMD.
  6. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  7. fn_update_steamcmd_localbuild(){
  8. # Gets local build info.
  9. fn_print_dots "Checking local build: ${remotelocation}"
  10. fn_appmanifest_check
  11. # Uses appmanifest to find local build.
  12. localbuild=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\ -f3)
  13. # Set branch for updateinfo.
  14. IFS=' ' read -ra branchsplits <<< "${branch}"
  15. if [ "${#branchsplits[@]}" -gt 1 ]; then
  16. branchname="${branchsplits[1]}"
  17. else
  18. branchname="public"
  19. fi
  20. # Checks if localbuild variable has been set.
  21. if [ -z "${localbuild}" ]||[ "${localbuild}" == "null" ]; then
  22. fn_print_fail "Checking local build: ${remotelocation}"
  23. fn_script_log_fatal "Checking local build"
  24. core_exit.sh
  25. else
  26. fn_print_ok "Checking local build: ${remotelocation}"
  27. fn_script_log_pass "Checking local build"
  28. fi
  29. }
  30. fn_update_steamcmd_remotebuild(){
  31. # Gets remote build info.
  32. if [ -d "${steamcmddir}" ]; then
  33. cd "${steamcmddir}" || exit
  34. fi
  35. # Removes appinfo.vdf as a fix for not always getting up to date version info from SteamCMD.
  36. if [ "$(find "${HOME}" -type f -name "appinfo.vdf" | wc -l)" -ne "0" ]; then
  37. find "${HOME}" -type f -name "appinfo.vdf" -exec rm -f {} \;
  38. fi
  39. remotebuild=$(${steamcmdcommand} +login "${steamuser}" "${steampass}" +app_info_update 1 +app_info_print "${appid}" +quit | sed '1,/branches/d' | sed "1,/${branchname}/d" | grep -m 1 buildid | tr -cd '[:digit:]')
  40. if [ "${installer}" != "1" ]; then
  41. fn_print_dots "Checking remote build: ${remotelocation}"
  42. # Checks if remotebuild variable has been set.
  43. if [ -z "${remotebuild}" ]||[ "${remotebuild}" == "null" ]; then
  44. fn_print_fail "Checking remote build: ${remotelocation}"
  45. fn_script_log_fatal "Checking remote build"
  46. core_exit.sh
  47. else
  48. fn_print_ok "Checking remote build: ${remotelocation}"
  49. fn_script_log_pass "Checking remote build"
  50. fi
  51. else
  52. # Checks if remotebuild variable has been set.
  53. if [ -z "${remotebuild}" ]||[ "${remotebuild}" == "null" ]; then
  54. fn_print_failure "Unable to get remote build"
  55. fn_script_log_fatal "Unable to get remote build"
  56. core_exit.sh
  57. fi
  58. fi
  59. }
  60. fn_update_steamcmd_compare(){
  61. fn_print_dots "Checking for update: ${remotelocation}"
  62. if [ "${localbuild}" != "${remotebuild}" ]; then
  63. fn_print_ok_nl "Checking for update: ${remotelocation}"
  64. echo -en "\n"
  65. echo -e "Update available"
  66. echo -e "* Local build: ${red}${localbuild}${default}"
  67. echo -e "* Remote build: ${green}${remotebuild}${default}"
  68. if [ -v "${branch}" ]; then
  69. echo -e "* Branch: ${branch}"
  70. fi
  71. echo -e "https://steamdb.info/app/${appid}/"
  72. echo -en "\n"
  73. fn_script_log_info "Update available"
  74. fn_script_log_info "Local build: ${localbuild}"
  75. fn_script_log_info "Remote build: ${remotebuild}"
  76. if [ -v "${branch}" ]; then
  77. fn_script_log_info "Branch: ${branch}"
  78. fi
  79. fn_script_log_info "${localbuild} > ${remotebuild}"
  80. unset updateonstart
  81. check_status.sh
  82. # If server stopped.
  83. if [ "${status}" == "0" ]; then
  84. fn_dl_steamcmd
  85. # If server started.
  86. else
  87. fn_print_restart_warning
  88. exitbypass=1
  89. command_stop.sh
  90. fn_commandname
  91. exitbypass=1
  92. fn_dl_steamcmd
  93. exitbypass=1
  94. command_start.sh
  95. fn_commandname
  96. fi
  97. date +%s > "${lockdir}/lastupdate.lock"
  98. alert="update"
  99. alert.sh
  100. else
  101. fn_print_ok_nl "Checking for update: ${remotelocation}"
  102. echo -en "\n"
  103. echo -e "No update available"
  104. echo -e "* Local build: ${green}${localbuild}${default}"
  105. echo -e "* Remote build: ${green}${remotebuild}${default}"
  106. if [ -v "${branch}" ]; then
  107. echo -e "* Branch: ${branch}"
  108. fi
  109. echo -e "https://steamdb.info/app/${appid}/"
  110. echo -en "\n"
  111. fn_script_log_info "No update available"
  112. fn_script_log_info "Local build: ${localbuild}"
  113. fn_script_log_info "Remote build: ${remotebuild}"
  114. if [ -v "${branch}" ]; then
  115. fn_script_log_info "Branch: ${branch}"
  116. fi
  117. fi
  118. }
  119. fn_appmanifest_info(){
  120. appmanifestfile=$(find "${serverfiles}" -type f -name "appmanifest_${appid}.acf")
  121. appmanifestfilewc=$(find "${serverfiles}" -type f -name "appmanifest_${appid}.acf" | wc -l)
  122. }
  123. fn_appmanifest_check(){
  124. fn_appmanifest_info
  125. # Multiple or no matching appmanifest files may sometimes be present.
  126. # This error is corrected if required.
  127. if [ "${appmanifestfilewc}" -ge "2" ]; then
  128. fn_print_error "Multiple appmanifest_${appid}.acf files found"
  129. fn_script_log_error "Multiple appmanifest_${appid}.acf files found"
  130. fn_print_dots "Removing x${appmanifestfilewc} appmanifest_${appid}.acf files"
  131. for appfile in ${appmanifestfile}; do
  132. rm -f "${appfile:?}"
  133. done
  134. appmanifestfilewc1="${appmanifestfilewc}"
  135. fn_appmanifest_info
  136. # if error can not be resolved.
  137. if [ "${appmanifestfilewc}" -ge "2" ]; then
  138. fn_print_fail "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  139. fn_script_log_fatal "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  140. echo -e "* Check user permissions"
  141. for appfile in ${appmanifestfile}; do
  142. echo -e " ${appfile}"
  143. done
  144. core_exit.sh
  145. else
  146. fn_print_ok "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  147. fn_script_log_pass "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  148. fn_print_info_nl "Forcing update to correct issue"
  149. fn_script_log_info "Forcing update to correct issue"
  150. fn_dl_steamcmd
  151. fi
  152. elif [ "${appmanifestfilewc}" -eq "0" ]; then
  153. fn_print_error_nl "No appmanifest_${appid}.acf found"
  154. fn_script_log_error "No appmanifest_${appid}.acf found"
  155. fn_print_info_nl "Forcing update to correct issue"
  156. fn_script_log_info "Forcing update to correct issue"
  157. fn_dl_steamcmd
  158. fn_appmanifest_info
  159. if [ "${appmanifestfilewc}" -eq "0" ]; then
  160. fn_print_fail_nl "Still no appmanifest_${appid}.acf found"
  161. fn_script_log_fatal "Still no appmanifest_${appid}.acf found"
  162. core_exit.sh
  163. fi
  164. fi
  165. }
  166. # The location where the builds are checked and downloaded.
  167. remotelocation="SteamCMD"
  168. check.sh
  169. fn_print_dots "${remotelocation}"
  170. if [ "${forceupdate}" == "1" ]; then
  171. # forceupdate bypasses update checks.
  172. if [ "${status}" != "0" ]; then
  173. fn_print_restart_warning
  174. exitbypass=1
  175. command_stop.sh
  176. fn_commandname
  177. fn_dl_steamcmd
  178. date +%s > "${lockdir}/lastupdate.lock"
  179. exitbypass=1
  180. command_start.sh
  181. fn_commandname
  182. else
  183. fn_dl_steamcmd
  184. date +%s > "${lockdir}/lastupdate.lock"
  185. fi
  186. else
  187. fn_update_steamcmd_localbuild
  188. fn_update_steamcmd_remotebuild
  189. fn_update_steamcmd_compare
  190. fi