update_steamcmd.sh 7.3 KB

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