4
0

command_update_linuxgsm.sh 8.1 KB

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