update_steamcmd.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 "${steamcmddir}"
  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. cd "${steamcmddir}"
  23. if [ "${engine}" == "goldsource" ]; then
  24. ${unbuffer} ./steamcmd.sh +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_set_config 90 mod ${appidmod} +app_update "${appid}" ${branch} +quit | tee -a "${scriptlog}"
  25. else
  26. ${unbuffer} ./steamcmd.sh +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" ${branch} +quit | tee -a "${scriptlog}"
  27. fi
  28. fix.sh
  29. }
  30. fn_appmanifest_info(){
  31. appmanifestfile=$(find "${serverfiles}" -type f -name "appmanifest_${appid}.acf")
  32. appmanifestfilewc=$(find "${serverfiles}" -type f -name "appmanifest_${appid}.acf"|wc -l)
  33. }
  34. fn_appmanifest_check(){
  35. fn_appmanifest_info
  36. # Multiple or no matching appmanifest files may sometimes be present.
  37. # This error is corrected if required.
  38. if [ "${appmanifestfilewc}" -ge "2" ]; then
  39. sleep 1
  40. fn_print_error "Multiple appmanifest_${appid}.acf files found"
  41. fn_script_log_error "Multiple appmanifest_${appid}.acf files found"
  42. sleep 2
  43. fn_print_dots "Removing x${appmanifestfilewc} appmanifest_${appid}.acf files"
  44. sleep 1
  45. for appfile in ${appmanifestfile}; do
  46. rm "${appfile}"
  47. done
  48. sleep 1
  49. appmanifestfilewc1="${appmanifestfilewc}"
  50. fn_appmanifest_info
  51. if [ "${appmanifestfilewc}" -ge "2" ]; then
  52. fn_print_fail "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  53. fn_script_log_fatal "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  54. sleep 1
  55. echo " * Check user permissions"
  56. for appfile in ${appmanifestfile}; do
  57. echo " ${appfile}"
  58. done
  59. core_exit.sh
  60. else
  61. fn_print_ok "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  62. fn_script_log_pass "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  63. sleep 1
  64. fn_print_info_nl "Forcing update to correct issue"
  65. fn_script_log_info "Forcing update to correct issue"
  66. sleep 1
  67. fn_update_steamcmd_dl
  68. fn_update_request_log
  69. fi
  70. elif [ "${appmanifestfilewc}" -eq "0" ]; then
  71. fn_print_error "No appmanifest_${appid}.acf found"
  72. fn_script_log_error "No appmanifest_${appid}.acf found"
  73. sleep 1
  74. fn_print_info_nl "Forcing update to correct issue"
  75. fn_script_log_info "Forcing update to correct issue"
  76. sleep 1
  77. fn_update_steamcmd_dl
  78. fn_update_request_log
  79. fn_appmanifest_info
  80. if [ "${appmanifestfilewc}" -eq "0" ]; then
  81. fn_print_fatal "Still no appmanifest_${appid}.acf found"
  82. fn_script_log_fatal "Still no appmanifest_${appid}.acf found"
  83. core_exit.sh
  84. fi
  85. fi
  86. }
  87. fn_update_request_log(){
  88. # Checks for server update requests from server logs.
  89. fn_print_dots "Checking for update: Server logs"
  90. fn_script_log_info "Checking for update: Server logs"
  91. sleep 1
  92. if [ -f ${consolelog} ]; then
  93. requestrestart=$(grep -Ec "MasterRequestRestart" "${consolelog}")
  94. else
  95. requestrestart="0"
  96. fi
  97. if [ "${requestrestart}" -ge "1" ]; then
  98. fn_print_ok_nl "Checking for update: Server logs: Update requested"
  99. fn_script_log_pass "Checking for update: Server logs: Update requested"
  100. sleep 1
  101. echo ""
  102. echo -en "Applying update.\r"
  103. sleep 1
  104. echo -en "Applying update..\r"
  105. sleep 1
  106. echo -en "Applying update...\r"
  107. sleep 1
  108. echo -en "\n"
  109. unset updateonstart
  110. check_status.sh
  111. if [ "${status}" != "0" ]; then
  112. exitbypass=1
  113. command_stop.sh
  114. fn_update_steamcmd_dl
  115. exitbypass=1
  116. command_start.sh
  117. else
  118. fn_update_steamcmd_dl
  119. fi
  120. alert="update"
  121. alert.sh
  122. else
  123. fn_print_ok "Checking for update: Server logs: No update requested"
  124. sleep 1
  125. fi
  126. }
  127. fn_update_steamcmd_check(){
  128. fn_appmanifest_check
  129. # Checks for server update from SteamCMD
  130. fn_print_dots "Checking for update: SteamCMD"
  131. fn_script_log_info "Checking for update: SteamCMD"
  132. sleep 1
  133. # Gets currentbuild
  134. currentbuild=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\ -f3)
  135. # Removes appinfo.vdf as a fix for not always getting up to date version info from 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. cd "${steamcmddir}"
  148. 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:]')
  149. if [ -z "${availablebuild}" ]; then
  150. fn_print_fail "Checking for update: SteamCMD"
  151. sleep 1
  152. fn_print_fail_nl "Checking for update: SteamCMD: Not returning version info"
  153. fn_script_log_fatal "Checking for update: SteamCMD: Not returning version info"
  154. core_exit.sh
  155. else
  156. fn_print_ok "Checking for update: SteamCMD"
  157. fn_script_log_pass "Checking for update: SteamCMD"
  158. sleep 1
  159. fi
  160. if [ "${currentbuild}" != "${availablebuild}" ]; then
  161. fn_print_ok "Checking for update: SteamCMD: Update available"
  162. fn_script_log_pass "Checking for update: SteamCMD: Update available"
  163. echo -e "\n"
  164. echo -e "Update available:"
  165. sleep 1
  166. echo -e " Current build: ${red}${currentbuild}${default}"
  167. echo -e " Available build: ${green}${availablebuild}${default}"
  168. echo -e ""
  169. echo -e " https://steamdb.info/app/${appid}/"
  170. sleep 1
  171. echo ""
  172. echo -en "Applying update.\r"
  173. sleep 1
  174. echo -en "Applying update..\r"
  175. sleep 1
  176. echo -en "Applying update...\r"
  177. sleep 1
  178. echo -en "\n"
  179. fn_script_log_info "Update available"
  180. fn_script_log_info "Current build: ${currentbuild}"
  181. fn_script_log_info "Available build: ${availablebuild}"
  182. fn_script_log_info "${currentbuild} > ${availablebuild}"
  183. unset updateonstart
  184. check_status.sh
  185. if [ "${status}" != "0" ]; then
  186. exitbypass=1
  187. command_stop.sh
  188. fn_update_steamcmd_dl
  189. exitbypass=1
  190. command_start.sh
  191. else
  192. fn_update_steamcmd_dl
  193. fi
  194. alert="update"
  195. alert.sh
  196. else
  197. fn_print_ok "Checking for update: SteamCMD: No update available"
  198. fn_script_log_pass "Checking for update: SteamCMD: No update available"
  199. echo -e "\n"
  200. echo -e "No update available:"
  201. echo -e " Current version: ${green}${currentbuild}${default}"
  202. echo -e " Available version: ${green}${availablebuild}${default}"
  203. echo -e " https://steamdb.info/app/${appid}/"
  204. echo -e ""
  205. fn_script_log_info "Current build: ${currentbuild}"
  206. fn_script_log_info "Available build: ${availablebuild}"
  207. fi
  208. }
  209. if [ "${engine}" == "goldsource" ]||[ "${forceupdate}" == "1" ]; then
  210. # Goldsource servers bypass checks as fn_update_steamcmd_check does not work for appid 90 servers.
  211. # forceupdate bypasses checks
  212. check_status.sh
  213. if [ "${status}" != "0" ]; then
  214. exitbypass=1
  215. command_stop.sh
  216. fn_update_steamcmd_dl
  217. exitbypass=1
  218. command_start.sh
  219. else
  220. fn_update_steamcmd_dl
  221. fi
  222. else
  223. fn_update_request_log
  224. fn_update_steamcmd_check
  225. fi