command_update_linuxgsm.sh 8.4 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. fn_firstcommand_set
  10. check.sh
  11. fn_print_dots ""
  12. fn_script_log_info "Updating LinuxGSM"
  13. fn_print_dots "Selecting repo"
  14. fn_script_log_info "Selecting repo"
  15. # Select remotereponame
  16. curl --connect-timeout 10 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh" 1>/dev/null
  17. if [ $? != "0" ]; then
  18. curl --connect-timeout 10 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/linuxgsm.sh" 1>/dev/null
  19. if [ $? != "0" ]; then
  20. fn_print_fail_nl "Selecting repo: Unable to to access GitHub or Bitbucket repositories"
  21. fn_script_log_fatal "Selecting repo: Unable to to access GitHub or Bitbucket repositories"
  22. core_exit.sh
  23. else
  24. remotereponame="Bitbucket"
  25. fn_print_ok_nl "Selecting repo: ${remotereponame}"
  26. fi
  27. else
  28. remotereponame="GitHub"
  29. fn_print_ok_nl "Selecting repo: ${remotereponame}"
  30. fi
  31. # Check linuxsm.sh
  32. echo -en "checking ${remotereponame} linuxgsm.sh...\c"
  33. if [ "${remotereponame}" == "GitHub" ]; then
  34. curl --connect-timeout 10 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh" 1>/dev/null
  35. else
  36. curl --connect-timeout 10 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/linuxgsm.sh" 1>/dev/null
  37. fi
  38. if [ $? != "0" ]; then
  39. fn_print_fail_eol_nl
  40. fn_script_log_fatal "Checking ${remotereponame} linuxgsm.sh"
  41. fn_script_log_fatal "Curl returned error: $?"
  42. core_exit.sh
  43. fi
  44. if [ "${remotereponame}" == "GitHub" ]; then
  45. tmp_script_diff=$(diff "${tmpdir}/linuxgsm.sh" <(curl --connect-timeout 10 -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh"))
  46. else
  47. tmp_script_diff=$(diff "${tmpdir}/linuxgsm.sh" <(curl --connect-timeout 10 -s "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/linuxgsm.sh"))
  48. fi
  49. if [ "${tmp_script_diff}" != "" ]; then
  50. fn_print_update_eol_nl
  51. fn_script_log_update "Checking ${remotereponame} linuxgsm.sh"
  52. rm -f "${tmpdir:?}/linuxgsm.sh"
  53. fn_fetch_file_github "" "linuxgsm.sh" "${tmpdir}" "nochmodx" "norun" "noforcedl" "nomd5"
  54. else
  55. fn_print_ok_eol_nl
  56. fn_script_log_pass "Checking ${remotereponame} linuxgsm.sh"
  57. fi
  58. # Check gameserver.sh
  59. # Compare gameserver.sh against linuxgsm.sh in the tmp dir.
  60. # Ignoring server specific vars.
  61. echo -en "checking ${selfname}...\c"
  62. fn_script_log_info "Checking ${selfname}"
  63. 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}"))
  64. if [ "${script_diff}" != "" ]; then
  65. fn_print_update_eol_nl
  66. fn_script_log_update "Checking ${selfname}"
  67. echo -en "backup ${selfname}...\c"
  68. fn_script_log_info "Backup ${selfname}"
  69. if [ ! -d "${backupdir}/script" ]; then
  70. mkdir -p "${backupdir}/script"
  71. fi
  72. cp "${rootdir}/${selfname}" "${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  73. if [ $? != 0 ]; then
  74. fn_print_fail_eol_nl
  75. fn_script_log_fatal "Backup ${selfname}"
  76. core_exit.sh
  77. else
  78. fn_print_ok_eol_nl
  79. fn_script_log_pass "Backup ${selfname}"
  80. echo -e "backup location ${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  81. fn_script_log_pass "Backup location ${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak"
  82. fi
  83. echo -en "copying ${selfname}...\c"
  84. fn_script_log_info "copying ${selfname}"
  85. cp "${tmpdir}/linuxgsm.sh" "${rootdir}/${selfname}"
  86. sed -i "s+shortname=\"core\"+shortname=\"${shortname}\"+g" "${rootdir}/${selfname}"
  87. sed -i "s+gameservername=\"core\"+gameservername=\"${gameservername}\"+g" "${rootdir}/${selfname}"
  88. sed -i "s+gamename=\"core\"+gamename=\"${gamename}\"+g" "${rootdir}/${selfname}"
  89. sed -i "s+githubuser=\"GameServerManagers\"+githubuser=\"${githubuser}\"+g" "${rootdir}/${selfname}"
  90. sed -i "s+githubrepo=\"LinuxGSM\"+githubrepo=\"${githubrepo}\"+g" "${rootdir}/${selfname}"
  91. sed -i "s+githubbranch=\"master\"+githubbranch=\"${githubbranch}\"+g" "${rootdir}/${selfname}"
  92. if [ $? != "0" ]; then
  93. fn_print_fail_eol_nl
  94. fn_script_log_fatal "copying ${selfname}"
  95. core_exit.sh
  96. else
  97. fn_print_ok_eol_nl
  98. fn_script_log_pass "copying ${selfname}"
  99. fi
  100. else
  101. fn_print_ok_eol_nl
  102. fn_script_log_info "Checking ${selfname}"
  103. fi
  104. # Check _default.cfg.
  105. echo -en "checking ${remotereponame} config _default.cfg...\c"
  106. fn_script_log_info "Checking ${remotereponame} config _default.cfg"
  107. if [ "${remotereponame}" == "GitHub" ]; then
  108. curl --connect-timeout 10 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/config-default/config-lgsm/${gameservername}/_default.cfg" 1>/dev/null
  109. else
  110. curl --connect-timeout 10 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/lgsm/config-default/config-lgsm/${gameservername}/_default.cfg" 1>/dev/null
  111. fi
  112. if [ $? != "0" ]; then
  113. fn_print_fail_eol_nl
  114. fn_script_log_fatal "Checking ${remotereponame} config _default.cfg"
  115. fn_script_log_fatal "Curl returned error: $?"
  116. core_exit.sh
  117. fi
  118. if [ "${remotereponame}" == "GitHub" ]; then
  119. 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"))
  120. else
  121. 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"))
  122. fi
  123. if [ "${config_file_diff}" != "" ]; then
  124. fn_print_update_eol_nl
  125. fn_script_log_update "Checking ${remotereponame} config _default.cfg"
  126. rm -f "${configdirdefault:?}/config-lgsm/${gameservername:?}/_default.cfg"
  127. fn_fetch_file_github "lgsm/config-default/config-lgsm/${gameservername}" "_default.cfg" "${configdirdefault}/config-lgsm/${gameservername}" "nochmodx" "norun" "noforce" "nomd5"
  128. alert="config"
  129. alert.sh
  130. else
  131. fn_print_ok_eol_nl
  132. fn_script_log_pass "Checking ${remotereponame} config _default.cfg"
  133. fi
  134. # Check and update modules.
  135. if [ -n "${functionsdir}" ]; then
  136. if [ -d "${functionsdir}" ]; then
  137. cd "${functionsdir}" || exit
  138. for functionfile in *; 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 --connect-timeout 10 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}" 1>/dev/null
  145. else
  146. curl --connect-timeout 10 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${functionfile}" 1>/dev/null
  147. fi
  148. if [ $? != 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 --connect-timeout 10 -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}"))
  164. else
  165. function_file_diff=$(diff "${functionsdir}/${functionfile}" <(curl --connect-timeout 10 -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