command_update_linuxgsm.sh 9.7 KB

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