update_steamcmd.sh 8.6 KB

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