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 gameserver.sh
  31. # Compare gameserver.sh against linuxgsm.sh in the tmp dir.
  32. # Ignoring server specific vars.
  33. echo -en "checking ${selfname}...\c"
  34. fn_script_log_info "Checking ${selfname}"
  35. 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}"))
  36. if [ "${script_diff}" != "" ]; then
  37. fn_print_update_eol_nl
  38. fn_script_log_update "Checking ${selfname}"
  39. echo -en "backup ${selfname}...\c"
  40. fn_script_log_info "Backup ${selfname}"
  41. if [ ! -d "${backupdir}/script" ]; then
  42. mkdir -p "${backupdir}/script"
  43. fi
  44. cp "${rootdir}/${selfname}" "${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  45. if [ $? -ne 0 ]; then
  46. fn_print_fail_eol_nl
  47. fn_script_log_fatal "Backup ${selfname}"
  48. core_exit.sh
  49. else
  50. fn_print_ok_eol_nl
  51. fn_script_log_pass "Backup ${selfname}"
  52. echo -e "backup location ${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  53. fn_script_log_pass "Backup location ${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  54. fi
  55. echo -en "copying ${selfname}...\c"
  56. fn_script_log_info "copying ${selfname}"
  57. cp "${tmpdir}/linuxgsm.sh" "${rootdir}/${selfname}"
  58. sed -i "s+shortname=\"core\"+shortname=\"${shortname}\"+g" "${rootdir}/${selfname}"
  59. sed -i "s+gameservername=\"core\"+gameservername=\"${gameservername}\"+g" "${rootdir}/${selfname}"
  60. sed -i "s+gamename=\"core\"+gamename=\"${gamename}\"+g" "${rootdir}/${selfname}"
  61. sed -i "s+githubuser=\"GameServerManagers\"+githubuser=\"${githubuser}\"+g" "${rootdir}/${selfname}"
  62. sed -i "s+githubrepo=\"LinuxGSM\"+githubrepo=\"${githubrepo}\"+g" "${rootdir}/${selfname}"
  63. sed -i "s+githubbranch=\"master\"+githubbranch=\"${githubbranch}\"+g" "${rootdir}/${selfname}"
  64. if [ $? != "0" ]; then
  65. fn_print_fail_eol_nl
  66. fn_script_log_fatal "copying ${selfname}"
  67. core_exit.sh
  68. else
  69. fn_print_ok_eol_nl
  70. fn_script_log_pass "copying ${selfname}"
  71. fi
  72. else
  73. fn_print_ok_eol_nl
  74. fn_script_log_info "Checking ${selfname}"
  75. fi
  76. # Check _default.cfg.
  77. echo -en "checking ${remotereponame} config _default.cfg...\c"
  78. fn_script_log_info "Checking ${remotereponame} config _default.cfg"
  79. if [ "${remotereponame}" == "GitHub" ]; then
  80. curl -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/config-default/config-lgsm/${gameservername}/_default.cfg" 1>/dev/null
  81. else
  82. curl -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/lgsm/config-default/config-lgsm/${gameservername}/_default.cfg" 1>/dev/null
  83. fi
  84. if [ $? != "0" ]; then
  85. fn_print_fail_eol_nl
  86. fn_script_log_fatal "Checking ${remotereponame} config _default.cfg"
  87. fn_script_log_fatal "Curl returned error: $?"
  88. core_exit.sh
  89. fi
  90. if [ "${remotereponame}" == "GitHub" ]; then
  91. 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"))
  92. else
  93. 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"))
  94. fi
  95. if [ "${config_file_diff}" != "" ]; then
  96. fn_print_update_eol_nl
  97. fn_script_log_update "Checking ${remotereponame} config _default.cfg"
  98. rm -f "${configdirdefault:?}/config-lgsm/${gameservername:?}/_default.cfg"
  99. fn_fetch_file_github "lgsm/config-default/config-lgsm/${gameservername}" "_default.cfg" "${configdirdefault}/config-lgsm/${gameservername}" "nochmodx" "norun" "noforce" "nomd5"
  100. alert="config"
  101. alert.sh
  102. else
  103. fn_print_ok_eol_nl
  104. fn_script_log_pass "Checking ${remotereponame} config _default.cfg"
  105. fi
  106. # Check linuxsm.sh
  107. echo -en "checking ${remotereponame} linuxgsm.sh...\c"
  108. if [ "${remotereponame}" == "GitHub" ]; then
  109. curl -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh" 1>/dev/null
  110. else
  111. curl -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/linuxgsm.sh" 1>/dev/null
  112. fi
  113. if [ $? != "0" ]; then
  114. fn_print_fail_eol_nl
  115. fn_script_log_fatal "Checking ${remotereponame} linuxgsm.sh"
  116. fn_script_log_fatal "Curl returned error: $?"
  117. core_exit.sh
  118. fi
  119. if [ "${remotereponame}" == "GitHub" ]; then
  120. tmp_script_diff=$(diff "${tmpdir}/linuxgsm.sh" <(curl -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh"))
  121. else
  122. tmp_script_diff=$(diff "${tmpdir}/linuxgsm.sh" <(curl -s "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/linuxgsm.sh"))
  123. fi
  124. if [ "${tmp_script_diff}" != "" ]; then
  125. fn_print_update_eol_nl
  126. fn_script_log_update "Checking ${remotereponame} linuxgsm.sh"
  127. rm -f "${tmpdir:?}/linuxgsm.sh"
  128. fn_fetch_file_github "" "linuxgsm.sh" "${tmpdir}" "nochmodx" "norun" "noforcedl" "nomd5"
  129. else
  130. fn_print_ok_eol_nl
  131. fn_script_log_pass "Checking ${remotereponame} linuxgsm.sh"
  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