update_steamcmd.sh 7.5 KB

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