update_steamcmd.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. #!/bin/bash
  2. # LinuxGSM update_steamcmd.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: Handles updating using SteamCMD.
  6. local commandname="UPDATE"
  7. local commandaction="Update"
  8. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  9. check.sh
  10. fn_update_steamcmd_dl(){
  11. info_config.sh
  12. fn_print_dots "SteamCMD"
  13. sleep 1
  14. fn_print_ok_nl "SteamCMD"
  15. fn_script_log_info "Starting SteamCMD"
  16. cd "${rootdir}/steamcmd"
  17. # Detects if unbuffer command is available for 32 bit distributions only.
  18. info_distro.sh
  19. if [ $(command -v stdbuf) ]&&[ "${arch}" != "x86_64" ]; then
  20. unbuffer="stdbuf -i0 -o0 -e0"
  21. fi
  22. if [ "${engine}" == "goldsource" ]; then
  23. ${unbuffer} ./steamcmd.sh +login "${steamuser}" "${steampass}" +force_install_dir "${filesdir}" +app_set_config 90 mod ${appidmod} +app_update "${appid}" ${branch} +quit | tee -a "${scriptlog}"
  24. else
  25. ${unbuffer} ./steamcmd.sh +login "${steamuser}" "${steampass}" +force_install_dir "${filesdir}" +app_update "${appid}" ${branch} +quit | tee -a "${scriptlog}"
  26. fi
  27. fix.sh
  28. }
  29. fn_appmanifest_info(){
  30. appmanifestfile=$(find "${filesdir}" -type f -name "appmanifest_${appid}.acf")
  31. appmanifestfilewc=$(find "${filesdir}" -type f -name "appmanifest_${appid}.acf"|wc -l)
  32. }
  33. fn_appmanifest_check(){
  34. fn_appmanifest_info
  35. # Multiple or no matching appmanifest files may sometimes be present.
  36. # This error is corrected if required.
  37. if [ "${appmanifestfilewc}" -ge "2" ]; then
  38. sleep 1
  39. fn_print_error "Multiple appmanifest_${appid}.acf files found"
  40. fn_script_log_error "Multiple appmanifest_${appid}.acf files found"
  41. sleep 2
  42. fn_print_dots "Removing x${appmanifestfilewc} appmanifest_${appid}.acf files"
  43. sleep 1
  44. for appfile in ${appmanifestfile}; do
  45. rm "${appfile}"
  46. done
  47. sleep 1
  48. appmanifestfilewc1="${appmanifestfilewc}"
  49. fn_appmanifest_info
  50. if [ "${appmanifestfilewc}" -ge "2" ]; then
  51. fn_print_fail "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  52. fn_script_log_fatal "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  53. sleep 1
  54. echo " * Check user permissions"
  55. for appfile in ${appmanifestfile}; do
  56. echo " ${appfile}"
  57. done
  58. core_exit.sh
  59. else
  60. fn_print_ok "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  61. fn_script_log_pass "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  62. sleep 1
  63. fn_print_info_nl "Forcing update to correct issue"
  64. fn_script_log_info "Forcing update to correct issue"
  65. sleep 1
  66. fn_update_steamcmd_dl
  67. fn_update_request_log
  68. fi
  69. elif [ "${appmanifestfilewc}" -eq "0" ]; then
  70. fn_print_error "No appmanifest_${appid}.acf found"
  71. fn_script_log_error "No appmanifest_${appid}.acf found"
  72. sleep 1
  73. fn_print_info_nl "Forcing update to correct issue"
  74. fn_script_log_info "Forcing update to correct issue"
  75. sleep 1
  76. fn_update_steamcmd_dl
  77. fn_update_request_log
  78. fn_appmanifest_info
  79. if [ "${appmanifestfilewc}" -eq "0" ]; then
  80. fn_print_fatal "Still no appmanifest_${appid}.acf found"
  81. fn_script_log_fatal "Still no appmanifest_${appid}.acf found"
  82. core_exit.sh
  83. fi
  84. fi
  85. }
  86. fn_update_request_log(){
  87. # Checks for server update requests from server logs.
  88. fn_print_dots "Checking for update: Server logs"
  89. fn_script_log_info "Checking for update: Server logs"
  90. sleep 1
  91. if [ -f ${consolelog} ]; then
  92. requestrestart=$(grep -Ec "MasterRequestRestart" "${consolelog}")
  93. else
  94. requestrestart="0"
  95. fi
  96. if [ "${requestrestart}" -ge "1" ]; then
  97. fn_print_ok_nl "Checking for update: Server logs: Update requested"
  98. fn_script_log_pass "Checking for update: Server logs: Update requested"
  99. sleep 1
  100. echo ""
  101. echo -en "Applying update.\r"
  102. sleep 1
  103. echo -en "Applying update..\r"
  104. sleep 1
  105. echo -en "Applying update...\r"
  106. sleep 1
  107. echo -en "\n"
  108. unset updateonstart
  109. check_status.sh
  110. if [ "${status}" != "0" ]; then
  111. exitbypass=1
  112. command_stop.sh
  113. fn_update_steamcmd_dl
  114. exitbypass=1
  115. command_start.sh
  116. else
  117. fn_update_steamcmd_dl
  118. fi
  119. alert="update"
  120. alert.sh
  121. else
  122. fn_print_ok "Checking for update: Server logs: No update requested"
  123. sleep 1
  124. fi
  125. }
  126. fn_update_steamcmd_check(){
  127. fn_appmanifest_check
  128. # Checks for server update from SteamCMD
  129. fn_print_dots "Checking for update: SteamCMD"
  130. fn_script_log_info "Checking for update: SteamCMD"
  131. sleep 1
  132. # Gets currentbuild
  133. currentbuild=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\ -f3)
  134. # Removes appinfo.vdf as a fix for not always getting up to date version info from SteamCMD
  135. cd "${rootdir}/steamcmd"
  136. if [ -f "${HOME}/Steam/appcache/appinfo.vdf" ]; then
  137. rm -f "${HOME}/Steam/appcache/appinfo.vdf"
  138. fi
  139. # Set branch for updateinfo
  140. IFS=' ' read -a branchsplits <<< "${branch}"
  141. if [ "${#branchsplits[@]}" -gt 1 ]; then
  142. branchname="${branchsplits[1]}"
  143. else
  144. branchname="public"
  145. fi
  146. # Gets availablebuild info
  147. availablebuild=$(./steamcmd.sh +login "${steamuser}" "${steampass}" +app_info_update 1 +app_info_print "${appid}" +app_info_print "${appid}" +quit | sed -n '/branch/,$p' | grep -m 1 buildid | tr -cd '[:digit:]')
  148. if [ -z "${availablebuild}" ]; then
  149. fn_print_fail "Checking for update: SteamCMD"
  150. sleep 1
  151. fn_print_fail_nl "Checking for update: SteamCMD: Not returning version info"
  152. fn_script_log_fatal "Checking for update: SteamCMD: Not returning version info"
  153. core_exit.sh
  154. else
  155. fn_print_ok "Checking for update: SteamCMD"
  156. fn_script_log_pass "Checking for update: SteamCMD"
  157. sleep 1
  158. fi
  159. if [ "${currentbuild}" != "${availablebuild}" ]; then
  160. fn_print_ok "Checking for update: SteamCMD: Update available"
  161. fn_script_log_pass "Checking for update: SteamCMD: Update available"
  162. echo -e "\n"
  163. echo -e "Update available:"
  164. sleep 1
  165. echo -e " Current build: ${red}${currentbuild}${default}"
  166. echo -e " Available build: ${green}${availablebuild}${default}"
  167. echo -e ""
  168. echo -e " https://steamdb.info/app/${appid}/"
  169. sleep 1
  170. echo ""
  171. echo -en "Applying update.\r"
  172. sleep 1
  173. echo -en "Applying update..\r"
  174. sleep 1
  175. echo -en "Applying update...\r"
  176. sleep 1
  177. echo -en "\n"
  178. fn_script_log_info "Update available"
  179. fn_script_log_info "Current build: ${currentbuild}"
  180. fn_script_log_info "Available build: ${availablebuild}"
  181. fn_script_log_info "${currentbuild} > ${availablebuild}"
  182. unset updateonstart
  183. check_status.sh
  184. if [ "${status}" != "0" ]; then
  185. exitbypass=1
  186. command_stop.sh
  187. fn_update_steamcmd_dl
  188. exitbypass=1
  189. command_start.sh
  190. else
  191. fn_update_steamcmd_dl
  192. fi
  193. alert="update"
  194. alert.sh
  195. else
  196. fn_print_ok "Checking for update: SteamCMD: No update available"
  197. fn_script_log_pass "Checking for update: SteamCMD: No update available"
  198. echo -e "\n"
  199. echo -e "No update available:"
  200. echo -e " Current version: ${green}${currentbuild}${default}"
  201. echo -e " Available version: ${green}${availablebuild}${default}"
  202. echo -e " https://steamdb.info/app/${appid}/"
  203. echo -e ""
  204. fn_script_log_info "Current build: ${currentbuild}"
  205. fn_script_log_info "Available build: ${availablebuild}"
  206. fi
  207. }
  208. if [ "${engine}" == "goldsource" ]||[ "${forceupdate}" == "1" ]; then
  209. # Goldsource servers bypass checks as fn_update_steamcmd_check does not work for appid 90 servers.
  210. # forceupdate bypasses checks
  211. check_status.sh
  212. if [ "${status}" != "0" ]; then
  213. exitbypass=1
  214. command_stop.sh
  215. fn_update_steamcmd_dl
  216. exitbypass=1
  217. command_start.sh
  218. else
  219. fn_update_steamcmd_dl
  220. fi
  221. else
  222. fn_update_request_log
  223. fn_update_steamcmd_check
  224. fi