command_update_linuxgsm.sh 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #!/bin/bash
  2. # LinuxGSM command_update_linuxgsm.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://linuxgsm.com
  5. # Description: Deletes the functions dir to allow re-downloading of functions from GitHub.
  6. commandname="UPDATE-LGSM"
  7. commandaction="Updating LinuxGSM"
  8. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  9. check.sh
  10. fn_print_dots ""
  11. fn_script_log_info "Updating LinuxGSM"
  12. fn_print_dots "Selecting repo"
  13. fn_script_log_info "Selecting repo"
  14. # Select remotereponame
  15. curl -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh" 1>/dev/null
  16. if [ $? != "0" ]; then
  17. curl -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/linuxgsm.sh" 1>/dev/null
  18. if [ $? != "0" ]; then
  19. fn_print_fail_nl "Selecting repo: Unable to to access GitHub or Bitbucket repositories"
  20. fn_script_log_fatal "Selecting repo: Unable to to access GitHub or Bitbucket repositories"
  21. core_exit.sh
  22. else
  23. remotereponame="Bitbucket"
  24. fn_print_ok_nl "Selecting repo: ${remotereponame}"
  25. fi
  26. else
  27. remotereponame="GitHub"
  28. fn_print_ok_nl "Selecting repo: ${remotereponame}"
  29. fi
  30. # Check _default.cfg.
  31. echo -en "checking ${remotereponame} config _default.cfg...\c"
  32. fn_script_log_info "Checking ${remotereponame} config _default.cfg"
  33. if [ "${remotereponame}" == "GitHub" ]; then
  34. curl -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/config-default/config-lgsm/${gameservername}/_default.cfg" 1>/dev/null
  35. else
  36. curl -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/lgsm/config-default/config-lgsm/${gameservername}/_default.cfg" 1>/dev/null
  37. fi
  38. if [ $? != "0" ]; then
  39. fn_print_fail_eol_nl
  40. fn_script_log_fatal "Checking ${remotereponame} config _default.cfg"
  41. fn_script_log_fatal "Curl returned error: $?"
  42. core_exit.sh
  43. fi
  44. if [ "${remotereponame}" == "GitHub" ]; then
  45. config_file_diff=$(diff "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" <(curl -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/config-default/config-lgsm/${gameservername}/_default.cfg"))
  46. else
  47. config_file_diff=$(diff "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" <(curl -s "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/lgsm/config-default/config-lgsm/${gameservername}/_default.cfg"))
  48. fi
  49. if [ "${config_file_diff}" != "" ]; then
  50. fn_print_update_eol_nl
  51. fn_script_log_update "Checking ${remotereponame} config _default.cfg"
  52. rm -f "${configdirdefault:?}/config-lgsm/${gameservername:?}/_default.cfg"
  53. fn_fetch_file_github "lgsm/config-default/config-lgsm/${gameservername}" "_default.cfg" "${configdirdefault}/config-lgsm/${gameservername}" "nochmodx" "norun" "noforce" "nomd5"
  54. alert="config"
  55. alert.sh
  56. else
  57. fn_print_ok_eol_nl
  58. fn_script_log_pass "Checking ${remotereponame} config _default.cfg"
  59. fi
  60. # Check linuxsm.sh
  61. echo -en "checking ${remotereponame} linuxgsm.sh...\c"
  62. if [ "${remotereponame}" == "GitHub" ]; then
  63. curl -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh" 1>/dev/null
  64. else
  65. curl -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/linuxgsm.sh" 1>/dev/null
  66. fi
  67. if [ $? != "0" ]; then
  68. fn_print_fail_eol_nl
  69. fn_script_log_fatal "Checking ${remotereponame} linuxgsm.sh"
  70. fn_script_log_fatal "Curl returned error: $?"
  71. core_exit.sh
  72. fi
  73. if [ "${remotereponame}" == "GitHub" ]; then
  74. tmp_script_diff=$(diff "${tmpdir}/linuxgsm.sh" <(curl -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh"))
  75. else
  76. tmp_script_diff=$(diff "${tmpdir}/linuxgsm.sh" <(curl -s "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/linuxgsm.sh"))
  77. fi
  78. if [ "${tmp_script_diff}" != "" ]; then
  79. fn_print_update_eol_nl
  80. fn_script_log_update "Checking ${remotereponame} linuxgsm.sh"
  81. rm -f "${tmpdir:?}/linuxgsm.sh"
  82. fn_fetch_file_github "" "linuxgsm.sh" "${tmpdir}" "nochmodx" "norun" "noforcedl" "nomd5"
  83. else
  84. fn_print_ok_eol_nl
  85. fn_script_log_pass "Checking ${remotereponame} linuxgsm.sh"
  86. fi
  87. # Check gameserver.sh
  88. # Compare gameserver.sh against linuxgsm.sh in the tmp dir.
  89. # Ignoring server specific vars.
  90. echo -en "checking ${selfname}...\c"
  91. fn_script_log_info "Checking ${selfname}"
  92. echo "TMPDIR: ${tmpdir}"
  93. echo "ROOTDIR: ${rootdir}"
  94. echo "SELFNAME: ${selfname}"
  95. script_diff=$(diff <(sed '\/shortname/d;\/gameservername/d;\/gamename/d;\/githubuser/d;\/githubrepo/d;\/githubbranch/d' "${tmpdir}/linuxgsm.sh") <(sed '\/shortname/d;\/gameservername/d;\/gamename/d;\/githubuser/d;\/githubrepo/d;\/githubbranch/d' "${rootdir}/${selfname}"))
  96. echo "=========================================="
  97. if [ "${script_diff}" != "" ]; then
  98. fn_print_update_eol_nl
  99. fn_script_log_update "Checking ${selfname}"
  100. echo -en "backup ${selfname}...\c"
  101. fn_script_log_info "Backup ${selfname}"
  102. if [ ! -d "${backupdir}/script" ]; then
  103. mkdir -p "${backupdir}/script"
  104. fi
  105. cp "${rootdir}/${selfname}" "${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  106. if [ $? -ne 0 ]; then
  107. fn_print_fail_eol_nl
  108. fn_script_log_fatal "Backup ${selfname}"
  109. core_exit.sh
  110. else
  111. fn_print_ok_eol_nl
  112. fn_script_log_pass "Backup ${selfname}"
  113. echo -e "backup location ${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  114. fn_script_log_pass "Backup location ${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  115. fi
  116. echo -en "copying ${selfname}...\c"
  117. fn_script_log_info "copying ${selfname}"
  118. cp "${tmpdir}/linuxgsm.sh" "${rootdir}/${selfname}"
  119. sed -i "s+shortname=\"core\"+shortname=\"${shortname}\"+g" "${rootdir}/${selfname}"
  120. sed -i "s+gameservername=\"core\"+gameservername=\"${gameservername}\"+g" "${rootdir}/${selfname}"
  121. sed -i "s+gamename=\"core\"+gamename=\"${gamename}\"+g" "${rootdir}/${selfname}"
  122. sed -i "s+githubuser=\"GameServerManagers\"+githubuser=\"${githubuser}\"+g" "${rootdir}/${selfname}"
  123. sed -i "s+githubrepo=\"LinuxGSM\"+githubrepo=\"${githubrepo}\"+g" "${rootdir}/${selfname}"
  124. sed -i "s+githubbranch=\"master\"+githubbranch=\"${githubbranch}\"+g" "${rootdir}/${selfname}"
  125. if [ $? != "0" ]; then
  126. fn_print_fail_eol_nl
  127. fn_script_log_fatal "copying ${selfname}"
  128. core_exit.sh
  129. else
  130. fn_print_ok_eol_nl
  131. fn_script_log_pass "copying ${selfname}"
  132. fi
  133. else
  134. fn_print_ok_eol_nl
  135. fn_script_log_info "Checking ${selfname}"
  136. fi
  137. # Check and update modules.
  138. if [ -n "${functionsdir}" ]; then
  139. if [ -d "${functionsdir}" ]; then
  140. cd "${functionsdir}" || exit
  141. for functionfile in *
  142. do
  143. # check if module exists in the repo and remove if missing.
  144. # commonly used if module names change.
  145. echo -en "checking ${remotereponame} module ${functionfile}...\c"
  146. github_file_url_dir="lgsm/functions"
  147. if [ "${remotereponame}" == "GitHub" ]; then
  148. curl -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}" 1>/dev/null
  149. else
  150. curl -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${functionfile}" 1>/dev/null
  151. fi
  152. if [ $? -ne 0 ]; then
  153. fn_print_error_eol_nl
  154. fn_script_log_error "Checking ${remotereponame} module ${functionfile}"
  155. echo -en "removing module ${functionfile}...\c"
  156. if ! rm -f "${functionfile:?}"; then
  157. fn_print_fail_eol_nl
  158. fn_script_log_fatal "Removing module ${functionfile}"
  159. core_exit.sh
  160. else
  161. fn_print_ok_eol_nl
  162. fn_script_log_pass "Removing module ${functionfile}"
  163. fi
  164. else
  165. # compare file
  166. if [ "${remotereponame}" == "GitHub" ]; then
  167. function_file_diff=$(diff "${functionsdir}/${functionfile}" <(curl -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}"))
  168. else
  169. function_file_diff=$(diff "${functionsdir}/${functionfile}" <(curl -s "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${functionfile}"))
  170. fi
  171. # results
  172. if [ "${function_file_diff}" != "" ]; then
  173. fn_print_update_eol_nl
  174. fn_script_log_update "Checking ${remotereponame} module ${functionfile}"
  175. rm -rf "${functionsdir:?}/${functionfile}"
  176. fn_update_function
  177. else
  178. fn_print_ok_eol_nl
  179. fn_script_log_pass "Checking ${remotereponame} module ${functionfile}"
  180. fi
  181. fi
  182. done
  183. fi
  184. fi
  185. fn_print_ok "Updating functions"
  186. fn_script_log_pass "Updating functions"
  187. core_exit.sh