update_steamcmd.sh 7.8 KB

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