update_steamcmd.sh 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. local modulename="UPDATE"
  7. local commandaction="Update"
  8. local function_selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")
  9. fn_update_steamcmd_dl(){
  10. info_config.sh
  11. # Detects if unbuffer command is available for 32 bit distributions only.
  12. info_distro.sh
  13. if [ "$(command -v stdbuf)" ]&&[ "${arch}" != "x86_64" ]; then
  14. unbuffer="stdbuf -i0 -o0 -e0"
  15. fi
  16. if [ -d "${steamcmddir}" ]; then
  17. cd "${steamcmddir}" || exit
  18. fi
  19. if [ "${appid}" == "90" ]; then
  20. ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_set_config 90 mod "${appidmod}" +app_update "${appid}" -beta "${branch}" +quit | tee -a "${lgsmlog}"
  21. else
  22. ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" -beta "${branch}" +quit | tee -a "${lgsmlog}"
  23. fi
  24. fix.sh
  25. }
  26. fn_update_steamcmd_localbuild(){
  27. # Gets local build info.
  28. fn_print_dots "Checking local build: ${remotelocation}"
  29. fn_appmanifest_check
  30. # Uses appmanifest to find local build.
  31. localbuild=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\ -f3)
  32. # Removes appinfo.vdf as a fix for not always getting up to date version info from SteamCMD.
  33. if [ -f "${HOME}/Steam/appcache/appinfo.vdf" ]; then
  34. rm -f "${HOME}/Steam/appcache/appinfo.vdf"
  35. fi
  36. # Set branch for updateinfo.
  37. IFS=' ' read -ra branchsplits <<< "${branch}"
  38. if [ "${#branchsplits[@]}" -gt 1 ]; then
  39. branchname="${branchsplits[1]}"
  40. else
  41. branchname="public"
  42. fi
  43. # Checks if localbuild variable has been set.
  44. if [ -z "${localbuild}" ]||[ "${localbuild}" == "null" ]; then
  45. fn_print_fail "Checking local build: ${remotelocation}"
  46. fn_script_log_fatal "Checking local build"
  47. core_exit.sh
  48. else
  49. fn_print_ok "Checking local build: ${remotelocation}"
  50. fn_script_log_pass "Checking local build"
  51. fi
  52. }
  53. fn_update_steamcmd_remotebuild(){
  54. # Gets remote build info.
  55. if [ -d "${steamcmddir}" ]; then
  56. cd "${steamcmddir}" || exit
  57. fi
  58. 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:]')
  59. if [ "${installer}" != "1" ]; then
  60. fn_print_dots "Checking remote build: ${remotelocation}"
  61. # Checks if remotebuild variable has been set.
  62. if [ -z "${remotebuild}" ]||[ "${remotebuild}" == "null" ]; then
  63. fn_print_fail "Checking remote build: ${remotelocation}"
  64. fn_script_log_fatal "Checking remote build"
  65. core_exit.sh
  66. else
  67. fn_print_ok "Checking remote build: ${remotelocation}"
  68. fn_script_log_pass "Checking remote build"
  69. fi
  70. else
  71. # Checks if remotebuild variable has been set.
  72. if [ -z "${remotebuild}" ]||[ "${remotebuild}" == "null" ]; then
  73. fn_print_failure "Unable to get remote build"
  74. fn_script_log_fatal "Unable to get remote build"
  75. core_exit.sh
  76. fi
  77. fi
  78. }
  79. fn_update_steamcmd_compare(){
  80. fn_print_dots "Checking for update: ${remotelocation}"
  81. if [ "${localbuild}" != "${remotebuild}" ]; then
  82. fn_print_ok_nl "Checking for update: ${remotelocation}"
  83. echo -en "\n"
  84. echo -e "Update available"
  85. echo -e "* Local build: ${red}${localbuild}${default}"
  86. echo -e "* Remote build: ${green}${remotebuild}${default}"
  87. if [ -v "${branch}" ]; then
  88. echo -e "* Branch: ${branch}"
  89. fi
  90. echo -e "https://steamdb.info/app/${appid}/"
  91. fn_script_log_info "Update available"
  92. fn_script_log_info "Local build: ${localbuild}"
  93. fn_script_log_info "Remote build: ${remotebuild}"
  94. if [ -v "${branch}" ]; then
  95. fn_script_log_info "Branch: ${branch}"
  96. fi
  97. fn_script_log_info "${localbuild} > ${remotebuild}"
  98. unset updateonstart
  99. check_status.sh
  100. # If server stopped.
  101. if [ "${status}" == "0" ]; then
  102. fn_update_steamcmd_dl
  103. # If server started.
  104. else
  105. fn_stop_warning
  106. exitbypass=1
  107. command_stop.sh
  108. exitbypass=1
  109. fn_update_steamcmd_dl
  110. exitbypass=1
  111. command_start.sh
  112. fi
  113. alert="update"
  114. alert.sh
  115. else
  116. fn_print_ok_nl "Checking for update: ${remotelocation}"
  117. echo -en "\n"
  118. echo -e "No update available"
  119. echo -e "* Local build: ${green}${localbuild}${default}"
  120. echo -e "* Remote build: ${green}${remotebuild}${default}"
  121. if [ -v "${branch}" ]; then
  122. echo -e "* Branch: ${branch}"
  123. fi
  124. echo -e "https://steamdb.info/app/${appid}/"
  125. fn_script_log_info "No update available"
  126. fn_script_log_info "Local build: ${localbuild}"
  127. fn_script_log_info "Remote build: ${remotebuild}"
  128. if [ -v "${branch}" ]; then
  129. fn_script_log_info "Branch: ${branch}"
  130. fi
  131. fi
  132. }
  133. fn_appmanifest_info(){
  134. appmanifestfile=$(find "${serverfiles}" -type f -name "appmanifest_${appid}.acf")
  135. appmanifestfilewc=$(find "${serverfiles}" -type f -name "appmanifest_${appid}.acf" | wc -l)
  136. }
  137. fn_appmanifest_check(){
  138. fn_appmanifest_info
  139. # Multiple or no matching appmanifest files may sometimes be present.
  140. # This error is corrected if required.
  141. if [ "${appmanifestfilewc}" -ge "2" ]; then
  142. fn_print_error "Multiple appmanifest_${appid}.acf files found"
  143. fn_script_log_error "Multiple appmanifest_${appid}.acf files found"
  144. fn_print_dots "Removing x${appmanifestfilewc} appmanifest_${appid}.acf files"
  145. for appfile in ${appmanifestfile}; do
  146. rm -f "${appfile:?}"
  147. done
  148. appmanifestfilewc1="${appmanifestfilewc}"
  149. fn_appmanifest_info
  150. # if error can not be resolved.
  151. if [ "${appmanifestfilewc}" -ge "2" ]; then
  152. fn_print_fail "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  153. fn_script_log_fatal "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  154. echo -e "* Check user permissions"
  155. for appfile in ${appmanifestfile}; do
  156. echo -e " ${appfile}"
  157. done
  158. core_exit.sh
  159. else
  160. fn_print_ok "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  161. fn_script_log_pass "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  162. fn_print_info_nl "Forcing update to correct issue"
  163. fn_script_log_info "Forcing update to correct issue"
  164. fn_update_steamcmd_dl
  165. fi
  166. elif [ "${appmanifestfilewc}" -eq "0" ]; then
  167. fn_print_error_nl "No appmanifest_${appid}.acf found"
  168. fn_script_log_error "No appmanifest_${appid}.acf found"
  169. fn_print_info_nl "Forcing update to correct issue"
  170. fn_script_log_info "Forcing update to correct issue"
  171. fn_update_steamcmd_dl
  172. fn_appmanifest_info
  173. if [ "${appmanifestfilewc}" -eq "0" ]; then
  174. fn_print_fail_nl "Still no appmanifest_${appid}.acf found"
  175. fn_script_log_fatal "Still no appmanifest_${appid}.acf found"
  176. core_exit.sh
  177. fi
  178. fi
  179. }
  180. fn_stop_warning(){
  181. fn_print_warn "Updating server: SteamCMD: ${selfname} will be stopped during update"
  182. fn_script_log_warn "Updating server: SteamCMD: ${selfname} will be stopped during update"
  183. totalseconds=3
  184. for seconds in {3..1}; do
  185. fn_print_warn "Updating server: SteamCMD: ${selfname} will be stopped during update: ${totalseconds}"
  186. totalseconds=$((totalseconds - 1))
  187. sleep 1
  188. if [ "${seconds}" == "0" ]; then
  189. break
  190. fi
  191. done
  192. fn_print_warn_nl "Updating server: SteamCMD: ${selfname} will be stopped during update"
  193. }
  194. # The location where the builds are checked and downloaded.
  195. remotelocation="SteamCMD"
  196. check.sh
  197. if [ "${forceupdate}" == "1" ]; then
  198. # forceupdate bypasses update checks.
  199. check_status.sh
  200. if [ "${status}" != "0" ]; then
  201. fn_stop_warning
  202. exitbypass=1
  203. command_stop.sh
  204. fn_update_steamcmd_dl
  205. exitbypass=1
  206. command_start.sh
  207. else
  208. fn_update_steamcmd_dl
  209. fi
  210. else
  211. fn_print_dots "Checking for update"
  212. fn_print_dots "Checking for update: ${remotelocation}"
  213. fn_update_steamcmd_localbuild
  214. fn_update_steamcmd_remotebuild
  215. fn_update_steamcmd_compare
  216. fi