update_steamcmd.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 modulename="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 -e "Update available"
  76. echo -e "* Local build: ${red}${localbuild}${default}"
  77. echo -e "* Remote build: ${green}${remotebuild}${default}"
  78. if [ -v "${branch}" ]; then
  79. echo -e "* Branch: ${branch}"
  80. fi
  81. echo -e "https://steamdb.info/app/${appid}/"
  82. fn_script_log_info "Update available"
  83. fn_script_log_info "Local build: ${localbuild}"
  84. fn_script_log_info "Remote build: ${remotebuild}"
  85. if [ -v "${branch}" ]; then
  86. fn_script_log_info "Branch: ${branch}"
  87. fi
  88. fn_script_log_info "${localbuild} > ${remotebuild}"
  89. fn_sleep_time
  90. echo -en "\n"
  91. echo -en "applying update.\r"
  92. sleep 1
  93. echo -en "applying update..\r"
  94. sleep 1
  95. echo -en "applying update...\r"
  96. sleep 1
  97. echo -en "\n"
  98. unset updateonstart
  99. check_status.sh
  100. # If server stopped.
  101. if [ "${status}" == "0" ]; then
  102. fn_update_steamcmd_dl
  103. # If server started.
  104. else
  105. exitbypass=1
  106. command_stop.sh
  107. exitbypass=1
  108. fn_update_steamcmd_dl
  109. exitbypass=1
  110. command_start.sh
  111. fi
  112. alert="update"
  113. alert.sh
  114. else
  115. fn_print_ok_nl "Checking for update: ${remotelocation}"
  116. echo -e "No update available"
  117. echo -e "* Local build: ${green}${localbuild}${default}"
  118. echo -e "* Remote build: ${green}${remotebuild}${default}"
  119. if [ -v "${branch}" ]; then
  120. echo -e "* Branch: ${branch}"
  121. fi
  122. echo -e "https://steamdb.info/app/${appid}/"
  123. fn_script_log_info "No update available"
  124. fn_script_log_info "Local build: ${localbuild}"
  125. fn_script_log_info "Remote build: ${remotebuild}"
  126. if [ -v "${branch}" ]; then
  127. fn_script_log_info "Branch: ${branch}"
  128. fi
  129. fi
  130. }
  131. fn_appmanifest_info(){
  132. appmanifestfile=$(find "${serverfiles}" -type f -name "appmanifest_${appid}.acf")
  133. appmanifestfilewc=$(find "${serverfiles}" -type f -name "appmanifest_${appid}.acf" | wc -l)
  134. }
  135. fn_appmanifest_check(){
  136. fn_appmanifest_info
  137. # Multiple or no matching appmanifest files may sometimes be present.
  138. # This error is corrected if required.
  139. if [ "${appmanifestfilewc}" -ge "2" ]; then
  140. fn_sleep_time
  141. fn_print_error "Multiple appmanifest_${appid}.acf files found"
  142. fn_script_log_error "Multiple appmanifest_${appid}.acf files found"
  143. fn_print_dots "Removing x${appmanifestfilewc} appmanifest_${appid}.acf files"
  144. for appfile in ${appmanifestfile}; do
  145. rm -f "${appfile:?}"
  146. done
  147. appmanifestfilewc1="${appmanifestfilewc}"
  148. fn_appmanifest_info
  149. if [ "${appmanifestfilewc}" -ge "2" ]; then
  150. fn_print_fail "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  151. fn_script_log_fatal "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
  152. echo -e " * Check user permissions"
  153. for appfile in ${appmanifestfile}; do
  154. echo -e " ${appfile}"
  155. done
  156. core_exit.sh
  157. else
  158. fn_print_ok "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  159. fn_script_log_pass "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
  160. fn_print_info "Forcing update to correct issue"
  161. fn_script_log_info "Forcing update to correct issue"
  162. fn_update_steamcmd_dl
  163. fi
  164. elif [ "${appmanifestfilewc}" -eq "0" ]; then
  165. fn_print_error "No appmanifest_${appid}.acf found"
  166. fn_script_log_error "No appmanifest_${appid}.acf found"
  167. fn_print_info "Forcing update to correct issue"
  168. fn_script_log_info "Forcing update to correct issue"
  169. fn_update_steamcmd_dl
  170. fn_appmanifest_info
  171. if [ "${appmanifestfilewc}" -eq "0" ]; then
  172. fn_print_fail "Still no appmanifest_${appid}.acf found"
  173. fn_script_log_fatal "Still no appmanifest_${appid}.acf found"
  174. core_exit.sh
  175. fi
  176. fi
  177. }
  178. # The location where the builds are checked and downloaded.
  179. remotelocation="SteamCMD"
  180. check.sh
  181. if [ "${forceupdate}" == "1" ]; then
  182. # forceupdate bypasses update checks.
  183. check_status.sh
  184. if [ "${status}" != "0" ]; then
  185. exitbypass=1
  186. command_stop.sh
  187. fn_update_steamcmd_dl
  188. exitbypass=1
  189. command_start.sh
  190. else
  191. fn_update_steamcmd_dl
  192. fi
  193. else
  194. fn_update_steamcmd_localbuild
  195. fn_update_steamcmd_remotebuild
  196. fn_update_steamcmd_compare
  197. fi