update_steamcmd.sh 8.5 KB

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