command_update_linuxgsm.sh 8.5 KB

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