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