update_steamcmd.sh 6.9 KB

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