update_steamcmd.sh 7.1 KB

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